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

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

Issue 1494223003: cc: Shrink size of display item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some compilation issues in ui oops Created 5 years 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
« no previous file with comments | « cc/playback/drawing_display_item.h ('k') | cc/playback/filter_display_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 7 #include <string>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event_argument.h" 10 #include "base/trace_event/trace_event_argument.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "cc/debug/picture_debug_util.h" 12 #include "cc/debug/picture_debug_util.h"
13 #include "cc/proto/display_item.pb.h" 13 #include "cc/proto/display_item.pb.h"
14 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
15 #include "third_party/skia/include/core/SkData.h" 15 #include "third_party/skia/include/core/SkData.h"
16 #include "third_party/skia/include/core/SkMatrix.h" 16 #include "third_party/skia/include/core/SkMatrix.h"
17 #include "third_party/skia/include/core/SkPicture.h" 17 #include "third_party/skia/include/core/SkPicture.h"
18 #include "third_party/skia/include/core/SkStream.h" 18 #include "third_party/skia/include/core/SkStream.h"
19 #include "third_party/skia/include/utils/SkPictureUtils.h" 19 #include "third_party/skia/include/utils/SkPictureUtils.h"
20 #include "ui/gfx/skia_util.h" 20 #include "ui/gfx/skia_util.h"
21 21
22 namespace cc { 22 namespace cc {
23 23
24 DrawingDisplayItem::DrawingDisplayItem() { 24 DrawingDisplayItem::DrawingDisplayItem() {}
25
26 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture) {
27 SetNew(std::move(picture));
28 }
29
30 DrawingDisplayItem::DrawingDisplayItem(const proto::DisplayItem& proto) {
31 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type());
32
33 skia::RefPtr<SkPicture> picture;
34 const proto::DrawingDisplayItem& details = proto.drawing_item();
35 if (details.has_picture()) {
36 SkMemoryStream stream(details.picture().data(), details.picture().size());
37
38 // TODO(dtrainor, nyquist): Add an image decoder.
39 picture = skia::AdoptRef(SkPicture::CreateFromStream(&stream, nullptr));
40 }
41
42 SetNew(std::move(picture));
43 }
44
45 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) {
46 item.CloneTo(this);
25 } 47 }
26 48
27 DrawingDisplayItem::~DrawingDisplayItem() { 49 DrawingDisplayItem::~DrawingDisplayItem() {
28 } 50 }
29 51
30 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { 52 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) {
31 picture_ = std::move(picture); 53 picture_ = std::move(picture);
32 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL),
33 picture_->approximateOpCount(),
34 SkPictureUtils::ApproximateBytesUsed(picture_.get()));
35 } 54 }
36 55
37 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 56 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
38 proto->set_type(proto::DisplayItem::Type_Drawing); 57 proto->set_type(proto::DisplayItem::Type_Drawing);
39 58
40 proto::DrawingDisplayItem* details = proto->mutable_drawing_item(); 59 proto::DrawingDisplayItem* details = proto->mutable_drawing_item();
41 60
42 // Just use skia's serialize() method for now. 61 // Just use skia's serialize() method for now.
43 if (picture_) { 62 if (picture_) {
44 SkDynamicMemoryWStream stream; 63 SkDynamicMemoryWStream stream;
45 64
46 // TODO(dtrainor, nyquist): Add an SkPixelSerializer to not serialize images 65 // TODO(dtrainor, nyquist): Add an SkPixelSerializer to not serialize images
47 // more than once (crbug.com/548434). 66 // more than once (crbug.com/548434).
48 picture_->serialize(&stream, nullptr); 67 picture_->serialize(&stream, nullptr);
49 if (stream.bytesWritten() > 0) { 68 if (stream.bytesWritten() > 0) {
50 SkAutoDataUnref data(stream.copyToData()); 69 SkAutoDataUnref data(stream.copyToData());
51 details->set_picture(data->data(), data->size()); 70 details->set_picture(data->data(), data->size());
52 } 71 }
53 } 72 }
54 } 73 }
55 74
56 void DrawingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
57 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type());
58
59 skia::RefPtr<SkPicture> picture;
60 const proto::DrawingDisplayItem& details = proto.drawing_item();
61 if (details.has_picture()) {
62 SkMemoryStream stream(details.picture().data(), details.picture().size());
63
64 // TODO(dtrainor, nyquist): Add an image decoder.
65 picture = skia::AdoptRef(SkPicture::CreateFromStream(&stream, nullptr));
66 }
67
68 SetNew(std::move(picture));
69 }
70
71 void DrawingDisplayItem::Raster(SkCanvas* canvas, 75 void DrawingDisplayItem::Raster(SkCanvas* canvas,
72 const gfx::Rect& canvas_target_playback_rect, 76 const gfx::Rect& canvas_target_playback_rect,
73 SkPicture::AbortCallback* callback) const { 77 SkPicture::AbortCallback* callback) const {
74 // The canvas_playback_rect can be empty to signify no culling is desired. 78 // The canvas_playback_rect can be empty to signify no culling is desired.
75 if (!canvas_target_playback_rect.IsEmpty()) { 79 if (!canvas_target_playback_rect.IsEmpty()) {
76 const SkMatrix& matrix = canvas->getTotalMatrix(); 80 const SkMatrix& matrix = canvas->getTotalMatrix();
77 const SkRect& cull_rect = picture_->cullRect(); 81 const SkRect& cull_rect = picture_->cullRect();
78 SkRect target_rect; 82 SkRect target_rect;
79 matrix.mapRect(&target_rect, cull_rect); 83 matrix.mapRect(&target_rect, cull_rect);
80 if (!target_rect.intersect(gfx::RectToSkRect(canvas_target_playback_rect))) 84 if (!target_rect.intersect(gfx::RectToSkRect(canvas_target_playback_rect)))
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 std::string b64_picture; 116 std::string b64_picture;
113 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); 117 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture);
114 array->SetString("skp64", b64_picture); 118 array->SetString("skp64", b64_picture);
115 array->EndDictionary(); 119 array->EndDictionary();
116 } 120 }
117 121
118 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { 122 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const {
119 item->SetNew(picture_); 123 item->SetNew(picture_);
120 } 124 }
121 125
126 size_t DrawingDisplayItem::ExternalMemoryUsage() const {
127 return SkPictureUtils::ApproximateBytesUsed(picture_.get());
128 }
129
130 int DrawingDisplayItem::ApproximateOpCount() const {
131 return picture_->approximateOpCount();
132 }
133
134 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const {
135 return picture_->suitableForGpuRasterization(NULL);
136 }
137
122 } // namespace cc 138 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/drawing_display_item.h ('k') | cc/playback/filter_display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698