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 const 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 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); |
| 28 |
| 29 const proto::ClipDisplayItem& details = proto.clip_item(); |
| 30 gfx::Rect clip_rect = ProtoToRect(details.clip_rect()); |
| 31 std::vector<SkRRect> rounded_clip_rects; |
| 32 rounded_clip_rects.reserve(details.rounded_rects_size()); |
| 33 for (int i = 0; i < details.rounded_rects_size(); i++) { |
| 34 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i))); |
| 35 } |
| 36 SetNew(clip_rect, rounded_clip_rects); |
24 } | 37 } |
25 | 38 |
26 void ClipDisplayItem::SetNew(gfx::Rect clip_rect, | 39 void ClipDisplayItem::SetNew(const gfx::Rect& clip_rect, |
27 const std::vector<SkRRect>& rounded_clip_rects) { | 40 const std::vector<SkRRect>& rounded_clip_rects) { |
28 clip_rect_ = clip_rect; | 41 clip_rect_ = clip_rect; |
29 rounded_clip_rects_ = rounded_clip_rects; | 42 rounded_clip_rects_ = rounded_clip_rects; |
| 43 } |
30 | 44 |
31 size_t external_memory_usage = | 45 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 | 46 |
38 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 47 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
39 proto->set_type(proto::DisplayItem::Type_Clip); | 48 proto->set_type(proto::DisplayItem::Type_Clip); |
40 | 49 |
41 proto::ClipDisplayItem* details = proto->mutable_clip_item(); | 50 proto::ClipDisplayItem* details = proto->mutable_clip_item(); |
42 RectToProto(clip_rect_, details->mutable_clip_rect()); | 51 RectToProto(clip_rect_, details->mutable_clip_rect()); |
43 DCHECK_EQ(0, details->rounded_rects_size()); | 52 DCHECK_EQ(0, details->rounded_rects_size()); |
44 for (const auto& rrect : rounded_clip_rects_) { | 53 for (const auto& rrect : rounded_clip_rects_) { |
45 SkRRectToProto(rrect, details->add_rounded_rects()); | 54 SkRRectToProto(rrect, details->add_rounded_rects()); |
46 } | 55 } |
47 } | 56 } |
48 | 57 |
49 void ClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
50 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); | |
51 | |
52 const proto::ClipDisplayItem& details = proto.clip_item(); | |
53 gfx::Rect clip_rect = ProtoToRect(details.clip_rect()); | |
54 std::vector<SkRRect> rounded_clip_rects; | |
55 rounded_clip_rects.reserve(details.rounded_rects_size()); | |
56 for (int i = 0; i < details.rounded_rects_size(); i++) { | |
57 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i))); | |
58 } | |
59 SetNew(clip_rect, rounded_clip_rects); | |
60 } | |
61 | |
62 void ClipDisplayItem::Raster(SkCanvas* canvas, | 58 void ClipDisplayItem::Raster(SkCanvas* canvas, |
63 const gfx::Rect& canvas_target_playback_rect, | 59 const gfx::Rect& canvas_target_playback_rect, |
64 SkPicture::AbortCallback* callback) const { | 60 SkPicture::AbortCallback* callback) const { |
65 canvas->save(); | 61 canvas->save(); |
66 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), | 62 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), |
67 clip_rect_.width(), clip_rect_.height())); | 63 clip_rect_.width(), clip_rect_.height())); |
68 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { | 64 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { |
69 if (rounded_clip_rects_[i].isRect()) { | 65 if (rounded_clip_rects_[i].isRect()) { |
70 canvas->clipRect(rounded_clip_rects_[i].rect()); | 66 canvas->clipRect(rounded_clip_rects_[i].rect()); |
71 } else { | 67 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
97 rounded_rect.radii(SkRRect::kLowerRight_Corner); | 93 rounded_rect.radii(SkRRect::kLowerRight_Corner); |
98 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(), | 94 base::StringAppendF(&value, " [%f,%f],", lower_right_radius.x(), |
99 lower_right_radius.y()); | 95 lower_right_radius.y()); |
100 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); | 96 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); |
101 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), | 97 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), |
102 lower_left_radius.y()); | 98 lower_left_radius.y()); |
103 } | 99 } |
104 array->AppendString(value); | 100 array->AppendString(value); |
105 } | 101 } |
106 | 102 |
107 EndClipDisplayItem::EndClipDisplayItem() { | 103 size_t ClipDisplayItem::ExternalMemoryUsage() const { |
108 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 104 return rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]); |
109 0 /* external_memory_usage */); | 105 } |
| 106 |
| 107 EndClipDisplayItem::EndClipDisplayItem() {} |
| 108 |
| 109 EndClipDisplayItem::EndClipDisplayItem(const proto::DisplayItem& proto) { |
| 110 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); |
110 } | 111 } |
111 | 112 |
112 EndClipDisplayItem::~EndClipDisplayItem() { | 113 EndClipDisplayItem::~EndClipDisplayItem() { |
113 } | 114 } |
114 | 115 |
115 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 116 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
116 proto->set_type(proto::DisplayItem::Type_EndClip); | 117 proto->set_type(proto::DisplayItem::Type_EndClip); |
117 } | 118 } |
118 | 119 |
119 void EndClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
120 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); | |
121 } | |
122 | |
123 void EndClipDisplayItem::Raster(SkCanvas* canvas, | 120 void EndClipDisplayItem::Raster(SkCanvas* canvas, |
124 const gfx::Rect& canvas_target_playback_rect, | 121 const gfx::Rect& canvas_target_playback_rect, |
125 SkPicture::AbortCallback* callback) const { | 122 SkPicture::AbortCallback* callback) const { |
126 canvas->restore(); | 123 canvas->restore(); |
127 } | 124 } |
128 | 125 |
129 void EndClipDisplayItem::AsValueInto( | 126 void EndClipDisplayItem::AsValueInto( |
130 const gfx::Rect& visual_rect, | 127 const gfx::Rect& visual_rect, |
131 base::trace_event::TracedValue* array) const { | 128 base::trace_event::TracedValue* array) const { |
132 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", | 129 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", |
133 visual_rect.ToString().c_str())); | 130 visual_rect.ToString().c_str())); |
134 } | 131 } |
135 | 132 |
| 133 size_t EndClipDisplayItem::ExternalMemoryUsage() const { |
| 134 return 0; |
| 135 } |
| 136 |
136 } // namespace cc | 137 } // namespace cc |
OLD | NEW |