Skip to content

Commit 1bb1c2a

Browse files
Glenn Watsonweb-flow
Glenn Watson
authored andcommitted
Bug 1887810 - Use quad-mask path for clip-out mode r=gfx-reviewers,nical
This is needed in order to support box-shadow rendering via the quad rendering paths. Differential Revision: https://phabricator.services.mozilla.com/D205670
1 parent ad2fa65 commit 1bb1c2a

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

webrender/src/prepare.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ fn can_use_clip_chain_for_quad_path(
121121

122122
match clip_node.item.kind {
123123
ClipItemKind::Rectangle { mode: ClipMode::ClipOut, .. } |
124-
ClipItemKind::RoundedRectangle { mode: ClipMode::ClipOut, .. } => {
125-
return false;
126-
}
124+
ClipItemKind::RoundedRectangle { mode: ClipMode::ClipOut, .. } |
127125
ClipItemKind::RoundedRectangle { .. } | ClipItemKind::Rectangle { .. } => {}
128126
ClipItemKind::BoxShadow { .. } => {
129127
// legacy path for box-shadows for now (move them to a separate primitive next)

webrender/src/quad.rs

+43-13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum QuadRenderStrategy {
4747
NinePatch {
4848
radius: LayoutVector2D,
4949
clip_rect: LayoutRect,
50+
mode: ClipMode,
5051
},
5152
/// Split the primitive into coarse tiles so that each tile independently
5253
/// has the opportunity to be drawn directly in the destination target or
@@ -260,19 +261,36 @@ pub fn push_quad(
260261
&scratch.quad_segments,
261262
);
262263
}
263-
QuadRenderStrategy::NinePatch { clip_rect, radius } => {
264+
QuadRenderStrategy::NinePatch { clip_rect, radius, mode } => {
264265
let unclipped_surface_rect = surface
265266
.map_to_device_rect(&clip_chain.pic_coverage_rect, frame_context.spatial_tree);
266267

267-
let local_corner_0 = LayoutRect::new(
268-
clip_rect.min,
269-
clip_rect.min + radius,
270-
);
271-
272-
let local_corner_1 = LayoutRect::new(
273-
clip_rect.max - radius,
274-
clip_rect.max,
275-
);
268+
let (local_corner_0, local_corner_1) = match mode {
269+
ClipMode::Clip => {
270+
(
271+
LayoutRect::new(
272+
clip_rect.min,
273+
clip_rect.min + radius,
274+
),
275+
LayoutRect::new(
276+
clip_rect.max - radius,
277+
clip_rect.max,
278+
),
279+
)
280+
}
281+
ClipMode::ClipOut => {
282+
(
283+
LayoutRect::new(
284+
local_rect.min,
285+
clip_rect.min + radius,
286+
),
287+
LayoutRect::new(
288+
clip_rect.max - radius,
289+
local_rect.max,
290+
),
291+
)
292+
}
293+
};
276294

277295
let pic_corner_0 = pic_state.map_local_to_pic.map(&local_corner_0).unwrap();
278296
let pic_corner_1 = pic_state.map_local_to_pic.map(&local_corner_1).unwrap();
@@ -316,8 +334,19 @@ pub fn push_quad(
316334
continue;
317335
}
318336

319-
// Only create render tasks for the corners.
320-
let create_task = x != 1 && y != 1;
337+
let create_task = match mode {
338+
ClipMode::Clip => {
339+
// Only create render tasks for the corners.
340+
x != 1 && y != 1
341+
}
342+
ClipMode::ClipOut => {
343+
if x == 1 && y == 1 {
344+
continue;
345+
}
346+
347+
true
348+
}
349+
};
321350

322351
let rect = DeviceIntRect::new(point2(x0, y0), point2(x1, y1));
323352

@@ -389,7 +418,7 @@ fn get_prim_render_strategy(
389418
let clip_instance = clip_store.get_instance_from_range(&clip_chain.clips_range, 0);
390419
let clip_node = &interned_clips[clip_instance.handle];
391420

392-
if let ClipItemKind::RoundedRectangle { ref radius, mode: ClipMode::Clip, rect, .. } = clip_node.item.kind {
421+
if let ClipItemKind::RoundedRectangle { ref radius, mode, rect, .. } = clip_node.item.kind {
393422
let max_corner_width = radius.top_left.width
394423
.max(radius.bottom_left.width)
395424
.max(radius.top_right.width)
@@ -419,6 +448,7 @@ fn get_prim_render_strategy(
419448
return QuadRenderStrategy::NinePatch {
420449
radius: LayoutVector2D::new(max_corner_width, max_corner_height),
421450
clip_rect: rect,
451+
mode,
422452
};
423453
}
424454
}

webrender/src/render_target.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55

6-
use api::{units::*, PremultipliedColorF, ClipMode};
6+
use api::{units::*, PremultipliedColorF};
77
use api::{ColorF, ImageFormat, LineOrientation, BorderStyle};
88
use crate::batch::{AlphaBatchBuilder, AlphaBatchContainer, BatchTextures};
99
use crate::batch::{ClipBatcher, BatchBuilder, INVALID_SEGMENT_INDEX, ClipMaskInstanceList};
@@ -1018,8 +1018,6 @@ fn build_mask_tasks(
10181018
(clip_address, fast_path)
10191019
}
10201020
ClipItemKind::Rectangle { rect, mode, .. } => {
1021-
assert_eq!(mode, ClipMode::Clip);
1022-
10231021
let mut writer = gpu_buffer_builder.f32.write_blocks(3);
10241022
writer.push_one(rect);
10251023
writer.push_one([0.0, 0.0, 0.0, 0.0]);
Loading

0 commit comments

Comments
 (0)