Skip to content

Commit c4aff05

Browse files
committed
Manually revert: cc: Support ClipRRect in SolidColorAnalyzer
This CL reverts a previous CL here: https://chromium-review.googlesource.com/c/chromium/src/+/591913 The previous CL caused a regression on Mac. GL renderer has difficulties dealing with RPDQs converted from SolidColorDrawQuads, this CL will make mask layer produce solid quads. We need to keep it reverted before we fix the gl renderer bug. NOTRY=true [email protected] (cherry picked from commit 8d1900b) Bug: 760807 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I844d02886329acbbbebd98200f8d2f90681adb8a Reviewed-on: https://chromium-review.googlesource.com/653317 Commit-Queue: Xida Chen <[email protected]> Reviewed-by: Vladimir Levin <[email protected]> Reviewed-by: Xianda Sun <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#500036} Reviewed-on: https://chromium-review.googlesource.com/653803 Reviewed-by: Xida Chen <[email protected]> Cr-Commit-Position: refs/branch-heads/3202@{#55} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
1 parent 12642a1 commit c4aff05

File tree

2 files changed

+23
-154
lines changed

2 files changed

+23
-154
lines changed

cc/paint/solid_color_analyzer.cc

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ bool IsSolidColorPaint(const PaintFlags& flags) {
4545
flags.getStyle() == PaintFlags::kFill_Style;
4646
}
4747

48-
// Returns true if the specified |drawn_shape| will cover the entire canvas
49-
// and that the canvas is not clipped (i.e. it covers ALL of the canvas).
50-
template <typename T>
51-
bool IsFullQuad(const SkCanvas& canvas, const T& drawn_shape) {
52-
if (!canvas.isClipRect())
53-
return false;
54-
48+
// Returns true if the specified drawn_rect will cover the entire canvas, and
49+
// that the canvas is not clipped (i.e. it covers ALL of the canvas).
50+
bool IsFullQuad(const SkCanvas& canvas, const SkRect& drawn_rect) {
5551
SkIRect clip_irect;
5652
if (!canvas.getDeviceClipBounds(&clip_irect))
5753
return false;
@@ -66,13 +62,11 @@ bool IsFullQuad(const SkCanvas& canvas, const T& drawn_shape) {
6662
if (!matrix.rectStaysRect())
6763
return false;
6864

69-
SkMatrix inverse;
70-
if (!matrix.invert(&inverse))
71-
return false;
72-
73-
SkRect clip_rect = SkRect::Make(clip_irect);
74-
inverse.mapRect(&clip_rect, clip_rect);
75-
return drawn_shape.contains(clip_rect);
65+
SkRect device_rect;
66+
matrix.mapRect(&device_rect, drawn_rect);
67+
SkRect clip_rect;
68+
clip_rect.set(clip_irect);
69+
return device_rect.contains(clip_rect);
7670
}
7771

7872
void CheckIfSolidColor(const SkCanvas& canvas,
@@ -103,19 +97,18 @@ void CheckIfSolidColor(const SkCanvas& canvas,
10397
}
10498
}
10599

106-
template <typename T>
107-
void CheckIfSolidShape(const SkCanvas& canvas,
108-
const T& shape,
109-
const PaintFlags& flags,
110-
bool* is_solid_color,
111-
bool* is_transparent,
112-
SkColor* color) {
100+
void CheckIfSolidRect(const SkCanvas& canvas,
101+
const SkRect& rect,
102+
const PaintFlags& flags,
103+
bool* is_solid_color,
104+
bool* is_transparent,
105+
SkColor* color) {
113106
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
114-
"SolidColorAnalyzer::CheckIfSolidShape");
107+
"SolidColorAnalyzer::HandleDrawRect");
115108
if (flags.nothingToDraw())
116109
return;
117110

118-
bool does_cover_canvas = IsFullQuad(canvas, shape);
111+
bool does_cover_canvas = IsFullQuad(canvas, rect);
119112
SkBlendMode blendmode = flags.getBlendMode();
120113
if (does_cover_canvas && ActsLikeClear(blendmode, flags.getAlpha()))
121114
*is_transparent = true;
@@ -130,13 +123,6 @@ void CheckIfSolidShape(const SkCanvas& canvas,
130123
}
131124
}
132125

133-
bool CheckIfRRectClipCoversCanvas(const SkCanvas& canvas,
134-
const SkRRect& rrect) {
135-
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
136-
"SolidColorAnalyzer::CheckIfRRectClipCoversCanvas");
137-
return IsFullQuad(canvas, rrect);
138-
}
139-
140126
} // namespace
141127

142128
base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
@@ -174,7 +160,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
174160
stack.emplace_back(PaintOpBuffer::CompositeIterator(buffer, offsets),
175161
canvas.getTotalMatrix(), canvas.getSaveCount());
176162

177-
int num_draw_ops = 0;
163+
int num_ops = 0;
178164
while (!stack.empty()) {
179165
auto& frame = stack.back();
180166
if (!frame.iter) {
@@ -205,15 +191,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
205191
case PaintOpType::DrawOval:
206192
case PaintOpType::DrawPath:
207193
return base::nullopt;
208-
// TODO(vmpstr): Add more tests on exceeding max_ops_to_analyze.
209-
case PaintOpType::DrawRRect: {
210-
if (++num_draw_ops > max_ops_to_analyze)
211-
return base::nullopt;
212-
const DrawRRectOp* rrect_op = static_cast<const DrawRRectOp*>(op);
213-
CheckIfSolidShape(canvas, rrect_op->rrect, rrect_op->flags, &is_solid,
214-
&is_transparent, &color);
215-
break;
216-
}
194+
case PaintOpType::DrawRRect:
217195
case PaintOpType::DrawTextBlob:
218196
// Anything that has to do a save layer is probably not solid. As it will
219197
// likely need more than one draw op.
@@ -224,27 +202,18 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
224202
// cover the canvas.
225203
// TODO(vmpstr): We could investigate handling these.
226204
case PaintOpType::ClipPath:
205+
case PaintOpType::ClipRRect:
227206
return base::nullopt;
228-
case PaintOpType::ClipRRect: {
229-
const ClipRRectOp* rrect_op = static_cast<const ClipRRectOp*>(op);
230-
bool does_cover_canvas =
231-
CheckIfRRectClipCoversCanvas(canvas, rrect_op->rrect);
232-
// If the clip covers the full canvas, we can treat it as if there's no
233-
// clip at all and continue, otherwise this is no longer a solid color.
234-
if (!does_cover_canvas)
235-
return base::nullopt;
236-
break;
237-
}
238207
case PaintOpType::DrawRect: {
239-
if (++num_draw_ops > max_ops_to_analyze)
208+
if (++num_ops > max_ops_to_analyze)
240209
return base::nullopt;
241210
const DrawRectOp* rect_op = static_cast<const DrawRectOp*>(op);
242-
CheckIfSolidShape(canvas, rect_op->rect, rect_op->flags, &is_solid,
243-
&is_transparent, &color);
211+
CheckIfSolidRect(canvas, rect_op->rect, rect_op->flags, &is_solid,
212+
&is_transparent, &color);
244213
break;
245214
}
246215
case PaintOpType::DrawColor: {
247-
if (++num_draw_ops > max_ops_to_analyze)
216+
if (++num_ops > max_ops_to_analyze)
248217
return base::nullopt;
249218
const DrawColorOp* color_op = static_cast<const DrawColorOp*>(op);
250219
CheckIfSolidColor(canvas, color_op->color, color_op->mode, &is_solid,

cc/paint/solid_color_analyzer_unittest.cc

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ class SolidColorAnalyzerTest : public testing::Test {
2929
buffer_ = nullptr;
3030
}
3131

32-
void Reset() {
33-
TearDown();
34-
SetUp();
35-
}
36-
3732
void Initialize(const gfx::Rect& rect = gfx::Rect(0, 0, 100, 100)) {
3833
canvas_.emplace(display_item_list_.get(), gfx::RectToSkRect(rect));
3934
rect_ = rect;
@@ -132,21 +127,6 @@ TEST_F(SolidColorAnalyzerTest, DrawRect) {
132127
EXPECT_EQ(color, GetColor());
133128
}
134129

135-
// TODO(vmpstr): Generalize the DrawRect test cases so that we can test both
136-
// Rect and RRect.
137-
TEST_F(SolidColorAnalyzerTest, DrawRRect) {
138-
SkRect rect = SkRect::MakeWH(200, 200);
139-
SkRRect rrect;
140-
rrect.setRectXY(rect, 5, 5);
141-
gfx::Rect canvas_rect(5, 5, 190, 190);
142-
Initialize(canvas_rect);
143-
PaintFlags flags;
144-
SkColor color = SkColorSetARGB(255, 11, 22, 33);
145-
flags.setColor(color);
146-
canvas()->drawRRect(rrect, flags);
147-
EXPECT_EQ(color, GetColor());
148-
}
149-
150130
TEST_F(SolidColorAnalyzerTest, DrawRectClipped) {
151131
Initialize();
152132
PaintFlags flags;
@@ -298,85 +278,5 @@ TEST_F(SolidColorAnalyzerTest, SaveLayer) {
298278
EXPECT_FALSE(IsSolidColor());
299279
}
300280

301-
TEST_F(SolidColorAnalyzerTest, ClipRRectCoversCanvas) {
302-
SkVector radii[4] = {
303-
SkVector::Make(10.0, 15.0), SkVector::Make(20.0, 25.0),
304-
SkVector::Make(30.0, 35.0), SkVector::Make(40.0, 45.0),
305-
};
306-
307-
SkVector radii_scale[4] = {
308-
SkVector::Make(100.0, 150.0), SkVector::Make(200.0, 250.0),
309-
SkVector::Make(300.0, 350.0), SkVector::Make(400.0, 450.0),
310-
};
311-
312-
int rr_size = 600;
313-
int canvas_size = 255;
314-
gfx::Rect canvas_rect(canvas_size, canvas_size);
315-
PaintFlags flags;
316-
flags.setColor(SK_ColorWHITE);
317-
318-
struct {
319-
SkVector offset;
320-
SkVector offset_scale;
321-
bool expected;
322-
} cases[] = {
323-
// Not within bounding box of |rr|.
324-
{SkVector::Make(100, 100), SkVector::Make(100, 100), false},
325-
326-
// Intersects UL corner.
327-
{SkVector::Make(0, 0), SkVector::Make(0, 0), false},
328-
329-
// Between UL and UR.
330-
{SkVector::Make(-50, 0), SkVector::Make(-50, -15), true},
331-
332-
// Intersects UR corner.
333-
{SkVector::Make(canvas_size - rr_size, 0),
334-
SkVector::Make(canvas_size - rr_size, 0), false},
335-
336-
// Between UR and LR.
337-
{SkVector::Make(canvas_size - rr_size, -50), SkVector::Make(-305, -80),
338-
true},
339-
340-
// Intersects LR corner.
341-
{SkVector::Make(canvas_size - rr_size, canvas_size - rr_size),
342-
SkVector::Make(canvas_size - rr_size, canvas_size - rr_size), false},
343-
344-
// Between LL and LR
345-
{SkVector::Make(-50, canvas_size - rr_size), SkVector::Make(-205, -310),
346-
true},
347-
348-
// Intersects LL corner
349-
{SkVector::Make(0, canvas_size - rr_size),
350-
SkVector::Make(0, canvas_size - rr_size), false},
351-
352-
// Between UL and LL
353-
{SkVector::Make(0, -50), SkVector::Make(-15, -60), true},
354-
355-
// In center
356-
{SkVector::Make(-100, -100), SkVector::Make(-100, -100), true},
357-
};
358-
359-
for (int case_scale = 0; case_scale < 2; ++case_scale) {
360-
bool scaled = case_scale > 0;
361-
for (size_t i = 0; i < arraysize(cases); ++i) {
362-
Reset();
363-
Initialize(canvas_rect);
364-
365-
SkRect bounding_rect = SkRect::MakeXYWH(
366-
scaled ? cases[i].offset_scale.x() : cases[i].offset.x(),
367-
scaled ? cases[i].offset_scale.y() : cases[i].offset.y(), rr_size,
368-
rr_size);
369-
370-
SkRRect rr;
371-
rr.setRectRadii(bounding_rect, scaled ? radii_scale : radii);
372-
373-
canvas()->clipRRect(rr, SkClipOp::kIntersect, false);
374-
canvas()->drawRect(RectToSkRect(canvas_rect), flags);
375-
EXPECT_EQ(cases[i].expected, IsSolidColor())
376-
<< "Case " << i << ", " << scaled << " failed.";
377-
}
378-
}
379-
}
380-
381281
} // namespace
382282
} // namespace cc

0 commit comments

Comments
 (0)