Chromium Code Reviews| 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 // Using a single id for images captured using the hijack canvas. | |
| 17 // TODO(khushalsagar): This should not be necessary once this is eliminated and | |
| 18 // we replace images while iterating through the ops in PaintOpBuffer. | |
| 19 PaintImage::Id s_canvas_paint_image_id = PaintImage::GetNextId(); | |
|
vmpstr
2017/05/12 22:15:42
I think this should be a static int instead of Get
Khushal
2017/05/13 02:45:50
Do you mean like kNonLazyStableId?
vmpstr
2017/05/15 15:02:55
Either kNonLazyStableId or some other identifier,
Khushal
2017/05/15 21:22:14
Done. I added a kWrongStableId to mark it clearly
| |
| 20 | |
| 16 SkIRect RoundOutRect(const SkRect& rect) { | 21 SkIRect RoundOutRect(const SkRect& rect) { |
| 17 SkIRect result; | 22 SkIRect result; |
| 18 rect.roundOut(&result); | 23 rect.roundOut(&result); |
| 19 return result; | 24 return result; |
| 20 } | 25 } |
| 21 | 26 |
| 22 class ScopedDecodedImageLock { | 27 class ScopedDecodedImageLock { |
| 23 public: | 28 public: |
| 24 ScopedDecodedImageLock(ImageDecodeCache* image_decode_cache, | 29 ScopedDecodedImageLock(ImageDecodeCache* image_decode_cache, |
| 25 sk_sp<const SkImage> image, | 30 sk_sp<SkImage> image, |
| 26 const SkRect& src_rect, | 31 const SkRect& src_rect, |
| 27 const SkMatrix& matrix, | 32 const SkMatrix& matrix, |
| 28 const SkPaint* paint, | 33 const SkPaint* paint, |
| 29 const gfx::ColorSpace& target_color_space) | 34 const gfx::ColorSpace& target_color_space) |
| 30 : image_decode_cache_(image_decode_cache), | 35 : image_decode_cache_(image_decode_cache), |
| 31 draw_image_(std::move(image), | 36 draw_image_(PaintImage(s_canvas_paint_image_id, std::move(image)), |
| 32 RoundOutRect(src_rect), | 37 RoundOutRect(src_rect), |
| 33 paint ? paint->getFilterQuality() : kNone_SkFilterQuality, | 38 paint ? paint->getFilterQuality() : kNone_SkFilterQuality, |
| 34 matrix, | 39 matrix, |
| 35 target_color_space), | 40 target_color_space), |
| 36 decoded_draw_image_( | 41 decoded_draw_image_( |
| 37 image_decode_cache_->GetDecodedImageForDraw(draw_image_)) { | 42 image_decode_cache_->GetDecodedImageForDraw(draw_image_)) { |
| 38 DCHECK(draw_image_.image()->isLazyGenerated()); | 43 DCHECK(draw_image_.image()->isLazyGenerated()); |
| 39 if (paint) { | 44 if (paint) { |
| 40 decoded_paint_ = *paint; | 45 decoded_paint_ = *paint; |
| 41 decoded_paint_->setFilterQuality(decoded_draw_image_.filter_quality()); | 46 decoded_paint_->setFilterQuality(decoded_draw_image_.filter_quality()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 SkMatrix matrix; | 92 SkMatrix matrix; |
| 88 SkShader::TileMode xy[2]; | 93 SkShader::TileMode xy[2]; |
| 89 SkImage* image = shader->isAImage(&matrix, xy); | 94 SkImage* image = shader->isAImage(&matrix, xy); |
| 90 if (!image || !image->isLazyGenerated()) | 95 if (!image || !image->isLazyGenerated()) |
| 91 return base::Optional<ScopedImagePaint>(); | 96 return base::Optional<ScopedImagePaint>(); |
| 92 | 97 |
| 93 SkMatrix total_image_matrix = matrix; | 98 SkMatrix total_image_matrix = matrix; |
| 94 total_image_matrix.preConcat(ctm); | 99 total_image_matrix.preConcat(ctm); |
| 95 | 100 |
| 96 ScopedDecodedImageLock scoped_lock( | 101 ScopedDecodedImageLock scoped_lock( |
| 97 image_decode_cache, sk_ref_sp(image), | 102 image_decode_cache, sk_ref_sp(const_cast<SkImage*>(image)), |
|
vmpstr
2017/05/12 22:15:42
image is already non const?
Khushal
2017/05/15 21:22:14
Done.
| |
| 98 SkRect::MakeIWH(image->width(), image->height()), total_image_matrix, | 103 SkRect::MakeIWH(image->width(), image->height()), total_image_matrix, |
| 99 &paint, target_color_space); | 104 &paint, target_color_space); |
| 100 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 105 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
| 101 if (!decoded_image.image()) | 106 if (!decoded_image.image()) |
| 102 return base::Optional<ScopedImagePaint>(); | 107 return base::Optional<ScopedImagePaint>(); |
| 103 | 108 |
| 104 bool need_scale = !decoded_image.is_scale_adjustment_identity(); | 109 bool need_scale = !decoded_image.is_scale_adjustment_identity(); |
| 105 if (need_scale) { | 110 if (need_scale) { |
| 106 matrix.preScale(1.f / decoded_image.scale_adjustment().width(), | 111 matrix.preScale(1.f / decoded_image.scale_adjustment().width(), |
| 107 1.f / decoded_image.scale_adjustment().height()); | 112 1.f / decoded_image.scale_adjustment().height()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 126 const SkImage* GetImageInPaint(const SkPaint& paint) { | 131 const SkImage* GetImageInPaint(const SkPaint& paint) { |
| 127 SkShader* shader = paint.getShader(); | 132 SkShader* shader = paint.getShader(); |
| 128 return shader ? shader->isAImage(nullptr, nullptr) : nullptr; | 133 return shader ? shader->isAImage(nullptr, nullptr) : nullptr; |
| 129 } | 134 } |
| 130 | 135 |
| 131 } // namespace | 136 } // namespace |
| 132 | 137 |
| 133 ImageHijackCanvas::ImageHijackCanvas(int width, | 138 ImageHijackCanvas::ImageHijackCanvas(int width, |
| 134 int height, | 139 int height, |
| 135 ImageDecodeCache* image_decode_cache, | 140 ImageDecodeCache* image_decode_cache, |
| 136 const ImageIdFlatSet* images_to_skip, | 141 const SkImageIdFlatSet* images_to_skip, |
| 137 const gfx::ColorSpace& target_color_space) | 142 const gfx::ColorSpace& target_color_space) |
| 138 : SkNWayCanvas(width, height), | 143 : SkNWayCanvas(width, height), |
| 139 image_decode_cache_(image_decode_cache), | 144 image_decode_cache_(image_decode_cache), |
| 140 images_to_skip_(images_to_skip), | 145 images_to_skip_(images_to_skip), |
| 141 target_color_space_(target_color_space) {} | 146 target_color_space_(target_color_space) {} |
| 142 | 147 |
| 143 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, | 148 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, |
| 144 const SkMatrix* matrix, | 149 const SkMatrix* matrix, |
| 145 const SkPaint* paint) { | 150 const SkPaint* paint) { |
| 146 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 151 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 166 SkNWayCanvas::onDrawImage(image, x, y, paint); | 171 SkNWayCanvas::onDrawImage(image, x, y, paint); |
| 167 return; | 172 return; |
| 168 } | 173 } |
| 169 | 174 |
| 170 if (ShouldSkipImage(image)) | 175 if (ShouldSkipImage(image)) |
| 171 return; | 176 return; |
| 172 | 177 |
| 173 SkMatrix ctm = getTotalMatrix(); | 178 SkMatrix ctm = getTotalMatrix(); |
| 174 | 179 |
| 175 ScopedDecodedImageLock scoped_lock( | 180 ScopedDecodedImageLock scoped_lock( |
| 176 image_decode_cache_, sk_ref_sp(image), | 181 image_decode_cache_, sk_ref_sp(const_cast<SkImage*>(image)), |
| 177 SkRect::MakeIWH(image->width(), image->height()), ctm, paint, | 182 SkRect::MakeIWH(image->width(), image->height()), ctm, paint, |
| 178 target_color_space_); | 183 target_color_space_); |
| 179 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 184 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
| 180 if (!decoded_image.image()) | 185 if (!decoded_image.image()) |
| 181 return; | 186 return; |
| 182 | 187 |
| 183 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); | 188 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())); | 189 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().height())); |
| 185 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | 190 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); |
| 186 | 191 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 216 | 221 |
| 217 SkRect src_storage; | 222 SkRect src_storage; |
| 218 if (!src) { | 223 if (!src) { |
| 219 src_storage = SkRect::MakeIWH(image->width(), image->height()); | 224 src_storage = SkRect::MakeIWH(image->width(), image->height()); |
| 220 src = &src_storage; | 225 src = &src_storage; |
| 221 } | 226 } |
| 222 SkMatrix matrix; | 227 SkMatrix matrix; |
| 223 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | 228 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
| 224 matrix.postConcat(getTotalMatrix()); | 229 matrix.postConcat(getTotalMatrix()); |
| 225 | 230 |
| 226 ScopedDecodedImageLock scoped_lock(image_decode_cache_, sk_ref_sp(image), | 231 ScopedDecodedImageLock scoped_lock(image_decode_cache_, |
| 232 sk_ref_sp(const_cast<SkImage*>(image)), | |
| 227 *src, matrix, paint, target_color_space_); | 233 *src, matrix, paint, target_color_space_); |
| 228 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 234 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
| 229 if (!decoded_image.image()) | 235 if (!decoded_image.image()) |
| 230 return; | 236 return; |
| 231 | 237 |
| 232 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | 238 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); |
| 233 | 239 |
| 234 SkRect adjusted_src = | 240 SkRect adjusted_src = |
| 235 src->makeOffset(decoded_image.src_rect_offset().width(), | 241 src->makeOffset(decoded_image.src_rect_offset().width(), |
| 236 decoded_image.src_rect_offset().height()); | 242 decoded_image.src_rect_offset().height()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 SkRect tmp = rect; | 374 SkRect tmp = rect; |
| 369 if (paint) | 375 if (paint) |
| 370 paint->computeFastBounds(tmp, &tmp); | 376 paint->computeFastBounds(tmp, &tmp); |
| 371 return quickReject(tmp); | 377 return quickReject(tmp); |
| 372 } | 378 } |
| 373 | 379 |
| 374 return false; | 380 return false; |
| 375 } | 381 } |
| 376 | 382 |
| 377 } // namespace cc | 383 } // namespace cc |
| OLD | NEW |