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/compositing_display_item.h" | 5 #include "cc/playback/compositing_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" |
| 10 #include "cc/proto/gfx_conversions.h" |
| 11 #include "cc/proto/skia_conversions.h" |
9 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkData.h" |
| 14 #include "third_party/skia/include/core/SkFlattenable.h" |
| 15 #include "third_party/skia/include/core/SkFlattenableSerialization.h" |
10 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
11 #include "third_party/skia/include/core/SkXfermode.h" | 17 #include "third_party/skia/include/core/SkXfermode.h" |
12 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
13 | 19 |
14 namespace cc { | 20 namespace cc { |
15 | 21 |
16 CompositingDisplayItem::CompositingDisplayItem() { | 22 CompositingDisplayItem::CompositingDisplayItem() { |
17 } | 23 } |
18 | 24 |
19 CompositingDisplayItem::~CompositingDisplayItem() { | 25 CompositingDisplayItem::~CompositingDisplayItem() { |
20 } | 26 } |
21 | 27 |
22 void CompositingDisplayItem::SetNew(uint8_t alpha, | 28 void CompositingDisplayItem::SetNew(uint8_t alpha, |
23 SkXfermode::Mode xfermode, | 29 SkXfermode::Mode xfermode, |
24 SkRect* bounds, | 30 SkRect* bounds, |
25 skia::RefPtr<SkColorFilter> cf) { | 31 skia::RefPtr<SkColorFilter> cf) { |
26 alpha_ = alpha; | 32 alpha_ = alpha; |
27 xfermode_ = xfermode; | 33 xfermode_ = xfermode; |
28 has_bounds_ = !!bounds; | 34 has_bounds_ = !!bounds; |
29 if (bounds) | 35 if (bounds) |
30 bounds_ = SkRect(*bounds); | 36 bounds_ = SkRect(*bounds); |
31 color_filter_ = cf; | 37 color_filter_ = cf; |
32 | 38 |
33 // TODO(pdr): Include color_filter's memory here. | 39 // TODO(pdr): Include color_filter's memory here. |
34 size_t external_memory_usage = 0; | 40 size_t external_memory_usage = 0; |
35 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | 41 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, |
36 external_memory_usage); | 42 external_memory_usage); |
37 } | 43 } |
38 | 44 |
| 45 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) { |
| 46 proto->set_type(proto::DisplayItem::Type_Compositing); |
| 47 |
| 48 proto::CompositingDisplayItem* details = proto->mutable_details_compositing(); |
| 49 details->set_alpha(static_cast<uint32_t>(alpha_)); |
| 50 details->set_mode(SkXfermodeModeToProto(xfermode_)); |
| 51 if (has_bounds_) |
| 52 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); |
| 53 |
| 54 if (color_filter_) { |
| 55 skia::RefPtr<SkData> data = |
| 56 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get())); |
| 57 if (data->size() > 0) |
| 58 details->set_color_filter(data->data(), data->size()); |
| 59 } |
| 60 } |
| 61 |
| 62 void CompositingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 63 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type()); |
| 64 |
| 65 const proto::CompositingDisplayItem& details = proto.details_compositing(); |
| 66 uint8_t alpha = static_cast<uint8_t>(details.alpha()); |
| 67 SkXfermode::Mode xfermode = SkXfermodeModeFromProto(details.mode()); |
| 68 scoped_ptr<SkRect> bounds; |
| 69 if (details.has_bounds()) { |
| 70 bounds.reset( |
| 71 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds())))); |
| 72 } |
| 73 |
| 74 skia::RefPtr<SkColorFilter> filter; |
| 75 if (details.has_color_filter()) { |
| 76 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable( |
| 77 details.color_filter().c_str(), details.color_filter().size(), |
| 78 SkColorFilter::GetFlattenableType()); |
| 79 filter = skia::AdoptRef(static_cast<SkColorFilter*>(flattenable)); |
| 80 } |
| 81 |
| 82 SetNew(alpha, xfermode, bounds.get(), filter.Pass()); |
| 83 } |
| 84 |
39 void CompositingDisplayItem::Raster( | 85 void CompositingDisplayItem::Raster( |
40 SkCanvas* canvas, | 86 SkCanvas* canvas, |
41 const gfx::Rect& canvas_target_playback_rect, | 87 const gfx::Rect& canvas_target_playback_rect, |
42 SkPicture::AbortCallback* callback) const { | 88 SkPicture::AbortCallback* callback) const { |
43 SkPaint paint; | 89 SkPaint paint; |
44 paint.setXfermodeMode(xfermode_); | 90 paint.setXfermodeMode(xfermode_); |
45 paint.setAlpha(alpha_); | 91 paint.setAlpha(alpha_); |
46 paint.setColorFilter(color_filter_.get()); | 92 paint.setColorFilter(color_filter_.get()); |
47 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); | 93 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); |
48 } | 94 } |
(...skipping 16 matching lines...) Expand all Loading... |
65 } | 111 } |
66 | 112 |
67 EndCompositingDisplayItem::EndCompositingDisplayItem() { | 113 EndCompositingDisplayItem::EndCompositingDisplayItem() { |
68 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 114 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, |
69 0 /* external_memory_usage */); | 115 0 /* external_memory_usage */); |
70 } | 116 } |
71 | 117 |
72 EndCompositingDisplayItem::~EndCompositingDisplayItem() { | 118 EndCompositingDisplayItem::~EndCompositingDisplayItem() { |
73 } | 119 } |
74 | 120 |
| 121 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) { |
| 122 proto->set_type(proto::DisplayItem::Type_EndCompositing); |
| 123 } |
| 124 |
| 125 void EndCompositingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 126 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type()); |
| 127 } |
| 128 |
75 void EndCompositingDisplayItem::Raster( | 129 void EndCompositingDisplayItem::Raster( |
76 SkCanvas* canvas, | 130 SkCanvas* canvas, |
77 const gfx::Rect& canvas_target_playback_rect, | 131 const gfx::Rect& canvas_target_playback_rect, |
78 SkPicture::AbortCallback* callback) const { | 132 SkPicture::AbortCallback* callback) const { |
79 canvas->restore(); | 133 canvas->restore(); |
80 } | 134 } |
81 | 135 |
82 void EndCompositingDisplayItem::ProcessForBounds( | 136 void EndCompositingDisplayItem::ProcessForBounds( |
83 DisplayItemListBoundsCalculator* calculator) const { | 137 DisplayItemListBoundsCalculator* calculator) const { |
84 calculator->Restore(); | 138 calculator->Restore(); |
85 calculator->AddEndingDisplayItem(); | 139 calculator->AddEndingDisplayItem(); |
86 } | 140 } |
87 | 141 |
88 void EndCompositingDisplayItem::AsValueInto( | 142 void EndCompositingDisplayItem::AsValueInto( |
89 base::trace_event::TracedValue* array) const { | 143 base::trace_event::TracedValue* array) const { |
90 array->AppendString("EndCompositingDisplayItem"); | 144 array->AppendString("EndCompositingDisplayItem"); |
91 } | 145 } |
92 | 146 |
93 } // namespace cc | 147 } // namespace cc |
OLD | NEW |