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) const { |
| 39 proto->set_type(proto::DisplayItem::Type_Clip); |
| 40 |
| 41 proto::ClipDisplayItem* details = proto->mutable_clip_item(); |
| 42 RectToProto(clip_rect_, details->mutable_clip_rect()); |
| 43 DCHECK_EQ(0, details->rounded_rects_size()); |
| 44 for (const auto& rrect : rounded_clip_rects_) { |
| 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.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 |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 103 } |
76 | 104 |
77 EndClipDisplayItem::EndClipDisplayItem() { | 105 EndClipDisplayItem::EndClipDisplayItem() { |
78 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 106 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, |
79 0 /* external_memory_usage */); | 107 0 /* external_memory_usage */); |
80 } | 108 } |
81 | 109 |
82 EndClipDisplayItem::~EndClipDisplayItem() { | 110 EndClipDisplayItem::~EndClipDisplayItem() { |
83 } | 111 } |
84 | 112 |
| 113 void EndClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 114 proto->set_type(proto::DisplayItem::Type_EndClip); |
| 115 } |
| 116 |
| 117 void EndClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 118 DCHECK_EQ(proto::DisplayItem::Type_EndClip, proto.type()); |
| 119 } |
| 120 |
85 void EndClipDisplayItem::Raster(SkCanvas* canvas, | 121 void EndClipDisplayItem::Raster(SkCanvas* canvas, |
86 const gfx::Rect& canvas_target_playback_rect, | 122 const gfx::Rect& canvas_target_playback_rect, |
87 SkPicture::AbortCallback* callback) const { | 123 SkPicture::AbortCallback* callback) const { |
88 canvas->restore(); | 124 canvas->restore(); |
89 } | 125 } |
90 | 126 |
91 void EndClipDisplayItem::AsValueInto( | 127 void EndClipDisplayItem::AsValueInto( |
92 base::trace_event::TracedValue* array) const { | 128 base::trace_event::TracedValue* array) const { |
93 array->AppendString("EndClipDisplayItem"); | 129 array->AppendString("EndClipDisplayItem"); |
94 } | 130 } |
95 | 131 |
96 } // namespace cc | 132 } // namespace cc |
OLD | NEW |