OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/playback/image_hijack_canvas.h" | 5 #include "cc/playback/image_hijack_canvas.h" |
6 | 6 |
7 #include "base/optional.h" | 7 #include "base/optional.h" |
| 8 #include "base/trace_event/trace_event.h" |
8 #include "cc/playback/discardable_image_map.h" | 9 #include "cc/playback/discardable_image_map.h" |
9 #include "cc/tiles/image_decode_cache.h" | 10 #include "cc/tiles/image_decode_cache.h" |
10 #include "third_party/skia/include/core/SkPath.h" | 11 #include "third_party/skia/include/core/SkPath.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 namespace { | 14 namespace { |
14 | 15 |
15 SkIRect RoundOutRect(const SkRect& rect) { | 16 SkIRect RoundOutRect(const SkRect& rect) { |
16 SkIRect result; | 17 SkIRect result; |
17 rect.roundOut(&result); | 18 rect.roundOut(&result); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 int height, | 131 int height, |
131 ImageDecodeCache* image_decode_cache, | 132 ImageDecodeCache* image_decode_cache, |
132 const ImageIdFlatSet* images_to_skip) | 133 const ImageIdFlatSet* images_to_skip) |
133 : SkNWayCanvas(width, height), | 134 : SkNWayCanvas(width, height), |
134 image_decode_cache_(image_decode_cache), | 135 image_decode_cache_(image_decode_cache), |
135 images_to_skip_(images_to_skip) {} | 136 images_to_skip_(images_to_skip) {} |
136 | 137 |
137 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, | 138 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, |
138 const SkMatrix* matrix, | 139 const SkMatrix* matrix, |
139 const SkPaint* paint) { | 140 const SkPaint* paint) { |
| 141 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 142 "ImageHijackCanvas::onDrawPicture"); |
140 // Ensure that pictures are unpacked by this canvas, instead of being | 143 // Ensure that pictures are unpacked by this canvas, instead of being |
141 // forwarded to the raster canvas. | 144 // forwarded to the raster canvas. |
142 SkCanvas::onDrawPicture(picture, matrix, paint); | 145 SkCanvas::onDrawPicture(picture, matrix, paint); |
143 } | 146 } |
144 | 147 |
145 void ImageHijackCanvas::onDrawImage(const SkImage* image, | 148 void ImageHijackCanvas::onDrawImage(const SkImage* image, |
146 SkScalar x, | 149 SkScalar x, |
147 SkScalar y, | 150 SkScalar y, |
148 const SkPaint* paint) { | 151 const SkPaint* paint) { |
| 152 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 153 "ImageHijackCanvas::onDrawImage"); |
149 if (!image->isLazyGenerated()) { | 154 if (!image->isLazyGenerated()) { |
150 DCHECK(!ShouldSkipImage(image)); | 155 DCHECK(!ShouldSkipImage(image)); |
151 SkNWayCanvas::onDrawImage(image, x, y, paint); | 156 SkNWayCanvas::onDrawImage(image, x, y, paint); |
152 return; | 157 return; |
153 } | 158 } |
154 | 159 |
155 if (ShouldSkipImage(image)) | 160 if (ShouldSkipImage(image)) |
156 return; | 161 return; |
157 | 162 |
158 SkMatrix ctm = getTotalMatrix(); | 163 SkMatrix ctm = getTotalMatrix(); |
(...skipping 18 matching lines...) Expand all Loading... |
177 SkNWayCanvas::onDrawImage(decoded_image.image().get(), x, y, decoded_paint); | 182 SkNWayCanvas::onDrawImage(decoded_image.image().get(), x, y, decoded_paint); |
178 if (need_scale) | 183 if (need_scale) |
179 SkNWayCanvas::restore(); | 184 SkNWayCanvas::restore(); |
180 } | 185 } |
181 | 186 |
182 void ImageHijackCanvas::onDrawImageRect(const SkImage* image, | 187 void ImageHijackCanvas::onDrawImageRect(const SkImage* image, |
183 const SkRect* src, | 188 const SkRect* src, |
184 const SkRect& dst, | 189 const SkRect& dst, |
185 const SkPaint* paint, | 190 const SkPaint* paint, |
186 SrcRectConstraint constraint) { | 191 SrcRectConstraint constraint) { |
| 192 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 193 "ImageHijackCanvas::onDrawImageRect"); |
187 if (!image->isLazyGenerated()) { | 194 if (!image->isLazyGenerated()) { |
188 DCHECK(!ShouldSkipImage(image)); | 195 DCHECK(!ShouldSkipImage(image)); |
189 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint); | 196 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint); |
190 return; | 197 return; |
191 } | 198 } |
192 | 199 |
193 if (ShouldSkipImage(image)) | 200 if (ShouldSkipImage(image)) |
194 return; | 201 return; |
195 | 202 |
196 SkRect src_storage; | 203 SkRect src_storage; |
(...skipping 21 matching lines...) Expand all Loading... |
218 float y_scale = decoded_image.scale_adjustment().height(); | 225 float y_scale = decoded_image.scale_adjustment().height(); |
219 adjusted_src = SkRect::MakeXYWH( | 226 adjusted_src = SkRect::MakeXYWH( |
220 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale, | 227 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale, |
221 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale); | 228 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale); |
222 } | 229 } |
223 SkNWayCanvas::onDrawImageRect(decoded_image.image().get(), &adjusted_src, dst, | 230 SkNWayCanvas::onDrawImageRect(decoded_image.image().get(), &adjusted_src, dst, |
224 decoded_paint, constraint); | 231 decoded_paint, constraint); |
225 } | 232 } |
226 | 233 |
227 void ImageHijackCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { | 234 void ImageHijackCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { |
| 235 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 236 "ImageHijackCanvas::onDrawRect"); |
228 if (ShouldSkipImageInPaint(paint)) | 237 if (ShouldSkipImageInPaint(paint)) |
229 return; | 238 return; |
230 | 239 |
231 base::Optional<ScopedImagePaint> image_paint = | 240 base::Optional<ScopedImagePaint> image_paint = |
232 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 241 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
233 if (!image_paint.has_value()) { | 242 if (!image_paint.has_value()) { |
234 SkNWayCanvas::onDrawRect(r, paint); | 243 SkNWayCanvas::onDrawRect(r, paint); |
235 return; | 244 return; |
236 } | 245 } |
237 SkNWayCanvas::onDrawRect(r, image_paint.value().paint()); | 246 SkNWayCanvas::onDrawRect(r, image_paint.value().paint()); |
238 } | 247 } |
239 | 248 |
240 void ImageHijackCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | 249 void ImageHijackCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
| 250 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 251 "ImageHijackCanvas::onDrawPath"); |
241 if (ShouldSkipImageInPaint(paint)) | 252 if (ShouldSkipImageInPaint(paint)) |
242 return; | 253 return; |
243 | 254 |
244 base::Optional<ScopedImagePaint> image_paint = | 255 base::Optional<ScopedImagePaint> image_paint = |
245 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 256 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
246 if (!image_paint.has_value()) { | 257 if (!image_paint.has_value()) { |
247 SkNWayCanvas::onDrawPath(path, paint); | 258 SkNWayCanvas::onDrawPath(path, paint); |
248 return; | 259 return; |
249 } | 260 } |
250 SkNWayCanvas::onDrawPath(path, image_paint.value().paint()); | 261 SkNWayCanvas::onDrawPath(path, image_paint.value().paint()); |
251 } | 262 } |
252 | 263 |
253 void ImageHijackCanvas::onDrawOval(const SkRect& r, const SkPaint& paint) { | 264 void ImageHijackCanvas::onDrawOval(const SkRect& r, const SkPaint& paint) { |
| 265 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 266 "ImageHijackCanvas::onDrawOval"); |
254 if (ShouldSkipImageInPaint(paint)) | 267 if (ShouldSkipImageInPaint(paint)) |
255 return; | 268 return; |
256 | 269 |
257 base::Optional<ScopedImagePaint> image_paint = | 270 base::Optional<ScopedImagePaint> image_paint = |
258 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 271 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
259 if (!image_paint.has_value()) { | 272 if (!image_paint.has_value()) { |
260 SkNWayCanvas::onDrawOval(r, paint); | 273 SkNWayCanvas::onDrawOval(r, paint); |
261 return; | 274 return; |
262 } | 275 } |
263 SkNWayCanvas::onDrawOval(r, image_paint.value().paint()); | 276 SkNWayCanvas::onDrawOval(r, image_paint.value().paint()); |
264 } | 277 } |
265 | 278 |
266 void ImageHijackCanvas::onDrawArc(const SkRect& r, | 279 void ImageHijackCanvas::onDrawArc(const SkRect& r, |
267 SkScalar start_angle, | 280 SkScalar start_angle, |
268 SkScalar sweep_angle, | 281 SkScalar sweep_angle, |
269 bool use_center, | 282 bool use_center, |
270 const SkPaint& paint) { | 283 const SkPaint& paint) { |
| 284 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 285 "ImageHijackCanvas::onDrawArc"); |
271 if (ShouldSkipImageInPaint(paint)) | 286 if (ShouldSkipImageInPaint(paint)) |
272 return; | 287 return; |
273 | 288 |
274 base::Optional<ScopedImagePaint> image_paint = | 289 base::Optional<ScopedImagePaint> image_paint = |
275 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 290 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
276 if (!image_paint.has_value()) { | 291 if (!image_paint.has_value()) { |
277 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, paint); | 292 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, paint); |
278 return; | 293 return; |
279 } | 294 } |
280 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, | 295 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, |
281 image_paint.value().paint()); | 296 image_paint.value().paint()); |
282 } | 297 } |
283 | 298 |
284 void ImageHijackCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) { | 299 void ImageHijackCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) { |
| 300 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 301 "ImageHijackCanvas::onDrawRRect"); |
285 if (ShouldSkipImageInPaint(paint)) | 302 if (ShouldSkipImageInPaint(paint)) |
286 return; | 303 return; |
287 | 304 |
288 base::Optional<ScopedImagePaint> image_paint = | 305 base::Optional<ScopedImagePaint> image_paint = |
289 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 306 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
290 if (!image_paint.has_value()) { | 307 if (!image_paint.has_value()) { |
291 SkNWayCanvas::onDrawRRect(rr, paint); | 308 SkNWayCanvas::onDrawRRect(rr, paint); |
292 return; | 309 return; |
293 } | 310 } |
294 SkNWayCanvas::onDrawRRect(rr, image_paint.value().paint()); | 311 SkNWayCanvas::onDrawRRect(rr, image_paint.value().paint()); |
295 } | 312 } |
296 | 313 |
297 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, | 314 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, |
298 const SkIRect& center, | 315 const SkIRect& center, |
299 const SkRect& dst, | 316 const SkRect& dst, |
300 const SkPaint* paint) { | 317 const SkPaint* paint) { |
301 // No cc embedder issues image nine calls. | 318 // No cc embedder issues image nine calls. |
302 NOTREACHED(); | 319 NOTREACHED(); |
303 } | 320 } |
304 | 321 |
305 bool ImageHijackCanvas::ShouldSkipImage(const SkImage* image) const { | 322 bool ImageHijackCanvas::ShouldSkipImage(const SkImage* image) const { |
306 return images_to_skip_->find(image->uniqueID()) != images_to_skip_->end(); | 323 bool skip = |
| 324 images_to_skip_->find(image->uniqueID()) != images_to_skip_->end(); |
| 325 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 326 "ImageHijackCanvas::ShouldSkipImage", "imageId", |
| 327 image->uniqueID(), "skip", skip); |
| 328 return skip; |
307 } | 329 } |
308 | 330 |
309 bool ImageHijackCanvas::ShouldSkipImageInPaint(const SkPaint& paint) const { | 331 bool ImageHijackCanvas::ShouldSkipImageInPaint(const SkPaint& paint) const { |
310 const SkImage* image = GetImageInPaint(paint); | 332 const SkImage* image = GetImageInPaint(paint); |
311 return image ? ShouldSkipImage(image) : false; | 333 return image ? ShouldSkipImage(image) : false; |
312 } | 334 } |
313 | 335 |
314 } // namespace cc | 336 } // namespace cc |
OLD | NEW |