Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify how local rects are accumulated for 3d contexts. #2975

Merged
merged 1 commit into from Aug 16, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Simplify how local rects are accumulated for 3d contexts.

Pictures in a 3d rendering context are re-parented during
flattening, to ensure correct ordering during plane splitting
when un-transformed content is present.

Previously, we determined the spatial node index based on
the re-parented hierarchy, and this complicated local rect
calculation for items inside a 3d rendering context. For
these, we needed to retain the original spatial node index
and do extra calculations.

Now, we determine the correct spatial node index during
flattening, and store it inside each primitive directly
(rather than via the primitive runs inside a picture).

This greatly simplifies the process of accumulating a
local rect for a picture as we recurse through the
picture tree - allowing pictures inside a 3d context
to be processed just as any normal primitives are.

This simplifies some upcoming work to rasterize pictures
in local space, and is also a small optimization that
reduces the number of local rects we need to build and
transform.
  • Loading branch information
gw3583 committed Aug 16, 2018
commit 842c1a28a26e0b19bab67649e40ff452a093cc72
@@ -458,12 +458,8 @@ impl AlphaBatchBuilder {

// Add each run in this picture to the batch.
for run in &pic.runs {
let transform_id = ctx
.transforms
.get_id(run.spatial_node_index);
self.add_run_to_batch(
run,
transform_id,
ctx,
gpu_cache,
render_tasks,
@@ -525,7 +521,6 @@ impl AlphaBatchBuilder {
fn add_run_to_batch(
&mut self,
run: &PrimitiveRun,
transform_id: TransformPaletteId,
ctx: &RenderTargetContext,
gpu_cache: &mut GpuCache,
render_tasks: &RenderTaskTree,
@@ -541,6 +536,10 @@ impl AlphaBatchBuilder {
let metadata = &ctx.prim_store.primitives[prim_index.0].metadata;

if metadata.screen_rect.is_some() {
let transform_id = ctx
.transforms
.get_id(metadata.spatial_node_index);

self.add_prim_to_batch(
transform_id,
prim_index,
@@ -655,12 +654,12 @@ impl AlphaBatchBuilder {
// Push into parent plane splitter.
debug_assert!(picture.surface.is_some());
let transform = &ctx.transforms
.get_transform(picture.original_spatial_node_index);
.get_transform_by_id(transform_id);

match transform.transform_kind {
TransformedRectKind::AxisAligned => {
let polygon = Polygon::from_transformed_rect(
picture.real_local_rect.cast(),
prim_metadata.local_rect.cast(),
transform.m.cast(),
prim_index.0,
).unwrap();
@@ -671,7 +670,7 @@ impl AlphaBatchBuilder {
let bounds = (screen_rect.clipped.to_f32() / ctx.device_pixel_scale).to_f64();
let matrix = transform.m.cast();
let results = clipper.clip_transformed(
Polygon::from_rect(picture.real_local_rect.cast(), prim_index.0),
Polygon::from_rect(prim_metadata.local_rect.cast(), prim_index.0),
&matrix,
Some(bounds),
);
@@ -777,6 +777,7 @@ impl<'a> DisplayListFlattener<'a> {
&mut self,
info: &LayoutPrimitiveInfo,
clip_chain_id: ClipChainId,
spatial_node_index: SpatialNodeIndex,
container: PrimitiveContainer,
) -> PrimitiveIndex {
let stacking_context = self.sc_stack.last().expect("bug: no stacking context!");
@@ -786,6 +787,7 @@ impl<'a> DisplayListFlattener<'a> {
&info.clip_rect,
info.is_backface_visible && stacking_context.is_backface_visible,
clip_chain_id,
spatial_node_index,
info.tag,
container,
)
@@ -818,12 +820,11 @@ impl<'a> DisplayListFlattener<'a> {
pub fn add_primitive_to_draw_list(
&mut self,
prim_index: PrimitiveIndex,
spatial_node_index: SpatialNodeIndex,
) {
// Add primitive to the top-most Picture on the stack.
let pic_prim_index = *self.picture_stack.last().unwrap();
let pic = self.prim_store.get_pic_mut(pic_prim_index);
pic.add_primitive(prim_index, spatial_node_index);
pic.add_primitive(prim_index);
}

/// Convenience interface that creates a primitive entry and adds it
@@ -860,15 +861,13 @@ impl<'a> DisplayListFlattener<'a> {
let shadow_prim_index = self.create_primitive(
&info,
clip_chain_id,
clip_and_scroll.spatial_node_index,
container.create_shadow(shadow),
);

// Add the new primitive to the shadow picture.
let shadow_pic = self.prim_store.get_pic_mut(shadow_pic_prim_index);
shadow_pic.add_primitive(
shadow_prim_index,
clip_and_scroll.spatial_node_index,
);
shadow_pic.add_primitive(shadow_prim_index);
}
self.shadow_stack = shadow_stack;
}
@@ -879,15 +878,19 @@ impl<'a> DisplayListFlattener<'a> {
clip_and_scroll.spatial_node_index,
clip_and_scroll.clip_chain_id,
);
let prim_index = self.create_primitive(info, clip_chain_id, container);
let prim_index = self.create_primitive(
info,
clip_chain_id,
clip_and_scroll.spatial_node_index,
container,
);
if cfg!(debug_assertions) && ChasePrimitive::LocalRect(info.rect) == self.config.chase_primitive {
println!("Chasing {:?}", prim_index);
self.prim_store.chase_id = Some(prim_index);
}
self.add_primitive_to_hit_testing_list(info, clip_and_scroll);
self.add_primitive_to_draw_list(
prim_index,
clip_and_scroll.spatial_node_index,
);
}
}
@@ -936,7 +939,6 @@ impl<'a> DisplayListFlattener<'a> {
None,
false,
pipeline_id,
spatial_node_index,
None,
true,
);
@@ -946,6 +948,7 @@ impl<'a> DisplayListFlattener<'a> {
&max_clip,
true,
ClipChainId::NONE,
spatial_node_index,
None,
PrimitiveContainer::Brush(BrushPrimitive::new_picture(picture)),
);
@@ -1002,7 +1005,6 @@ impl<'a> DisplayListFlattener<'a> {
None,
false,
pipeline_id,
spatial_node_index,
None,
true,
);
@@ -1014,14 +1016,15 @@ impl<'a> DisplayListFlattener<'a> {
&max_clip,
is_backface_visible,
clip_chain_id,
spatial_node_index,
None,
PrimitiveContainer::Brush(prim),
);

let parent_prim_index = *self.picture_stack.last().unwrap();

let pic = self.prim_store.get_pic_mut(parent_prim_index);
pic.add_primitive(prim_index, spatial_node_index);
pic.add_primitive(prim_index);

self.picture_stack.push(prim_index);

@@ -1053,7 +1056,6 @@ impl<'a> DisplayListFlattener<'a> {
Some(PictureCompositeMode::Filter(*filter)),
false,
pipeline_id,
spatial_node_index,
None,
true,
);
@@ -1064,14 +1066,15 @@ impl<'a> DisplayListFlattener<'a> {
&max_clip,
is_backface_visible,
clip_chain_id,
spatial_node_index,
None,
PrimitiveContainer::Brush(src_prim),
);

let parent_pic = self.prim_store.get_pic_mut(parent_prim_index);
parent_prim_index = src_prim_index;

parent_pic.add_primitive(src_prim_index, spatial_node_index);
parent_pic.add_primitive(src_prim_index);

self.picture_stack.push(src_prim_index);
}
@@ -1083,7 +1086,6 @@ impl<'a> DisplayListFlattener<'a> {
Some(PictureCompositeMode::MixBlend(mix_blend_mode)),
false,
pipeline_id,
spatial_node_index,
None,
true,
);
@@ -1095,13 +1097,14 @@ impl<'a> DisplayListFlattener<'a> {
&max_clip,
is_backface_visible,
clip_chain_id,
spatial_node_index,
None,
PrimitiveContainer::Brush(src_prim),
);

let parent_pic = self.prim_store.get_pic_mut(parent_prim_index);
parent_prim_index = src_prim_index;
parent_pic.add_primitive(src_prim_index, spatial_node_index);
parent_pic.add_primitive(src_prim_index);

self.picture_stack.push(src_prim_index);
}
@@ -1139,7 +1142,6 @@ impl<'a> DisplayListFlattener<'a> {
composite_mode,
participating_in_3d_context,
pipeline_id,
spatial_node_index,
frame_output_pipeline_id,
true,
);
@@ -1153,12 +1155,13 @@ impl<'a> DisplayListFlattener<'a> {
&max_clip,
is_backface_visible,
clip_chain_id,
spatial_node_index,
None,
PrimitiveContainer::Brush(sc_prim),
);

let parent_pic = self.prim_store.get_pic_mut(parent_prim_index);
parent_pic.add_primitive(sc_prim_index, spatial_node_index);
parent_pic.add_primitive(sc_prim_index);

// Add this as the top-most picture for primitives to be added to.
self.picture_stack.push(sc_prim_index);
@@ -1385,7 +1388,6 @@ impl<'a> DisplayListFlattener<'a> {
Some(PictureCompositeMode::Filter(FilterOp::Blur(std_deviation))),
false,
pipeline_id,
clip_and_scroll.spatial_node_index,
None,
apply_local_clip_rect,
);
@@ -1397,6 +1399,7 @@ impl<'a> DisplayListFlattener<'a> {
&max_clip,
info.is_backface_visible,
clip_and_scroll.clip_chain_id,
clip_and_scroll.spatial_node_index,
None,
PrimitiveContainer::Brush(shadow_prim),
);
@@ -1405,7 +1408,6 @@ impl<'a> DisplayListFlattener<'a> {
// picture on to the shadow stack, to avoid infinite recursion!
self.add_primitive_to_draw_list(
shadow_prim_index,
clip_and_scroll.spatial_node_index,
);
self.shadow_stack.push((shadow, shadow_prim_index));
}
@@ -1480,12 +1482,12 @@ impl<'a> DisplayListFlattener<'a> {
let prim_index = self.create_primitive(
info,
ClipChainId::NONE,
spatial_node_index,
PrimitiveContainer::Brush(prim),
);

self.add_primitive_to_draw_list(
prim_index,
spatial_node_index,
);

self.scrollbar_prims.push(ScrollbarPrimitive {
@@ -13,7 +13,7 @@ use gpu_types::{PrimitiveHeaders, TransformPalette, UvRectKind};
use hit_test::{HitTester, HitTestingRun};
use internal_types::{FastHashMap};
use picture::PictureSurface;
use prim_store::{PrimitiveIndex, PrimitiveRun, PrimitiveStore, Transform};
use prim_store::{PrimitiveIndex, PrimitiveRun, LocalRectBuilder, PrimitiveStore, Transform};
use profiler::{FrameProfileCounters, GpuCacheProfileCounters, TextureCacheProfileCounters};
use render_backend::FrameId;
use render_task::{RenderTask, RenderTaskId, RenderTaskLocation, RenderTaskTree};
@@ -89,8 +89,6 @@ pub struct FrameBuildingState<'a> {
pub struct PictureContext {
pub pipeline_id: PipelineId,
pub prim_runs: Vec<PrimitiveRun>,
pub spatial_node_index: SpatialNodeIndex,
pub original_spatial_node_index: SpatialNodeIndex,
pub apply_local_clip_rect: bool,
pub inflation_factor: f32,
pub allow_subpixel_aa: bool,
@@ -112,20 +110,20 @@ impl PictureState {
}
}

pub struct PrimitiveRunContext<'a> {
pub scroll_node: &'a SpatialNode,
pub struct PrimitiveContext<'a> {
pub spatial_node: &'a SpatialNode,
pub spatial_node_index: SpatialNodeIndex,
pub transform: Transform<'a>,
}

impl<'a> PrimitiveRunContext<'a> {
impl<'a> PrimitiveContext<'a> {
pub fn new(
scroll_node: &'a SpatialNode,
spatial_node: &'a SpatialNode,
spatial_node_index: SpatialNodeIndex,
transform: Transform<'a>,
) -> Self {
PrimitiveRunContext {
scroll_node,
PrimitiveContext {
spatial_node,
spatial_node_index,
transform,
}
@@ -231,22 +229,24 @@ impl FrameBuilder {
let pic_context = self
.prim_store
.get_pic_mut(root_prim_index)
.take_context(
root_spatial_node_index,
true,
);
.take_context(true);

let mut local_rect_builder = LocalRectBuilder::new(
root_spatial_node_index,
);

let result = self.prim_store.prepare_prim_runs(
self.prim_store.prepare_prim_runs(
&pic_context,
&mut pic_state,
&frame_context,
&mut frame_state,
&mut local_rect_builder,
);

let pic = self
.prim_store
.get_pic_mut(root_prim_index);
pic.restore_context(pic_context, result);
pic.restore_context(pic_context, local_rect_builder);

let root_render_task = RenderTask::new_picture(
RenderTaskLocation::Fixed(frame_context.screen_rect),
@@ -354,7 +354,7 @@ impl TransformPaletteId {
pub const IDENTITY: Self = TransformPaletteId(0);

/// Extract the spatial node index from the id.
pub fn _spatial_node_index(&self) -> SpatialNodeIndex {
pub fn spatial_node_index(&self) -> SpatialNodeIndex {
SpatialNodeIndex(self.0 as usize & 0xFFFFFF)
}

@@ -480,6 +480,13 @@ impl TransformPalette {
}
}

pub fn get_transform_by_id(
&self,
id: TransformPaletteId,
) -> Transform {
self.get_transform(id.spatial_node_index())
}

// Get a transform palette id for the given spatial node.
// TODO(gw): In the future, it will be possible to specify
// a coordinate system id here, to allow retrieving
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.