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() {
19 ClipDisplayItem::~ClipDisplayItem() {
22 void ClipDisplayItem::SetNew(gfx::Rect clip_rect
,
23 const std::vector
<SkRRect
>& rounded_clip_rects
) {
24 clip_rect_
= clip_rect
;
25 rounded_clip_rects_
= rounded_clip_rects
;
27 size_t memory_usage
= sizeof(gfx::Rect
);
28 for (size_t i
= 0; i
< rounded_clip_rects_
.size(); ++i
) {
29 memory_usage
+= sizeof(rounded_clip_rects_
[i
]);
31 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
35 void ClipDisplayItem::Raster(SkCanvas
* canvas
,
36 SkDrawPictureCallback
* callback
) const {
38 canvas
->clipRect(SkRect::MakeXYWH(clip_rect_
.x(), clip_rect_
.y(),
39 clip_rect_
.width(), clip_rect_
.height()));
40 for (size_t i
= 0; i
< rounded_clip_rects_
.size(); ++i
) {
41 if (rounded_clip_rects_
[i
].isRect()) {
42 canvas
->clipRect(rounded_clip_rects_
[i
].rect());
44 bool antialiased
= true;
45 canvas
->clipRRect(rounded_clip_rects_
[i
], SkRegion::kIntersect_Op
,
51 void ClipDisplayItem::AsValueInto(base::trace_event::TracedValue
* array
) const {
52 std::string value
= base::StringPrintf("ClipDisplayItem rect: [%s]",
53 clip_rect_
.ToString().c_str());
54 for (const SkRRect
& rounded_rect
: rounded_clip_rects_
) {
56 &value
, " rounded_rect: [rect: [%s]",
57 gfx::SkRectToRectF(rounded_rect
.rect()).ToString().c_str());
58 base::StringAppendF(&value
, " radii: [");
59 SkVector upper_left_radius
= rounded_rect
.radii(SkRRect::kUpperLeft_Corner
);
60 base::StringAppendF(&value
, "[%f,%f],", upper_left_radius
.x(),
61 upper_left_radius
.y());
62 SkVector upper_right_radius
=
63 rounded_rect
.radii(SkRRect::kUpperRight_Corner
);
64 base::StringAppendF(&value
, " [%f,%f],", upper_right_radius
.x(),
65 upper_right_radius
.y());
66 SkVector lower_right_radius
=
67 rounded_rect
.radii(SkRRect::kLowerRight_Corner
);
68 base::StringAppendF(&value
, " [%f,%f],", lower_right_radius
.x(),
69 lower_right_radius
.y());
70 SkVector lower_left_radius
= rounded_rect
.radii(SkRRect::kLowerLeft_Corner
);
71 base::StringAppendF(&value
, " [%f,%f]]", lower_left_radius
.x(),
72 lower_left_radius
.y());
74 array
->AppendString(value
);
77 EndClipDisplayItem::EndClipDisplayItem() {
78 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
79 0 /* memory_usage */);
82 EndClipDisplayItem::~EndClipDisplayItem() {
85 void EndClipDisplayItem::Raster(SkCanvas
* canvas
,
86 SkDrawPictureCallback
* callback
) const {
90 void EndClipDisplayItem::AsValueInto(
91 base::trace_event::TracedValue
* array
) const {
92 array
->AppendString("EndClipDisplayItem");