| OLD | NEW |
| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 GatherPixelRefDevice::drawRect(draw, bounds, paint); | 87 GatherPixelRefDevice::drawRect(draw, bounds, paint); |
| 88 } | 88 } |
| 89 void drawRect(const SkDraw& draw, | 89 void drawRect(const SkDraw& draw, |
| 90 const SkRect& rect, | 90 const SkRect& rect, |
| 91 const SkPaint& paint) override { | 91 const SkPaint& paint) override { |
| 92 SkBitmap bitmap; | 92 SkBitmap bitmap; |
| 93 if (GetBitmapFromPaint(paint, &bitmap)) { | 93 if (GetBitmapFromPaint(paint, &bitmap)) { |
| 94 SkRect mapped_rect; | 94 SkRect mapped_rect; |
| 95 draw.fMatrix->mapRect(&mapped_rect, rect); | 95 draw.fMatrix->mapRect(&mapped_rect, rect); |
| 96 mapped_rect.intersect(SkRect::Make(draw.fRC->getBounds())); | 96 if (mapped_rect.intersect(SkRect::Make(draw.fRC->getBounds()))) |
| 97 AddBitmap(bitmap, mapped_rect); | 97 AddBitmap(bitmap, mapped_rect); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 void drawOval(const SkDraw& draw, | 100 void drawOval(const SkDraw& draw, |
| 101 const SkRect& rect, | 101 const SkRect& rect, |
| 102 const SkPaint& paint) override { | 102 const SkPaint& paint) override { |
| 103 GatherPixelRefDevice::drawRect(draw, rect, paint); | 103 GatherPixelRefDevice::drawRect(draw, rect, paint); |
| 104 } | 104 } |
| 105 void drawRRect(const SkDraw& draw, | 105 void drawRRect(const SkDraw& draw, |
| 106 const SkRRect& rect, | 106 const SkRRect& rect, |
| 107 const SkPaint& paint) override { | 107 const SkPaint& paint) override { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 int y) override { | 320 int y) override { |
| 321 return false; | 321 return false; |
| 322 } | 322 } |
| 323 | 323 |
| 324 private: | 324 private: |
| 325 DiscardablePixelRefSet* pixel_ref_set_; | 325 DiscardablePixelRefSet* pixel_ref_set_; |
| 326 | 326 |
| 327 void AddBitmap(const SkBitmap& bm, const SkRect& rect) { | 327 void AddBitmap(const SkBitmap& bm, const SkRect& rect) { |
| 328 SkRect canvas_rect = SkRect::MakeWH(width(), height()); | 328 SkRect canvas_rect = SkRect::MakeWH(width(), height()); |
| 329 SkRect paint_rect = SkRect::MakeEmpty(); | 329 SkRect paint_rect = SkRect::MakeEmpty(); |
| 330 paint_rect.intersect(rect, canvas_rect); | 330 if (paint_rect.intersect(rect, canvas_rect)) |
| 331 pixel_ref_set_->Add(bm.pixelRef(), paint_rect); | 331 pixel_ref_set_->Add(bm.pixelRef(), paint_rect); |
| 332 } | 332 } |
| 333 | 333 |
| 334 bool GetBitmapFromPaint(const SkPaint& paint, SkBitmap* bm) { | 334 bool GetBitmapFromPaint(const SkPaint& paint, SkBitmap* bm) { |
| 335 SkShader* shader = paint.getShader(); | 335 SkShader* shader = paint.getShader(); |
| 336 if (shader) { | 336 if (shader) { |
| 337 // Check whether the shader is a gradient in order to prevent generation | 337 // Check whether the shader is a gradient in order to prevent generation |
| 338 // of bitmaps from gradient shaders, which implement asABitmap. | 338 // of bitmaps from gradient shaders, which implement asABitmap. |
| 339 if (SkShader::kNone_GradientType == shader->asAGradient(NULL)) | 339 if (SkShader::kNone_GradientType == shader->asAGradient(NULL)) |
| 340 return shader->asABitmap(bm, NULL, NULL); | 340 return shader->asABitmap(bm, NULL, NULL); |
| 341 } | 341 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 359 | 359 |
| 360 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); | 360 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); |
| 361 SkNoSaveLayerCanvas canvas(&device); | 361 SkNoSaveLayerCanvas canvas(&device); |
| 362 | 362 |
| 363 // Draw the picture pinned against our top/left corner. | 363 // Draw the picture pinned against our top/left corner. |
| 364 canvas.translate(-picture_bounds.left(), -picture_bounds.top()); | 364 canvas.translate(-picture_bounds.left(), -picture_bounds.top()); |
| 365 canvas.drawPicture(picture); | 365 canvas.drawPicture(picture); |
| 366 } | 366 } |
| 367 | 367 |
| 368 } // namespace skia | 368 } // namespace skia |
| OLD | NEW |