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 "cc/playback/clip_display_item.h" | 5 #include "cc/playback/clip_display_item.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
12 #include "cc/proto/display_item.pb.h" | 12 #include "cc/proto/display_item.pb.h" |
13 #include "cc/proto/gfx_conversions.h" | 13 #include "cc/proto/gfx_conversions.h" |
14 #include "cc/proto/skia_conversions.h" | 14 #include "cc/proto/skia_conversions.h" |
15 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
16 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 ClipDisplayItem::ClipDisplayItem() { | 20 ClipDisplayItem::ClipDisplayItem( |
| 21 gfx::Rect clip_rect, |
| 22 const std::vector<SkRRect>& rounded_clip_rects) { |
| 23 SetNew(clip_rect, rounded_clip_rects); |
21 } | 24 } |
22 | 25 |
23 ClipDisplayItem::~ClipDisplayItem() { | 26 ClipDisplayItem::ClipDisplayItem(const proto::DisplayItem& proto) { |
| 27 FromProtobuf(proto); |
24 } | 28 } |
25 | 29 |
26 void ClipDisplayItem::SetNew(gfx::Rect clip_rect, | 30 void ClipDisplayItem::SetNew(gfx::Rect clip_rect, |
27 const std::vector<SkRRect>& rounded_clip_rects) { | 31 const std::vector<SkRRect>& rounded_clip_rects) { |
28 clip_rect_ = clip_rect; | 32 clip_rect_ = clip_rect; |
29 rounded_clip_rects_ = rounded_clip_rects; | 33 rounded_clip_rects_ = rounded_clip_rects; |
| 34 } |
30 | 35 |
31 size_t external_memory_usage = | 36 ClipDisplayItem::~ClipDisplayItem() {} |
32 rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]); | |
33 | |
34 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | |
35 external_memory_usage); | |
36 } | |
37 | 37 |
38 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 38 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
39 proto->set_type(proto::DisplayItem::Type_Clip); | 39 proto->set_type(proto::DisplayItem::Type_Clip); |
40 | 40 |
41 proto::ClipDisplayItem* details = proto->mutable_clip_item(); | 41 proto::ClipDisplayItem* details = proto->mutable_clip_item(); |
42 RectToProto(clip_rect_, details->mutable_clip_rect()); | 42 RectToProto(clip_rect_, details->mutable_clip_rect()); |
43 DCHECK_EQ(0, details->rounded_rects_size()); | 43 DCHECK_EQ(0, details->rounded_rects_size()); |
44 for (const auto& rrect : rounded_clip_rects_) { | 44 for (const auto& rrect : rounded_clip_rects_) { |
45 SkRRectToProto(rrect, details->add_rounded_rects()); | 45 SkRRectToProto(rrect, details->add_rounded_rects()); |
46 } | 46 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 rounded_rect.radii(SkRRect::kLowerRight_Corner); | 97 rounded_rect.radii(SkRRect::kLowerRight_Corner); |
98 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(), | 98 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(), |
99 lower_right_radius.y()); | 99 lower_right_radius.y()); |
100 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); | 100 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); |
101 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), | 101 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), |
102 lower_left_radius.y()); | 102 lower_left_radius.y()); |
103 } | 103 } |
104 array->AppendString(value); | 104 array->AppendString(value); |
105 } | 105 } |
106 | 106 |
107 EndClipDisplayItem::EndClipDisplayItem() { | 107 size_t ClipDisplayItem::ExternalMemoryUsage() const { |
108 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 108 return rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]); |
109 0 /* external_memory_usage */); | 109 } |
| 110 |
| 111 int ClipDisplayItem::ApproximateOpCount() const { |
| 112 return 1; |
| 113 } |
| 114 |
| 115 EndClipDisplayItem::EndClipDisplayItem() {} |
| 116 |
| 117 EndClipDisplayItem::EndClipDisplayItem(const proto::DisplayItem& proto) { |
| 118 FromProtobuf(proto); |
110 } | 119 } |
111 | 120 |
112 EndClipDisplayItem::~EndClipDisplayItem() { | 121 EndClipDisplayItem::~EndClipDisplayItem() { |
113 } | 122 } |
114 | 123 |
115 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 124 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
116 proto->set_type(proto::DisplayItem::Type_EndClip); | 125 proto->set_type(proto::DisplayItem::Type_EndClip); |
117 } | 126 } |
118 | 127 |
119 void EndClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | 128 void EndClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
120 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); | 129 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); |
121 } | 130 } |
122 | 131 |
123 void EndClipDisplayItem::Raster(SkCanvas* canvas, | 132 void EndClipDisplayItem::Raster(SkCanvas* canvas, |
124 const gfx::Rect& canvas_target_playback_rect, | 133 const gfx::Rect& canvas_target_playback_rect, |
125 SkPicture::AbortCallback* callback) const { | 134 SkPicture::AbortCallback* callback) const { |
126 canvas->restore(); | 135 canvas->restore(); |
127 } | 136 } |
128 | 137 |
129 void EndClipDisplayItem::AsValueInto( | 138 void EndClipDisplayItem::AsValueInto( |
130 const gfx::Rect& visual_rect, | 139 const gfx::Rect& visual_rect, |
131 base::trace_event::TracedValue* array) const { | 140 base::trace_event::TracedValue* array) const { |
132 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", | 141 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", |
133 visual_rect.ToString().c_str())); | 142 visual_rect.ToString().c_str())); |
134 } | 143 } |
135 | 144 |
| 145 size_t EndClipDisplayItem::ExternalMemoryUsage() const { |
| 146 return 0; |
| 147 } |
| 148 |
| 149 int EndClipDisplayItem::ApproximateOpCount() const { |
| 150 return 0; |
| 151 } |
| 152 |
136 } // namespace cc | 153 } // namespace cc |
OLD | NEW |