OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/float_clip_display_item.h" | 5 #include "cc/playback/float_clip_display_item.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/trace_event/trace_event_argument.h" | 8 #include "base/trace_event/trace_event_argument.h" |
9 #include "cc/proto/display_item.pb.h" | 9 #include "cc/proto/display_item.pb.h" |
10 #include "cc/proto/gfx_conversions.h" | 10 #include "cc/proto/gfx_conversions.h" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 FloatClipDisplayItem::FloatClipDisplayItem() { | 16 FloatClipDisplayItem::FloatClipDisplayItem(const gfx::RectF& clip_rect) { |
| 17 SetNew(clip_rect); |
| 18 } |
| 19 |
| 20 FloatClipDisplayItem::FloatClipDisplayItem(const proto::DisplayItem& proto) { |
| 21 DCHECK_EQ(proto::DisplayItem::Type_FloatClip, proto.type()); |
| 22 |
| 23 const proto::FloatClipDisplayItem& details = proto.float_clip_item(); |
| 24 gfx::RectF clip_rect = ProtoToRectF(details.clip_rect()); |
| 25 |
| 26 SetNew(clip_rect); |
17 } | 27 } |
18 | 28 |
19 FloatClipDisplayItem::~FloatClipDisplayItem() { | 29 FloatClipDisplayItem::~FloatClipDisplayItem() { |
20 } | 30 } |
21 | 31 |
22 void FloatClipDisplayItem::SetNew(const gfx::RectF& clip_rect) { | 32 void FloatClipDisplayItem::SetNew(const gfx::RectF& clip_rect) { |
23 clip_rect_ = clip_rect; | 33 clip_rect_ = clip_rect; |
24 | |
25 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | |
26 0 /* external_memory_usage */); | |
27 } | 34 } |
28 | 35 |
29 void FloatClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 36 void FloatClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
30 proto->set_type(proto::DisplayItem::Type_FloatClip); | 37 proto->set_type(proto::DisplayItem::Type_FloatClip); |
31 | 38 |
32 proto::FloatClipDisplayItem* details = proto->mutable_float_clip_item(); | 39 proto::FloatClipDisplayItem* details = proto->mutable_float_clip_item(); |
33 RectFToProto(clip_rect_, details->mutable_clip_rect()); | 40 RectFToProto(clip_rect_, details->mutable_clip_rect()); |
34 } | 41 } |
35 | 42 |
36 void FloatClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
37 DCHECK_EQ(proto::DisplayItem::Type_FloatClip, proto.type()); | |
38 | |
39 const proto::FloatClipDisplayItem& details = proto.float_clip_item(); | |
40 gfx::RectF clip_rect = ProtoToRectF(details.clip_rect()); | |
41 | |
42 SetNew(clip_rect); | |
43 } | |
44 | |
45 void FloatClipDisplayItem::Raster(SkCanvas* canvas, | 43 void FloatClipDisplayItem::Raster(SkCanvas* canvas, |
46 const gfx::Rect& canvas_target_playback_rect, | 44 const gfx::Rect& canvas_target_playback_rect, |
47 SkPicture::AbortCallback* callback) const { | 45 SkPicture::AbortCallback* callback) const { |
48 canvas->save(); | 46 canvas->save(); |
49 canvas->clipRect(gfx::RectFToSkRect(clip_rect_)); | 47 canvas->clipRect(gfx::RectFToSkRect(clip_rect_)); |
50 } | 48 } |
51 | 49 |
52 void FloatClipDisplayItem::AsValueInto( | 50 void FloatClipDisplayItem::AsValueInto( |
53 const gfx::Rect& visual_rect, | 51 const gfx::Rect& visual_rect, |
54 base::trace_event::TracedValue* array) const { | 52 base::trace_event::TracedValue* array) const { |
55 array->AppendString(base::StringPrintf( | 53 array->AppendString(base::StringPrintf( |
56 "FloatClipDisplayItem rect: [%s] visualRect: [%s]", | 54 "FloatClipDisplayItem rect: [%s] visualRect: [%s]", |
57 clip_rect_.ToString().c_str(), visual_rect.ToString().c_str())); | 55 clip_rect_.ToString().c_str(), visual_rect.ToString().c_str())); |
58 } | 56 } |
59 | 57 |
60 EndFloatClipDisplayItem::EndFloatClipDisplayItem() { | 58 size_t FloatClipDisplayItem::ExternalMemoryUsage() const { |
61 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 59 return 0; |
62 0 /* external_memory_usage */); | 60 } |
| 61 |
| 62 EndFloatClipDisplayItem::EndFloatClipDisplayItem() {} |
| 63 |
| 64 EndFloatClipDisplayItem::EndFloatClipDisplayItem( |
| 65 const proto::DisplayItem& proto) { |
| 66 DCHECK_EQ(proto::DisplayItem::Type_EndFloatClip, proto.type()); |
63 } | 67 } |
64 | 68 |
65 EndFloatClipDisplayItem::~EndFloatClipDisplayItem() { | 69 EndFloatClipDisplayItem::~EndFloatClipDisplayItem() { |
66 } | 70 } |
67 | 71 |
68 void EndFloatClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 72 void EndFloatClipDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
69 proto->set_type(proto::DisplayItem::Type_EndFloatClip); | 73 proto->set_type(proto::DisplayItem::Type_EndFloatClip); |
70 } | 74 } |
71 | 75 |
72 void EndFloatClipDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
73 DCHECK_EQ(proto::DisplayItem::Type_EndFloatClip, proto.type()); | |
74 } | |
75 | |
76 void EndFloatClipDisplayItem::Raster( | 76 void EndFloatClipDisplayItem::Raster( |
77 SkCanvas* canvas, | 77 SkCanvas* canvas, |
78 const gfx::Rect& canvas_target_playback_rect, | 78 const gfx::Rect& canvas_target_playback_rect, |
79 SkPicture::AbortCallback* callback) const { | 79 SkPicture::AbortCallback* callback) const { |
80 canvas->restore(); | 80 canvas->restore(); |
81 } | 81 } |
82 | 82 |
83 void EndFloatClipDisplayItem::AsValueInto( | 83 void EndFloatClipDisplayItem::AsValueInto( |
84 const gfx::Rect& visual_rect, | 84 const gfx::Rect& visual_rect, |
85 base::trace_event::TracedValue* array) const { | 85 base::trace_event::TracedValue* array) const { |
86 array->AppendString( | 86 array->AppendString( |
87 base::StringPrintf("EndFloatClipDisplayItem visualRect: [%s]", | 87 base::StringPrintf("EndFloatClipDisplayItem visualRect: [%s]", |
88 visual_rect.ToString().c_str())); | 88 visual_rect.ToString().c_str())); |
89 } | 89 } |
90 | 90 |
| 91 size_t EndFloatClipDisplayItem::ExternalMemoryUsage() const { |
| 92 return 0; |
| 93 } |
| 94 |
91 } // namespace cc | 95 } // namespace cc |
OLD | NEW |