OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/resources/clip_display_item.h" |
| 6 |
| 7 #include "third_party/skia/include/core/SkCanvas.h" |
| 8 |
| 9 namespace cc { |
| 10 |
| 11 ClipDisplayItem::ClipDisplayItem(gfx::Rect clip_rect, |
| 12 const std::vector<SkRRect>& rounded_clip_rects) |
| 13 : clip_rect_(clip_rect), rounded_clip_rects_(rounded_clip_rects) { |
| 14 } |
| 15 |
| 16 ClipDisplayItem::~ClipDisplayItem() { |
| 17 } |
| 18 |
| 19 void ClipDisplayItem::Raster(SkCanvas* canvas, |
| 20 SkDrawPictureCallback* callback) const { |
| 21 canvas->save(); |
| 22 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), |
| 23 clip_rect_.width(), clip_rect_.height())); |
| 24 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { |
| 25 if (rounded_clip_rects_[i].isRect()) { |
| 26 canvas->clipRect(rounded_clip_rects_[i].rect()); |
| 27 } else { |
| 28 bool antialiased = true; |
| 29 canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op, |
| 30 antialiased); |
| 31 } |
| 32 } |
| 33 } |
| 34 |
| 35 bool ClipDisplayItem::IsSuitableForGpuRasterization() const { |
| 36 return true; |
| 37 } |
| 38 |
| 39 int ClipDisplayItem::ApproximateOpCount() const { |
| 40 return 1; |
| 41 } |
| 42 |
| 43 size_t ClipDisplayItem::PictureMemoryUsage() const { |
| 44 size_t total_size = sizeof(gfx::Rect); |
| 45 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { |
| 46 total_size += sizeof(rounded_clip_rects_[i]); |
| 47 } |
| 48 return total_size; |
| 49 } |
| 50 |
| 51 EndClipDisplayItem::EndClipDisplayItem() { |
| 52 } |
| 53 |
| 54 EndClipDisplayItem::~EndClipDisplayItem() { |
| 55 } |
| 56 |
| 57 void EndClipDisplayItem::Raster(SkCanvas* canvas, |
| 58 SkDrawPictureCallback* callback) const { |
| 59 canvas->restore(); |
| 60 } |
| 61 |
| 62 bool EndClipDisplayItem::IsSuitableForGpuRasterization() const { |
| 63 return true; |
| 64 } |
| 65 |
| 66 int EndClipDisplayItem::ApproximateOpCount() const { |
| 67 return 0; |
| 68 } |
| 69 |
| 70 size_t EndClipDisplayItem::PictureMemoryUsage() const { |
| 71 return 0; |
| 72 } |
| 73 |
| 74 } // namespace cc |
OLD | NEW |