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

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

Issue 1494223003: cc: Shrink size of display item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some compilation issues in ui oops Created 5 years 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" 9 #include "cc/proto/display_item.pb.h"
10 #include "cc/proto/gfx_conversions.h" 10 #include "cc/proto/gfx_conversions.h"
11 #include "cc/proto/skia_conversions.h" 11 #include "cc/proto/skia_conversions.h"
12 #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" 13 #include "third_party/skia/include/core/SkData.h"
14 #include "third_party/skia/include/core/SkFlattenable.h" 14 #include "third_party/skia/include/core/SkFlattenable.h"
15 #include "third_party/skia/include/core/SkFlattenableSerialization.h" 15 #include "third_party/skia/include/core/SkFlattenableSerialization.h"
16 #include "third_party/skia/include/core/SkPaint.h" 16 #include "third_party/skia/include/core/SkPaint.h"
17 #include "third_party/skia/include/core/SkXfermode.h" 17 #include "third_party/skia/include/core/SkXfermode.h"
18 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
19 19
20 namespace cc { 20 namespace cc {
21 21
22 CompositingDisplayItem::CompositingDisplayItem() { 22 CompositingDisplayItem::CompositingDisplayItem(uint8_t alpha,
23 SkXfermode::Mode xfermode,
24 SkRect* bounds,
25 skia::RefPtr<SkColorFilter> cf) {
26 SetNew(alpha, xfermode, bounds, std::move(cf));
27 }
28
29 CompositingDisplayItem::CompositingDisplayItem(
30 const proto::DisplayItem& proto) {
31 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type());
32
33 const proto::CompositingDisplayItem& details = proto.compositing_item();
34 uint8_t alpha = static_cast<uint8_t>(details.alpha());
35 SkXfermode::Mode xfermode = SkXfermodeModeFromProto(details.mode());
36 scoped_ptr<SkRect> bounds;
37 if (details.has_bounds()) {
38 bounds.reset(
39 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds()))));
40 }
41
42 skia::RefPtr<SkColorFilter> filter;
43 if (details.has_color_filter()) {
44 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
45 details.color_filter().c_str(), details.color_filter().size(),
46 SkColorFilter::GetFlattenableType());
47 filter = skia::AdoptRef(static_cast<SkColorFilter*>(flattenable));
48 }
49
50 SetNew(alpha, xfermode, bounds.get(), std::move(filter));
23 } 51 }
24 52
25 CompositingDisplayItem::~CompositingDisplayItem() { 53 CompositingDisplayItem::~CompositingDisplayItem() {
26 } 54 }
27 55
28 void CompositingDisplayItem::SetNew(uint8_t alpha, 56 void CompositingDisplayItem::SetNew(uint8_t alpha,
29 SkXfermode::Mode xfermode, 57 SkXfermode::Mode xfermode,
30 SkRect* bounds, 58 SkRect* bounds,
31 skia::RefPtr<SkColorFilter> cf) { 59 skia::RefPtr<SkColorFilter> cf) {
32 alpha_ = alpha; 60 alpha_ = alpha;
33 xfermode_ = xfermode; 61 xfermode_ = xfermode;
34 has_bounds_ = !!bounds; 62 has_bounds_ = !!bounds;
35 if (bounds) 63 if (bounds)
36 bounds_ = SkRect(*bounds); 64 bounds_ = SkRect(*bounds);
37 color_filter_ = cf; 65 color_filter_ = std::move(cf);
38
39 // TODO(pdr): Include color_filter's memory here.
40 size_t external_memory_usage = 0;
41 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
42 external_memory_usage);
43 } 66 }
44 67
45 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 68 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
46 proto->set_type(proto::DisplayItem::Type_Compositing); 69 proto->set_type(proto::DisplayItem::Type_Compositing);
47 70
48 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); 71 proto::CompositingDisplayItem* details = proto->mutable_compositing_item();
49 details->set_alpha(static_cast<uint32_t>(alpha_)); 72 details->set_alpha(static_cast<uint32_t>(alpha_));
50 details->set_mode(SkXfermodeModeToProto(xfermode_)); 73 details->set_mode(SkXfermodeModeToProto(xfermode_));
51 if (has_bounds_) 74 if (has_bounds_)
52 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); 75 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds());
53 76
54 if (color_filter_) { 77 if (color_filter_) {
55 skia::RefPtr<SkData> data = 78 skia::RefPtr<SkData> data =
56 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get())); 79 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get()));
57 if (data->size() > 0) 80 if (data->size() > 0)
58 details->set_color_filter(data->data(), data->size()); 81 details->set_color_filter(data->data(), data->size());
59 } 82 }
60 } 83 }
61 84
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(), std::move(filter));
83 }
84
85 void CompositingDisplayItem::Raster( 85 void CompositingDisplayItem::Raster(
86 SkCanvas* canvas, 86 SkCanvas* canvas,
87 const gfx::Rect& canvas_target_playback_rect, 87 const gfx::Rect& canvas_target_playback_rect,
88 SkPicture::AbortCallback* callback) const { 88 SkPicture::AbortCallback* callback) const {
89 SkPaint paint; 89 SkPaint paint;
90 paint.setXfermodeMode(xfermode_); 90 paint.setXfermodeMode(xfermode_);
91 paint.setAlpha(alpha_); 91 paint.setAlpha(alpha_);
92 paint.setColorFilter(color_filter_.get()); 92 paint.setColorFilter(color_filter_.get());
93 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); 93 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint);
94 } 94 }
95 95
96 void CompositingDisplayItem::AsValueInto( 96 void CompositingDisplayItem::AsValueInto(
97 const gfx::Rect& visual_rect, 97 const gfx::Rect& visual_rect,
98 base::trace_event::TracedValue* array) const { 98 base::trace_event::TracedValue* array) const {
99 array->AppendString(base::StringPrintf( 99 array->AppendString(base::StringPrintf(
100 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]", 100 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]",
101 alpha_, xfermode_, visual_rect.ToString().c_str())); 101 alpha_, xfermode_, visual_rect.ToString().c_str()));
102 if (has_bounds_) 102 if (has_bounds_)
103 array->AppendString(base::StringPrintf( 103 array->AppendString(base::StringPrintf(
104 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), 104 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()),
105 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), 105 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()),
106 static_cast<float>(bounds_.height()))); 106 static_cast<float>(bounds_.height())));
107 } 107 }
108 108
109 EndCompositingDisplayItem::EndCompositingDisplayItem() { 109 size_t CompositingDisplayItem::ExternalMemoryUsage() const {
110 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, 110 // TODO(pdr): Include color_filter's memory here.
111 0 /* external_memory_usage */); 111 return 0;
112 }
113
114 EndCompositingDisplayItem::EndCompositingDisplayItem() {}
115
116 EndCompositingDisplayItem::EndCompositingDisplayItem(
117 const proto::DisplayItem& proto) {
118 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type());
112 } 119 }
113 120
114 EndCompositingDisplayItem::~EndCompositingDisplayItem() { 121 EndCompositingDisplayItem::~EndCompositingDisplayItem() {
115 } 122 }
116 123
117 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 124 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
118 proto->set_type(proto::DisplayItem::Type_EndCompositing); 125 proto->set_type(proto::DisplayItem::Type_EndCompositing);
119 } 126 }
120 127
121 void EndCompositingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
122 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type());
123 }
124
125 void EndCompositingDisplayItem::Raster( 128 void EndCompositingDisplayItem::Raster(
126 SkCanvas* canvas, 129 SkCanvas* canvas,
127 const gfx::Rect& canvas_target_playback_rect, 130 const gfx::Rect& canvas_target_playback_rect,
128 SkPicture::AbortCallback* callback) const { 131 SkPicture::AbortCallback* callback) const {
129 canvas->restore(); 132 canvas->restore();
130 } 133 }
131 134
132 void EndCompositingDisplayItem::AsValueInto( 135 void EndCompositingDisplayItem::AsValueInto(
133 const gfx::Rect& visual_rect, 136 const gfx::Rect& visual_rect,
134 base::trace_event::TracedValue* array) const { 137 base::trace_event::TracedValue* array) const {
135 array->AppendString( 138 array->AppendString(
136 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", 139 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]",
137 visual_rect.ToString().c_str())); 140 visual_rect.ToString().c_str()));
138 } 141 }
139 142
143 size_t EndCompositingDisplayItem::ExternalMemoryUsage() const {
144 return 0;
145 }
146
140 } // namespace cc 147 } // 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