Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: cc/playback/image_hijack_canvas.cc

Issue 2668873002: cc: Add checker-imaging support to TileManager. (Closed)
Patch Set: remove include Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/image_hijack_canvas.h ('k') | cc/playback/image_hijack_canvas_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const SkPaint& paint() { return paint_; } 112 const SkPaint& paint() { return paint_; }
113 113
114 private: 114 private:
115 ScopedImagePaint(ScopedDecodedImageLock lock, SkPaint paint) 115 ScopedImagePaint(ScopedDecodedImageLock lock, SkPaint paint)
116 : lock_(std::move(lock)), paint_(std::move(paint)) {} 116 : lock_(std::move(lock)), paint_(std::move(paint)) {}
117 117
118 ScopedDecodedImageLock lock_; 118 ScopedDecodedImageLock lock_;
119 SkPaint paint_; 119 SkPaint paint_;
120 }; 120 };
121 121
122 const SkImage* GetImageInPaint(const SkPaint& paint) {
123 SkShader* shader = paint.getShader();
124 return shader ? shader->isAImage(nullptr, nullptr) : nullptr;
125 }
126
122 } // namespace 127 } // namespace
123 128
124 ImageHijackCanvas::ImageHijackCanvas(int width, 129 ImageHijackCanvas::ImageHijackCanvas(int width,
125 int height, 130 int height,
126 ImageDecodeCache* image_decode_cache) 131 ImageDecodeCache* image_decode_cache,
127 : SkNWayCanvas(width, height), image_decode_cache_(image_decode_cache) {} 132 const ImageIdFlatSet* images_to_skip)
133 : SkNWayCanvas(width, height),
134 image_decode_cache_(image_decode_cache),
135 images_to_skip_(images_to_skip) {}
128 136
129 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture, 137 void ImageHijackCanvas::onDrawPicture(const SkPicture* picture,
130 const SkMatrix* matrix, 138 const SkMatrix* matrix,
131 const SkPaint* paint) { 139 const SkPaint* paint) {
132 // Ensure that pictures are unpacked by this canvas, instead of being 140 // Ensure that pictures are unpacked by this canvas, instead of being
133 // forwarded to the raster canvas. 141 // forwarded to the raster canvas.
134 SkCanvas::onDrawPicture(picture, matrix, paint); 142 SkCanvas::onDrawPicture(picture, matrix, paint);
135 } 143 }
136 144
137 void ImageHijackCanvas::onDrawImage(const SkImage* image, 145 void ImageHijackCanvas::onDrawImage(const SkImage* image,
138 SkScalar x, 146 SkScalar x,
139 SkScalar y, 147 SkScalar y,
140 const SkPaint* paint) { 148 const SkPaint* paint) {
141 if (!image->isLazyGenerated()) { 149 if (!image->isLazyGenerated()) {
150 DCHECK(!ShouldSkipImage(image));
142 SkNWayCanvas::onDrawImage(image, x, y, paint); 151 SkNWayCanvas::onDrawImage(image, x, y, paint);
143 return; 152 return;
144 } 153 }
145 154
155 if (ShouldSkipImage(image))
156 return;
157
146 SkMatrix ctm = getTotalMatrix(); 158 SkMatrix ctm = getTotalMatrix();
147 159
148 ScopedDecodedImageLock scoped_lock( 160 ScopedDecodedImageLock scoped_lock(
149 image_decode_cache_, sk_ref_sp(image), 161 image_decode_cache_, sk_ref_sp(image),
150 SkRect::MakeIWH(image->width(), image->height()), ctm, paint); 162 SkRect::MakeIWH(image->width(), image->height()), ctm, paint);
151 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); 163 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image();
152 if (!decoded_image.image()) 164 if (!decoded_image.image())
153 return; 165 return;
154 166
155 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); 167 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width()));
(...skipping 10 matching lines...) Expand all
166 if (need_scale) 178 if (need_scale)
167 SkNWayCanvas::restore(); 179 SkNWayCanvas::restore();
168 } 180 }
169 181
170 void ImageHijackCanvas::onDrawImageRect(const SkImage* image, 182 void ImageHijackCanvas::onDrawImageRect(const SkImage* image,
171 const SkRect* src, 183 const SkRect* src,
172 const SkRect& dst, 184 const SkRect& dst,
173 const SkPaint* paint, 185 const SkPaint* paint,
174 SrcRectConstraint constraint) { 186 SrcRectConstraint constraint) {
175 if (!image->isLazyGenerated()) { 187 if (!image->isLazyGenerated()) {
188 DCHECK(!ShouldSkipImage(image));
176 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint); 189 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint);
177 return; 190 return;
178 } 191 }
179 192
193 if (ShouldSkipImage(image))
194 return;
195
180 SkRect src_storage; 196 SkRect src_storage;
181 if (!src) { 197 if (!src) {
182 src_storage = SkRect::MakeIWH(image->width(), image->height()); 198 src_storage = SkRect::MakeIWH(image->width(), image->height());
183 src = &src_storage; 199 src = &src_storage;
184 } 200 }
185 SkMatrix matrix; 201 SkMatrix matrix;
186 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); 202 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit);
187 matrix.postConcat(getTotalMatrix()); 203 matrix.postConcat(getTotalMatrix());
188 204
189 ScopedDecodedImageLock scoped_lock(image_decode_cache_, sk_ref_sp(image), 205 ScopedDecodedImageLock scoped_lock(image_decode_cache_, sk_ref_sp(image),
(...skipping 12 matching lines...) Expand all
202 float y_scale = decoded_image.scale_adjustment().height(); 218 float y_scale = decoded_image.scale_adjustment().height();
203 adjusted_src = SkRect::MakeXYWH( 219 adjusted_src = SkRect::MakeXYWH(
204 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale, 220 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale,
205 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale); 221 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale);
206 } 222 }
207 SkNWayCanvas::onDrawImageRect(decoded_image.image().get(), &adjusted_src, dst, 223 SkNWayCanvas::onDrawImageRect(decoded_image.image().get(), &adjusted_src, dst,
208 decoded_paint, constraint); 224 decoded_paint, constraint);
209 } 225 }
210 226
211 void ImageHijackCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { 227 void ImageHijackCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) {
228 if (ShouldSkipImageInPaint(paint))
229 return;
230
212 base::Optional<ScopedImagePaint> image_paint = 231 base::Optional<ScopedImagePaint> image_paint =
213 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); 232 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint);
214 if (!image_paint.has_value()) { 233 if (!image_paint.has_value()) {
215 SkNWayCanvas::onDrawRect(r, paint); 234 SkNWayCanvas::onDrawRect(r, paint);
216 return; 235 return;
217 } 236 }
218 SkNWayCanvas::onDrawRect(r, image_paint.value().paint()); 237 SkNWayCanvas::onDrawRect(r, image_paint.value().paint());
219 } 238 }
220 239
221 void ImageHijackCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { 240 void ImageHijackCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
241 if (ShouldSkipImageInPaint(paint))
242 return;
243
222 base::Optional<ScopedImagePaint> image_paint = 244 base::Optional<ScopedImagePaint> image_paint =
223 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); 245 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint);
224 if (!image_paint.has_value()) { 246 if (!image_paint.has_value()) {
225 SkNWayCanvas::onDrawPath(path, paint); 247 SkNWayCanvas::onDrawPath(path, paint);
226 return; 248 return;
227 } 249 }
228 SkNWayCanvas::onDrawPath(path, image_paint.value().paint()); 250 SkNWayCanvas::onDrawPath(path, image_paint.value().paint());
229 } 251 }
230 252
231 void ImageHijackCanvas::onDrawOval(const SkRect& r, const SkPaint& paint) { 253 void ImageHijackCanvas::onDrawOval(const SkRect& r, const SkPaint& paint) {
254 if (ShouldSkipImageInPaint(paint))
255 return;
256
232 base::Optional<ScopedImagePaint> image_paint = 257 base::Optional<ScopedImagePaint> image_paint =
233 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); 258 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint);
234 if (!image_paint.has_value()) { 259 if (!image_paint.has_value()) {
235 SkNWayCanvas::onDrawOval(r, paint); 260 SkNWayCanvas::onDrawOval(r, paint);
236 return; 261 return;
237 } 262 }
238 SkNWayCanvas::onDrawOval(r, image_paint.value().paint()); 263 SkNWayCanvas::onDrawOval(r, image_paint.value().paint());
239 } 264 }
240 265
241 void ImageHijackCanvas::onDrawArc(const SkRect& r, 266 void ImageHijackCanvas::onDrawArc(const SkRect& r,
242 SkScalar start_angle, 267 SkScalar start_angle,
243 SkScalar sweep_angle, 268 SkScalar sweep_angle,
244 bool use_center, 269 bool use_center,
245 const SkPaint& paint) { 270 const SkPaint& paint) {
271 if (ShouldSkipImageInPaint(paint))
272 return;
273
246 base::Optional<ScopedImagePaint> image_paint = 274 base::Optional<ScopedImagePaint> image_paint =
247 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); 275 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint);
248 if (!image_paint.has_value()) { 276 if (!image_paint.has_value()) {
249 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, paint); 277 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, paint);
250 return; 278 return;
251 } 279 }
252 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center, 280 SkNWayCanvas::onDrawArc(r, start_angle, sweep_angle, use_center,
253 image_paint.value().paint()); 281 image_paint.value().paint());
254 } 282 }
255 283
256 void ImageHijackCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) { 284 void ImageHijackCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) {
285 if (ShouldSkipImageInPaint(paint))
286 return;
287
257 base::Optional<ScopedImagePaint> image_paint = 288 base::Optional<ScopedImagePaint> image_paint =
258 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint); 289 ScopedImagePaint::TryCreate(image_decode_cache_, getTotalMatrix(), paint);
259 if (!image_paint.has_value()) { 290 if (!image_paint.has_value()) {
260 SkNWayCanvas::onDrawRRect(rr, paint); 291 SkNWayCanvas::onDrawRRect(rr, paint);
261 return; 292 return;
262 } 293 }
263 SkNWayCanvas::onDrawRRect(rr, image_paint.value().paint()); 294 SkNWayCanvas::onDrawRRect(rr, image_paint.value().paint());
264 } 295 }
265 296
266 void ImageHijackCanvas::onDrawImageNine(const SkImage* image, 297 void ImageHijackCanvas::onDrawImageNine(const SkImage* image,
267 const SkIRect& center, 298 const SkIRect& center,
268 const SkRect& dst, 299 const SkRect& dst,
269 const SkPaint* paint) { 300 const SkPaint* paint) {
270 // No cc embedder issues image nine calls. 301 // No cc embedder issues image nine calls.
271 NOTREACHED(); 302 NOTREACHED();
272 } 303 }
273 304
305 bool ImageHijackCanvas::ShouldSkipImage(const SkImage* image) const {
306 return images_to_skip_->find(image->uniqueID()) != images_to_skip_->end();
307 }
308
309 bool ImageHijackCanvas::ShouldSkipImageInPaint(const SkPaint& paint) const {
310 const SkImage* image = GetImageInPaint(paint);
311 return image ? ShouldSkipImage(image) : false;
312 }
313
274 } // namespace cc 314 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/image_hijack_canvas.h ('k') | cc/playback/image_hijack_canvas_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698