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 18 matching lines...) Expand all Loading... | |
207 decoded_paint, constraint); | 219 decoded_paint, constraint); |
208 } | 220 } |
209 | 221 |
210 void ImageHijackCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { | 222 void ImageHijackCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { |
211 base::Optional<ScopedImagePaint> image_paint = | 223 base::Optional<ScopedImagePaint> image_paint = |
212 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 224 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
213 if (!image_paint.has_value()) { | 225 if (!image_paint.has_value()) { |
214 SkNWayCanvas::onDrawRect(r, paint); | 226 SkNWayCanvas::onDrawRect(r, paint); |
215 return; | 227 return; |
216 } | 228 } |
217 SkNWayCanvas::onDrawRect(r, image_paint.value().paint()); | 229 SkNWayCanvas::onDrawRect(r, image_paint.value().paint()); |
vmpstr
2017/02/10 19:25:42
There's a case here that is a bit awkward. Specifi
Khushal
2017/02/10 22:09:19
Thanks for pointing this out. I've added a check f
| |
218 } | 230 } |
219 | 231 |
220 void ImageHijackCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | 232 void ImageHijackCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
221 base::Optional<ScopedImagePaint> image_paint = | 233 base::Optional<ScopedImagePaint> image_paint = |
222 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); | 234 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); |
223 if (!image_paint.has_value()) { | 235 if (!image_paint.has_value()) { |
224 SkNWayCanvas::onDrawPath(path, paint); | 236 SkNWayCanvas::onDrawPath(path, paint); |
225 return; | 237 return; |
226 } | 238 } |
227 SkNWayCanvas::onDrawPath(path, image_paint.value().paint()); | 239 SkNWayCanvas::onDrawPath(path, image_paint.value().paint()); |
(...skipping 35 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 |