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 "cc/playback/discardable_image_map.h" | 8 #include "cc/playback/discardable_image_map.h" |
9 #include "cc/tiles/image_decode_cache.h" | 9 #include "cc/tiles/image_decode_cache.h" |
10 #include "third_party/skia/include/core/SkPath.h" | 10 #include "third_party/skia/include/core/SkPath.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 private: | 113 private: |
114 ScopedImagePaint(ScopedDecodedImageLock lock, SkPaint paint) | 114 ScopedImagePaint(ScopedDecodedImageLock lock, SkPaint paint) |
115 : lock_(std::move(lock)), paint_(std::move(paint)) {} | 115 : lock_(std::move(lock)), paint_(std::move(paint)) {} |
116 | 116 |
117 ScopedDecodedImageLock lock_; | 117 ScopedDecodedImageLock lock_; |
118 SkPaint paint_; | 118 SkPaint paint_; |
119 }; | 119 }; |
120 | 120 |
121 } // namespace | 121 } // namespace |
122 | 122 |
123 ImageHijackCanvas::ImageHijackCanvas(int width, | 123 ImageHijackCanvas::ImageHijackCanvas( |
124 int height, | 124 int width, |
125 ImageDecodeCache* image_decode_cache) | 125 int height, |
126 : SkNWayCanvas(width, height), image_decode_cache_(image_decode_cache) {} | 126 ImageDecodeCache* image_decode_cache, |
| 127 const std::unordered_set<ImageId>* images_to_skip) |
| 128 : SkNWayCanvas(width, height), |
| 129 image_decode_cache_(image_decode_cache), |
| 130 images_to_skip_(images_to_skip) {} |
127 | 131 |
128 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, | 132 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, |
129 const SkMatrix* matrix, | 133 const SkMatrix* matrix, |
130 const SkPaint* paint) { | 134 const SkPaint* paint) { |
131 // Ensure that pictures are unpacked by this canvas, instead of being | 135 // Ensure that pictures are unpacked by this canvas, instead of being |
132 // forwarded to the raster canvas. | 136 // forwarded to the raster canvas. |
133 SkCanvas::onDrawPicture(picture, matrix, paint); | 137 SkCanvas::onDrawPicture(picture, matrix, paint); |
134 } | 138 } |
135 | 139 |
136 void ImageHijackCanvas::onDrawImage(const SkImage* image, | 140 void ImageHijackCanvas::onDrawImage(const SkImage* image, |
137 SkScalar x, | 141 SkScalar x, |
138 SkScalar y, | 142 SkScalar y, |
139 const SkPaint* paint) { | 143 const SkPaint* paint) { |
140 if (!image->isLazyGenerated()) { | 144 if (!image->isLazyGenerated()) { |
| 145 DCHECK(!ShouldSkipImage(image)); |
141 SkNWayCanvas::onDrawImage(image, x, y, paint); | 146 SkNWayCanvas::onDrawImage(image, x, y, paint); |
142 return; | 147 return; |
143 } | 148 } |
144 | 149 |
| 150 if (ShouldSkipImage(image)) |
| 151 return; |
| 152 |
145 SkMatrix ctm = getTotalMatrix(); | 153 SkMatrix ctm = getTotalMatrix(); |
146 | 154 |
147 ScopedDecodedImageLock scoped_lock( | 155 ScopedDecodedImageLock scoped_lock( |
148 image_decode_cache_, sk_ref_sp(image), | 156 image_decode_cache_, sk_ref_sp(image), |
149 SkRect::MakeIWH(image->width(), image->height()), ctm, paint); | 157 SkRect::MakeIWH(image->width(), image->height()), ctm, paint); |
150 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 158 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
151 if (!decoded_image.image()) | 159 if (!decoded_image.image()) |
152 return; | 160 return; |
153 | 161 |
154 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); | 162 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); |
(...skipping 10 matching lines...) Expand all Loading... |
165 if (need_scale) | 173 if (need_scale) |
166 SkNWayCanvas::restore(); | 174 SkNWayCanvas::restore(); |
167 } | 175 } |
168 | 176 |
169 void ImageHijackCanvas::onDrawImageRect(const SkImage* image, | 177 void ImageHijackCanvas::onDrawImageRect(const SkImage* image, |
170 const SkRect* src, | 178 const SkRect* src, |
171 const SkRect& dst, | 179 const SkRect& dst, |
172 const SkPaint* paint, | 180 const SkPaint* paint, |
173 SrcRectConstraint constraint) { | 181 SrcRectConstraint constraint) { |
174 if (!image->isLazyGenerated()) { | 182 if (!image->isLazyGenerated()) { |
| 183 DCHECK(!ShouldSkipImage(image)); |
175 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint); | 184 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint); |
176 return; | 185 return; |
177 } | 186 } |
178 | 187 |
| 188 if (ShouldSkipImage(image)) |
| 189 return; |
| 190 |
179 SkRect src_storage; | 191 SkRect src_storage; |
180 if (!src) { | 192 if (!src) { |
181 src_storage = SkRect::MakeIWH(image->width(), image->height()); | 193 src_storage = SkRect::MakeIWH(image->width(), image->height()); |
182 src = &src_storage; | 194 src = &src_storage; |
183 } | 195 } |
184 SkMatrix matrix; | 196 SkMatrix matrix; |
185 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | 197 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
186 matrix.postConcat(getTotalMatrix()); | 198 matrix.postConcat(getTotalMatrix()); |
187 | 199 |
188 ScopedDecodedImageLock scoped_lock(image_decode_cache_, sk_ref_sp(image), | 200 ScopedDecodedImageLock scoped_lock(image_decode_cache_, sk_ref_sp(image), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 275 } |
264 | 276 |
265 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, | 277 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, |
266 const SkIRect& center, | 278 const SkIRect& center, |
267 const SkRect& dst, | 279 const SkRect& dst, |
268 const SkPaint* paint) { | 280 const SkPaint* paint) { |
269 // No cc embedder issues image nine calls. | 281 // No cc embedder issues image nine calls. |
270 NOTREACHED(); | 282 NOTREACHED(); |
271 } | 283 } |
272 | 284 |
| 285 bool ImageHijackCanvas::ShouldSkipImage(const SkImage* image) { |
| 286 return images_to_skip_->find(image->uniqueID()) != images_to_skip_->end(); |
| 287 } |
| 288 |
273 } // namespace cc | 289 } // namespace cc |
OLD | NEW |