@@ -45,13 +45,9 @@ bool IsSolidColorPaint(const PaintFlags& flags) {
45
45
flags.getStyle () == PaintFlags::kFill_Style ;
46
46
}
47
47
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) {
55
51
SkIRect clip_irect;
56
52
if (!canvas.getDeviceClipBounds (&clip_irect))
57
53
return false ;
@@ -66,13 +62,11 @@ bool IsFullQuad(const SkCanvas& canvas, const T& drawn_shape) {
66
62
if (!matrix.rectStaysRect ())
67
63
return false ;
68
64
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);
76
70
}
77
71
78
72
void CheckIfSolidColor (const SkCanvas& canvas,
@@ -103,19 +97,18 @@ void CheckIfSolidColor(const SkCanvas& canvas,
103
97
}
104
98
}
105
99
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) {
113
106
TRACE_EVENT0 (TRACE_DISABLED_BY_DEFAULT (" cc.debug" ),
114
- " SolidColorAnalyzer::CheckIfSolidShape " );
107
+ " SolidColorAnalyzer::HandleDrawRect " );
115
108
if (flags.nothingToDraw ())
116
109
return ;
117
110
118
- bool does_cover_canvas = IsFullQuad (canvas, shape );
111
+ bool does_cover_canvas = IsFullQuad (canvas, rect );
119
112
SkBlendMode blendmode = flags.getBlendMode ();
120
113
if (does_cover_canvas && ActsLikeClear (blendmode, flags.getAlpha ()))
121
114
*is_transparent = true ;
@@ -130,13 +123,6 @@ void CheckIfSolidShape(const SkCanvas& canvas,
130
123
}
131
124
}
132
125
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
-
140
126
} // namespace
141
127
142
128
base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor (
@@ -174,7 +160,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
174
160
stack.emplace_back (PaintOpBuffer::CompositeIterator (buffer, offsets),
175
161
canvas.getTotalMatrix (), canvas.getSaveCount ());
176
162
177
- int num_draw_ops = 0 ;
163
+ int num_ops = 0 ;
178
164
while (!stack.empty ()) {
179
165
auto & frame = stack.back ();
180
166
if (!frame.iter ) {
@@ -205,15 +191,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
205
191
case PaintOpType::DrawOval:
206
192
case PaintOpType::DrawPath:
207
193
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:
217
195
case PaintOpType::DrawTextBlob:
218
196
// Anything that has to do a save layer is probably not solid. As it will
219
197
// likely need more than one draw op.
@@ -224,27 +202,18 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
224
202
// cover the canvas.
225
203
// TODO(vmpstr): We could investigate handling these.
226
204
case PaintOpType::ClipPath:
205
+ case PaintOpType::ClipRRect:
227
206
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
- }
238
207
case PaintOpType::DrawRect: {
239
- if (++num_draw_ops > max_ops_to_analyze)
208
+ if (++num_ops > max_ops_to_analyze)
240
209
return base::nullopt;
241
210
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);
244
213
break ;
245
214
}
246
215
case PaintOpType::DrawColor: {
247
- if (++num_draw_ops > max_ops_to_analyze)
216
+ if (++num_ops > max_ops_to_analyze)
248
217
return base::nullopt;
249
218
const DrawColorOp* color_op = static_cast <const DrawColorOp*>(op);
250
219
CheckIfSolidColor (canvas, color_op->color , color_op->mode , &is_solid,
0 commit comments