| 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() { | 22 CompositingDisplayItem::CompositingDisplayItem(uint8_t alpha, |
| 23 SkXfermode::Mode xfermode, |
| 24 SkRect* bounds, |
| 25 skia::RefPtr<SkColorFilter> cf) { |
| 26 SetNew(alpha, xfermode, bounds, cf); |
| 27 } |
| 28 |
| 29 CompositingDisplayItem::CompositingDisplayItem( |
| 30 const proto::DisplayItem& proto) { |
| 31 FromProtobuf(proto); |
| 23 } | 32 } |
| 24 | 33 |
| 25 CompositingDisplayItem::~CompositingDisplayItem() { | 34 CompositingDisplayItem::~CompositingDisplayItem() { |
| 26 } | 35 } |
| 27 | 36 |
| 28 void CompositingDisplayItem::SetNew(uint8_t alpha, | 37 void CompositingDisplayItem::SetNew(uint8_t alpha, |
| 29 SkXfermode::Mode xfermode, | 38 SkXfermode::Mode xfermode, |
| 30 SkRect* bounds, | 39 SkRect* bounds, |
| 31 skia::RefPtr<SkColorFilter> cf) { | 40 skia::RefPtr<SkColorFilter> cf) { |
| 32 alpha_ = alpha; | 41 alpha_ = alpha; |
| 33 xfermode_ = xfermode; | 42 xfermode_ = xfermode; |
| 34 has_bounds_ = !!bounds; | 43 has_bounds_ = !!bounds; |
| 35 if (bounds) | 44 if (bounds) |
| 36 bounds_ = SkRect(*bounds); | 45 bounds_ = SkRect(*bounds); |
| 37 color_filter_ = cf; | 46 color_filter_ = 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 } | 47 } |
| 44 | 48 |
| 45 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 49 void CompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 46 proto->set_type(proto::DisplayItem::Type_Compositing); | 50 proto->set_type(proto::DisplayItem::Type_Compositing); |
| 47 | 51 |
| 48 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); | 52 proto::CompositingDisplayItem* details = proto->mutable_compositing_item(); |
| 49 details->set_alpha(static_cast<uint32_t>(alpha_)); | 53 details->set_alpha(static_cast<uint32_t>(alpha_)); |
| 50 details->set_mode(SkXfermodeModeToProto(xfermode_)); | 54 details->set_mode(SkXfermodeModeToProto(xfermode_)); |
| 51 if (has_bounds_) | 55 if (has_bounds_) |
| 52 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); | 56 RectFToProto(gfx::SkRectToRectF(bounds_), details->mutable_bounds()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 array->AppendString(base::StringPrintf( | 103 array->AppendString(base::StringPrintf( |
| 100 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]", | 104 "CompositingDisplayItem alpha: %d, xfermode: %d, visualRect: [%s]", |
| 101 alpha_, xfermode_, visual_rect.ToString().c_str())); | 105 alpha_, xfermode_, visual_rect.ToString().c_str())); |
| 102 if (has_bounds_) | 106 if (has_bounds_) |
| 103 array->AppendString(base::StringPrintf( | 107 array->AppendString(base::StringPrintf( |
| 104 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), | 108 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), |
| 105 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), | 109 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), |
| 106 static_cast<float>(bounds_.height()))); | 110 static_cast<float>(bounds_.height()))); |
| 107 } | 111 } |
| 108 | 112 |
| 109 EndCompositingDisplayItem::EndCompositingDisplayItem() { | 113 size_t CompositingDisplayItem::ExternalMemoryUsage() const { |
| 110 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 114 // TODO(pdr): Include color_filter's memory here. |
| 111 0 /* external_memory_usage */); | 115 return 0; |
| 116 } |
| 117 |
| 118 int CompositingDisplayItem::ApproximateOpCount() const { |
| 119 return 1; |
| 120 } |
| 121 |
| 122 EndCompositingDisplayItem::EndCompositingDisplayItem() {} |
| 123 |
| 124 EndCompositingDisplayItem::EndCompositingDisplayItem( |
| 125 const proto::DisplayItem& proto) { |
| 126 FromProtobuf(proto); |
| 112 } | 127 } |
| 113 | 128 |
| 114 EndCompositingDisplayItem::~EndCompositingDisplayItem() { | 129 EndCompositingDisplayItem::~EndCompositingDisplayItem() { |
| 115 } | 130 } |
| 116 | 131 |
| 117 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 132 void EndCompositingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 118 proto->set_type(proto::DisplayItem::Type_EndCompositing); | 133 proto->set_type(proto::DisplayItem::Type_EndCompositing); |
| 119 } | 134 } |
| 120 | 135 |
| 121 void EndCompositingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { | 136 void EndCompositingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 122 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type()); | 137 DCHECK_EQ(proto::DisplayItem::Type_EndCompositing, proto.type()); |
| 123 } | 138 } |
| 124 | 139 |
| 125 void EndCompositingDisplayItem::Raster( | 140 void EndCompositingDisplayItem::Raster( |
| 126 SkCanvas* canvas, | 141 SkCanvas* canvas, |
| 127 const gfx::Rect& canvas_target_playback_rect, | 142 const gfx::Rect& canvas_target_playback_rect, |
| 128 SkPicture::AbortCallback* callback) const { | 143 SkPicture::AbortCallback* callback) const { |
| 129 canvas->restore(); | 144 canvas->restore(); |
| 130 } | 145 } |
| 131 | 146 |
| 132 void EndCompositingDisplayItem::AsValueInto( | 147 void EndCompositingDisplayItem::AsValueInto( |
| 133 const gfx::Rect& visual_rect, | 148 const gfx::Rect& visual_rect, |
| 134 base::trace_event::TracedValue* array) const { | 149 base::trace_event::TracedValue* array) const { |
| 135 array->AppendString( | 150 array->AppendString( |
| 136 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", | 151 base::StringPrintf("EndCompositingDisplayItem visualRect: [%s]", |
| 137 visual_rect.ToString().c_str())); | 152 visual_rect.ToString().c_str())); |
| 138 } | 153 } |
| 139 | 154 |
| 155 size_t EndCompositingDisplayItem::ExternalMemoryUsage() const { |
| 156 return 0; |
| 157 } |
| 158 |
| 159 int EndCompositingDisplayItem::ApproximateOpCount() const { |
| 160 return 0; |
| 161 } |
| 162 |
| 140 } // namespace cc | 163 } // namespace cc |
| OLD | NEW |