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

Side by Side Diff: skia/ext/pixel_ref_utils.cc

Issue 1279843004: cc: Plumb more details about pixel refs to tile manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« cc/playback/pixel_ref_map.cc ('K') | « skia/ext/pixel_ref_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "skia/ext/pixel_ref_utils.h" 5 #include "skia/ext/pixel_ref_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "third_party/skia/include/core/SkBitmapDevice.h" 9 #include "third_party/skia/include/core/SkBitmapDevice.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 GatherPixelRefDevice::drawRect(draw, bounds, paint); 94 GatherPixelRefDevice::drawRect(draw, bounds, paint);
95 } 95 }
96 void drawRect(const SkDraw& draw, 96 void drawRect(const SkDraw& draw,
97 const SkRect& rect, 97 const SkRect& rect,
98 const SkPaint& paint) override { 98 const SkPaint& paint) override {
99 SkBitmap bitmap; 99 SkBitmap bitmap;
100 if (GetBitmapFromPaint(paint, &bitmap)) { 100 if (GetBitmapFromPaint(paint, &bitmap)) {
101 SkRect mapped_rect; 101 SkRect mapped_rect;
102 draw.fMatrix->mapRect(&mapped_rect, rect); 102 draw.fMatrix->mapRect(&mapped_rect, rect);
103 if (mapped_rect.intersect(SkRect::Make(draw.fRC->getBounds()))) { 103 if (mapped_rect.intersects(SkRect::Make(draw.fRC->getBounds()))) {
104 AddBitmap(bitmap, mapped_rect, *draw.fMatrix, paint.getFilterQuality()); 104 AddBitmap(bitmap, mapped_rect, *draw.fMatrix, paint.getFilterQuality());
105 } 105 }
106 } 106 }
107 } 107 }
108 void drawOval(const SkDraw& draw, 108 void drawOval(const SkDraw& draw,
109 const SkRect& rect, 109 const SkRect& rect,
110 const SkPaint& paint) override { 110 const SkPaint& paint) override {
111 GatherPixelRefDevice::drawRect(draw, rect, paint); 111 GatherPixelRefDevice::drawRect(draw, rect, paint);
112 } 112 }
113 void drawRRect(const SkDraw& draw, 113 void drawRRect(const SkDraw& draw,
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 348 }
349 349
350 private: 350 private:
351 DiscardablePixelRefSet* pixel_ref_set_; 351 DiscardablePixelRefSet* pixel_ref_set_;
352 352
353 void AddBitmap(const SkBitmap& bm, 353 void AddBitmap(const SkBitmap& bm,
354 const SkRect& rect, 354 const SkRect& rect,
355 const SkMatrix& matrix, 355 const SkMatrix& matrix,
356 SkFilterQuality filter_quality) { 356 SkFilterQuality filter_quality) {
357 SkRect canvas_rect = SkRect::MakeWH(width(), height()); 357 SkRect canvas_rect = SkRect::MakeWH(width(), height());
358 SkRect paint_rect = SkRect::MakeEmpty(); 358 if (rect.intersects(canvas_rect)) {
359 if (paint_rect.intersect(rect, canvas_rect)) { 359 pixel_ref_set_->Add(bm.pixelRef(), rect, matrix, filter_quality);
360 pixel_ref_set_->Add(bm.pixelRef(), paint_rect, matrix,
361 filter_quality);
362 } 360 }
363 } 361 }
364 362
365 bool GetBitmapFromPaint(const SkPaint& paint, SkBitmap* bm) { 363 bool GetBitmapFromPaint(const SkPaint& paint, SkBitmap* bm) {
366 SkShader* shader = paint.getShader(); 364 SkShader* shader = paint.getShader();
367 if (shader) { 365 if (shader) {
368 // Check whether the shader is a gradient in order to prevent generation 366 // Check whether the shader is a gradient in order to prevent generation
369 // of bitmaps from gradient shaders, which implement asABitmap. 367 // of bitmaps from gradient shaders, which implement asABitmap.
370 if (SkShader::kNone_GradientType == shader->asAGradient(NULL)) 368 if (SkShader::kNone_GradientType == shader->asAGradient(NULL))
371 return shader->asABitmap(bm, NULL, NULL); 369 return shader->asABitmap(bm, NULL, NULL);
372 } 370 }
373 return false; 371 return false;
374 } 372 }
375 }; 373 };
376 374
377 } // namespace 375 } // namespace
378 376
379 void PixelRefUtils::GatherDiscardablePixelRefs( 377 void PixelRefUtils::GatherDiscardablePixelRefs(
380 SkPicture* picture, 378 SkPicture* picture,
381 std::vector<PositionPixelRef>* pixel_refs) { 379 std::vector<PositionPixelRef>* pixel_refs) {
382 pixel_refs->clear(); 380 pixel_refs->clear();
383 DiscardablePixelRefSet pixel_ref_set(pixel_refs); 381 DiscardablePixelRefSet pixel_ref_set(pixel_refs);
384 382
385 SkRect picture_bounds = picture->cullRect(); 383 SkRect picture_bounds = picture->cullRect();
386 SkIRect picture_ibounds = picture_bounds.roundOut(); 384 SkIRect picture_ibounds = picture_bounds.roundOut();
387 SkBitmap empty_bitmap; 385 SkBitmap empty_bitmap;
388 empty_bitmap.setInfo(SkImageInfo::MakeUnknown(picture_ibounds.width(), 386 empty_bitmap.setInfo(SkImageInfo::MakeUnknown(picture_ibounds.right(),
reed1 2015/08/10 17:58:38 it might justify a comment here, why we're using r
vmpstr 2015/08/11 21:00:49 Done.
389 picture_ibounds.height())); 387 picture_ibounds.bottom()));
390 388
391 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); 389 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set);
392 SkNoSaveLayerCanvas canvas(&device); 390 SkNoSaveLayerCanvas canvas(&device);
393 391
394 // Draw the picture pinned against our top/left corner.
395 canvas.translate(-picture_bounds.left(), -picture_bounds.top());
396 canvas.drawPicture(picture); 392 canvas.drawPicture(picture);
397 } 393 }
398 394
399 } // namespace skia 395 } // namespace skia
OLDNEW
« cc/playback/pixel_ref_map.cc ('K') | « skia/ext/pixel_ref_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698