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 <string> | |
8 | |
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" | |
13 | |
14 namespace cc { | |
15 | |
16 ClipDisplayItem::ClipDisplayItem() { | |
17 } | |
18 | |
19 ClipDisplayItem::~ClipDisplayItem() { | |
20 } | |
21 | |
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; | |
26 | |
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]); | |
30 } | |
31 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | |
32 memory_usage); | |
33 } | |
34 | |
35 void ClipDisplayItem::Raster(SkCanvas* canvas, | |
36 SkDrawPictureCallback* callback) const { | |
37 canvas->save(); | |
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()); | |
43 } else { | |
44 bool antialiased = true; | |
45 canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op, | |
46 antialiased); | |
47 } | |
48 } | |
49 } | |
50 | |
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_) { | |
55 base::StringAppendF( | |
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()); | |
73 } | |
74 array->AppendString(value); | |
75 } | |
76 | |
77 EndClipDisplayItem::EndClipDisplayItem() { | |
78 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | |
79 0 /* memory_usage */); | |
80 } | |
81 | |
82 EndClipDisplayItem::~EndClipDisplayItem() { | |
83 } | |
84 | |
85 void EndClipDisplayItem::Raster(SkCanvas* canvas, | |
86 SkDrawPictureCallback* callback) const { | |
87 canvas->restore(); | |
88 } | |
89 | |
90 void EndClipDisplayItem::AsValueInto( | |
91 base::trace_event::TracedValue* array) const { | |
92 array->AppendString("EndClipDisplayItem"); | |
93 } | |
94 | |
95 } // namespace cc | |
OLD | NEW |