Commit 7f6fc0f6 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[SPv175+] Combine clips in more cases

For consecutive clips in the same transform space, we combine the clips
in following more cases:
1. A rectangular clip and a rounded clip can bombine if the rectangular
   clip contains the rounded clip;
2. A clip path clip can combine with previous clips (but not following
   clips) if other combination conditions are satisfied.

Also no longer issue a pair of ClipRectOp and ClipRRectOp for one
rounded clip rect. It was needed when we didn't antialias clip rects.

Bug: 841227
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I2daf83ede63e3d6f65bd3eb5f89d8d1ca52cd440
Reviewed-on: https://chromium-review.googlesource.com/1052859
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557578}
parent 0fe1faa1
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x356
LayoutBlockFlow {HTML} at (0,0) size 800x356
LayoutBlockFlow {BODY} at (8,8) size 784x340
LayoutTable {TABLE} at (0,0) size 610x340
LayoutTableSection {TBODY} at (0,0) size 610x340
LayoutTableRow {TR} at (0,2) size 610x155
LayoutTableCell {TD} at (2,2) size 150x155 [r=0 c=0 rs=1 cs=1]
LayoutTableCell {TD} at (154,2) size 150x155 [r=0 c=1 rs=1 cs=1]
LayoutTableCell {TD} at (306,2) size 150x155 [r=0 c=2 rs=1 cs=1]
LayoutTableCell {TD} at (458,2) size 150x155 [r=0 c=3 rs=1 cs=1]
LayoutTableRow {TR} at (0,316) size 610x22
LayoutTableCell {TD} at (2,316) size 150x22 [r=2 c=0 rs=1 cs=1]
LayoutText {#text} at (58,1) size 34x19
text run at (58,1) width 34: "PNG"
LayoutTableCell {TD} at (154,316) size 150x22 [r=2 c=1 rs=1 cs=1]
LayoutText {#text} at (58,1) size 34x19
text run at (58,1) width 34: "SVG"
LayoutTableCell {TD} at (306,316) size 150x22 [r=2 c=2 rs=1 cs=1]
LayoutText {#text} at (58,1) size 34x19
text run at (58,1) width 34: "PNG"
LayoutTableCell {TD} at (458,316) size 150x22 [r=2 c=3 rs=1 cs=1]
LayoutText {#text} at (58,1) size 34x19
text run at (58,1) width 34: "SVG"
layer at (31,31) size 108x108 clip at (35,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (183,31) size 108x108 clip at (187,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (335,31) size 108x108 clip at (339,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (487,31) size 108x108 clip at (491,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (8,167) size 610x155
LayoutTableRow {TR} at (0,159) size 610x155
LayoutTableCell {TD} at (2,159) size 150x155 [r=1 c=0 rs=1 cs=1]
LayoutTableCell {TD} at (154,159) size 150x155 [r=1 c=1 rs=1 cs=1]
LayoutTableCell {TD} at (306,159) size 150x155 [r=1 c=2 rs=1 cs=1]
LayoutTableCell {TD} at (458,159) size 150x155 [r=1 c=3 rs=1 cs=1]
layer at (31,188) size 108x108 clip at (35,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (183,188) size 108x108 clip at (187,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (335,188) size 108x108 clip at (339,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (487,188) size 108x108 clip at (491,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x352
LayoutBlockFlow {HTML} at (0,0) size 800x352
LayoutBlockFlow {BODY} at (8,8) size 784x336
LayoutTable {TABLE} at (0,0) size 610x336
LayoutTableSection {TBODY} at (0,0) size 610x336
LayoutTableRow {TR} at (0,2) size 610x154
LayoutTableCell {TD} at (2,2) size 150x154 [r=0 c=0 rs=1 cs=1]
LayoutTableCell {TD} at (154,2) size 150x154 [r=0 c=1 rs=1 cs=1]
LayoutTableCell {TD} at (306,2) size 150x154 [r=0 c=2 rs=1 cs=1]
LayoutTableCell {TD} at (458,2) size 150x154 [r=0 c=3 rs=1 cs=1]
LayoutTableRow {TR} at (0,314) size 610x20
LayoutTableCell {TD} at (2,314) size 150x20 [r=2 c=0 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x18
text run at (59,1) width 32: "PNG"
LayoutTableCell {TD} at (154,314) size 150x20 [r=2 c=1 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x18
text run at (59,1) width 32: "SVG"
LayoutTableCell {TD} at (306,314) size 150x20 [r=2 c=2 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x18
text run at (59,1) width 32: "PNG"
LayoutTableCell {TD} at (458,314) size 150x20 [r=2 c=3 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x18
text run at (59,1) width 32: "SVG"
layer at (31,31) size 108x108 clip at (35,35) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (183,31) size 108x108 clip at (187,35) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (335,31) size 108x108 clip at (339,35) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (487,31) size 108x108 clip at (491,35) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (8,166) size 610x154
LayoutTableRow {TR} at (0,158) size 610x154
LayoutTableCell {TD} at (2,158) size 150x154 [r=1 c=0 rs=1 cs=1]
LayoutTableCell {TD} at (154,158) size 150x154 [r=1 c=1 rs=1 cs=1]
LayoutTableCell {TD} at (306,158) size 150x154 [r=1 c=2 rs=1 cs=1]
LayoutTableCell {TD} at (458,158) size 150x154 [r=1 c=3 rs=1 cs=1]
layer at (31,187) size 108x108 clip at (35,191) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (183,187) size 108x108 clip at (187,191) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (335,187) size 108x108 clip at (339,191) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (487,187) size 108x108 clip at (491,191) size 100x100 scrollHeight 104
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x356
LayoutBlockFlow {HTML} at (0,0) size 800x356
LayoutBlockFlow {BODY} at (8,8) size 784x340
LayoutTable {TABLE} at (0,0) size 610x340
LayoutTableSection {TBODY} at (0,0) size 610x340
LayoutTableRow {TR} at (0,2) size 610x155
LayoutTableCell {TD} at (2,2) size 150x155 [r=0 c=0 rs=1 cs=1]
LayoutTableCell {TD} at (154,2) size 150x155 [r=0 c=1 rs=1 cs=1]
LayoutTableCell {TD} at (306,2) size 150x155 [r=0 c=2 rs=1 cs=1]
LayoutTableCell {TD} at (458,2) size 150x155 [r=0 c=3 rs=1 cs=1]
LayoutTableRow {TR} at (0,316) size 610x22
LayoutTableCell {TD} at (2,316) size 150x22 [r=2 c=0 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x19
text run at (59,1) width 32: "PNG"
LayoutTableCell {TD} at (154,316) size 150x22 [r=2 c=1 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x19
text run at (59,1) width 32: "SVG"
LayoutTableCell {TD} at (306,316) size 150x22 [r=2 c=2 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x19
text run at (59,1) width 32: "PNG"
LayoutTableCell {TD} at (458,316) size 150x22 [r=2 c=3 rs=1 cs=1]
LayoutText {#text} at (59,1) size 32x19
text run at (59,1) width 32: "SVG"
layer at (31,31) size 108x108 clip at (35,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (183,31) size 108x108 clip at (187,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (335,31) size 108x108 clip at (339,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (487,31) size 108x108 clip at (491,35) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (8,167) size 610x155
LayoutTableRow {TR} at (0,159) size 610x155
LayoutTableCell {TD} at (2,159) size 150x155 [r=1 c=0 rs=1 cs=1]
LayoutTableCell {TD} at (154,159) size 150x155 [r=1 c=1 rs=1 cs=1]
LayoutTableCell {TD} at (306,159) size 150x155 [r=1 c=2 rs=1 cs=1]
LayoutTableCell {TD} at (458,159) size 150x155 [r=1 c=3 rs=1 cs=1]
layer at (31,188) size 108x108 clip at (35,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (183,188) size 108x108 clip at (187,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (335,188) size 108x108 clip at (339,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
layer at (487,188) size 108x108 clip at (491,192) size 100x100 scrollHeight 105
LayoutBlockFlow {DIV} at (21,21) size 108x108 [bgcolor=#FF0000] [border: (4px solid #008000)]
LayoutImage {IMG} at (4,4) size 100x100
LayoutText {#text} at (0,0) size 0x0
......@@ -164,16 +164,11 @@ class ConversionContext {
void UpdateEffectBounds(const FloatRect&, const TransformPaintPropertyNode*);
// Starts a clip state by adjusting the transform state, applying
// |combined_clip_rect| which is combined from multiple rectangular
// consecutive clips, and updating the current state.
// |lowest_combined_clip_node| is the lowest node of the combined clips.
void StartCombinedClip(
const FloatRect& combined_clip_rect,
const ClipPaintPropertyNode* lowest_combined_clip_node);
// Starts a clip state by adjusting the transform state, applying the single
// clip node which can't be combined with other clips, and updating the
// current state.
void StartSingleClip(const ClipPaintPropertyNode*);
// |combined_clip_rect| which is combined from one or more consecutive clips,
// and updating the current state. |lowest_combined_clip_node| is the lowest
// node of the combined clips.
void StartClip(const FloatRoundedRect& combined_clip_rect,
const ClipPaintPropertyNode* lowest_combined_clip_node);
// Pop one clip state from the top of the stack.
void EndClip();
// Pop clip states from the top of the stack until the top is an effect state
......@@ -274,6 +269,46 @@ void ConversionContext::SwitchToChunkState(const PaintChunk& chunk) {
SwitchToTransform(chunk_state.Transform());
}
// Tries to combine a clip node's clip rect into |combined_clip_rect|.
// Returns whether the clip has been combined.
static bool CombineClip(const ClipPaintPropertyNode* clip,
FloatRoundedRect& combined_clip_rect) {
// Don't combine into a clip with clip path.
if (clip->Parent()->ClipPath())
return false;
// Don't combine clips in different transform spaces.
if (clip->LocalTransformSpace() != clip->Parent()->LocalTransformSpace() &&
!GeometryMapper::SourceToDestinationProjection(
clip->Parent()->LocalTransformSpace(), clip->LocalTransformSpace())
.IsIdentity())
return false;
// Don't combine two rounded clip rects.
bool clip_is_rounded = clip->ClipRect().IsRounded();
bool combined_is_rounded = combined_clip_rect.IsRounded();
if (clip_is_rounded && combined_is_rounded)
return false;
// If one is rounded and the other contains the rounded bounds, use the
// rounded as the combined.
if (combined_is_rounded)
return clip->ClipRect().Rect().Contains(combined_clip_rect.Rect());
if (clip_is_rounded) {
if (combined_clip_rect.Rect().Contains(clip->ClipRect().Rect())) {
combined_clip_rect = clip->ClipRect();
return true;
}
return false;
}
// The combined is the intersection if both are rectangular.
DCHECK(!combined_is_rounded && !clip_is_rounded);
combined_clip_rect = FloatRoundedRect(
Intersection(combined_clip_rect.Rect(), clip->ClipRect().Rect()));
return true;
}
void ConversionContext::SwitchToClip(const ClipPaintPropertyNode* target_clip) {
if (target_clip == current_clip_)
return;
......@@ -317,49 +352,29 @@ void ConversionContext::SwitchToClip(const ClipPaintPropertyNode* target_clip) {
}
// Step 3: Now apply the list of clips in top-down order.
base::Optional<FloatRect> pending_combined_clip_rect;
const ClipPaintPropertyNode* lowest_combined_clip_node = nullptr;
for (size_t i = pending_clips.size(); i--;) {
DCHECK(pending_clips.size());
auto pending_combined_clip_rect = pending_clips.back()->ClipRect();
const auto* lowest_combined_clip_node = pending_clips.back();
for (size_t i = pending_clips.size() - 1; i--;) {
const auto* sub_clip = pending_clips[i];
bool has_rounded_clip_or_clip_path =
sub_clip->ClipRect().IsRounded() || sub_clip->ClipPath();
if (!has_rounded_clip_or_clip_path && pending_combined_clip_rect &&
(sub_clip->Parent()->LocalTransformSpace() ==
sub_clip->LocalTransformSpace() ||
GeometryMapper::SourceToDestinationProjection(
sub_clip->Parent()->LocalTransformSpace(),
sub_clip->LocalTransformSpace())
.IsIdentity())) {
// Continue to combine rectangular clips in the same transform space.
pending_combined_clip_rect->Intersect(sub_clip->ClipRect().Rect());
if (CombineClip(sub_clip, pending_combined_clip_rect)) {
// Continue to combine.
lowest_combined_clip_node = sub_clip;
continue;
}
if (pending_combined_clip_rect) {
StartCombinedClip(*pending_combined_clip_rect, lowest_combined_clip_node);
lowest_combined_clip_node = nullptr;
pending_combined_clip_rect.reset();
}
if (has_rounded_clip_or_clip_path) {
// The clip can't be combined with others.
StartSingleClip(sub_clip);
} else {
// Start to combine clips.
pending_combined_clip_rect = sub_clip->ClipRect().Rect();
// |sub_clip| can't be combined to previous clips. Output the current
// combined clip, and start new combination.
StartClip(pending_combined_clip_rect, lowest_combined_clip_node);
pending_combined_clip_rect = sub_clip->ClipRect();
lowest_combined_clip_node = sub_clip;
}
}
if (pending_combined_clip_rect)
StartCombinedClip(*pending_combined_clip_rect, lowest_combined_clip_node);
StartClip(pending_combined_clip_rect, lowest_combined_clip_node);
DCHECK_EQ(current_clip_, target_clip);
}
void ConversionContext::StartCombinedClip(
const FloatRect& combined_clip_rect,
void ConversionContext::StartClip(
const FloatRoundedRect& combined_clip_rect,
const ClipPaintPropertyNode* lowest_combined_clip_node) {
if (lowest_combined_clip_node->LocalTransformSpace() != current_transform_)
EndTransform();
......@@ -367,37 +382,23 @@ void ConversionContext::StartCombinedClip(
cc_list_.push<cc::SaveOp>();
ApplyTransform(lowest_combined_clip_node->LocalTransformSpace());
const bool antialias = true;
cc_list_.push<cc::ClipRectOp>(combined_clip_rect, SkClipOp::kIntersect,
antialias);
cc_list_.EndPaintOfPairedBegin();
PushState(StateEntry::kClip, 1);
current_clip_ = lowest_combined_clip_node;
current_transform_ = lowest_combined_clip_node->LocalTransformSpace();
}
void ConversionContext::StartSingleClip(const ClipPaintPropertyNode* clip) {
if (clip->LocalTransformSpace() != current_transform_)
EndTransform();
cc_list_.StartPaint();
cc_list_.push<cc::SaveOp>();
ApplyTransform(clip->LocalTransformSpace());
const bool antialias = true;
cc_list_.push<cc::ClipRectOp>(static_cast<SkRect>(clip->ClipRect().Rect()),
SkClipOp::kIntersect, antialias);
if (clip->ClipRect().IsRounded()) {
cc_list_.push<cc::ClipRRectOp>(static_cast<SkRRect>(clip->ClipRect()),
SkClipOp::kIntersect, antialias);
}
if (clip->ClipPath()) {
cc_list_.push<cc::ClipPathOp>(clip->ClipPath()->GetSkPath(),
if (combined_clip_rect.IsRounded()) {
cc_list_.push<cc::ClipRRectOp>(combined_clip_rect, SkClipOp::kIntersect,
antialias);
} else {
cc_list_.push<cc::ClipRectOp>(combined_clip_rect.Rect(),
SkClipOp::kIntersect, antialias);
}
if (lowest_combined_clip_node->ClipPath()) {
cc_list_.push<cc::ClipPathOp>(
lowest_combined_clip_node->ClipPath()->GetSkPath(),
SkClipOp::kIntersect, antialias);
}
cc_list_.EndPaintOfPairedBegin();
PushState(StateEntry::kClip, 1);
current_clip_ = clip;
current_transform_ = clip->LocalTransformSpace();
current_clip_ = lowest_combined_clip_node;
current_transform_ = lowest_combined_clip_node->LocalTransformSpace();
}
void ConversionContext::SwitchToEffect(
......
......@@ -129,6 +129,22 @@ class PaintRecordMatcher
EXPECT_EQ(y, translate->dy); \
} while (false)
#define EXPECT_CLIP(r, op_buffer, index) \
do { \
const auto* clip_op = \
(op_buffer).GetOpAtForTesting<cc::ClipRectOp>(index); \
ASSERT_NE(nullptr, clip_op); \
EXPECT_EQ(SkRect(r), clip_op->rect); \
} while (false)
#define EXPECT_ROUNDED_CLIP(r, op_buffer, index) \
do { \
const auto* clip_op = \
(op_buffer).GetOpAtForTesting<cc::ClipRRectOp>(index); \
ASSERT_NE(nullptr, clip_op); \
EXPECT_EQ(SkRRect(r), clip_op->rrect); \
} while (false)
// Convenient shorthands.
const TransformPaintPropertyNode* t0() {
return TransformPaintPropertyNode::Root();
......@@ -691,15 +707,12 @@ TEST_F(PaintChunksToCcLayerTest, EmptyEffectsAreStored) {
TEST_F(PaintChunksToCcLayerTest, CombineClips) {
FloatRoundedRect clip_rect(0, 0, 100, 100);
FloatSize corner(5, 5);
FloatRoundedRect rounded_clip_rect(clip_rect.Rect(), corner, corner, corner,
corner);
auto t1 = CreateTransform(t0(), TransformationMatrix().Scale(2.f));
auto c1 = CreateClip(c0(), t0(), clip_rect);
auto c2 = CreateClip(c1, t0(), clip_rect);
auto c3 = CreateClip(c2, t1, clip_rect);
auto c4 = CreateClip(c3, t1, clip_rect);
auto c5 = CreateClip(c4, t1, rounded_clip_rect);
auto c5 = CreateClipPathClip(c4, t1, clip_rect);
auto c6 = CreateClip(c5, t1, clip_rect);
TestChunks chunks;
......@@ -715,21 +728,65 @@ TEST_F(PaintChunksToCcLayerTest, CombineClips) {
EXPECT_THAT(
*output,
PaintRecordMatcher::Make(
{cc::PaintOpType::Save, cc::PaintOpType::ClipRect, // <c1+c2>
cc::PaintOpType::Save, cc::PaintOpType::Concat, // <t1
cc::PaintOpType::ClipRect, // c3+c4>
cc::PaintOpType::Save, cc::PaintOpType::ClipRect,
cc::PaintOpType::ClipRRect, // <c5>
cc::PaintOpType::Save, cc::PaintOpType::ClipRect, // <c6>
cc::PaintOpType::DrawRecord, // <p0/>
cc::PaintOpType::Restore, // </c6>
cc::PaintOpType::Restore, // </c5>
cc::PaintOpType::Restore, // </c3+c4 t1>
cc::PaintOpType::Save, cc::PaintOpType::Concat, // <t1
cc::PaintOpType::ClipRect, // c3>
cc::PaintOpType::DrawRecord, // <p1/>
cc::PaintOpType::Restore, // </c3 t1>
cc::PaintOpType::Restore})); // </c1+c2>
{cc::PaintOpType::Save, cc::PaintOpType::ClipRect, // <c1+c2>
cc::PaintOpType::Save, cc::PaintOpType::Concat, // <t1
cc::PaintOpType::ClipRect, cc::PaintOpType::ClipPath, // c3+c4+c5>
cc::PaintOpType::Save, cc::PaintOpType::ClipRect, // <c6>
cc::PaintOpType::DrawRecord, // <p0/>
cc::PaintOpType::Restore, // </c6>
cc::PaintOpType::Restore, // </c3+c4+c5 t1>
cc::PaintOpType::Save, cc::PaintOpType::Concat, // <t1
cc::PaintOpType::ClipRect, // c3>
cc::PaintOpType::DrawRecord, // <p1/>
cc::PaintOpType::Restore, // </c3 t1>
cc::PaintOpType::Restore})); // </c1+c2>
}
TEST_F(PaintChunksToCcLayerTest, CombineClipsWithRoundedRects) {
FloatRoundedRect clip_rect(0, 0, 100, 100);
FloatSize corner(5, 5);
FloatRoundedRect big_rounded_clip_rect(FloatRect(0, 0, 200, 200), corner,
corner, corner, corner);
FloatRoundedRect small_rounded_clip_rect(FloatRect(0, 0, 100, 100), corner,
corner, corner, corner);
auto c1 = CreateClip(c0(), t0(), clip_rect);
auto c2 = CreateClip(c1, t0(), small_rounded_clip_rect);
auto c3 = CreateClip(c2, t0(), clip_rect);
auto c4 = CreateClip(c3, t0(), big_rounded_clip_rect);
auto c5 = CreateClip(c4, t0(), clip_rect);
auto c6 = CreateClip(c5, t0(), big_rounded_clip_rect);
auto c7 = CreateClip(c6, t0(), small_rounded_clip_rect);
TestChunks chunks;
chunks.AddChunk(t0(), c7.get(), e0());
sk_sp<PaintRecord> output =
PaintChunksToCcLayer::Convert(
chunks.chunks, PropertyTreeState(t0(), c0(), e0()), gfx::Vector2dF(),
chunks.items, cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer)
->ReleaseAsRecord();
EXPECT_THAT(
*output,
PaintRecordMatcher::Make(
{cc::PaintOpType::Save, cc::PaintOpType::ClipRRect, // <c1+c2+c3>
cc::PaintOpType::Save, cc::PaintOpType::ClipRRect, // <c4>
cc::PaintOpType::Save, cc::PaintOpType::ClipRect, // <c5>
cc::PaintOpType::Save, cc::PaintOpType::ClipRRect, // <c6>
cc::PaintOpType::Save, cc::PaintOpType::ClipRRect, // <c7>
cc::PaintOpType::DrawRecord, // <p0/>
cc::PaintOpType::Restore, // </c7>
cc::PaintOpType::Restore, // </c6>
cc::PaintOpType::Restore, // </c5>
cc::PaintOpType::Restore, // </c4>
cc::PaintOpType::Restore})); // </c1+c2+c3>
EXPECT_ROUNDED_CLIP(small_rounded_clip_rect, *output, 1);
EXPECT_ROUNDED_CLIP(big_rounded_clip_rect, *output, 3);
EXPECT_CLIP(clip_rect.Rect(), *output, 5);
EXPECT_ROUNDED_CLIP(big_rounded_clip_rect, *output, 7);
EXPECT_ROUNDED_CLIP(small_rounded_clip_rect, *output, 9);
}
TEST_F(PaintChunksToCcLayerTest, ChunksSamePropertyTreeState) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment