Skip to content

Commit

Permalink
Auto merge of #2968 - gw3583:pic-context, r=kvark
Browse files Browse the repository at this point in the history
Optimize how local rects are calculated during culling.

Apply similar logic to the clip code to minimize the
amount of work that is needed when building local
rects for a picture. This change is quite a
significant optimization - in most cases it halves
the amount of work done here, by skipping the extra
rect calculation for non-3d rendering context
pictures. It also saves some rect x matrix transforms
in various cases.

This is a bit more preparation work for rasterizing
pictures in difference coordinate spaces. There are a
few other miscellaneous improvements too:

 * Rename some fields to be more appropriate.
 * Reduce number of matrix inverse calls.
 * Remove reference_frame_stack, which is no longer
   required.
 * Remove BuiltDisplayList from PrimitiveContext, which
   will be helpful in future patches.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2968)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 13, 2018
2 parents a16e311 + da19712 commit 890f374
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 132 deletions.
2 changes: 1 addition & 1 deletion webrender/src/batch.rs
Expand Up @@ -670,7 +670,7 @@ impl AlphaBatchBuilder {
// Push into parent plane splitter.
debug_assert!(picture.surface.is_some());
let transform = &ctx.transforms
.get_transform(picture.reference_frame_index);
.get_transform(picture.original_spatial_node_index);

match transform.transform_kind {
TransformedRectKind::AxisAligned => {
Expand Down
34 changes: 6 additions & 28 deletions webrender/src/display_list_flattener.rs
Expand Up @@ -105,10 +105,6 @@ pub struct DisplayListFlattener<'a> {
/// types that the ClipScrollTree uses.
id_to_index_mapper: ClipIdToIndexMapper,

/// A stack of scroll nodes used during display list processing to properly
/// parent new scroll nodes.
reference_frame_stack: Vec<(ClipId, SpatialNodeIndex)>,

/// A stack of stacking context properties.
sc_stack: Vec<FlattenedStackingContext>,

Expand Down Expand Up @@ -169,7 +165,6 @@ impl<'a> DisplayListFlattener<'a> {
id_to_index_mapper: ClipIdToIndexMapper::default(),
hit_testing_runs: recycle_vec(old_builder.hit_testing_runs),
scrollbar_prims: recycle_vec(old_builder.scrollbar_prims),
reference_frame_stack: Vec::new(),
picture_stack: Vec::new(),
shadow_stack: Vec::new(),
sc_stack: Vec::new(),
Expand Down Expand Up @@ -396,8 +391,6 @@ impl<'a> DisplayListFlattener<'a> {
);

self.flatten_items(traversal, pipeline_id, LayoutVector2D::zero());

self.pop_reference_frame();
}

fn flatten_stacking_context(
Expand Down Expand Up @@ -496,7 +489,6 @@ impl<'a> DisplayListFlattener<'a> {

self.flatten_root(pipeline, &iframe_rect.size);

self.pop_reference_frame();
self.pipeline_clip_chain_stack.pop();
}

Expand Down Expand Up @@ -922,10 +914,6 @@ impl<'a> DisplayListFlattener<'a> {
None => ClipChainId::NONE,
};

// Construct the necessary set of Picture primitives
// to draw this stacking context.
let current_reference_frame_index = self.current_reference_frame_index();

// An arbitrary large clip rect. For now, we don't
// specify a clip specific to the stacking context.
// However, now that they are represented as Picture
Expand All @@ -947,7 +935,7 @@ impl<'a> DisplayListFlattener<'a> {
None,
false,
pipeline_id,
current_reference_frame_index,
spatial_node_index,
None,
true,
);
Expand Down Expand Up @@ -1013,7 +1001,7 @@ impl<'a> DisplayListFlattener<'a> {
None,
false,
pipeline_id,
current_reference_frame_index,
spatial_node_index,
None,
true,
);
Expand Down Expand Up @@ -1064,7 +1052,7 @@ impl<'a> DisplayListFlattener<'a> {
Some(PictureCompositeMode::Filter(*filter)),
false,
pipeline_id,
current_reference_frame_index,
spatial_node_index,
None,
true,
);
Expand Down Expand Up @@ -1094,7 +1082,7 @@ impl<'a> DisplayListFlattener<'a> {
Some(PictureCompositeMode::MixBlend(mix_blend_mode)),
false,
pipeline_id,
current_reference_frame_index,
spatial_node_index,
None,
true,
);
Expand Down Expand Up @@ -1150,7 +1138,7 @@ impl<'a> DisplayListFlattener<'a> {
composite_mode,
participating_in_3d_context,
pipeline_id,
current_reference_frame_index,
spatial_node_index,
frame_output_pipeline_id,
true,
);
Expand Down Expand Up @@ -1240,7 +1228,6 @@ impl<'a> DisplayListFlattener<'a> {
origin_in_parent_reference_frame,
pipeline_id,
);
self.reference_frame_stack.push((reference_frame_id, index));
self.id_to_index_mapper.map_spatial_node(reference_frame_id, index);

match parent_id {
Expand All @@ -1251,10 +1238,6 @@ impl<'a> DisplayListFlattener<'a> {
index
}

pub fn current_reference_frame_index(&self) -> SpatialNodeIndex {
self.reference_frame_stack.last().unwrap().1
}

pub fn setup_viewport_offset(
&mut self,
inner_rect: DeviceUintRect,
Expand Down Expand Up @@ -1372,18 +1355,13 @@ impl<'a> DisplayListFlattener<'a> {
node_index
}

pub fn pop_reference_frame(&mut self) {
self.reference_frame_stack.pop();
}

pub fn push_shadow(
&mut self,
shadow: Shadow,
clip_and_scroll: ScrollNodeAndClipChain,
info: &LayoutPrimitiveInfo,
) {
let pipeline_id = self.sc_stack.last().unwrap().pipeline_id;
let current_reference_frame_index = self.current_reference_frame_index();
let max_clip = LayoutRect::max_rect();

// Quote from https://drafts.csswg.org/css-backgrounds-3/#shadow-blur
Expand All @@ -1406,7 +1384,7 @@ impl<'a> DisplayListFlattener<'a> {
Some(PictureCompositeMode::Filter(FilterOp::Blur(std_deviation))),
false,
pipeline_id,
current_reference_frame_index,
clip_and_scroll.spatial_node_index,
None,
apply_local_clip_rect,
);
Expand Down
25 changes: 9 additions & 16 deletions webrender/src/frame_builder.rs
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{BuiltDisplayList, ColorF, DeviceIntPoint, DeviceIntRect, DevicePixelScale};
use api::{ColorF, DeviceIntPoint, DeviceIntRect, DevicePixelScale};
use api::{DeviceUintPoint, DeviceUintRect, DeviceUintSize, DocumentLayer, FontRenderMode};
use api::{LayoutPoint, LayoutRect, LayoutSize, PipelineId, WorldPoint};
use clip::{ClipStore};
Expand All @@ -24,7 +24,7 @@ use std::{mem, f32};
use std::sync::Arc;
use tiling::{Frame, RenderPass, RenderPassKind, RenderTargetContext};
use tiling::{ScrollbarPrimitive, SpecialRenderPasses};
use util::{self, WorldToLayoutFastTransform};
use util;


#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down Expand Up @@ -86,12 +86,11 @@ pub struct FrameBuildingState<'a> {
pub special_render_passes: &'a mut SpecialRenderPasses,
}

pub struct PictureContext<'a> {
pub struct PictureContext {
pub pipeline_id: PipelineId,
pub prim_runs: Vec<PrimitiveRun>,
pub original_reference_frame_index: Option<SpatialNodeIndex>,
pub display_list: &'a BuiltDisplayList,
pub inv_world_transform: Option<WorldToLayoutFastTransform>,
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,
Expand Down Expand Up @@ -199,13 +198,8 @@ impl FrameBuilder {

// The root picture is always the first one added.
let root_prim_index = PrimitiveIndex(0);
let root_spatial_node =
&clip_scroll_tree.spatial_nodes[clip_scroll_tree.root_reference_frame_index().0];

let display_list = &pipelines
.get(&root_spatial_node.pipeline_id)
.expect("No display list?")
.display_list;
let root_spatial_node_index = clip_scroll_tree.root_reference_frame_index();
let root_spatial_node = &clip_scroll_tree.spatial_nodes[root_spatial_node_index.0];

const MAX_CLIP_COORD: f32 = 1.0e9;

Expand Down Expand Up @@ -238,9 +232,8 @@ impl FrameBuilder {
&mut self.prim_store.get_pic_mut(root_prim_index).runs,
Vec::new(),
),
original_reference_frame_index: None,
display_list,
inv_world_transform: None,
spatial_node_index: root_spatial_node_index,
original_spatial_node_index: root_spatial_node_index,
apply_local_clip_rect: true,
inflation_factor: 0.0,
allow_subpixel_aa: true,
Expand Down
15 changes: 9 additions & 6 deletions webrender/src/picture.rs
Expand Up @@ -146,10 +146,10 @@ pub struct PicturePrimitive {
// pages to a texture), this is the pipeline this
// picture is the root of.
pub frame_output_pipeline_id: Option<PipelineId>,
// The original reference frame ID for this picture.
// The original reference spatial node for this picture.
// It is only different if this is part of a 3D
// rendering context.
pub reference_frame_index: SpatialNodeIndex,
pub original_spatial_node_index: SpatialNodeIndex,
pub real_local_rect: LayoutRect,
// An optional cache handle for storing extra data
// in the GPU cache, depending on the type of
Expand Down Expand Up @@ -182,7 +182,7 @@ impl PicturePrimitive {
composite_mode: Option<PictureCompositeMode>,
is_in_3d_context: bool,
pipeline_id: PipelineId,
reference_frame_index: SpatialNodeIndex,
original_spatial_node_index: SpatialNodeIndex,
frame_output_pipeline_id: Option<PipelineId>,
apply_local_clip_rect: bool,
) -> Self {
Expand All @@ -193,7 +193,7 @@ impl PicturePrimitive {
composite_mode,
is_in_3d_context,
frame_output_pipeline_id,
reference_frame_index,
original_spatial_node_index,
real_local_rect: LayoutRect::zero(),
extra_gpu_data_handle: GpuCacheHandle::new(),
apply_local_clip_rect,
Expand Down Expand Up @@ -229,9 +229,12 @@ impl PicturePrimitive {
) -> LayoutRect {
self.runs = prim_runs;

let local_content_rect = prim_run_rect.local_rect_in_actual_parent_space;
let local_content_rect = prim_run_rect.mapping.local_rect;

self.real_local_rect = prim_run_rect.local_rect_in_original_parent_space;
self.real_local_rect = match prim_run_rect.original_mapping {
Some(mapping) => mapping.local_rect,
None => local_content_rect,
};

match self.composite_mode {
Some(PictureCompositeMode::Filter(FilterOp::Blur(blur_radius))) => {
Expand Down

0 comments on commit 890f374

Please sign in to comment.