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.
5 #include "cc/resources/clip_display_item.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "ui/gfx/skia_util.h"
16 ClipDisplayItem::ClipDisplayItem(gfx::Rect clip_rect
,
17 const std::vector
<SkRRect
>& rounded_clip_rects
)
18 : clip_rect_(clip_rect
), rounded_clip_rects_(rounded_clip_rects
) {
21 ClipDisplayItem::~ClipDisplayItem() {
24 void ClipDisplayItem::Raster(SkCanvas
* canvas
,
25 SkDrawPictureCallback
* callback
) const {
27 canvas
->clipRect(SkRect::MakeXYWH(clip_rect_
.x(), clip_rect_
.y(),
28 clip_rect_
.width(), clip_rect_
.height()));
29 for (size_t i
= 0; i
< rounded_clip_rects_
.size(); ++i
) {
30 if (rounded_clip_rects_
[i
].isRect()) {
31 canvas
->clipRect(rounded_clip_rects_
[i
].rect());
33 bool antialiased
= true;
34 canvas
->clipRRect(rounded_clip_rects_
[i
], SkRegion::kIntersect_Op
,
40 bool ClipDisplayItem::IsSuitableForGpuRasterization() const {
44 int ClipDisplayItem::ApproximateOpCount() const {
48 size_t ClipDisplayItem::PictureMemoryUsage() const {
49 size_t total_size
= sizeof(gfx::Rect
);
50 for (size_t i
= 0; i
< rounded_clip_rects_
.size(); ++i
) {
51 total_size
+= sizeof(rounded_clip_rects_
[i
]);
56 void ClipDisplayItem::AsValueInto(base::trace_event::TracedValue
* array
) const {
57 std::string value
= base::StringPrintf("ClipDisplayItem rect: [%s]",
58 clip_rect_
.ToString().c_str());
59 for (const SkRRect
& rounded_rect
: rounded_clip_rects_
) {
61 &value
, " rounded_rect: [rect: [%s]",
62 gfx::SkRectToRectF(rounded_rect
.rect()).ToString().c_str());
63 base::StringAppendF(&value
, " radii: [");
64 SkVector upper_left_radius
= rounded_rect
.radii(SkRRect::kUpperLeft_Corner
);
65 base::StringAppendF(&value
, "[%f,%f],", upper_left_radius
.x(),
66 upper_left_radius
.y());
67 SkVector upper_right_radius
=
68 rounded_rect
.radii(SkRRect::kUpperRight_Corner
);
69 base::StringAppendF(&value
, " [%f,%f],", upper_right_radius
.x(),
70 upper_right_radius
.y());
71 SkVector lower_right_radius
=
72 rounded_rect
.radii(SkRRect::kLowerRight_Corner
);
73 base::StringAppendF(&value
, " [%f,%f],", lower_right_radius
.x(),
74 lower_right_radius
.y());
75 SkVector lower_left_radius
= rounded_rect
.radii(SkRRect::kLowerLeft_Corner
);
76 base::StringAppendF(&value
, " [%f,%f]]", lower_left_radius
.x(),
77 lower_left_radius
.y());
79 array
->AppendString(value
);
82 EndClipDisplayItem::EndClipDisplayItem() {
85 EndClipDisplayItem::~EndClipDisplayItem() {
88 void EndClipDisplayItem::Raster(SkCanvas
* canvas
,
89 SkDrawPictureCallback
* callback
) const {
93 bool EndClipDisplayItem::IsSuitableForGpuRasterization() const {
97 int EndClipDisplayItem::ApproximateOpCount() const {
101 size_t EndClipDisplayItem::PictureMemoryUsage() const {
105 void EndClipDisplayItem::AsValueInto(
106 base::trace_event::TracedValue
* array
) const {
107 array
->AppendString("EndClipDisplayItem");