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" | 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(uint8_t alpha, | 22 CompositingDisplayItem::CompositingDisplayItem( |
23 SkXfermode::Mode xfermode, | 23 uint8_t alpha, |
24 SkRect* bounds, | 24 SkXfermode::Mode xfermode, |
25 skia::RefPtr<SkColorFilter> cf) { | 25 SkRect* bounds, |
26 SetNew(alpha, xfermode, bounds, std::move(cf)); | 26 skia::RefPtr<SkColorFilter> cf, |
| 27 bool lcd_text_requires_opaque_layer) { |
| 28 SetNew(alpha, xfermode, bounds, std::move(cf), |
| 29 lcd_text_requires_opaque_layer); |
27 } | 30 } |
28 | 31 |
29 CompositingDisplayItem::CompositingDisplayItem( | 32 CompositingDisplayItem::CompositingDisplayItem( |
30 const proto::DisplayItem& proto) { | 33 const proto::DisplayItem& proto) { |
31 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type()); | 34 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type()); |
32 | 35 |
33 const proto::CompositingDisplayItem& details = proto.compositing_item(); | 36 const proto::CompositingDisplayItem& details = proto.compositing_item(); |
34 uint8_t alpha = static_cast<uint8_t>(details.alpha()); | 37 uint8_t alpha = static_cast<uint8_t>(details.alpha()); |
35 SkXfermode::Mode xfermode = SkXfermodeModeFromProto(details.mode()); | 38 SkXfermode::Mode xfermode = SkXfermodeModeFromProto(details.mode()); |
36 scoped_ptr<SkRect> bounds; | 39 scoped_ptr<SkRect> bounds; |
37 if (details.has_bounds()) { | 40 if (details.has_bounds()) { |
38 bounds.reset( | 41 bounds.reset( |
39 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds())))); | 42 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds())))); |
40 } | 43 } |
41 | 44 |
42 skia::RefPtr<SkColorFilter> filter; | 45 skia::RefPtr<SkColorFilter> filter; |
43 if (details.has_color_filter()) { | 46 if (details.has_color_filter()) { |
44 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable( | 47 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable( |
45 details.color_filter().c_str(), details.color_filter().size(), | 48 details.color_filter().c_str(), details.color_filter().size(), |
46 SkColorFilter::GetFlattenableType()); | 49 SkColorFilter::GetFlattenableType()); |
47 filter = skia::AdoptRef(static_cast<SkColorFilter*>(flattenable)); | 50 filter = skia::AdoptRef(static_cast<SkColorFilter*>(flattenable)); |
48 } | 51 } |
49 | 52 |
50 SetNew(alpha, xfermode, bounds.get(), std::move(filter)); | 53 bool lcd_text_requires_opaque_layer = |
| 54 details.lcd_text_requires_opaque_layer(); |
| 55 |
| 56 SetNew(alpha, xfermode, bounds.get(), std::move(filter), |
| 57 lcd_text_requires_opaque_layer); |
51 } | 58 } |
52 | 59 |
53 CompositingDisplayItem::~CompositingDisplayItem() { | 60 CompositingDisplayItem::~CompositingDisplayItem() { |
54 } | 61 } |
55 | 62 |
56 void CompositingDisplayItem::SetNew(uint8_t alpha, | 63 void CompositingDisplayItem::SetNew(uint8_t alpha, |
57 SkXfermode::Mode xfermode, | 64 SkXfermode::Mode xfermode, |
58 SkRect* bounds, | 65 SkRect* bounds, |
59 skia::RefPtr<SkColorFilter> cf) { | 66 skia::RefPtr<SkColorFilter> cf, |
| 67 bool lcd_text_requires_opaque_layer) { |
60 alpha_ = alpha; | 68 alpha_ = alpha; |
61 xfermode_ = xfermode; | 69 xfermode_ = xfermode; |
62 has_bounds_ = !!bounds; | 70 has_bounds_ = !!bounds; |
63 if (bounds) | 71 if (bounds) |
64 bounds_ = SkRect(*bounds); | 72 bounds_ = SkRect(*bounds); |
65 color_filter_ = std::move(cf); | 73 color_filter_ = std::move(cf); |
| 74 lcd_text_requires_opaque_layer_ = lcd_text_requires_opaque_layer; |
66 } | 75 } |
67 | 76 |
68 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 77 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
69 proto->set_type(proto::DisplayItem::Type_Compositing); | 78 proto->set_type(proto::DisplayItem::Type_Compositing); |
70 | 79 |
71 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); | 80 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); |
72 details->set_alpha(static_cast<uint32_t>(alpha_)); | 81 details->set_alpha(static_cast<uint32_t>(alpha_)); |
73 details->set_mode(SkXfermodeModeToProto(xfermode_)); | 82 details->set_mode(SkXfermodeModeToProto(xfermode_)); |
74 if (has_bounds_) | 83 if (has_bounds_) |
75 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); | 84 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); |
76 | 85 |
77 if (color_filter_) { | 86 if (color_filter_) { |
78 skia::RefPtr<SkData> data = | 87 skia::RefPtr<SkData> data = |
79 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get())); | 88 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get())); |
80 if (data->size() > 0) | 89 if (data->size() > 0) |
81 details->set_color_filter(data->data(), data->size()); | 90 details->set_color_filter(data->data(), data->size()); |
82 } | 91 } |
| 92 |
| 93 details->set_lcd_text_requires_opaque_layer(lcd_text_requires_opaque_layer_); |
83 } | 94 } |
84 | 95 |
85 void CompositingDisplayItem::Raster( | 96 void CompositingDisplayItem::Raster( |
86 SkCanvas* canvas, | 97 SkCanvas* canvas, |
87 const gfx::Rect& canvas_target_playback_rect, | 98 const gfx::Rect& canvas_target_playback_rect, |
88 SkPicture::AbortCallback* callback) const { | 99 SkPicture::AbortCallback* callback) const { |
89 SkPaint paint; | 100 SkPaint paint; |
90 paint.setXfermodeMode(xfermode_); | 101 paint.setXfermodeMode(xfermode_); |
91 paint.setAlpha(alpha_); | 102 paint.setAlpha(alpha_); |
92 paint.setColorFilter(color_filter_.get()); | 103 paint.setColorFilter(color_filter_.get()); |
93 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); | 104 const SkRect* bounds = has_bounds_ ? &bounds_ : nullptr; |
| 105 if (lcd_text_requires_opaque_layer_) |
| 106 canvas->saveLayer(bounds, &paint); |
| 107 else |
| 108 canvas->saveLayerPreserveLCDTextRequests(bounds, &paint); |
94 } | 109 } |
95 | 110 |
96 void CompositingDisplayItem::AsValueInto( | 111 void CompositingDisplayItem::AsValueInto( |
97 const gfx::Rect& visual_rect, | 112 const gfx::Rect& visual_rect, |
98 base::trace_event::TracedValue* array) const { | 113 base::trace_event::TracedValue* array) const { |
99 array->AppendString(base::StringPrintf( | 114 array->AppendString(base::StringPrintf( |
100 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]", | 115 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]", |
101 alpha_, xfermode_, visual_rect.ToString().c_str())); | 116 alpha_, xfermode_, visual_rect.ToString().c_str())); |
102 if (has_bounds_) | 117 if (has_bounds_) |
103 array->AppendString(base::StringPrintf( | 118 array->AppendString(base::StringPrintf( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 array->AppendString( | 153 array->AppendString( |
139 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", | 154 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", |
140 visual_rect.ToString().c_str())); | 155 visual_rect.ToString().c_str())); |
141 } | 156 } |
142 | 157 |
143 size_t EndCompositingDisplayItem::ExternalMemoryUsage() const { | 158 size_t EndCompositingDisplayItem::ExternalMemoryUsage() const { |
144 return 0; | 159 return 0; |
145 } | 160 } |
146 | 161 |
147 } // namespace cc | 162 } // namespace cc |
OLD | NEW |