| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/drawing_display_item.h" | 5 #include "cc/playback/drawing_display_item.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "cc/blimp/client_picture_cache.h" | 15 #include "cc/blimp/client_picture_cache.h" |
| 16 #include "cc/blimp/image_serialization_processor.h" | 16 #include "cc/blimp/image_serialization_processor.h" |
| 17 #include "cc/debug/picture_debug_util.h" | 17 #include "cc/debug/picture_debug_util.h" |
| 18 #include "cc/proto/display_item.pb.h" | 18 #include "cc/proto/display_item.pb.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkData.h" | 20 #include "third_party/skia/include/core/SkData.h" |
| 21 #include "third_party/skia/include/core/SkMatrix.h" | 21 #include "third_party/skia/include/core/SkMatrix.h" |
| 22 #include "third_party/skia/include/core/SkPicture.h" | 22 #include "third_party/skia/include/core/SkPicture.h" |
| 23 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 23 #include "third_party/skia/include/core/SkStream.h" | 24 #include "third_party/skia/include/core/SkStream.h" |
| 24 #include "third_party/skia/include/utils/SkPictureUtils.h" | 25 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 26 #include "skia/ext/cdl_picture.h" |
| 25 #include "ui/gfx/skia_util.h" | 27 #include "ui/gfx/skia_util.h" |
| 26 | 28 |
| 27 namespace cc { | 29 namespace cc { |
| 28 | 30 |
| 29 DrawingDisplayItem::DrawingDisplayItem() {} | 31 DrawingDisplayItem::DrawingDisplayItem() {} |
| 30 | 32 |
| 31 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) { | 33 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const CdlPicture> picture) { |
| 32 SetNew(std::move(picture)); | 34 SetNew(std::move(picture)); |
| 33 } | 35 } |
| 34 | 36 |
| 35 DrawingDisplayItem::DrawingDisplayItem( | 37 DrawingDisplayItem::DrawingDisplayItem( |
| 36 const proto::DisplayItem& proto, | 38 const proto::DisplayItem& proto, |
| 37 ClientPictureCache* client_picture_cache, | 39 ClientPictureCache* client_picture_cache, |
| 38 std::vector<uint32_t>* used_engine_picture_ids) { | 40 std::vector<uint32_t>* used_engine_picture_ids) { |
| 39 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type()); | 41 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type()); |
| 40 DCHECK(client_picture_cache); | 42 DCHECK(client_picture_cache); |
| 41 | 43 |
| 42 const proto::DrawingDisplayItem& details = proto.drawing_item(); | 44 const proto::DrawingDisplayItem& details = proto.drawing_item(); |
| 43 DCHECK(details.has_id()); | 45 DCHECK(details.has_id()); |
| 44 const proto::SkPictureID& sk_picture_id = details.id(); | 46 const proto::SkPictureID& sk_picture_id = details.id(); |
| 45 DCHECK(sk_picture_id.has_unique_id()); | 47 DCHECK(sk_picture_id.has_unique_id()); |
| 46 | 48 |
| 47 uint32_t unique_id = sk_picture_id.unique_id(); | 49 uint32_t unique_id = sk_picture_id.unique_id(); |
| 48 sk_sp<const SkPicture> picture = client_picture_cache->GetPicture(unique_id); | 50 sk_sp<const CdlPicture> picture = client_picture_cache->GetPicture(unique_id); |
| 49 DCHECK(picture); | 51 DCHECK(picture); |
| 50 | 52 |
| 51 used_engine_picture_ids->push_back(unique_id); | 53 used_engine_picture_ids->push_back(unique_id); |
| 52 SetNew(std::move(picture)); | 54 SetNew(std::move(picture)); |
| 53 } | 55 } |
| 54 | 56 |
| 55 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) { | 57 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) { |
| 56 item.CloneTo(this); | 58 item.CloneTo(this); |
| 57 } | 59 } |
| 58 | 60 |
| 59 DrawingDisplayItem::~DrawingDisplayItem() { | 61 DrawingDisplayItem::~DrawingDisplayItem() { |
| 60 } | 62 } |
| 61 | 63 |
| 62 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { | 64 void DrawingDisplayItem::SetNew(sk_sp<const CdlPicture> picture) { |
| 63 picture_ = std::move(picture); | 65 picture_ = std::move(picture); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 68 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 67 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf"); | 69 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf"); |
| 68 proto->set_type(proto::DisplayItem::Type_Drawing); | 70 proto->set_type(proto::DisplayItem::Type_Drawing); |
| 69 | 71 |
| 70 if (!picture_) | 72 if (!picture_) |
| 71 return; | 73 return; |
| 72 | 74 |
| 73 proto->mutable_drawing_item()->mutable_id()->set_unique_id( | 75 proto->mutable_drawing_item()->mutable_id()->set_unique_id( |
| 74 picture_->uniqueID()); | 76 picture_->uniqueID()); |
| 75 } | 77 } |
| 76 | 78 |
| 77 sk_sp<const SkPicture> DrawingDisplayItem::GetPicture() const { | 79 sk_sp<const CdlPicture> DrawingDisplayItem::GetPicture() const { |
| 78 return picture_; | 80 return picture_; |
| 79 } | 81 } |
| 80 | 82 |
| 81 DISABLE_CFI_PERF | 83 DISABLE_CFI_PERF |
| 82 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 84 void DrawingDisplayItem::Raster(CdlCanvas* canvas, |
| 83 SkPicture::AbortCallback* callback) const { | 85 SkPicture::AbortCallback* callback) const { |
| 84 if (canvas->quickReject(picture_->cullRect())) | 86 if (canvas->quickReject(picture_->cullRect())) |
| 85 return; | 87 return; |
| 86 | 88 |
| 87 // SkPicture always does a wrapping save/restore on the canvas, so it is not | 89 // SkPicture always does a wrapping save/restore on the canvas, so it is not |
| 88 // necessary here. | 90 // necessary here. |
| 89 if (callback) | 91 if (callback) |
| 90 picture_->playback(canvas, callback); | 92 picture_->playback(canvas, callback); |
| 91 else | 93 else |
| 92 canvas->drawPicture(picture_.get()); | 94 canvas->drawPicture(picture_.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 array->AppendInteger(visual_rect.height()); | 107 array->AppendInteger(visual_rect.height()); |
| 106 array->EndArray(); | 108 array->EndArray(); |
| 107 | 109 |
| 108 array->BeginArray("cullRect"); | 110 array->BeginArray("cullRect"); |
| 109 array->AppendInteger(picture_->cullRect().x()); | 111 array->AppendInteger(picture_->cullRect().x()); |
| 110 array->AppendInteger(picture_->cullRect().y()); | 112 array->AppendInteger(picture_->cullRect().y()); |
| 111 array->AppendInteger(picture_->cullRect().width()); | 113 array->AppendInteger(picture_->cullRect().width()); |
| 112 array->AppendInteger(picture_->cullRect().height()); | 114 array->AppendInteger(picture_->cullRect().height()); |
| 113 array->EndArray(); | 115 array->EndArray(); |
| 114 | 116 |
| 117 // TODO(cdl): CdlPicture serialize. |
| 115 std::string b64_picture; | 118 std::string b64_picture; |
| 116 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | 119 PictureDebugUtil::SerializeAsBase64(ToSkPicture(picture_.get()).get(), |
| 120 &b64_picture); |
| 117 array->SetString("skp64", b64_picture); | 121 array->SetString("skp64", b64_picture); |
| 118 array->EndDictionary(); | 122 array->EndDictionary(); |
| 119 } | 123 } |
| 120 | 124 |
| 121 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { | 125 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { |
| 122 item->SetNew(picture_); | 126 item->SetNew(picture_); |
| 123 } | 127 } |
| 124 | 128 |
| 125 size_t DrawingDisplayItem::ExternalMemoryUsage() const { | 129 size_t DrawingDisplayItem::ExternalMemoryUsage() const { |
| 126 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 130 // TODO(cdl): Approximate CDL size. |
| 131 // return SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
| 132 return 1; |
| 127 } | 133 } |
| 128 | 134 |
| 129 DISABLE_CFI_PERF | 135 DISABLE_CFI_PERF |
| 130 int DrawingDisplayItem::ApproximateOpCount() const { | 136 int DrawingDisplayItem::ApproximateOpCount() const { |
| 131 return picture_->approximateOpCount(); | 137 return picture_->approximateOpCount(); |
| 132 } | 138 } |
| 133 | 139 |
| 134 } // namespace cc | 140 } // namespace cc |
| OLD | NEW |