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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
10 #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" | |
13 #include "cc/proto/gfx_conversions.h" | |
14 #include "cc/proto/skia_conversions.h" | |
11 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
13 | 17 |
14 namespace cc { | 18 namespace cc { |
15 | 19 |
16 ClipDisplayItem::ClipDisplayItem() { | 20 ClipDisplayItem::ClipDisplayItem() { |
17 } | 21 } |
18 | 22 |
19 ClipDisplayItem::~ClipDisplayItem() { | 23 ClipDisplayItem::~ClipDisplayItem() { |
20 } | 24 } |
21 | 25 |
22 void ClipDisplayItem::SetNew(gfx::Rect clip_rect, | 26 void ClipDisplayItem::SetNew(gfx::Rect clip_rect, |
23 const std::vector<SkRRect>& rounded_clip_rects) { | 27 const std::vector<SkRRect>& rounded_clip_rects) { |
24 clip_rect_ = clip_rect; | 28 clip_rect_ = clip_rect; |
25 rounded_clip_rects_ = rounded_clip_rects; | 29 rounded_clip_rects_ = rounded_clip_rects; |
26 | 30 |
27 size_t external_memory_usage = | 31 size_t external_memory_usage = |
28 rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]); | 32 rounded_clip_rects_.capacity() * sizeof(rounded_clip_rects_[0]); |
29 | 33 |
30 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | 34 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, |
31 external_memory_usage); | 35 external_memory_usage); |
32 } | 36 } |
33 | 37 |
38 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) { | |
39 proto->set_type(proto::DisplayItem::Type_Clip); | |
40 | |
41 proto::ClipDisplayItem* details = proto->mutable_details_clip(); | |
42 RectToProto(clip_rect_, details->mutable_clip_rect()); | |
43 details->clear_rounded_rects(); | |
vmpstr
2015/10/26 17:46:17
dcheck that the size is 0 instead
David Trainor- moved to gerrit
2015/10/26 20:42:56
Done.
| |
44 for (auto& rrect : rounded_clip_rects_) { | |
vmpstr
2015/10/26 17:46:17
const auto&
David Trainor- moved to gerrit
2015/10/26 20:42:56
Done.
| |
45 SkRRectToProto(rrect, details->add_rounded_rects()); | |
46 } | |
47 } | |
48 | |
49 void ClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
50 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); | |
51 | |
52 const proto::ClipDisplayItem& details = proto.details_clip(); | |
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 | |
34 void ClipDisplayItem::Raster(SkCanvas* canvas, | 62 void ClipDisplayItem::Raster(SkCanvas* canvas, |
35 const gfx::Rect& canvas_target_playback_rect, | 63 const gfx::Rect& canvas_target_playback_rect, |
36 SkPicture::AbortCallback* callback) const { | 64 SkPicture::AbortCallback* callback) const { |
37 canvas->save(); | 65 canvas->save(); |
38 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), | 66 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), |
39 clip_rect_.width(), clip_rect_.height())); | 67 clip_rect_.width(), clip_rect_.height())); |
40 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { | 68 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { |
41 if (rounded_clip_rects_[i].isRect()) { | 69 if (rounded_clip_rects_[i].isRect()) { |
42 canvas->clipRect(rounded_clip_rects_[i].rect()); | 70 canvas->clipRect(rounded_clip_rects_[i].rect()); |
43 } else { | 71 } else { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 } | 108 } |
81 | 109 |
82 EndClipDisplayItem::EndClipDisplayItem() { | 110 EndClipDisplayItem::EndClipDisplayItem() { |
83 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 111 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, |
84 0 /* external_memory_usage */); | 112 0 /* external_memory_usage */); |
85 } | 113 } |
86 | 114 |
87 EndClipDisplayItem::~EndClipDisplayItem() { | 115 EndClipDisplayItem::~EndClipDisplayItem() { |
88 } | 116 } |
89 | 117 |
118 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) { | |
119 proto->set_type(proto::DisplayItem::Type_EndClip); | |
120 } | |
121 | |
122 void EndClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
123 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); | |
124 } | |
125 | |
90 void EndClipDisplayItem::Raster(SkCanvas* canvas, | 126 void EndClipDisplayItem::Raster(SkCanvas* canvas, |
91 const gfx::Rect& canvas_target_playback_rect, | 127 const gfx::Rect& canvas_target_playback_rect, |
92 SkPicture::AbortCallback* callback) const { | 128 SkPicture::AbortCallback* callback) const { |
93 canvas->restore(); | 129 canvas->restore(); |
94 } | 130 } |
95 | 131 |
96 void EndClipDisplayItem::ProcessForBounds( | 132 void EndClipDisplayItem::ProcessForBounds( |
97 DisplayItemListBoundsCalculator* calculator) const { | 133 DisplayItemListBoundsCalculator* calculator) const { |
98 calculator->AddEndingDisplayItem(); | 134 calculator->AddEndingDisplayItem(); |
99 } | 135 } |
100 | 136 |
101 void EndClipDisplayItem::AsValueInto( | 137 void EndClipDisplayItem::AsValueInto( |
102 base::trace_event::TracedValue* array) const { | 138 base::trace_event::TracedValue* array) const { |
103 array->AppendString("EndClipDisplayItem"); | 139 array->AppendString("EndClipDisplayItem"); |
104 } | 140 } |
105 | 141 |
106 } // namespace cc | 142 } // namespace cc |
OLD | NEW |