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 PaintImage::Id s_canvas_paint_image_id = PaintImage::GetNextId(); | |
vmpstr
2017/05/16 17:43:27
My concern is just initializing globals using func
Khushal
2017/05/16 21:29:12
Oh, I'm sorry. Forgot to remove this. Its not nece
| |
18 | |
16 SkIRect RoundOutRect(const SkRect& rect) { | 19 SkIRect RoundOutRect(const SkRect& rect) { |
17 SkIRect result; | 20 SkIRect result; |
18 rect.roundOut(&result); | 21 rect.roundOut(&result); |
19 return result; | 22 return result; |
20 } | 23 } |
21 | 24 |
22 class ScopedDecodedImageLock { | 25 class ScopedDecodedImageLock { |
23 public: | 26 public: |
24 ScopedDecodedImageLock(ImageDecodeCache* image_decode_cache, | 27 ScopedDecodedImageLock(ImageDecodeCache* image_decode_cache, |
25 sk_sp<const SkImage> image, | 28 sk_sp<SkImage> image, |
26 const SkRect& src_rect, | 29 const SkRect& src_rect, |
27 const SkMatrix& matrix, | 30 const SkMatrix& matrix, |
28 const SkPaint* paint, | 31 const SkPaint* paint, |
29 const gfx::ColorSpace& target_color_space) | 32 const gfx::ColorSpace& target_color_space) |
30 : image_decode_cache_(image_decode_cache), | 33 : image_decode_cache_(image_decode_cache), |
31 draw_image_(std::move(image), | 34 // TODO(khushalsagar): Using the wrong id should not be necessary once |
35 // the hijack canvas is eliminated. | |
36 draw_image_(PaintImage(PaintImage::kWrongStableId, 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |