Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: cc/playback/compositing_display_item.cc

Issue 1407793002: Add protobuf serialization to DisplayItemList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_display2
Patch Set: Comments are hard Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/compositing_display_item.h ('k') | cc/playback/display_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) const {
46 proto->set_type(proto::DisplayItem::Type_Compositing);
47
48 proto::CompositingDisplayItem* details = proto->mutable_compositing_item();
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.compositing_item();
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 10 matching lines...) Expand all
59 } 105 }
60 106
61 EndCompositingDisplayItem::EndCompositingDisplayItem() { 107 EndCompositingDisplayItem::EndCompositingDisplayItem() {
62 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, 108 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
63 0 /* external_memory_usage */); 109 0 /* external_memory_usage */);
64 } 110 }
65 111
66 EndCompositingDisplayItem::~EndCompositingDisplayItem() { 112 EndCompositingDisplayItem::~EndCompositingDisplayItem() {
67 } 113 }
68 114
115 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
116 proto->set_type(proto::DisplayItem::Type_EndCompositing);
117 }
118
119 void EndCompositingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
120 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type());
121 }
122
69 void EndCompositingDisplayItem::Raster( 123 void EndCompositingDisplayItem::Raster(
70 SkCanvas* canvas, 124 SkCanvas* canvas,
71 const gfx::Rect& canvas_target_playback_rect, 125 const gfx::Rect& canvas_target_playback_rect,
72 SkPicture::AbortCallback* callback) const { 126 SkPicture::AbortCallback* callback) const {
73 canvas->restore(); 127 canvas->restore();
74 } 128 }
75 129
76 void EndCompositingDisplayItem::AsValueInto( 130 void EndCompositingDisplayItem::AsValueInto(
77 base::trace_event::TracedValue* array) const { 131 base::trace_event::TracedValue* array) const {
78 array->AppendString("EndCompositingDisplayItem"); 132 array->AppendString("EndCompositingDisplayItem");
79 } 133 }
80 134
81 } // namespace cc 135 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/compositing_display_item.h ('k') | cc/playback/display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698