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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "cc/proto/display_item.pb.h" | |
15 #include "cc/proto/gfx_conversions.h" | |
16 #include "cc/proto/skia_conversions.h" | |
17 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
18 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
19 | 16 |
20 namespace cc { | 17 namespace cc { |
21 class ImageSerializationProcessor; | 18 class ImageSerializationProcessor; |
22 | 19 |
23 ClipDisplayItem::ClipDisplayItem(const gfx::Rect& clip_rect, | 20 ClipDisplayItem::ClipDisplayItem(const gfx::Rect& clip_rect, |
24 const std::vector<SkRRect>& rounded_clip_rects, | 21 const std::vector<SkRRect>& rounded_clip_rects, |
25 bool antialias) | 22 bool antialias) |
26 : DisplayItem(CLIP) { | 23 : DisplayItem(CLIP) { |
27 SetNew(clip_rect, rounded_clip_rects, antialias); | 24 SetNew(clip_rect, rounded_clip_rects, antialias); |
28 } | 25 } |
29 | 26 |
30 ClipDisplayItem::ClipDisplayItem(const proto::DisplayItem& proto) | |
31 : DisplayItem(CLIP) { | |
32 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); | |
33 | |
34 const proto::ClipDisplayItem& details = proto.clip_item(); | |
35 gfx::Rect clip_rect = ProtoToRect(details.clip_rect()); | |
36 std::vector<SkRRect> rounded_clip_rects; | |
37 rounded_clip_rects.reserve(details.rounded_rects_size()); | |
38 for (int i = 0; i < details.rounded_rects_size(); i++) { | |
39 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i))); | |
40 } | |
41 bool antialias = details.antialias(); | |
42 SetNew(clip_rect, rounded_clip_rects, antialias); | |
43 } | |
44 | |
45 void ClipDisplayItem::SetNew(const gfx::Rect& clip_rect, | 27 void ClipDisplayItem::SetNew(const gfx::Rect& clip_rect, |
46 const std::vector<SkRRect>& rounded_clip_rects, | 28 const std::vector<SkRRect>& rounded_clip_rects, |
47 bool antialias) { | 29 bool antialias) { |
48 clip_rect_ = clip_rect; | 30 clip_rect_ = clip_rect; |
49 rounded_clip_rects_ = rounded_clip_rects; | 31 rounded_clip_rects_ = rounded_clip_rects; |
50 antialias_ = antialias; | 32 antialias_ = antialias; |
51 } | 33 } |
52 | 34 |
53 ClipDisplayItem::~ClipDisplayItem() {} | 35 ClipDisplayItem::~ClipDisplayItem() {} |
54 | 36 |
55 void ClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
56 proto->set_type(proto::DisplayItem::Type_Clip); | |
57 | |
58 proto::ClipDisplayItem* details = proto->mutable_clip_item(); | |
59 RectToProto(clip_rect_, details->mutable_clip_rect()); | |
60 DCHECK_EQ(0, details->rounded_rects_size()); | |
61 for (const auto& rrect : rounded_clip_rects_) { | |
62 SkRRectToProto(rrect, details->add_rounded_rects()); | |
63 } | |
64 details->set_antialias(antialias_); | |
65 } | |
66 | |
67 void ClipDisplayItem::Raster(SkCanvas* canvas, | 37 void ClipDisplayItem::Raster(SkCanvas* canvas, |
68 SkPicture::AbortCallback* callback) const { | 38 SkPicture::AbortCallback* callback) const { |
69 canvas->save(); | 39 canvas->save(); |
70 canvas->clipRect(gfx::RectToSkRect(clip_rect_), antialias_); | 40 canvas->clipRect(gfx::RectToSkRect(clip_rect_), antialias_); |
71 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { | 41 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { |
72 if (rounded_clip_rects_[i].isRect()) { | 42 if (rounded_clip_rects_[i].isRect()) { |
73 canvas->clipRect(rounded_clip_rects_[i].rect(), antialias_); | 43 canvas->clipRect(rounded_clip_rects_[i].rect(), antialias_); |
74 } else { | 44 } else { |
75 canvas->clipRRect(rounded_clip_rects_[i], antialias_); | 45 canvas->clipRRect(rounded_clip_rects_[i], antialias_); |
76 } | 46 } |
(...skipping 23 matching lines...) Expand all Loading... |
100 lower_right_radius.y()); | 70 lower_right_radius.y()); |
101 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); | 71 SkVector lower_left_radius = rounded_rect.radii(SkRRect::kLowerLeft_Corner); |
102 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), | 72 base::StringAppendF(&value, " [%f,%f]]", lower_left_radius.x(), |
103 lower_left_radius.y()); | 73 lower_left_radius.y()); |
104 } | 74 } |
105 array->AppendString(value); | 75 array->AppendString(value); |
106 } | 76 } |
107 | 77 |
108 EndClipDisplayItem::EndClipDisplayItem() : DisplayItem(END_CLIP) {} | 78 EndClipDisplayItem::EndClipDisplayItem() : DisplayItem(END_CLIP) {} |
109 | 79 |
110 EndClipDisplayItem::EndClipDisplayItem(const proto::DisplayItem& proto) | |
111 : DisplayItem(END_CLIP) { | |
112 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); | |
113 } | |
114 | |
115 EndClipDisplayItem::~EndClipDisplayItem() { | 80 EndClipDisplayItem::~EndClipDisplayItem() { |
116 } | 81 } |
117 | 82 |
118 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
119 proto->set_type(proto::DisplayItem::Type_EndClip); | |
120 } | |
121 | |
122 void EndClipDisplayItem::Raster(SkCanvas* canvas, | 83 void EndClipDisplayItem::Raster(SkCanvas* canvas, |
123 SkPicture::AbortCallback* callback) const { | 84 SkPicture::AbortCallback* callback) const { |
124 canvas->restore(); | 85 canvas->restore(); |
125 } | 86 } |
126 | 87 |
127 void EndClipDisplayItem::AsValueInto( | 88 void EndClipDisplayItem::AsValueInto( |
128 const gfx::Rect& visual_rect, | 89 const gfx::Rect& visual_rect, |
129 base::trace_event::TracedValue* array) const { | 90 base::trace_event::TracedValue* array) const { |
130 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", | 91 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", |
131 visual_rect.ToString().c_str())); | 92 visual_rect.ToString().c_str())); |
132 } | 93 } |
133 | 94 |
134 } // namespace cc | 95 } // namespace cc |
OLD | NEW |