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

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

Issue 1407793002: Add protobuf serialization to DisplayItemList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_display2
Patch Set: Rebased Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/clip_path_display_item.h" 5 #include "cc/playback/clip_path_display_item.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/trace_event/trace_event_argument.h" 8 #include "base/trace_event/trace_event_argument.h"
9 #include "cc/proto/display_item.pb.h"
10 #include "cc/proto/skia_conversions.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
10 12
11 namespace cc { 13 namespace cc {
12 14
13 ClipPathDisplayItem::ClipPathDisplayItem() { 15 ClipPathDisplayItem::ClipPathDisplayItem() {
14 } 16 }
15 17
16 ClipPathDisplayItem::~ClipPathDisplayItem() { 18 ClipPathDisplayItem::~ClipPathDisplayItem() {
17 } 19 }
18 20
19 void ClipPathDisplayItem::SetNew(const SkPath& clip_path, 21 void ClipPathDisplayItem::SetNew(const SkPath& clip_path,
20 SkRegion::Op clip_op, 22 SkRegion::Op clip_op,
21 bool antialias) { 23 bool antialias) {
22 clip_path_ = clip_path; 24 clip_path_ = clip_path;
23 clip_op_ = clip_op; 25 clip_op_ = clip_op;
24 antialias_ = antialias; 26 antialias_ = antialias;
25 27
26 // The size of SkPath's external storage is not currently accounted for (and 28 // The size of SkPath's external storage is not currently accounted for (and
27 // may well be shared anyway). 29 // may well be shared anyway).
28 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, 30 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
29 0 /* external_memory_usage */); 31 0 /* external_memory_usage */);
30 } 32 }
31 33
34 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) {
35 proto->set_type(proto::DisplayItem::Type_ClipPath);
36
37 proto::ClipPathDisplayItem* details = proto->mutable_details_clip_path();
38 details->set_clip_op(SkRegionOpToProto(clip_op_));
39 details->set_antialias(antialias_);
40
41 // Just use skia's serialization method for the SkPath for now.
42 size_t path_size = clip_path_.writeToMemory(nullptr);
43 if (path_size > 0) {
44 scoped_ptr<char[]> buffer(new char[path_size]);
45 clip_path_.writeToMemory(buffer.get());
46 details->set_clip_path(buffer.get(), path_size);
vmpstr 2015/10/26 17:46:17 What's the parameter to set_clip_path? Is this a c
David Trainor- moved to gerrit 2015/10/26 20:42:56 I believe protobufs always copy the data passed in
47 }
48 }
49
50 void ClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
51 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type());
52
53 const proto::ClipPathDisplayItem& details = proto.details_clip_path();
54 SkRegion::Op clip_op = SkRegionOpFromProto(details.clip_op());
55 bool antialias = details.antialias();
56
57 SkPath clip_path;
58 if (details.has_clip_path()) {
59 clip_path.readFromMemory(details.clip_path().c_str(),
vmpstr 2015/10/26 17:46:17 Does readFromMemory return some sort of a status c
David Trainor- moved to gerrit 2015/10/26 20:42:56 It returns the bytes read to build the SkPath. I
60 details.clip_path().size());
61 }
62
63 SetNew(clip_path, clip_op, antialias);
64 }
65
32 void ClipPathDisplayItem::Raster(SkCanvas* canvas, 66 void ClipPathDisplayItem::Raster(SkCanvas* canvas,
33 const gfx::Rect& canvas_target_playback_rect, 67 const gfx::Rect& canvas_target_playback_rect,
34 SkPicture::AbortCallback* callback) const { 68 SkPicture::AbortCallback* callback) const {
35 canvas->save(); 69 canvas->save();
36 canvas->clipPath(clip_path_, clip_op_, antialias_); 70 canvas->clipPath(clip_path_, clip_op_, antialias_);
37 } 71 }
38 72
39 void ClipPathDisplayItem::ProcessForBounds( 73 void ClipPathDisplayItem::ProcessForBounds(
40 DisplayItemListBoundsCalculator* calculator) const { 74 DisplayItemListBoundsCalculator* calculator) const {
41 calculator->AddStartingDisplayItem(); 75 calculator->AddStartingDisplayItem();
42 } 76 }
43 77
44 void ClipPathDisplayItem::AsValueInto( 78 void ClipPathDisplayItem::AsValueInto(
45 base::trace_event::TracedValue* array) const { 79 base::trace_event::TracedValue* array) const {
46 array->AppendString(base::StringPrintf("ClipPathDisplayItem length: %d", 80 array->AppendString(base::StringPrintf("ClipPathDisplayItem length: %d",
47 clip_path_.countPoints())); 81 clip_path_.countPoints()));
48 } 82 }
49 83
50 EndClipPathDisplayItem::EndClipPathDisplayItem() { 84 EndClipPathDisplayItem::EndClipPathDisplayItem() {
51 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, 85 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
52 0 /* external_memory_usage */); 86 0 /* external_memory_usage */);
53 } 87 }
54 88
55 EndClipPathDisplayItem::~EndClipPathDisplayItem() { 89 EndClipPathDisplayItem::~EndClipPathDisplayItem() {
56 } 90 }
57 91
92 void EndClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) {
93 proto->set_type(proto::DisplayItem::Type_EndClipPath);
94 }
95
96 void EndClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
97 DCHECK_EQ(proto::DisplayItem::Type_EndClipPath, proto.type());
98 }
99
58 void EndClipPathDisplayItem::Raster( 100 void EndClipPathDisplayItem::Raster(
59 SkCanvas* canvas, 101 SkCanvas* canvas,
60 const gfx::Rect& canvas_target_playback_rect, 102 const gfx::Rect& canvas_target_playback_rect,
61 SkPicture::AbortCallback* callback) const { 103 SkPicture::AbortCallback* callback) const {
62 canvas->restore(); 104 canvas->restore();
63 } 105 }
64 106
65 void EndClipPathDisplayItem::ProcessForBounds( 107 void EndClipPathDisplayItem::ProcessForBounds(
66 DisplayItemListBoundsCalculator* calculator) const { 108 DisplayItemListBoundsCalculator* calculator) const {
67 calculator->AddEndingDisplayItem(); 109 calculator->AddEndingDisplayItem();
68 } 110 }
69 111
70 void EndClipPathDisplayItem::AsValueInto( 112 void EndClipPathDisplayItem::AsValueInto(
71 base::trace_event::TracedValue* array) const { 113 base::trace_event::TracedValue* array) const {
72 array->AppendString("EndClipPathDisplayItem"); 114 array->AppendString("EndClipPathDisplayItem");
73 } 115 }
74 116
75 } // namespace cc 117 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698