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/transform_display_item.h" | 5 #include "cc/playback/transform_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 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 TransformDisplayItem::TransformDisplayItem() | 15 TransformDisplayItem::TransformDisplayItem(const gfx::Transform& transform) |
16 : transform_(gfx::Transform::kSkipInitialization) { | 16 : transform_(gfx::Transform::kSkipInitialization) { |
| 17 SetNew(transform); |
| 18 } |
| 19 |
| 20 TransformDisplayItem::TransformDisplayItem(const proto::DisplayItem& proto) { |
| 21 DCHECK_EQ(proto::DisplayItem::Type_Transform, proto.type()); |
| 22 |
| 23 const proto::TransformDisplayItem& details = proto.transform_item(); |
| 24 gfx::Transform transform = ProtoToTransform(details.transform()); |
| 25 |
| 26 SetNew(transform); |
17 } | 27 } |
18 | 28 |
19 TransformDisplayItem::~TransformDisplayItem() { | 29 TransformDisplayItem::~TransformDisplayItem() { |
20 } | 30 } |
21 | 31 |
22 void TransformDisplayItem::SetNew(const gfx::Transform& transform) { | 32 void TransformDisplayItem::SetNew(const gfx::Transform& transform) { |
23 transform_ = transform; | 33 transform_ = transform; |
24 | |
25 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | |
26 0 /* external_memory_usage */); | |
27 } | 34 } |
28 | 35 |
29 void TransformDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 36 void TransformDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
30 proto->set_type(proto::DisplayItem::Type_Transform); | 37 proto->set_type(proto::DisplayItem::Type_Transform); |
31 | 38 |
32 proto::TransformDisplayItem* details = proto->mutable_transform_item(); | 39 proto::TransformDisplayItem* details = proto->mutable_transform_item(); |
33 TransformToProto(transform_, details->mutable_transform()); | 40 TransformToProto(transform_, details->mutable_transform()); |
34 } | 41 } |
35 | 42 |
36 void TransformDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
37 DCHECK_EQ(proto::DisplayItem::Type_Transform, proto.type()); | |
38 | |
39 const proto::TransformDisplayItem& details = proto.transform_item(); | |
40 gfx::Transform transform = ProtoToTransform(details.transform()); | |
41 | |
42 SetNew(transform); | |
43 } | |
44 | |
45 void TransformDisplayItem::Raster(SkCanvas* canvas, | 43 void TransformDisplayItem::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 if (!transform_.IsIdentity()) | 47 if (!transform_.IsIdentity()) |
50 canvas->concat(transform_.matrix()); | 48 canvas->concat(transform_.matrix()); |
51 } | 49 } |
52 | 50 |
53 void TransformDisplayItem::AsValueInto( | 51 void TransformDisplayItem::AsValueInto( |
54 const gfx::Rect& visual_rect, | 52 const gfx::Rect& visual_rect, |
55 base::trace_event::TracedValue* array) const { | 53 base::trace_event::TracedValue* array) const { |
56 array->AppendString(base::StringPrintf( | 54 array->AppendString(base::StringPrintf( |
57 "TransformDisplayItem transform: [%s] visualRect: [%s]", | 55 "TransformDisplayItem transform: [%s] visualRect: [%s]", |
58 transform_.ToString().c_str(), visual_rect.ToString().c_str())); | 56 transform_.ToString().c_str(), visual_rect.ToString().c_str())); |
59 } | 57 } |
60 | 58 |
61 EndTransformDisplayItem::EndTransformDisplayItem() { | 59 size_t TransformDisplayItem::ExternalMemoryUsage() const { |
62 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 60 return 0; |
63 0 /* external_memory_usage */); | 61 } |
| 62 |
| 63 EndTransformDisplayItem::EndTransformDisplayItem() {} |
| 64 |
| 65 EndTransformDisplayItem::EndTransformDisplayItem( |
| 66 const proto::DisplayItem& proto) { |
| 67 DCHECK_EQ(proto::DisplayItem::Type_EndTransform, proto.type()); |
64 } | 68 } |
65 | 69 |
66 EndTransformDisplayItem::~EndTransformDisplayItem() { | 70 EndTransformDisplayItem::~EndTransformDisplayItem() { |
67 } | 71 } |
68 | 72 |
69 void EndTransformDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 73 void EndTransformDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
70 proto->set_type(proto::DisplayItem::Type_EndTransform); | 74 proto->set_type(proto::DisplayItem::Type_EndTransform); |
71 } | 75 } |
72 | 76 |
73 void EndTransformDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | |
74 DCHECK_EQ(proto::DisplayItem::Type_EndTransform, proto.type()); | |
75 } | |
76 | |
77 void EndTransformDisplayItem::Raster( | 77 void EndTransformDisplayItem::Raster( |
78 SkCanvas* canvas, | 78 SkCanvas* canvas, |
79 const gfx::Rect& canvas_target_playback_rect, | 79 const gfx::Rect& canvas_target_playback_rect, |
80 SkPicture::AbortCallback* callback) const { | 80 SkPicture::AbortCallback* callback) const { |
81 canvas->restore(); | 81 canvas->restore(); |
82 } | 82 } |
83 | 83 |
84 void EndTransformDisplayItem::AsValueInto( | 84 void EndTransformDisplayItem::AsValueInto( |
85 const gfx::Rect& visual_rect, | 85 const gfx::Rect& visual_rect, |
86 base::trace_event::TracedValue* array) const { | 86 base::trace_event::TracedValue* array) const { |
87 array->AppendString( | 87 array->AppendString( |
88 base::StringPrintf("EndTransformDisplayItem visualRect: [%s]", | 88 base::StringPrintf("EndTransformDisplayItem visualRect: [%s]", |
89 visual_rect.ToString().c_str())); | 89 visual_rect.ToString().c_str())); |
90 } | 90 } |
91 | 91 |
| 92 size_t EndTransformDisplayItem::ExternalMemoryUsage() const { |
| 93 return 0; |
| 94 } |
| 95 |
92 } // namespace cc | 96 } // namespace cc |
OLD | NEW |