| 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" | |
| 16 #include "cc/blimp/image_serialization_processor.h" | |
| 17 #include "cc/debug/picture_debug_util.h" | 15 #include "cc/debug/picture_debug_util.h" |
| 18 #include "cc/proto/display_item.pb.h" | |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkData.h" | 17 #include "third_party/skia/include/core/SkData.h" |
| 21 #include "third_party/skia/include/core/SkMatrix.h" | 18 #include "third_party/skia/include/core/SkMatrix.h" |
| 22 #include "third_party/skia/include/core/SkPicture.h" | 19 #include "third_party/skia/include/core/SkPicture.h" |
| 23 #include "third_party/skia/include/core/SkStream.h" | 20 #include "third_party/skia/include/core/SkStream.h" |
| 24 #include "third_party/skia/include/utils/SkPictureUtils.h" | 21 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 25 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 26 | 23 |
| 27 namespace cc { | 24 namespace cc { |
| 28 | 25 |
| 29 DrawingDisplayItem::DrawingDisplayItem() : DisplayItem(DRAWING) {} | 26 DrawingDisplayItem::DrawingDisplayItem() : DisplayItem(DRAWING) {} |
| 30 | 27 |
| 31 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) | 28 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) |
| 32 : DisplayItem(DRAWING) { | 29 : DisplayItem(DRAWING) { |
| 33 SetNew(std::move(picture)); | 30 SetNew(std::move(picture)); |
| 34 } | 31 } |
| 35 | 32 |
| 36 DrawingDisplayItem::DrawingDisplayItem( | |
| 37 const proto::DisplayItem& proto, | |
| 38 ClientPictureCache* client_picture_cache, | |
| 39 std::vector<uint32_t>* used_engine_picture_ids) | |
| 40 : DisplayItem(DRAWING) { | |
| 41 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type()); | |
| 42 DCHECK(client_picture_cache); | |
| 43 | |
| 44 const proto::DrawingDisplayItem& details = proto.drawing_item(); | |
| 45 DCHECK(details.has_id()); | |
| 46 const proto::SkPictureID& sk_picture_id = details.id(); | |
| 47 DCHECK(sk_picture_id.has_unique_id()); | |
| 48 | |
| 49 uint32_t unique_id = sk_picture_id.unique_id(); | |
| 50 sk_sp<const SkPicture> picture = client_picture_cache->GetPicture(unique_id); | |
| 51 DCHECK(picture); | |
| 52 | |
| 53 used_engine_picture_ids->push_back(unique_id); | |
| 54 SetNew(std::move(picture)); | |
| 55 } | |
| 56 | |
| 57 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) | 33 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) |
| 58 : DisplayItem(DRAWING) { | 34 : DisplayItem(DRAWING) { |
| 59 item.CloneTo(this); | 35 item.CloneTo(this); |
| 60 } | 36 } |
| 61 | 37 |
| 62 DrawingDisplayItem::~DrawingDisplayItem() { | 38 DrawingDisplayItem::~DrawingDisplayItem() { |
| 63 } | 39 } |
| 64 | 40 |
| 65 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { | 41 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { |
| 66 picture_ = std::move(picture); | 42 picture_ = std::move(picture); |
| 67 } | 43 } |
| 68 | 44 |
| 69 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
| 70 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf"); | |
| 71 proto->set_type(proto::DisplayItem::Type_Drawing); | |
| 72 | |
| 73 if (!picture_) | |
| 74 return; | |
| 75 | |
| 76 proto->mutable_drawing_item()->mutable_id()->set_unique_id( | |
| 77 picture_->uniqueID()); | |
| 78 } | |
| 79 | |
| 80 sk_sp<const SkPicture> DrawingDisplayItem::GetPicture() const { | 45 sk_sp<const SkPicture> DrawingDisplayItem::GetPicture() const { |
| 81 return picture_; | 46 return picture_; |
| 82 } | 47 } |
| 83 | 48 |
| 84 DISABLE_CFI_PERF | 49 DISABLE_CFI_PERF |
| 85 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 50 void DrawingDisplayItem::Raster(SkCanvas* canvas, |
| 86 SkPicture::AbortCallback* callback) const { | 51 SkPicture::AbortCallback* callback) const { |
| 87 if (canvas->quickReject(picture_->cullRect())) | 52 if (canvas->quickReject(picture_->cullRect())) |
| 88 return; | 53 return; |
| 89 | 54 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 size_t DrawingDisplayItem::ExternalMemoryUsage() const { | 93 size_t DrawingDisplayItem::ExternalMemoryUsage() const { |
| 129 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 94 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
| 130 } | 95 } |
| 131 | 96 |
| 132 DISABLE_CFI_PERF | 97 DISABLE_CFI_PERF |
| 133 int DrawingDisplayItem::ApproximateOpCount() const { | 98 int DrawingDisplayItem::ApproximateOpCount() const { |
| 134 return picture_->approximateOpCount(); | 99 return picture_->approximateOpCount(); |
| 135 } | 100 } |
| 136 | 101 |
| 137 } // namespace cc | 102 } // namespace cc |
| OLD | NEW |