| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "cc/proto/display_item.pb.h" | |
| 13 #include "cc/proto/gfx_conversions.h" | |
| 14 #include "cc/proto/skia_conversions.h" | |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkData.h" | 13 #include "third_party/skia/include/core/SkData.h" |
| 17 #include "third_party/skia/include/core/SkFlattenable.h" | 14 #include "third_party/skia/include/core/SkFlattenable.h" |
| 18 #include "third_party/skia/include/core/SkFlattenableSerialization.h" | 15 #include "third_party/skia/include/core/SkFlattenableSerialization.h" |
| 19 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 20 | 17 |
| 21 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
| 22 | 19 |
| 23 namespace cc { | 20 namespace cc { |
| 24 | 21 |
| 25 CompositingDisplayItem::CompositingDisplayItem( | 22 CompositingDisplayItem::CompositingDisplayItem( |
| 26 uint8_t alpha, | 23 uint8_t alpha, |
| 27 SkBlendMode xfermode, | 24 SkBlendMode xfermode, |
| 28 SkRect* bounds, | 25 SkRect* bounds, |
| 29 sk_sp<SkColorFilter> cf, | 26 sk_sp<SkColorFilter> cf, |
| 30 bool lcd_text_requires_opaque_layer) | 27 bool lcd_text_requires_opaque_layer) |
| 31 : DisplayItem(COMPOSITING) { | 28 : DisplayItem(COMPOSITING) { |
| 32 SetNew(alpha, xfermode, bounds, std::move(cf), | 29 SetNew(alpha, xfermode, bounds, std::move(cf), |
| 33 lcd_text_requires_opaque_layer); | 30 lcd_text_requires_opaque_layer); |
| 34 } | 31 } |
| 35 | 32 |
| 36 CompositingDisplayItem::CompositingDisplayItem(const proto::DisplayItem& proto) | |
| 37 : DisplayItem(COMPOSITING) { | |
| 38 DCHECK_EQ(proto::DisplayItem::Type_Compositing, proto.type()); | |
| 39 | |
| 40 const proto::CompositingDisplayItem& details = proto.compositing_item(); | |
| 41 uint8_t alpha = static_cast<uint8_t>(details.alpha()); | |
| 42 SkBlendMode xfermode = SkXfermodeModeFromProto(details.mode()); | |
| 43 std::unique_ptr<SkRect> bounds; | |
| 44 if (details.has_bounds()) { | |
| 45 bounds.reset( | |
| 46 new SkRect(gfx::RectFToSkRect(ProtoToRectF(details.bounds())))); | |
| 47 } | |
| 48 | |
| 49 sk_sp<SkColorFilter> filter; | |
| 50 if (details.has_color_filter()) { | |
| 51 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable( | |
| 52 details.color_filter().c_str(), details.color_filter().size(), | |
| 53 SkColorFilter::GetFlattenableType()); | |
| 54 filter.reset(static_cast<SkColorFilter*>(flattenable)); | |
| 55 } | |
| 56 | |
| 57 bool lcd_text_requires_opaque_layer = | |
| 58 details.lcd_text_requires_opaque_layer(); | |
| 59 | |
| 60 SetNew(alpha, xfermode, bounds.get(), std::move(filter), | |
| 61 lcd_text_requires_opaque_layer); | |
| 62 } | |
| 63 | |
| 64 CompositingDisplayItem::~CompositingDisplayItem() { | 33 CompositingDisplayItem::~CompositingDisplayItem() { |
| 65 } | 34 } |
| 66 | 35 |
| 67 void CompositingDisplayItem::SetNew(uint8_t alpha, | 36 void CompositingDisplayItem::SetNew(uint8_t alpha, |
| 68 SkBlendMode xfermode, | 37 SkBlendMode xfermode, |
| 69 SkRect* bounds, | 38 SkRect* bounds, |
| 70 sk_sp<SkColorFilter> cf, | 39 sk_sp<SkColorFilter> cf, |
| 71 bool lcd_text_requires_opaque_layer) { | 40 bool lcd_text_requires_opaque_layer) { |
| 72 alpha_ = alpha; | 41 alpha_ = alpha; |
| 73 xfermode_ = xfermode; | 42 xfermode_ = xfermode; |
| 74 has_bounds_ = !!bounds; | 43 has_bounds_ = !!bounds; |
| 75 if (bounds) | 44 if (bounds) |
| 76 bounds_ = SkRect(*bounds); | 45 bounds_ = SkRect(*bounds); |
| 77 color_filter_ = std::move(cf); | 46 color_filter_ = std::move(cf); |
| 78 lcd_text_requires_opaque_layer_ = lcd_text_requires_opaque_layer; | 47 lcd_text_requires_opaque_layer_ = lcd_text_requires_opaque_layer; |
| 79 } | 48 } |
| 80 | 49 |
| 81 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
| 82 proto->set_type(proto::DisplayItem::Type_Compositing); | |
| 83 | |
| 84 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); | |
| 85 details->set_alpha(static_cast<uint32_t>(alpha_)); | |
| 86 details->set_mode(SkXfermodeModeToProto(xfermode_)); | |
| 87 if (has_bounds_) | |
| 88 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); | |
| 89 | |
| 90 if (color_filter_) { | |
| 91 sk_sp<SkData> data(SkValidatingSerializeFlattenable(color_filter_.get())); | |
| 92 if (data->size() > 0) | |
| 93 details->set_color_filter(data->data(), data->size()); | |
| 94 } | |
| 95 | |
| 96 details->set_lcd_text_requires_opaque_layer(lcd_text_requires_opaque_layer_); | |
| 97 } | |
| 98 | |
| 99 void CompositingDisplayItem::Raster( | 50 void CompositingDisplayItem::Raster( |
| 100 SkCanvas* canvas, | 51 SkCanvas* canvas, |
| 101 SkPicture::AbortCallback* callback) const { | 52 SkPicture::AbortCallback* callback) const { |
| 102 SkPaint paint; | 53 SkPaint paint; |
| 103 paint.setBlendMode(xfermode_); | 54 paint.setBlendMode(xfermode_); |
| 104 paint.setAlpha(alpha_); | 55 paint.setAlpha(alpha_); |
| 105 paint.setColorFilter(color_filter_); | 56 paint.setColorFilter(color_filter_); |
| 106 const SkRect* bounds = has_bounds_ ? &bounds_ : nullptr; | 57 const SkRect* bounds = has_bounds_ ? &bounds_ : nullptr; |
| 107 if (lcd_text_requires_opaque_layer_) | 58 if (lcd_text_requires_opaque_layer_) |
| 108 canvas->saveLayer(bounds, &paint); | 59 canvas->saveLayer(bounds, &paint); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 121 &info, ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), | 72 &info, ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), |
| 122 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), | 73 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), |
| 123 static_cast<float>(bounds_.height())); | 74 static_cast<float>(bounds_.height())); |
| 124 } | 75 } |
| 125 array->AppendString(info); | 76 array->AppendString(info); |
| 126 } | 77 } |
| 127 | 78 |
| 128 EndCompositingDisplayItem::EndCompositingDisplayItem() | 79 EndCompositingDisplayItem::EndCompositingDisplayItem() |
| 129 : DisplayItem(END_COMPOSITING) {} | 80 : DisplayItem(END_COMPOSITING) {} |
| 130 | 81 |
| 131 EndCompositingDisplayItem::EndCompositingDisplayItem( | |
| 132 const proto::DisplayItem& proto) | |
| 133 : DisplayItem(END_COMPOSITING) { | |
| 134 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type()); | |
| 135 } | |
| 136 | |
| 137 EndCompositingDisplayItem::~EndCompositingDisplayItem() { | 82 EndCompositingDisplayItem::~EndCompositingDisplayItem() { |
| 138 } | 83 } |
| 139 | 84 |
| 140 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
| 141 proto->set_type(proto::DisplayItem::Type_EndCompositing); | |
| 142 } | |
| 143 | |
| 144 void EndCompositingDisplayItem::Raster( | 85 void EndCompositingDisplayItem::Raster( |
| 145 SkCanvas* canvas, | 86 SkCanvas* canvas, |
| 146 SkPicture::AbortCallback* callback) const { | 87 SkPicture::AbortCallback* callback) const { |
| 147 canvas->restore(); | 88 canvas->restore(); |
| 148 } | 89 } |
| 149 | 90 |
| 150 void EndCompositingDisplayItem::AsValueInto( | 91 void EndCompositingDisplayItem::AsValueInto( |
| 151 const gfx::Rect& visual_rect, | 92 const gfx::Rect& visual_rect, |
| 152 base::trace_event::TracedValue* array) const { | 93 base::trace_event::TracedValue* array) const { |
| 153 array->AppendString( | 94 array->AppendString( |
| 154 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", | 95 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", |
| 155 visual_rect.ToString().c_str())); | 96 visual_rect.ToString().c_str())); |
| 156 } | 97 } |
| 157 | 98 |
| 158 } // namespace cc | 99 } // namespace cc |
| OLD | NEW |