| 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 "cc/playback/discardable_image_map.h" | 7 #include "cc/playback/discardable_image_map.h" |
| 8 #include "cc/tiles/image_decode_controller.h" | 8 #include "cc/tiles/image_decode_controller.h" |
| 9 #include "third_party/skia/include/core/SkTLazy.h" | 9 #include "third_party/skia/include/core/SkTLazy.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 SkIRect RoundOutRect(const SkRect& rect) { | 14 SkIRect RoundOutRect(const SkRect& rect) { |
| 15 SkIRect result; | 15 SkIRect result; |
| 16 rect.roundOut(&result); | 16 rect.roundOut(&result); |
| 17 return result; | 17 return result; |
| 18 } | 18 } |
| 19 | 19 |
| 20 class ScopedDecodedImageLock { | 20 class ScopedDecodedImageLock { |
| 21 public: | 21 public: |
| 22 ScopedDecodedImageLock(ImageDecodeController* image_decode_controller, | 22 ScopedDecodedImageLock(ImageDecodeController* image_decode_controller, |
| 23 const SkImage* image, | 23 const SkImage* image, |
| 24 const SkRect& src_rect, | 24 const SkRect& src_rect, |
| 25 const SkMatrix& matrix, | 25 const SkMatrix& matrix, |
| 26 const SkPaint* paint) | 26 const SkPaint* paint, |
| 27 SkFilterQuality max_quality) |
| 27 : image_decode_controller_(image_decode_controller), | 28 : image_decode_controller_(image_decode_controller), |
| 28 draw_image_(image, | 29 draw_image_(image, |
| 29 RoundOutRect(src_rect), | 30 RoundOutRect(src_rect), |
| 30 paint ? paint->getFilterQuality() : kNone_SkFilterQuality, | 31 paint ? std::min(max_quality, paint->getFilterQuality()) |
| 32 : kNone_SkFilterQuality, |
| 31 matrix), | 33 matrix), |
| 32 decoded_draw_image_( | 34 decoded_draw_image_( |
| 33 image_decode_controller_->GetDecodedImageForDraw(draw_image_)) { | 35 image_decode_controller_->GetDecodedImageForDraw(draw_image_)) { |
| 34 DCHECK(image->isLazyGenerated()); | 36 DCHECK(image->isLazyGenerated()); |
| 35 if (paint) | 37 if (paint) |
| 36 decoded_paint_.set(*paint)->setFilterQuality( | 38 decoded_paint_.set(*paint)->setFilterQuality( |
| 37 decoded_draw_image_.filter_quality()); | 39 decoded_draw_image_.filter_quality()); |
| 38 } | 40 } |
| 39 | 41 |
| 40 ~ScopedDecodedImageLock() { | 42 ~ScopedDecodedImageLock() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 DecodedDrawImage decoded_draw_image_; | 53 DecodedDrawImage decoded_draw_image_; |
| 52 // TODO(fmalita): use base::Optional when it becomes available | 54 // TODO(fmalita): use base::Optional when it becomes available |
| 53 SkTLazy<SkPaint> decoded_paint_; | 55 SkTLazy<SkPaint> decoded_paint_; |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 } // namespace | 58 } // namespace |
| 57 | 59 |
| 58 ImageHijackCanvas::ImageHijackCanvas( | 60 ImageHijackCanvas::ImageHijackCanvas( |
| 59 int width, | 61 int width, |
| 60 int height, | 62 int height, |
| 61 ImageDecodeController* image_decode_controller) | 63 ImageDecodeController* image_decode_controller, |
| 64 SkFilterQuality max_quality) |
| 62 : SkNWayCanvas(width, height), | 65 : SkNWayCanvas(width, height), |
| 63 image_decode_controller_(image_decode_controller) {} | 66 image_decode_controller_(image_decode_controller), |
| 67 max_quality_(max_quality) {} |
| 64 | 68 |
| 65 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, | 69 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, |
| 66 const SkMatrix* matrix, | 70 const SkMatrix* matrix, |
| 67 const SkPaint* paint) { | 71 const SkPaint* paint) { |
| 68 // Ensure that pictures are unpacked by this canvas, instead of being | 72 // Ensure that pictures are unpacked by this canvas, instead of being |
| 69 // forwarded to the raster canvas. | 73 // forwarded to the raster canvas. |
| 70 SkCanvas::onDrawPicture(picture, matrix, paint); | 74 SkCanvas::onDrawPicture(picture, matrix, paint); |
| 71 } | 75 } |
| 72 | 76 |
| 73 void ImageHijackCanvas::onDrawImage(const SkImage* image, | 77 void ImageHijackCanvas::onDrawImage(const SkImage* image, |
| 74 SkScalar x, | 78 SkScalar x, |
| 75 SkScalar y, | 79 SkScalar y, |
| 76 const SkPaint* paint) { | 80 const SkPaint* paint) { |
| 77 if (!image->isLazyGenerated()) { | 81 if (!image->isLazyGenerated()) { |
| 78 SkNWayCanvas::onDrawImage(image, x, y, paint); | 82 SkNWayCanvas::onDrawImage(image, x, y, paint); |
| 79 return; | 83 return; |
| 80 } | 84 } |
| 81 | 85 |
| 82 SkMatrix ctm = getTotalMatrix(); | 86 SkMatrix ctm = getTotalMatrix(); |
| 83 | 87 |
| 84 ScopedDecodedImageLock scoped_lock( | 88 ScopedDecodedImageLock scoped_lock( |
| 85 image_decode_controller_, image, | 89 image_decode_controller_, image, |
| 86 SkRect::MakeIWH(image->width(), image->height()), ctm, paint); | 90 SkRect::MakeIWH(image->width(), image->height()), ctm, paint, |
| 91 max_quality_); |
| 87 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 92 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
| 88 if (!decoded_image.image()) | 93 if (!decoded_image.image()) |
| 89 return; | 94 return; |
| 90 | 95 |
| 91 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); | 96 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); |
| 92 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().height())); | 97 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().height())); |
| 93 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | 98 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); |
| 94 | 99 |
| 95 bool need_scale = !decoded_image.is_scale_adjustment_identity(); | 100 bool need_scale = !decoded_image.is_scale_adjustment_identity(); |
| 96 if (need_scale) { | 101 if (need_scale) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 116 SkRect src_storage; | 121 SkRect src_storage; |
| 117 if (!src) { | 122 if (!src) { |
| 118 src_storage = SkRect::MakeIWH(image->width(), image->height()); | 123 src_storage = SkRect::MakeIWH(image->width(), image->height()); |
| 119 src = &src_storage; | 124 src = &src_storage; |
| 120 } | 125 } |
| 121 SkMatrix matrix; | 126 SkMatrix matrix; |
| 122 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | 127 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
| 123 matrix.postConcat(getTotalMatrix()); | 128 matrix.postConcat(getTotalMatrix()); |
| 124 | 129 |
| 125 ScopedDecodedImageLock scoped_lock(image_decode_controller_, image, *src, | 130 ScopedDecodedImageLock scoped_lock(image_decode_controller_, image, *src, |
| 126 matrix, paint); | 131 matrix, paint, max_quality_); |
| 127 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | 132 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); |
| 128 if (!decoded_image.image()) | 133 if (!decoded_image.image()) |
| 129 return; | 134 return; |
| 130 | 135 |
| 131 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | 136 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); |
| 132 | 137 |
| 133 SkRect adjusted_src = | 138 SkRect adjusted_src = |
| 134 src->makeOffset(decoded_image.src_rect_offset().width(), | 139 src->makeOffset(decoded_image.src_rect_offset().width(), |
| 135 decoded_image.src_rect_offset().height()); | 140 decoded_image.src_rect_offset().height()); |
| 136 if (!decoded_image.is_scale_adjustment_identity()) { | 141 if (!decoded_image.is_scale_adjustment_identity()) { |
| 137 float x_scale = decoded_image.scale_adjustment().width(); | 142 float x_scale = decoded_image.scale_adjustment().width(); |
| 138 float y_scale = decoded_image.scale_adjustment().height(); | 143 float y_scale = decoded_image.scale_adjustment().height(); |
| 139 adjusted_src = SkRect::MakeXYWH( | 144 adjusted_src = SkRect::MakeXYWH( |
| 140 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale, | 145 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale, |
| 141 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale); | 146 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale); |
| 142 } | 147 } |
| 143 SkNWayCanvas::onDrawImageRect(decoded_image.image(), &adjusted_src, dst, | 148 SkNWayCanvas::onDrawImageRect(decoded_image.image(), &adjusted_src, dst, |
| 144 decoded_paint, constraint); | 149 decoded_paint, constraint); |
| 145 } | 150 } |
| 146 | 151 |
| 147 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, | 152 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, |
| 148 const SkIRect& center, | 153 const SkIRect& center, |
| 149 const SkRect& dst, | 154 const SkRect& dst, |
| 150 const SkPaint* paint) { | 155 const SkPaint* paint) { |
| 151 // No cc embedder issues image nine calls. | 156 // No cc embedder issues image nine calls. |
| 152 NOTREACHED(); | 157 NOTREACHED(); |
| 153 } | 158 } |
| 154 | 159 |
| 155 } // namespace cc | 160 } // namespace cc |
| OLD | NEW |