Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gw3583 committed Nov 11, 2018
1 parent 0e04c9f commit 47f5cf1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 76 deletions.
126 changes: 65 additions & 61 deletions webrender/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use gpu_types::{PrimitiveHeader, PrimitiveHeaderIndex, TransformPaletteId, Trans
use internal_types::{FastHashMap, SavedTargetIndex, TextureSource};
use picture::{Picture3DContext, PictureCompositeMode, PicturePrimitive, PictureSurface};
use prim_store::{BrushKind, BrushPrimitive, DeferredResolve};
use prim_store::{EdgeAaSegmentMask, ImageSource, PrimitiveInstanceKind, PrimitiveStore};
use prim_store::{EdgeAaSegmentMask, ImageSource, PrimitiveInstanceKind};
use prim_store::{VisibleGradientTile, PrimitiveInstance, PrimitiveOpacity};
use prim_store::{BrushSegment, BorderSource, ClipMaskKind, ClipTaskIndex, PrimitiveDetails};
use render_task::{RenderTaskAddress, RenderTaskId, RenderTaskTree};
Expand Down Expand Up @@ -538,10 +538,12 @@ impl AlphaBatchBuilder {
let z_id = z_generator.next();

// Get the clip task address for the global primitive, if one was set.
let clip_task_address = ctx
.prim_store
.get_clip_task_address(prim_instance.clip_task_index, 0, render_tasks)
.unwrap_or(OPAQUE_TASK_ADDRESS);
let clip_task_address = get_clip_task_address(
&ctx.prim_store.clip_mask_instances,
prim_instance.clip_task_index,
0,
render_tasks,
).unwrap_or(OPAQUE_TASK_ADDRESS);

match prim_instance.kind {
PrimitiveInstanceKind::Clear => {
Expand Down Expand Up @@ -823,10 +825,12 @@ impl AlphaBatchBuilder {
let pic = &ctx.prim_store.pictures[pic_index.0];

// Get clip task, if set, for the picture primitive.
let clip_task_address = ctx
.prim_store
.get_clip_task_address(prim_instance.clip_task_index, 0, render_tasks)
.unwrap_or(OPAQUE_TASK_ADDRESS);
let clip_task_address = get_clip_task_address(
&ctx.prim_store.clip_mask_instances,
prim_instance.clip_task_index,
0,
render_tasks,
).unwrap_or(OPAQUE_TASK_ADDRESS);

let prim_header = PrimitiveHeader {
local_rect: pic.local_rect,
Expand Down Expand Up @@ -1409,41 +1413,43 @@ impl AlphaBatchBuilder {

// Get GPU address of clip task for this segment, or None if
// the entire segment is clipped out.
let clip_task_address = ctx.prim_store.get_clip_task_address(
let clip_task_address = match get_clip_task_address(
&ctx.prim_store.clip_mask_instances,
clip_task_index,
segment_index,
render_tasks,
);
) {
Some(clip_task_address) => clip_task_address,
None => return,
};

// If a got a valid (or OPAQUE) clip task address, add the segment.
if let Some(clip_task_address) = clip_task_address {
let is_inner = segment.edge_flags.is_empty();
let needs_blending = !prim_opacity.is_opaque ||
clip_task_address != OPAQUE_TASK_ADDRESS ||
(!is_inner && transform_kind == TransformedRectKind::Complex);

let instance = PrimitiveInstanceData::from(BrushInstance {
segment_index,
edge_flags: segment.edge_flags,
clip_task_address,
brush_flags: BrushFlags::PERSPECTIVE_INTERPOLATION | segment.brush_flags,
prim_header_index,
user_data: segment_data.user_data,
});
let is_inner = segment.edge_flags.is_empty();
let needs_blending = !prim_opacity.is_opaque ||
clip_task_address != OPAQUE_TASK_ADDRESS ||
(!is_inner && transform_kind == TransformedRectKind::Complex);

let batch_key = BatchKey {
blend_mode: if needs_blending { alpha_blend_mode } else { BlendMode::None },
kind: BatchKind::Brush(batch_kind),
textures: segment_data.textures,
};
let instance = PrimitiveInstanceData::from(BrushInstance {
segment_index,
edge_flags: segment.edge_flags,
clip_task_address,
brush_flags: BrushFlags::PERSPECTIVE_INTERPOLATION | segment.brush_flags,
prim_header_index,
user_data: segment_data.user_data,
});

self.batch_list.push_single_instance(
batch_key,
bounding_rect,
z_id,
instance,
);
}
let batch_key = BatchKey {
blend_mode: if needs_blending { alpha_blend_mode } else { BlendMode::None },
kind: BatchKind::Brush(batch_kind),
textures: segment_data.textures,
};

self.batch_list.push_single_instance(
batch_key,
bounding_rect,
z_id,
instance,
);
}

/// Add any segment(s) from a brush to batches.
Expand Down Expand Up @@ -2206,29 +2212,27 @@ fn get_shader_opacity(opacity: f32) -> i32 {
(opacity * 65535.0).round() as i32
}

impl PrimitiveStore {
/// Retrieve the GPU task address for a given clip task instance.
/// Returns None if the segment was completely clipped out.
/// Returns Some(OPAQUE_TASK_ADDRESS) if no clip mask is needed.
/// Returns Some(task_address) if there was a valid clip mask.
fn get_clip_task_address(
&self,
clip_task_index: ClipTaskIndex,
offset: i32,
render_tasks: &RenderTaskTree,
) -> Option<RenderTaskAddress> {
let address = match self.clip_mask_instances[clip_task_index.0 as usize + offset as usize] {
ClipMaskKind::Mask(task_id) => {
render_tasks.get_task_address(task_id)
}
ClipMaskKind::None => {
OPAQUE_TASK_ADDRESS
}
ClipMaskKind::Clipped => {
return None;
}
};
/// Retrieve the GPU task address for a given clip task instance.
/// Returns None if the segment was completely clipped out.
/// Returns Some(OPAQUE_TASK_ADDRESS) if no clip mask is needed.
/// Returns Some(task_address) if there was a valid clip mask.
fn get_clip_task_address(
clip_mask_instances: &[ClipMaskKind],
clip_task_index: ClipTaskIndex,
offset: i32,
render_tasks: &RenderTaskTree,
) -> Option<RenderTaskAddress> {
let address = match clip_mask_instances[clip_task_index.0 as usize + offset as usize] {
ClipMaskKind::Mask(task_id) => {
render_tasks.get_task_address(task_id)
}
ClipMaskKind::None => {
OPAQUE_TASK_ADDRESS
}
ClipMaskKind::Clipped => {
return None;
}
};

Some(address)
}
Some(address)
}
2 changes: 1 addition & 1 deletion webrender/src/frame_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl FrameBuilder {
return None
}

self.prim_store.begin_frame();
self.prim_store.reset_clip_instances();

let root_spatial_node_index = clip_scroll_tree.root_reference_frame_index();

Expand Down
23 changes: 10 additions & 13 deletions webrender/src/prim_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,12 @@ impl BrushSegment {
pic_state: &mut PictureState,
frame_context: &FrameBuildingContext,
frame_state: &mut FrameBuildingState,
clip_mask_instances: &mut Vec<ClipMaskKind>,
) {
) -> ClipMaskKind {
match clip_chain {
Some(clip_chain) => {
if !clip_chain.needs_mask ||
(!self.may_need_clip_mask && !clip_chain.has_non_local_clips) {
clip_mask_instances.push(ClipMaskKind::None);
return;
return ClipMaskKind::None;
}

let (device_rect, _, _) = match get_raster_rects(
Expand All @@ -897,8 +895,7 @@ impl BrushSegment {
) {
Some(info) => info,
None => {
clip_mask_instances.push(ClipMaskKind::Clipped);
return;
return ClipMaskKind::Clipped;
}
};

Expand All @@ -915,10 +912,10 @@ impl BrushSegment {

let clip_task_id = frame_state.render_tasks.add(clip_task);
frame_state.surfaces[surface_index.0].tasks.push(clip_task_id);
clip_mask_instances.push(ClipMaskKind::Mask(clip_task_id));
ClipMaskKind::Mask(clip_task_id)
}
None => {
clip_mask_instances.push(ClipMaskKind::Clipped);
ClipMaskKind::Clipped
}
}
}
Expand Down Expand Up @@ -1932,7 +1929,7 @@ impl PrimitiveStore {
}
}

pub fn begin_frame(&mut self) {
pub fn reset_clip_instances(&mut self) {
// Clear the clip mask tasks for the beginning of the frame. Append
// a single kind representing no clip mask, at the ClipTaskIndex::INVALID
// location.
Expand Down Expand Up @@ -2859,16 +2856,16 @@ impl PrimitiveInstance {
// instance that was built for the main primitive. This is a
// significant optimization for the common case.
if segment_desc.segments.len() == 1 {
segment_desc.segments[0].update_clip_task(
let clip_mask_kind = segment_desc.segments[0].update_clip_task(
Some(prim_clip_chain),
prim_bounding_rect,
root_spatial_node_index,
surface_index,
pic_state,
frame_context,
frame_state,
clip_mask_instances,
);
clip_mask_instances.push(clip_mask_kind);
} else {
for segment in &mut segment_desc.segments {
// Build a clip chain for the smaller segment rect. This will
Expand All @@ -2892,16 +2889,16 @@ impl PrimitiveInstance {
&mut frame_state.resources.clip_data_store,
);

segment.update_clip_task(
let clip_mask_kind = segment.update_clip_task(
segment_clip_chain.as_ref(),
prim_bounding_rect,
root_spatial_node_index,
surface_index,
pic_state,
frame_context,
frame_state,
clip_mask_instances,
);
clip_mask_instances.push(clip_mask_kind);
}
}

Expand Down
2 changes: 1 addition & 1 deletion webrender/src/render_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct RenderTaskId {
pub index: u32,

#[cfg(debug_assertions)]
pub frame_id: FrameId,
frame_id: FrameId,
}

impl RenderTaskId {
Expand Down

0 comments on commit 47f5cf1

Please sign in to comment.