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

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

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git merge origin/master Created 4 years, 6 months 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 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/debug/picture_debug_util.h" 15 #include "cc/debug/picture_debug_util.h"
16 #include "cc/proto/display_item.pb.h" 16 #include "cc/proto/display_item.pb.h"
17 #include "cc/proto/image_serialization_processor.h" 17 #include "cc/proto/image_serialization_processor.h"
18 #include "cc/proto/picture_cache.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 19 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "third_party/skia/include/core/SkData.h" 20 #include "third_party/skia/include/core/SkData.h"
20 #include "third_party/skia/include/core/SkMatrix.h" 21 #include "third_party/skia/include/core/SkMatrix.h"
21 #include "third_party/skia/include/core/SkPicture.h" 22 #include "third_party/skia/include/core/SkPicture.h"
22 #include "third_party/skia/include/core/SkStream.h" 23 #include "third_party/skia/include/core/SkStream.h"
23 #include "third_party/skia/include/utils/SkPictureUtils.h" 24 #include "third_party/skia/include/utils/SkPictureUtils.h"
24 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
25 26
26 namespace cc { 27 namespace cc {
27 28
28 DrawingDisplayItem::DrawingDisplayItem() {} 29 DrawingDisplayItem::DrawingDisplayItem() {}
29 30
30 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) { 31 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) {
31 SetNew(std::move(picture)); 32 SetNew(std::move(picture));
32 } 33 }
33 34
34 DrawingDisplayItem::DrawingDisplayItem( 35 DrawingDisplayItem::DrawingDisplayItem(
35 const proto::DisplayItem& proto, 36 const proto::DisplayItem& proto,
36 ImageSerializationProcessor* image_serialization_processor) { 37 ClientPictureCache* client_picture_cache) {
37 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type()); 38 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type());
39 DCHECK(client_picture_cache);
38 40
39 sk_sp<SkPicture> picture;
40 const proto::DrawingDisplayItem& details = proto.drawing_item(); 41 const proto::DrawingDisplayItem& details = proto.drawing_item();
41 if (details.has_picture()) { 42 DCHECK(details.has_id());
42 SkMemoryStream stream(details.picture().data(), details.picture().size()); 43 const proto::SkPictureID& sk_picture_id = details.id();
44 DCHECK(sk_picture_id.has_unique_id());
43 45
44 picture = SkPicture::MakeFromStream( 46 uint32_t unique_id = sk_picture_id.unique_id();
45 &stream, image_serialization_processor->GetPixelDeserializer()); 47 sk_sp<const SkPicture> picture = client_picture_cache->GetPicture(unique_id);
46 } 48 DCHECK(picture);
47 49
48 SetNew(std::move(picture)); 50 SetNew(std::move(picture));
49 } 51 }
50 52
51 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) { 53 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) {
52 item.CloneTo(this); 54 item.CloneTo(this);
53 } 55 }
54 56
55 DrawingDisplayItem::~DrawingDisplayItem() { 57 DrawingDisplayItem::~DrawingDisplayItem() {
56 } 58 }
57 59
58 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { 60 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) {
59 picture_ = std::move(picture); 61 picture_ = std::move(picture);
60 } 62 }
61 63
62 void DrawingDisplayItem::ToProtobuf( 64 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
63 proto::DisplayItem* proto,
64 ImageSerializationProcessor* image_serialization_processor) const {
65 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf"); 65 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf");
66 proto->set_type(proto::DisplayItem::Type_Drawing); 66 proto->set_type(proto::DisplayItem::Type_Drawing);
67 67
68 proto::DrawingDisplayItem* details = proto->mutable_drawing_item(); 68 if (!picture_)
69 return;
69 70
70 // Just use skia's serialize() method for now. 71 proto->mutable_drawing_item()->mutable_id()->set_unique_id(
71 if (picture_) { 72 picture_->uniqueID());
72 TRACE_EVENT0("cc.remote", 73 }
73 "DrawingDisplayItem::ToProtobuf SkPicture::Serialize"); 74
74 SkDynamicMemoryWStream stream; 75 void DrawingDisplayItem::MarkForRegistrationEngine(
75 picture_->serialize(&stream, 76 EnginePictureCache* engine_picture_cache) const {
76 image_serialization_processor->GetPixelSerializer()); 77 if (picture_ && engine_picture_cache)
vmpstr 2016/06/16 22:09:59 Maybe just expose picture_?
nyquist 2016/06/24 11:11:14 Done.
77 if (stream.bytesWritten() > 0) { 78 engine_picture_cache->MarkPictureForRegistration(picture_.get());
78 SkAutoDataUnref data(stream.copyToData()); 79 }
79 details->set_picture(data->data(), data->size()); 80
80 } 81 void DrawingDisplayItem::MarkForUnregistrationEngine(
81 } 82 EnginePictureCache* engine_picture_cache) const {
83 if (picture_ && engine_picture_cache)
84 engine_picture_cache->MarkPictureForUnregistration(picture_.get());
82 } 85 }
83 86
84 void DrawingDisplayItem::Raster(SkCanvas* canvas, 87 void DrawingDisplayItem::Raster(SkCanvas* canvas,
85 const gfx::Rect& canvas_target_playback_rect, 88 const gfx::Rect& canvas_target_playback_rect,
86 SkPicture::AbortCallback* callback) const { 89 SkPicture::AbortCallback* callback) const {
87 // The canvas_playback_rect can be empty to signify no culling is desired. 90 // The canvas_playback_rect can be empty to signify no culling is desired.
88 if (!canvas_target_playback_rect.IsEmpty()) { 91 if (!canvas_target_playback_rect.IsEmpty()) {
89 const SkMatrix& matrix = canvas->getTotalMatrix(); 92 const SkMatrix& matrix = canvas->getTotalMatrix();
90 const SkRect& cull_rect = picture_->cullRect(); 93 const SkRect& cull_rect = picture_->cullRect();
91 SkRect target_rect; 94 SkRect target_rect;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 137
135 size_t DrawingDisplayItem::ExternalMemoryUsage() const { 138 size_t DrawingDisplayItem::ExternalMemoryUsage() const {
136 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); 139 return SkPictureUtils::ApproximateBytesUsed(picture_.get());
137 } 140 }
138 141
139 int DrawingDisplayItem::ApproximateOpCount() const { 142 int DrawingDisplayItem::ApproximateOpCount() const {
140 return picture_->approximateOpCount(); 143 return picture_->approximateOpCount();
141 } 144 }
142 145
143 } // namespace cc 146 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698