chore: Clean up use of gfx and constellation types (#31981)

This change contains three semi-related clean ups:

1. the `to_webrender()` and `from_webrender()` functions on Pipeline are
   turned into more-idiomatic `From` and `Into` implementations.
2. `combine_id_with_fragment_type` now returns a `u64` as that is what is
   expected for all callers and not a `usize`.
3. The `query_scroll_id` query is removed entirely. The
   `ExternalScrollId` that this queries is easily generated directly
   from the node's opaque id. Querying into layout isn't necessary at
   all.
This commit is contained in:
Martin Robinson 2024-04-09 08:43:48 +02:00 committed by GitHub
parent b79e2a0b65
commit dd9f62adcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 62 additions and 119 deletions

View file

@ -8,7 +8,6 @@ use std::env;
use std::fs::{create_dir_all, File}; use std::fs::{create_dir_all, File};
use std::io::Write; use std::io::Write;
use std::iter::once; use std::iter::once;
use std::num::NonZeroU32;
use std::rc::Rc; use std::rc::Rc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
@ -27,9 +26,7 @@ use image::{DynamicImage, ImageFormat};
use ipc_channel::ipc; use ipc_channel::ipc;
use libc::c_void; use libc::c_void;
use log::{debug, error, info, trace, warn}; use log::{debug, error, info, trace, warn};
use msg::constellation_msg::{ use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId, WebViewId};
PipelineId, PipelineIndex, PipelineNamespaceId, TopLevelBrowsingContextId, WebViewId,
};
use net_traits::image::base::Image; use net_traits::image::base::Image;
use net_traits::image_cache::CorsStatus; use net_traits::image_cache::CorsStatus;
use pixels::PixelFormat; use pixels::PixelFormat;
@ -79,20 +76,6 @@ enum NotReadyToPaint {
const MAX_ZOOM: f32 = 8.0; const MAX_ZOOM: f32 = 8.0;
const MIN_ZOOM: f32 = 0.1; const MIN_ZOOM: f32 = 0.1;
trait ConvertPipelineIdFromWebRender {
#[allow(clippy::wrong_self_convention)]
fn from_webrender(&self) -> PipelineId;
}
impl ConvertPipelineIdFromWebRender for WebRenderPipelineId {
fn from_webrender(&self) -> PipelineId {
PipelineId {
namespace_id: PipelineNamespaceId(self.0),
index: PipelineIndex(NonZeroU32::new(self.1).expect("Webrender pipeline zero?")),
}
}
}
/// Holds the state when running reftests that determines when it is /// Holds the state when running reftests that determines when it is
/// safe to save the output image. /// safe to save the output image.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -725,7 +708,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
external_scroll_id, external_scroll_id,
), ),
) => { ) => {
let pipeline_id = PipelineId::from_webrender(pipeline_id); let pipeline_id = pipeline_id.into();
let pipeline_details = match self.pipeline_details.get_mut(&pipeline_id) { let pipeline_details = match self.pipeline_details.get_mut(&pipeline_id) {
Some(details) => details, Some(details) => details,
None => return, None => return,
@ -798,7 +781,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
); );
let pipeline_id = display_list_info.pipeline_id; let pipeline_id = display_list_info.pipeline_id;
let details = self.pipeline_details(PipelineId::from_webrender(pipeline_id)); let details = self.pipeline_details(pipeline_id.into());
details.most_recent_display_list_epoch = Some(display_list_info.epoch); details.most_recent_display_list_epoch = Some(display_list_info.epoch);
details.hit_test_items = display_list_info.hit_test_info; details.hit_test_items = display_list_info.hit_test_info;
details.install_new_scroll_tree(display_list_info.scroll_tree); details.install_new_scroll_tree(display_list_info.scroll_tree);
@ -1114,7 +1097,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
spatial_id: zoom_reference_frame, spatial_id: zoom_reference_frame,
clip_chain_id, clip_chain_id,
}, },
pipeline_id.to_webrender(), pipeline_id.into(),
true, true,
); );
} }
@ -1480,7 +1463,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
.items .items
.iter() .iter()
.filter_map(|item| { .filter_map(|item| {
let pipeline_id = PipelineId::from_webrender(item.pipeline); let pipeline_id = item.pipeline.into();
let details = match self.pipeline_details.get(&pipeline_id) { let details = match self.pipeline_details.get(&pipeline_id) {
Some(details) => details, Some(details) => details,
None => return None, None => return None,
@ -1949,10 +1932,9 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
// frame tree. // frame tree.
let mut pipeline_epochs = HashMap::new(); let mut pipeline_epochs = HashMap::new();
for id in self.pipeline_details.keys() { for id in self.pipeline_details.keys() {
let webrender_pipeline_id = id.to_webrender();
if let Some(WebRenderEpoch(epoch)) = self if let Some(WebRenderEpoch(epoch)) = self
.webrender .webrender
.current_epoch(self.webrender_document, webrender_pipeline_id) .current_epoch(self.webrender_document, id.into())
{ {
let epoch = Epoch(epoch); let epoch = Epoch(epoch);
pipeline_epochs.insert(*id, epoch); pipeline_epochs.insert(*id, epoch);
@ -2104,7 +2086,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
// we get the last painted frame id from webrender // we get the last painted frame id from webrender
if let Some(WebRenderEpoch(epoch)) = self if let Some(WebRenderEpoch(epoch)) = self
.webrender .webrender
.current_epoch(self.webrender_document, id.to_webrender()) .current_epoch(self.webrender_document, id.into())
{ {
// and check if it is the one layout is expecting, // and check if it is the one layout is expecting,
let epoch = Epoch(epoch); let epoch = Epoch(epoch);

View file

@ -2270,7 +2270,7 @@ impl Fragment {
fn unique_id(&self) -> u64 { fn unique_id(&self) -> u64 {
let fragment_type = self.fragment_type(); let fragment_type = self.fragment_type();
let id = self.node.id(); let id = self.node.id();
combine_id_with_fragment_type(id, fragment_type) as u64 combine_id_with_fragment_type(id, fragment_type)
} }
fn fragment_type(&self) -> FragmentType { fn fragment_type(&self) -> FragmentType {
@ -2737,8 +2737,7 @@ impl BlockFlow {
let content_size = self.base.overflow.scroll.origin + self.base.overflow.scroll.size; let content_size = self.base.overflow.scroll.origin + self.base.overflow.scroll.size;
let content_size = Size2D::new(content_size.x, content_size.y); let content_size = Size2D::new(content_size.x, content_size.y);
let external_id = let external_id = ExternalScrollId(self.fragment.unique_id(), state.pipeline_id.into());
ExternalScrollId(self.fragment.unique_id(), state.pipeline_id.to_webrender());
let new_clip_scroll_index = state.add_clip_scroll_node(ClipScrollNode { let new_clip_scroll_index = state.add_clip_scroll_node(ClipScrollNode {
parent_index: self.clipping_and_scrolling().scrolling, parent_index: self.clipping_and_scrolling().scrolling,
clip, clip,

View file

@ -133,7 +133,7 @@ impl DisplayList {
viewport_size: LayoutSize, viewport_size: LayoutSize,
epoch: Epoch, epoch: Epoch,
) -> (DisplayListBuilder, CompositorDisplayListInfo, IsContentful) { ) -> (DisplayListBuilder, CompositorDisplayListInfo, IsContentful) {
let webrender_pipeline = pipeline_id.to_webrender(); let webrender_pipeline = pipeline_id.into();
let mut builder = DisplayListBuilder::new(webrender_pipeline); let mut builder = DisplayListBuilder::new(webrender_pipeline);
builder.begin(); builder.begin();
@ -314,7 +314,7 @@ impl DisplayItem {
spatial_id: common.spatial_id, spatial_id: common.spatial_id,
clip_chain_id: common.clip_chain_id, clip_chain_id: common.clip_chain_id,
}, },
item.iframe.to_webrender(), item.iframe.into(),
true, true,
); );
IsContentful(false) IsContentful(false)

View file

@ -9,7 +9,6 @@ use std::ops::Deref;
use app_units::Au; use app_units::Au;
use euclid::default::{Box2D, Point2D, Rect, Size2D, Vector2D}; use euclid::default::{Box2D, Point2D, Rect, Size2D, Vector2D};
use msg::constellation_msg::PipelineId;
use script_layout_interface::wrapper_traits::{ use script_layout_interface::wrapper_traits::{
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode, LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
}; };
@ -31,7 +30,6 @@ use style::selector_parser::PseudoElement;
use style::shared_lock::SharedRwLock; use style::shared_lock::SharedRwLock;
use style::stylesheets::{CssRuleType, Origin, UrlExtraData}; use style::stylesheets::{CssRuleType, Origin, UrlExtraData};
use style_traits::{ParsingMode, ToCss}; use style_traits::{ParsingMode, ToCss};
use webrender_api::ExternalScrollId;
use crate::construct::ConstructionResult; use crate::construct::ConstructionResult;
use crate::display_list::items::OpaqueNode; use crate::display_list::items::OpaqueNode;
@ -571,14 +569,6 @@ pub fn process_client_rect_query(
iterator.client_rect iterator.client_rect
} }
pub fn process_node_scroll_id_request<'dom>(
id: PipelineId,
requested_node: impl LayoutNode<'dom>,
) -> ExternalScrollId {
let layout_node = requested_node.to_threadsafe();
layout_node.generate_scroll_id(id)
}
/// <https://drafts.csswg.org/cssom-view/#scrolling-area> /// <https://drafts.csswg.org/cssom-view/#scrolling-area>
pub fn process_scrolling_area_request( pub fn process_scrolling_area_request(
requested_node: Option<OpaqueNode>, requested_node: Option<OpaqueNode>,

View file

@ -291,7 +291,7 @@ impl Fragment {
spatial_id: common.spatial_id, spatial_id: common.spatial_id,
clip_chain_id: common.clip_chain_id, clip_chain_id: common.clip_chain_id,
}, },
iframe.pipeline_id.to_webrender(), iframe.pipeline_id.into(),
true, true,
); );
}, },

View file

@ -126,6 +126,6 @@ impl Tag {
Some(PseudoElement::After) => FragmentType::AfterPseudoContent, Some(PseudoElement::After) => FragmentType::AfterPseudoContent,
_ => FragmentType::FragmentBody, _ => FragmentType::FragmentBody,
}; };
combine_id_with_fragment_type(self.node.id(), fragment_type) as u64 combine_id_with_fragment_type(self.node.id(), fragment_type)
} }
} }

View file

@ -9,7 +9,6 @@ use app_units::Au;
use euclid::default::{Point2D, Rect}; use euclid::default::{Point2D, Rect};
use euclid::{SideOffsets2D, Size2D, Vector2D}; use euclid::{SideOffsets2D, Size2D, Vector2D};
use log::warn; use log::warn;
use msg::constellation_msg::PipelineId;
use script_layout_interface::wrapper_traits::{ use script_layout_interface::wrapper_traits::{
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode, LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
}; };
@ -31,7 +30,6 @@ use style::stylist::RuleInclusion;
use style::traversal::resolve_style; use style::traversal::resolve_style;
use style::values::generics::font::LineHeight; use style::values::generics::font::LineHeight;
use style_traits::{ParsingMode, ToCss}; use style_traits::{ParsingMode, ToCss};
use webrender_api::ExternalScrollId;
use crate::fragment_tree::{Fragment, FragmentFlags, FragmentTree, Tag}; use crate::fragment_tree::{Fragment, FragmentFlags, FragmentTree, Tag};
@ -71,14 +69,6 @@ pub fn process_node_geometry_request(
} }
} }
pub fn process_node_scroll_id_request<'dom>(
id: PipelineId,
requested_node: impl LayoutNode<'dom>,
) -> ExternalScrollId {
let layout_node = requested_node.to_threadsafe();
layout_node.generate_scroll_id(id)
}
/// <https://drafts.csswg.org/cssom-view/#scrolling-area> /// <https://drafts.csswg.org/cssom-view/#scrolling-area>
pub fn process_node_scroll_area_request( pub fn process_node_scroll_area_request(
requested_node: Option<OpaqueNode>, requested_node: Option<OpaqueNode>,

View file

@ -39,7 +39,7 @@ use layout::flow_ref::FlowRef;
use layout::incremental::{RelayoutMode, SpecialRestyleDamage}; use layout::incremental::{RelayoutMode, SpecialRestyleDamage};
use layout::query::{ use layout::query::{
process_client_rect_query, process_content_box_request, process_content_boxes_request, process_client_rect_query, process_content_box_request, process_content_boxes_request,
process_element_inner_text_query, process_node_scroll_id_request, process_offset_parent_query, process_element_inner_text_query, process_offset_parent_query,
process_resolved_font_style_request, process_resolved_style_request, process_resolved_font_style_request, process_resolved_style_request,
process_scrolling_area_request, process_scrolling_area_request,
}; };
@ -365,9 +365,9 @@ impl Layout for LayoutThread {
flags.insert(HitTestFlags::POINT_RELATIVE_TO_PIPELINE_VIEWPORT); flags.insert(HitTestFlags::POINT_RELATIVE_TO_PIPELINE_VIEWPORT);
let client_point = units::DevicePoint::from_untyped(point); let client_point = units::DevicePoint::from_untyped(point);
let results = let results = self
self.webrender_api .webrender_api
.hit_test(Some(self.id.to_webrender()), client_point, flags); .hit_test(Some(self.id.into()), client_point, flags);
results.iter().map(|result| result.node).collect() results.iter().map(|result| result.node).collect()
} }
@ -451,14 +451,6 @@ impl Layout for LayoutThread {
) )
} }
fn query_scroll_id(
&self,
node: script_layout_interface::TrustedNodeAddress,
) -> webrender_api::ExternalScrollId {
let node = unsafe { ServoLayoutNode::new(&node) };
process_node_scroll_id_request(self.id, node)
}
fn query_scrolling_area(&self, node: Option<OpaqueNode>) -> UntypedRect<i32> { fn query_scrolling_area(&self, node: Option<OpaqueNode>) -> UntypedRect<i32> {
let Some(mut root_flow) = self.root_flow_for_query() else { let Some(mut root_flow) = self.root_flow_for_query() else {
return UntypedRect::zero(); return UntypedRect::zero();
@ -504,7 +496,7 @@ impl LayoutThread {
window_size: WindowSizeData, window_size: WindowSizeData,
) -> LayoutThread { ) -> LayoutThread {
// Let webrender know about this pipeline by sending an empty display list. // Let webrender know about this pipeline by sending an empty display list.
webrender_api.send_initial_transaction(id.to_webrender()); webrender_api.send_initial_transaction(id.into());
let device = Device::new( let device = Device::new(
MediaType::screen(), MediaType::screen(),
@ -1238,7 +1230,7 @@ impl LayoutThread {
let point = Point2D::new(-state.scroll_offset.x, -state.scroll_offset.y); let point = Point2D::new(-state.scroll_offset.x, -state.scroll_offset.y);
self.webrender_api.send_scroll_node( self.webrender_api.send_scroll_node(
self.id.to_webrender(), self.id.into(),
units::LayoutPoint::from_untyped(point), units::LayoutPoint::from_untyped(point),
state.scroll_id, state.scroll_id,
); );

View file

@ -30,9 +30,8 @@ use layout::context::LayoutContext;
use layout::display_list::{DisplayList, WebRenderImageInfo}; use layout::display_list::{DisplayList, WebRenderImageInfo};
use layout::query::{ use layout::query::{
process_content_box_request, process_content_boxes_request, process_element_inner_text_query, process_content_box_request, process_content_boxes_request, process_element_inner_text_query,
process_node_geometry_request, process_node_scroll_area_request, process_node_geometry_request, process_node_scroll_area_request, process_offset_parent_query,
process_node_scroll_id_request, process_offset_parent_query, process_resolved_font_style_query, process_resolved_font_style_query, process_resolved_style_request, process_text_index_request,
process_resolved_style_request, process_text_index_request,
}; };
use layout::traversal::RecalcStyle; use layout::traversal::RecalcStyle;
use layout::{layout_debug, BoxTree, FragmentTree}; use layout::{layout_debug, BoxTree, FragmentTree};
@ -328,9 +327,9 @@ impl Layout for LayoutThread {
flags.insert(HitTestFlags::POINT_RELATIVE_TO_PIPELINE_VIEWPORT); flags.insert(HitTestFlags::POINT_RELATIVE_TO_PIPELINE_VIEWPORT);
let client_point = units::DevicePoint::from_untyped(point); let client_point = units::DevicePoint::from_untyped(point);
let results = let results = self
self.webrender_api .webrender_api
.hit_test(Some(self.id.to_webrender()), client_point, flags); .hit_test(Some(self.id.into()), client_point, flags);
results.iter().map(|result| result.node).collect() results.iter().map(|result| result.node).collect()
} }
@ -406,14 +405,6 @@ impl Layout for LayoutThread {
) )
} }
fn query_scroll_id(
&self,
node: script_layout_interface::TrustedNodeAddress,
) -> ExternalScrollId {
let node = unsafe { ServoLayoutNode::new(&node) };
process_node_scroll_id_request(self.id, node)
}
fn query_scrolling_area(&self, node: Option<OpaqueNode>) -> UntypedRect<i32> { fn query_scrolling_area(&self, node: Option<OpaqueNode>) -> UntypedRect<i32> {
process_node_scroll_area_request(node, self.fragment_tree.borrow().clone()) process_node_scroll_area_request(node, self.fragment_tree.borrow().clone())
} }
@ -452,7 +443,7 @@ impl LayoutThread {
window_size: WindowSizeData, window_size: WindowSizeData,
) -> LayoutThread { ) -> LayoutThread {
// Let webrender know about this pipeline by sending an empty display list. // Let webrender know about this pipeline by sending an empty display list.
webrender_api_sender.send_initial_transaction(id.to_webrender()); webrender_api_sender.send_initial_transaction(id.into());
// The device pixel ratio is incorrect (it does not have the hidpi value), // The device pixel ratio is incorrect (it does not have the hidpi value),
// but it will be set correctly when the initial reflow takes place. // but it will be set correctly when the initial reflow takes place.
@ -878,7 +869,7 @@ impl LayoutThread {
.insert(state.scroll_id, state.scroll_offset); .insert(state.scroll_id, state.scroll_offset);
let point = Point2D::new(-state.scroll_offset.x, -state.scroll_offset.y); let point = Point2D::new(-state.scroll_offset.x, -state.scroll_offset.y);
self.webrender_api.send_scroll_node( self.webrender_api.send_scroll_node(
self.id.to_webrender(), self.id.into(),
units::LayoutPoint::from_untyped(point), units::LayoutPoint::from_untyped(point),
state.scroll_id, state.scroll_id,
); );
@ -950,7 +941,7 @@ impl LayoutThread {
let mut display_list = DisplayList::new( let mut display_list = DisplayList::new(
viewport_size, viewport_size,
fragment_tree.scrollable_overflow(), fragment_tree.scrollable_overflow(),
self.id.to_webrender(), self.id.into(),
epoch.into(), epoch.into(),
fragment_tree.root_scroll_sensitivity, fragment_tree.root_scroll_sensitivity,
); );

View file

@ -26,6 +26,7 @@ use dom_struct::dom_struct;
use embedder_traits::{EmbedderMsg, PromptDefinition, PromptOrigin, PromptResult}; use embedder_traits::{EmbedderMsg, PromptDefinition, PromptOrigin, PromptResult};
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect}; use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect};
use euclid::{Point2D, Rect, Scale, Size2D, Vector2D}; use euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
use gfx_traits::combine_id_with_fragment_type;
use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER; use ipc_channel::router::ROUTER;
use js::conversions::ToJSValConvertible; use js::conversions::ToJSValConvertible;
@ -2101,20 +2102,19 @@ impl Window {
// https://drafts.csswg.org/cssom-view/#element-scrolling-members // https://drafts.csswg.org/cssom-view/#element-scrolling-members
pub fn scroll_node(&self, node: &Node, x_: f64, y_: f64, behavior: ScrollBehavior) { pub fn scroll_node(&self, node: &Node, x_: f64, y_: f64, behavior: ScrollBehavior) {
if !self.layout_reflow(QueryMsg::NodeScrollIdQuery) {
return;
}
// The scroll offsets are immediatly updated since later calls // The scroll offsets are immediatly updated since later calls
// to topScroll and others may access the properties before // to topScroll and others may access the properties before
// webrender has a chance to update the offsets. // webrender has a chance to update the offsets.
self.scroll_offsets self.scroll_offsets
.borrow_mut() .borrow_mut()
.insert(node.to_opaque(), Vector2D::new(x_ as f32, y_ as f32)); .insert(node.to_opaque(), Vector2D::new(x_ as f32, y_ as f32));
let scroll_id = ExternalScrollId(
let scroll_id = self combine_id_with_fragment_type(
.with_layout(|layout| layout.query_scroll_id(node.to_trusted_node_address())) node.to_opaque().id(),
.unwrap(); gfx_traits::FragmentType::FragmentBody,
),
self.pipeline_id().into(),
);
// Step 12 // Step 12
self.perform_a_scroll( self.perform_a_scroll(
@ -2720,7 +2720,6 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow
QueryMsg::NodesFromPointQuery => "\tNodesFromPointQuery", QueryMsg::NodesFromPointQuery => "\tNodesFromPointQuery",
QueryMsg::ClientRectQuery => "\tClientRectQuery", QueryMsg::ClientRectQuery => "\tClientRectQuery",
QueryMsg::ScrollingAreaQuery => "\tNodeScrollGeometryQuery", QueryMsg::ScrollingAreaQuery => "\tNodeScrollGeometryQuery",
QueryMsg::NodeScrollIdQuery => "\tNodeScrollIdQuery",
QueryMsg::ResolvedStyleQuery => "\tResolvedStyleQuery", QueryMsg::ResolvedStyleQuery => "\tResolvedStyleQuery",
QueryMsg::ResolvedFontStyleQuery => "\nResolvedFontStyleQuery", QueryMsg::ResolvedFontStyleQuery => "\nResolvedFontStyleQuery",
QueryMsg::OffsetParentQuery => "\tOffsetParentQuery", QueryMsg::OffsetParentQuery => "\tOffsetParentQuery",

View file

@ -8,7 +8,7 @@
pub mod print_tree; pub mod print_tree;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicU64, Ordering};
use malloc_size_of_derive::MallocSizeOf; use malloc_size_of_derive::MallocSizeOf;
use range::{int_range_index, RangeIndex}; use range::{int_range_index, RangeIndex};
@ -90,30 +90,30 @@ pub enum FragmentType {
/// The next ID that will be used for a special scroll root id. /// The next ID that will be used for a special scroll root id.
/// ///
/// A special scroll root is a scroll root that is created for generated content. /// A special scroll root is a scroll root that is created for generated content.
static NEXT_SPECIAL_SCROLL_ROOT_ID: AtomicUsize = AtomicUsize::new(0); static NEXT_SPECIAL_SCROLL_ROOT_ID: AtomicU64 = AtomicU64::new(0);
/// If none of the bits outside this mask are set, the scroll root is a special scroll root. /// If none of the bits outside this mask are set, the scroll root is a special scroll root.
/// Note that we assume that the top 16 bits of the address space are unused on the platform. /// Note that we assume that the top 16 bits of the address space are unused on the platform.
const SPECIAL_SCROLL_ROOT_ID_MASK: usize = 0xffff; const SPECIAL_SCROLL_ROOT_ID_MASK: u64 = 0xffff;
/// Returns a new scroll root ID for a scroll root. /// Returns a new scroll root ID for a scroll root.
fn next_special_id() -> usize { fn next_special_id() -> u64 {
// We shift this left by 2 to make room for the fragment type ID. // We shift this left by 2 to make room for the fragment type ID.
((NEXT_SPECIAL_SCROLL_ROOT_ID.fetch_add(1, Ordering::SeqCst) + 1) << 2) & ((NEXT_SPECIAL_SCROLL_ROOT_ID.fetch_add(1, Ordering::SeqCst) + 1) << 2) &
SPECIAL_SCROLL_ROOT_ID_MASK SPECIAL_SCROLL_ROOT_ID_MASK
} }
pub fn combine_id_with_fragment_type(id: usize, fragment_type: FragmentType) -> usize { pub fn combine_id_with_fragment_type(id: usize, fragment_type: FragmentType) -> u64 {
debug_assert_eq!(id & (fragment_type as usize), 0); debug_assert_eq!(id & (fragment_type as usize), 0);
if fragment_type == FragmentType::FragmentBody { if fragment_type == FragmentType::FragmentBody {
id id as u64
} else { } else {
next_special_id() | (fragment_type as usize) next_special_id() | (fragment_type as u64)
} }
} }
pub fn node_id_from_scroll_id(id: usize) -> Option<usize> { pub fn node_id_from_scroll_id(id: usize) -> Option<usize> {
if (id & !SPECIAL_SCROLL_ROOT_ID_MASK) != 0 { if (id as u64 & !SPECIAL_SCROLL_ROOT_ID_MASK) != 0 {
return Some(id & !3); return Some(id & !3);
} }
None None

View file

@ -223,14 +223,14 @@ impl PipelineId {
}) })
} }
pub fn to_webrender(&self) -> WebRenderPipelineId { pub fn root_scroll_id(&self) -> webrender_api::ExternalScrollId {
let PipelineNamespaceId(namespace_id) = self.namespace_id; ExternalScrollId(0, self.into())
let PipelineIndex(index) = self.index;
WebRenderPipelineId(namespace_id, index.get())
} }
}
impl From<WebRenderPipelineId> for PipelineId {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn from_webrender(pipeline: WebRenderPipelineId) -> PipelineId { fn from(pipeline: WebRenderPipelineId) -> Self {
let WebRenderPipelineId(namespace_id, index) = pipeline; let WebRenderPipelineId(namespace_id, index) = pipeline;
unsafe { unsafe {
PipelineId { PipelineId {
@ -239,9 +239,19 @@ impl PipelineId {
} }
} }
} }
}
pub fn root_scroll_id(&self) -> webrender_api::ExternalScrollId { impl From<PipelineId> for WebRenderPipelineId {
ExternalScrollId(0, self.to_webrender()) fn from(value: PipelineId) -> Self {
let PipelineNamespaceId(namespace_id) = value.namespace_id;
let PipelineIndex(index) = value.index;
WebRenderPipelineId(namespace_id, index.get())
}
}
impl From<&PipelineId> for WebRenderPipelineId {
fn from(value: &PipelineId) -> Self {
(*value).into()
} }
} }

View file

@ -46,7 +46,7 @@ use style::properties::PropertyId;
use style::selector_parser::PseudoElement; use style::selector_parser::PseudoElement;
use style::stylesheets::Stylesheet; use style::stylesheets::Stylesheet;
use style_traits::CSSPixel; use style_traits::CSSPixel;
use webrender_api::{ExternalScrollId, ImageKey}; use webrender_api::ImageKey;
pub type GenericLayoutData = dyn Any + Send + Sync; pub type GenericLayoutData = dyn Any + Send + Sync;
@ -235,7 +235,6 @@ pub trait Layout {
animations: DocumentAnimationSet, animations: DocumentAnimationSet,
animation_timeline_value: f64, animation_timeline_value: f64,
) -> Option<ServoArc<Font>>; ) -> Option<ServoArc<Font>>;
fn query_scroll_id(&self, node: TrustedNodeAddress) -> ExternalScrollId;
fn query_scrolling_area(&self, node: Option<OpaqueNode>) -> Rect<i32>; fn query_scrolling_area(&self, node: Option<OpaqueNode>) -> Rect<i32>;
fn query_text_indext(&self, node: OpaqueNode, point: Point2D<f32>) -> Option<usize>; fn query_text_indext(&self, node: OpaqueNode, point: Point2D<f32>) -> Option<usize>;
} }

View file

@ -55,7 +55,6 @@ pub enum QueryMsg {
OffsetParentQuery, OffsetParentQuery,
TextIndexQuery, TextIndexQuery,
NodesFromPointQuery, NodesFromPointQuery,
NodeScrollIdQuery,
ResolvedStyleQuery, ResolvedStyleQuery,
StyleQuery, StyleQuery,
ElementInnerTextQuery, ElementInnerTextQuery,
@ -90,7 +89,6 @@ impl ReflowGoal {
QueryMsg::ClientRectQuery | QueryMsg::ClientRectQuery |
QueryMsg::ContentBox | QueryMsg::ContentBox |
QueryMsg::ContentBoxes | QueryMsg::ContentBoxes |
QueryMsg::NodeScrollIdQuery |
QueryMsg::OffsetParentQuery | QueryMsg::OffsetParentQuery |
QueryMsg::ResolvedFontStyleQuery | QueryMsg::ResolvedFontStyleQuery |
QueryMsg::ScrollingAreaQuery | QueryMsg::ScrollingAreaQuery |
@ -112,7 +110,6 @@ impl ReflowGoal {
QueryMsg::ContentBoxes | QueryMsg::ContentBoxes |
QueryMsg::ClientRectQuery | QueryMsg::ClientRectQuery |
QueryMsg::ScrollingAreaQuery | QueryMsg::ScrollingAreaQuery |
QueryMsg::NodeScrollIdQuery |
QueryMsg::ResolvedStyleQuery | QueryMsg::ResolvedStyleQuery |
QueryMsg::ResolvedFontStyleQuery | QueryMsg::ResolvedFontStyleQuery |
QueryMsg::OffsetParentQuery | QueryMsg::OffsetParentQuery |

View file

@ -9,7 +9,7 @@ use std::fmt::Debug;
use std::sync::Arc as StdArc; use std::sync::Arc as StdArc;
use atomic_refcell::AtomicRef; use atomic_refcell::AtomicRef;
use gfx_traits::{combine_id_with_fragment_type, ByteIndex, FragmentType}; use gfx_traits::{ByteIndex, FragmentType};
use html5ever::{local_name, namespace_url, ns, LocalName, Namespace}; use html5ever::{local_name, namespace_url, ns, LocalName, Namespace};
use msg::constellation_msg::{BrowsingContextId, PipelineId}; use msg::constellation_msg::{BrowsingContextId, PipelineId};
use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image::base::{Image, ImageMetadata};
@ -23,7 +23,6 @@ use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, TElement, TNode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::selector_parser::{PseudoElement, PseudoElementCascadeType, SelectorImpl}; use style::selector_parser::{PseudoElement, PseudoElementCascadeType, SelectorImpl};
use style::stylist::RuleInclusion; use style::stylist::RuleInclusion;
use webrender_api::ExternalScrollId;
use crate::{ use crate::{
GenericLayoutData, HTMLCanvasData, HTMLMediaData, LayoutNodeType, SVGSVGData, StyleData, GenericLayoutData, HTMLCanvasData, HTMLMediaData, LayoutNodeType, SVGSVGData, StyleData,
@ -315,11 +314,6 @@ pub trait ThreadSafeLayoutNode<'dom>: Clone + Copy + Debug + NodeInfo + PartialE
fn fragment_type(&self) -> FragmentType { fn fragment_type(&self) -> FragmentType {
self.get_pseudo_element_type().fragment_type() self.get_pseudo_element_type().fragment_type()
} }
fn generate_scroll_id(&self, pipeline_id: PipelineId) -> ExternalScrollId {
let id = combine_id_with_fragment_type(self.opaque().id(), self.fragment_type());
ExternalScrollId(id as u64, pipeline_id.to_webrender())
}
} }
pub trait ThreadSafeLayoutElement<'dom>: pub trait ThreadSafeLayoutElement<'dom>: