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

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

Issue 1506203008: Allow background tab titles to use LCD AA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use new Skia API name 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
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(uint8_t alpha, 22 CompositingDisplayItem::CompositingDisplayItem(uint8_t alpha,
23 SkXfermode::Mode xfermode, 23 SkXfermode::Mode xfermode,
24 SkRect* bounds, 24 SkRect* bounds,
25 skia::RefPtr<SkColorFilter> cf) { 25 skia::RefPtr<SkColorFilter> cf,
26 SetNew(alpha, xfermode, bounds, std::move(cf)); 26 bool allow_lcd_text) {
27 SetNew(alpha, xfermode, bounds, std::move(cf), allow_lcd_text);
27 } 28 }
28 29
29 CompositingDisplayItem::CompositingDisplayItem( 30 CompositingDisplayItem::CompositingDisplayItem(
30 const proto::DisplayItem& proto) { 31 const proto::DisplayItem& proto) {
31 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type()); 32 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type());
32 33
33 const proto::CompositingDisplayItem& details = proto.compositing_item(); 34 const proto::CompositingDisplayItem& details = proto.compositing_item();
34 uint8_t alpha = static_cast<uint8_t>(details.alpha()); 35 uint8_t alpha = static_cast<uint8_t>(details.alpha());
35 SkXfermode::Mode xfermode = SkXfermodeModeFromProto(details.mode()); 36 SkXfermode::Mode xfermode = SkXfermodeModeFromProto(details.mode());
36 scoped_ptr<SkRect> bounds; 37 scoped_ptr<SkRect> bounds;
37 if (details.has_bounds()) { 38 if (details.has_bounds()) {
38 bounds.reset( 39 bounds.reset(
39 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds())))); 40 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds()))));
40 } 41 }
41 42
42 skia::RefPtr<SkColorFilter> filter; 43 skia::RefPtr<SkColorFilter> filter;
43 if (details.has_color_filter()) { 44 if (details.has_color_filter()) {
44 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable( 45 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
45 details.color_filter().c_str(), details.color_filter().size(), 46 details.color_filter().c_str(), details.color_filter().size(),
46 SkColorFilter::GetFlattenableType()); 47 SkColorFilter::GetFlattenableType());
47 filter = skia::AdoptRef(static_cast<SkColorFilter*>(flattenable)); 48 filter = skia::AdoptRef(static_cast<SkColorFilter*>(flattenable));
48 } 49 }
49 50
50 SetNew(alpha, xfermode, bounds.get(), std::move(filter)); 51 SetNew(alpha, xfermode, bounds.get(), std::move(filter), false);
danakj 2015/12/11 19:07:00 Can you add this flag to the proto?
51 } 52 }
52 53
53 CompositingDisplayItem::~CompositingDisplayItem() { 54 CompositingDisplayItem::~CompositingDisplayItem() {
54 } 55 }
55 56
56 void CompositingDisplayItem::SetNew(uint8_t alpha, 57 void CompositingDisplayItem::SetNew(uint8_t alpha,
57 SkXfermode::Mode xfermode, 58 SkXfermode::Mode xfermode,
58 SkRect* bounds, 59 SkRect* bounds,
59 skia::RefPtr<SkColorFilter> cf) { 60 skia::RefPtr<SkColorFilter> cf,
61 bool allow_lcd_text) {
60 alpha_ = alpha; 62 alpha_ = alpha;
61 xfermode_ = xfermode; 63 xfermode_ = xfermode;
62 has_bounds_ = !!bounds; 64 has_bounds_ = !!bounds;
63 if (bounds) 65 if (bounds)
64 bounds_ = SkRect(*bounds); 66 bounds_ = SkRect(*bounds);
65 color_filter_ = std::move(cf); 67 color_filter_ = std::move(cf);
68 allow_lcd_text_ = allow_lcd_text;
66 } 69 }
67 70
68 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 71 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
69 proto->set_type(proto::DisplayItem::Type_Compositing); 72 proto->set_type(proto::DisplayItem::Type_Compositing);
70 73
71 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); 74 proto::CompositingDisplayItem* details = proto->mutable_compositing_item();
72 details->set_alpha(static_cast<uint32_t>(alpha_)); 75 details->set_alpha(static_cast<uint32_t>(alpha_));
73 details->set_mode(SkXfermodeModeToProto(xfermode_)); 76 details->set_mode(SkXfermodeModeToProto(xfermode_));
74 if (has_bounds_) 77 if (has_bounds_)
75 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); 78 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds());
76 79
77 if (color_filter_) { 80 if (color_filter_) {
78 skia::RefPtr<SkData> data = 81 skia::RefPtr<SkData> data =
79 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get())); 82 skia::AdoptRef(SkValidatingSerializeFlattenable(color_filter_.get()));
80 if (data->size() > 0) 83 if (data->size() > 0)
81 details->set_color_filter(data->data(), data->size()); 84 details->set_color_filter(data->data(), data->size());
82 } 85 }
83 } 86 }
84 87
85 void CompositingDisplayItem::Raster( 88 void CompositingDisplayItem::Raster(
86 SkCanvas* canvas, 89 SkCanvas* canvas,
87 const gfx::Rect& canvas_target_playback_rect, 90 const gfx::Rect& canvas_target_playback_rect,
88 SkPicture::AbortCallback* callback) const { 91 SkPicture::AbortCallback* callback) const {
89 SkPaint paint; 92 SkPaint paint;
90 paint.setXfermodeMode(xfermode_); 93 paint.setXfermodeMode(xfermode_);
91 paint.setAlpha(alpha_); 94 paint.setAlpha(alpha_);
92 paint.setColorFilter(color_filter_.get()); 95 paint.setColorFilter(color_filter_.get());
93 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); 96 const SkRect* bounds = has_bounds_ ? &bounds_ : nullptr;
97 if (allow_lcd_text_)
98 canvas->saveLayerPreserveLCDTextRequests(bounds, &paint);
99 else
100 canvas->saveLayer(bounds, &paint);
94 } 101 }
95 102
96 void CompositingDisplayItem::AsValueInto( 103 void CompositingDisplayItem::AsValueInto(
97 const gfx::Rect& visual_rect, 104 const gfx::Rect& visual_rect,
98 base::trace_event::TracedValue* array) const { 105 base::trace_event::TracedValue* array) const {
99 array->AppendString(base::StringPrintf( 106 array->AppendString(base::StringPrintf(
100 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]", 107 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]",
101 alpha_, xfermode_, visual_rect.ToString().c_str())); 108 alpha_, xfermode_, visual_rect.ToString().c_str()));
102 if (has_bounds_) 109 if (has_bounds_)
103 array->AppendString(base::StringPrintf( 110 array->AppendString(base::StringPrintf(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 array->AppendString( 145 array->AppendString(
139 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", 146 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]",
140 visual_rect.ToString().c_str())); 147 visual_rect.ToString().c_str()));
141 } 148 }
142 149
143 size_t EndCompositingDisplayItem::ExternalMemoryUsage() const { 150 size_t EndCompositingDisplayItem::ExternalMemoryUsage() const {
144 return 0; 151 return 0;
145 } 152 }
146 153
147 } // namespace cc 154 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698