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

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

Issue 1407793002: Add protobuf serialization to DisplayItemList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_display2
Patch Set: Comments are hard Created 5 years, 1 month 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 "cc/debug/picture_debug_util.h" 11 #include "cc/debug/picture_debug_util.h"
12 #include "cc/proto/display_item.pb.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkData.h"
13 #include "third_party/skia/include/core/SkMatrix.h" 15 #include "third_party/skia/include/core/SkMatrix.h"
14 #include "third_party/skia/include/core/SkPicture.h" 16 #include "third_party/skia/include/core/SkPicture.h"
17 #include "third_party/skia/include/core/SkStream.h"
15 #include "third_party/skia/include/utils/SkPictureUtils.h" 18 #include "third_party/skia/include/utils/SkPictureUtils.h"
16 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
17 20
18 namespace cc { 21 namespace cc {
19 22
20 DrawingDisplayItem::DrawingDisplayItem() { 23 DrawingDisplayItem::DrawingDisplayItem() {
21 } 24 }
22 25
23 DrawingDisplayItem::~DrawingDisplayItem() { 26 DrawingDisplayItem::~DrawingDisplayItem() {
24 } 27 }
25 28
26 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { 29 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) {
27 picture_ = picture.Pass(); 30 picture_ = picture.Pass();
28 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL), 31 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL),
29 picture_->approximateOpCount(), 32 picture_->approximateOpCount(),
30 SkPictureUtils::ApproximateBytesUsed(picture_.get())); 33 SkPictureUtils::ApproximateBytesUsed(picture_.get()));
31 } 34 }
32 35
36 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
37 proto->set_type(proto::DisplayItem::Type_Drawing);
38
39 proto::DrawingDisplayItem* details = proto->mutable_drawing_item();
40
41 // Just use skia's serialize() method for now.
42 if (picture_) {
43 SkDynamicMemoryWStream stream;
44
45 // TODO(dtrainor, nyquist): Add an SkPixelSerializer to not serialize images
46 // more than once (crbug.com/548434).
47 picture_->serialize(&stream, nullptr);
48 if (stream.bytesWritten() > 0) {
49 SkAutoDataUnref data(stream.copyToData());
50 details->set_picture(data->data(), data->size());
51 }
52 }
53 }
54
55 void DrawingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
56 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type());
57
58 skia::RefPtr<SkPicture> picture;
59 const proto::DrawingDisplayItem& details = proto.drawing_item();
60 if (details.has_picture()) {
61 SkMemoryStream stream(details.picture().data(), details.picture().size());
62
63 // TODO(dtrainor, nyquist): Add an image decoder.
64 picture = skia::AdoptRef(SkPicture::CreateFromStream(&stream, nullptr));
65 }
66
67 SetNew(picture.Pass());
68 }
69
33 void DrawingDisplayItem::Raster(SkCanvas* canvas, 70 void DrawingDisplayItem::Raster(SkCanvas* canvas,
34 const gfx::Rect& canvas_target_playback_rect, 71 const gfx::Rect& canvas_target_playback_rect,
35 SkPicture::AbortCallback* callback) const { 72 SkPicture::AbortCallback* callback) const {
36 // The canvas_playback_rect can be empty to signify no culling is desired. 73 // The canvas_playback_rect can be empty to signify no culling is desired.
37 if (!canvas_target_playback_rect.IsEmpty()) { 74 if (!canvas_target_playback_rect.IsEmpty()) {
38 const SkMatrix& matrix = canvas->getTotalMatrix(); 75 const SkMatrix& matrix = canvas->getTotalMatrix();
39 const SkRect& cull_rect = picture_->cullRect(); 76 const SkRect& cull_rect = picture_->cullRect();
40 SkRect target_rect; 77 SkRect target_rect;
41 matrix.mapRect(&target_rect, cull_rect); 78 matrix.mapRect(&target_rect, cull_rect);
42 if (!target_rect.intersect(gfx::RectToSkRect(canvas_target_playback_rect))) 79 if (!target_rect.intersect(gfx::RectToSkRect(canvas_target_playback_rect)))
(...skipping 21 matching lines...) Expand all
64 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); 101 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture);
65 array->SetString("skp64", b64_picture); 102 array->SetString("skp64", b64_picture);
66 array->EndDictionary(); 103 array->EndDictionary();
67 } 104 }
68 105
69 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { 106 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const {
70 item->SetNew(picture_); 107 item->SetNew(picture_);
71 } 108 }
72 109
73 } // namespace cc 110 } // 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