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/raster/image_hijack_canvas.h" | 5 #include "cc/raster/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 "base/trace_event/trace_event.h" |
9 #include "cc/paint/discardable_image_map.h" | 9 #include "cc/paint/discardable_image_map.h" |
10 #include "cc/tiles/image_decode_cache.h" | 10 #include "cc/tiles/image_decode_cache.h" |
11 #include "third_party/skia/include/core/SkPath.h" | 11 #include "third_party/skia/include/core/SkPath.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 namespace { | 14 namespace { |
15 | 15 |
16 SkIRect RoundOutRect(const SkRect& rect) { | 16 SkIRect RoundOutRect(const SkRect& rect) { |
17 SkIRect result; | 17 SkIRect result; |
18 rect.roundOut(&result); | 18 rect.roundOut(&result); |
19 return result; | 19 return result; |
20 } | 20 } |
21 | 21 |
22 class ScopedDecodedImageLock { | 22 class ScopedDecodedImageLock { |
23 public: | 23 public: |
24 ScopedDecodedImageLock(ImageDecodeCache* image_decode_cache, | 24 ScopedDecodedImageLock(ImageDecodeCache* image_decode_cache, |
25 sk_sp<const SkImage> image, | 25 sk_sp<SkImage> image, |
26 const SkRect& src_rect, | 26 const SkRect& src_rect, |
27 const SkMatrix& matrix, | 27 const SkMatrix& matrix, |
28 const SkPaint* paint, | 28 const SkPaint* paint, |
29 const gfx::ColorSpace& target_color_space) | 29 const gfx::ColorSpace& target_color_space) |
30 : image_decode_cache_(image_decode_cache), | 30 : image_decode_cache_(image_decode_cache), |
31 draw_image_(std::move(image), | 31 // TODO(khushalsagar): Using the wrong id should not be necessary once |
| 32 // the hijack canvas is eliminated. |
| 33 draw_image_(PaintImage(PaintImage::kUnknownStableId, std::move(image)), |
32 RoundOutRect(src_rect), | 34 RoundOutRect(src_rect), |
33 paint ? paint->getFilterQuality() : kNone_SkFilterQuality, | 35 paint ? paint->getFilterQuality() : kNone_SkFilterQuality, |
34 matrix, | 36 matrix, |
35 target_color_space), | 37 target_color_space), |
36 decoded_draw_image_( | 38 decoded_draw_image_( |
37 image_decode_cache_->GetDecodedImageForDraw(draw_image_)) { | 39 image_decode_cache_->GetDecodedImageForDraw(draw_image_)) { |
38 DCHECK(draw_image_.image()->isLazyGenerated()); | 40 DCHECK(draw_image_.image()->isLazyGenerated()); |
39 if (paint) { | 41 if (paint) { |
40 decoded_paint_ = *paint; | 42 decoded_paint_ = *paint; |
41 decoded_paint_->setFilterQuality(decoded_draw_image_.filter_quality()); | 43 decoded_paint_->setFilterQuality(decoded_draw_image_.filter_quality()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 const SkImage* GetImageInPaint(const SkPaint& paint) { | 128 const SkImage* GetImageInPaint(const SkPaint& paint) { |
127 SkShader* shader = paint.getShader(); | 129 SkShader* shader = paint.getShader(); |
128 return shader ? shader->isAImage(nullptr, nullptr) : nullptr; | 130 return shader ? shader->isAImage(nullptr, nullptr) : nullptr; |
129 } | 131 } |
130 | 132 |
131 } // namespace | 133 } // namespace |
132 | 134 |
133 ImageHijackCanvas::ImageHijackCanvas(int width, | 135 ImageHijackCanvas::ImageHijackCanvas(int width, |
134 int height, | 136 int height, |
135 ImageDecodeCache* image_decode_cache, | 137 ImageDecodeCache* image_decode_cache, |
136 const ImageIdFlatSet* images_to_skip, | 138 const SkImageIdFlatSet* images_to_skip, |
137 const gfx::ColorSpace& target_color_space) | 139 const gfx::ColorSpace& target_color_space) |
138 : SkNWayCanvas(width, height), | 140 : SkNWayCanvas(width, height), |
139 image_decode_cache_(image_decode_cache), | 141 image_decode_cache_(image_decode_cache), |
140 images_to_skip_(images_to_skip), | 142 images_to_skip_(images_to_skip), |
141 target_color_space_(target_color_space) {} | 143 target_color_space_(target_color_space) {} |
142 | 144 |
143 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, | 145 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, |
144 const SkMatrix* matrix, | 146 const SkMatrix* matrix, |
145 const SkPaint* paint) { | 147 const SkPaint* paint) { |
146 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 148 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
(...skipping 19 matching lines...) Expand all Loading... |
166 SkNWayCanvas::onDrawImage(image, x, y, paint); | 168 SkNWayCanvas::onDrawImage(image, x, y, paint); |
167 return; | 169 return; |
168 } | 170 } |
169 | 171 |
170 if (ShouldSkipImage(image)) | 172 if (ShouldSkipImage(image)) |
171 return; | 173 return; |
172 | 174 |
173 SkMatrix ctm = getTotalMatrix(); | 175 SkMatrix ctm = getTotalMatrix(); |
174 | 176 |
175 ScopedDecodedImageLock scoped_lock( | 177 ScopedDecodedImageLock scoped_lock( |
176 image_decode_cache_, sk_ref_sp(image), | 178 image_decode_cache_, sk_ref_sp(const_cast<SkImage*>(image)), |
177 SkRect::MakeIWH(image->width(), image->height()), ctm, paint, | 179 SkRect::MakeIWH(image->width(), image->height()), ctm, paint, |
178 target_color_space_); | 180 target_color_space_); |
179 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 181 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
180 if (!decoded_image.image()) | 182 if (!decoded_image.image()) |
181 return; | 183 return; |
182 | 184 |
183 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); | 185 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); |
184 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().height())); | 186 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().height())); |
185 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | 187 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); |
186 | 188 |
(...skipping 29 matching lines...) Expand all Loading... |
216 | 218 |
217 SkRect src_storage; | 219 SkRect src_storage; |
218 if (!src) { | 220 if (!src) { |
219 src_storage = SkRect::MakeIWH(image->width(), image->height()); | 221 src_storage = SkRect::MakeIWH(image->width(), image->height()); |
220 src = &src_storage; | 222 src = &src_storage; |
221 } | 223 } |
222 SkMatrix matrix; | 224 SkMatrix matrix; |
223 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | 225 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
224 matrix.postConcat(getTotalMatrix()); | 226 matrix.postConcat(getTotalMatrix()); |
225 | 227 |
226 ScopedDecodedImageLock scoped_lock(image_decode_cache_, sk_ref_sp(image), | 228 ScopedDecodedImageLock scoped_lock(image_decode_cache_, |
| 229 sk_ref_sp(const_cast<SkImage*>(image)), |
227 *src, matrix, paint, target_color_space_); | 230 *src, matrix, paint, target_color_space_); |
228 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 231 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
229 if (!decoded_image.image()) | 232 if (!decoded_image.image()) |
230 return; | 233 return; |
231 | 234 |
232 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | 235 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); |
233 | 236 |
234 SkRect adjusted_src = | 237 SkRect adjusted_src = |
235 src->makeOffset(decoded_image.src_rect_offset().width(), | 238 src->makeOffset(decoded_image.src_rect_offset().width(), |
236 decoded_image.src_rect_offset().height()); | 239 decoded_image.src_rect_offset().height()); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 SkRect tmp = rect; | 371 SkRect tmp = rect; |
369 if (paint) | 372 if (paint) |
370 paint->computeFastBounds(tmp, &tmp); | 373 paint->computeFastBounds(tmp, &tmp); |
371 return quickReject(tmp); | 374 return quickReject(tmp); |
372 } | 375 } |
373 | 376 |
374 return false; | 377 return false; |
375 } | 378 } |
376 | 379 |
377 } // namespace cc | 380 } // namespace cc |
OLD | NEW |