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

Side by Side Diff: cc/playback/clip_path_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/clip_path_display_item.h ('k') | cc/playback/compositing_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 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" 9 #include "cc/proto/display_item.pb.h"
10 #include "cc/proto/skia_conversions.h" 10 #include "cc/proto/skia_conversions.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
12 12
13 namespace cc { 13 namespace cc {
14 14
15 ClipPathDisplayItem::ClipPathDisplayItem() { 15 ClipPathDisplayItem::ClipPathDisplayItem(const SkPath& clip_path,
16 SkRegion::Op clip_op,
17 bool antialias) {
18 SetNew(clip_path, clip_op, antialias);
19 }
20
21 ClipPathDisplayItem::ClipPathDisplayItem(const proto::DisplayItem& proto) {
22 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type());
23
24 const proto::ClipPathDisplayItem& details = proto.clip_path_item();
25 SkRegion::Op clip_op = SkRegionOpFromProto(details.clip_op());
26 bool antialias = details.antialias();
27
28 SkPath clip_path;
29 if (details.has_clip_path()) {
30 size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(),
31 details.clip_path().size());
32 DCHECK_EQ(details.clip_path().size(), bytes_read);
33 }
34
35 SetNew(clip_path, clip_op, antialias);
16 } 36 }
17 37
18 ClipPathDisplayItem::~ClipPathDisplayItem() { 38 ClipPathDisplayItem::~ClipPathDisplayItem() {
19 } 39 }
20 40
21 void ClipPathDisplayItem::SetNew(const SkPath& clip_path, 41 void ClipPathDisplayItem::SetNew(const SkPath& clip_path,
22 SkRegion::Op clip_op, 42 SkRegion::Op clip_op,
23 bool antialias) { 43 bool antialias) {
24 clip_path_ = clip_path; 44 clip_path_ = clip_path;
25 clip_op_ = clip_op; 45 clip_op_ = clip_op;
26 antialias_ = antialias; 46 antialias_ = antialias;
27
28 // The size of SkPath's external storage is not currently accounted for (and
29 // may well be shared anyway).
30 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
31 0 /* external_memory_usage */);
32 } 47 }
33 48
34 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 49 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
35 proto->set_type(proto::DisplayItem::Type_ClipPath); 50 proto->set_type(proto::DisplayItem::Type_ClipPath);
36 51
37 proto::ClipPathDisplayItem* details = proto->mutable_clip_path_item(); 52 proto::ClipPathDisplayItem* details = proto->mutable_clip_path_item();
38 details->set_clip_op(SkRegionOpToProto(clip_op_)); 53 details->set_clip_op(SkRegionOpToProto(clip_op_));
39 details->set_antialias(antialias_); 54 details->set_antialias(antialias_);
40 55
41 // Just use skia's serialization method for the SkPath for now. 56 // Just use skia's serialization method for the SkPath for now.
42 size_t path_size = clip_path_.writeToMemory(nullptr); 57 size_t path_size = clip_path_.writeToMemory(nullptr);
43 if (path_size > 0) { 58 if (path_size > 0) {
44 scoped_ptr<uint8_t[]> buffer(new uint8_t[path_size]); 59 scoped_ptr<uint8_t[]> buffer(new uint8_t[path_size]);
45 clip_path_.writeToMemory(buffer.get()); 60 clip_path_.writeToMemory(buffer.get());
46 details->set_clip_path(buffer.get(), path_size); 61 details->set_clip_path(buffer.get(), path_size);
47 } 62 }
48 } 63 }
49 64
50 void ClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
51 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type());
52
53 const proto::ClipPathDisplayItem& details = proto.clip_path_item();
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 size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(),
60 details.clip_path().size());
61 DCHECK_EQ(details.clip_path().size(), bytes_read);
62 }
63
64 SetNew(clip_path, clip_op, antialias);
65 }
66
67 void ClipPathDisplayItem::Raster(SkCanvas* canvas, 65 void ClipPathDisplayItem::Raster(SkCanvas* canvas,
68 const gfx::Rect& canvas_target_playback_rect, 66 const gfx::Rect& canvas_target_playback_rect,
69 SkPicture::AbortCallback* callback) const { 67 SkPicture::AbortCallback* callback) const {
70 canvas->save(); 68 canvas->save();
71 canvas->clipPath(clip_path_, clip_op_, antialias_); 69 canvas->clipPath(clip_path_, clip_op_, antialias_);
72 } 70 }
73 71
74 void ClipPathDisplayItem::AsValueInto( 72 void ClipPathDisplayItem::AsValueInto(
75 const gfx::Rect& visual_rect, 73 const gfx::Rect& visual_rect,
76 base::trace_event::TracedValue* array) const { 74 base::trace_event::TracedValue* array) const {
77 array->AppendString(base::StringPrintf( 75 array->AppendString(base::StringPrintf(
78 "ClipPathDisplayItem length: %d visualRect: [%s]", 76 "ClipPathDisplayItem length: %d visualRect: [%s]",
79 clip_path_.countPoints(), visual_rect.ToString().c_str())); 77 clip_path_.countPoints(), visual_rect.ToString().c_str()));
80 } 78 }
81 79
82 EndClipPathDisplayItem::EndClipPathDisplayItem() { 80 size_t ClipPathDisplayItem::ExternalMemoryUsage() const {
83 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, 81 // The size of SkPath's external storage is not currently accounted for (and
84 0 /* external_memory_usage */); 82 // may well be shared anyway).
83 return 0;
84 }
85
86 EndClipPathDisplayItem::EndClipPathDisplayItem() {}
87
88 EndClipPathDisplayItem::EndClipPathDisplayItem(
89 const proto::DisplayItem& proto) {
90 DCHECK_EQ(proto::DisplayItem::Type_EndClipPath, proto.type());
85 } 91 }
86 92
87 EndClipPathDisplayItem::~EndClipPathDisplayItem() { 93 EndClipPathDisplayItem::~EndClipPathDisplayItem() {
88 } 94 }
89 95
90 void EndClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 96 void EndClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
91 proto->set_type(proto::DisplayItem::Type_EndClipPath); 97 proto->set_type(proto::DisplayItem::Type_EndClipPath);
92 } 98 }
93 99
94 void EndClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
95 DCHECK_EQ(proto::DisplayItem::Type_EndClipPath, proto.type());
96 }
97
98 void EndClipPathDisplayItem::Raster( 100 void EndClipPathDisplayItem::Raster(
99 SkCanvas* canvas, 101 SkCanvas* canvas,
100 const gfx::Rect& canvas_target_playback_rect, 102 const gfx::Rect& canvas_target_playback_rect,
101 SkPicture::AbortCallback* callback) const { 103 SkPicture::AbortCallback* callback) const {
102 canvas->restore(); 104 canvas->restore();
103 } 105 }
104 106
105 void EndClipPathDisplayItem::AsValueInto( 107 void EndClipPathDisplayItem::AsValueInto(
106 const gfx::Rect& visual_rect, 108 const gfx::Rect& visual_rect,
107 base::trace_event::TracedValue* array) const { 109 base::trace_event::TracedValue* array) const {
108 array->AppendString( 110 array->AppendString(
109 base::StringPrintf("EndClipPathDisplayItem visualRect: [%s]", 111 base::StringPrintf("EndClipPathDisplayItem visualRect: [%s]",
110 visual_rect.ToString().c_str())); 112 visual_rect.ToString().c_str()));
111 } 113 }
112 114
115 size_t EndClipPathDisplayItem::ExternalMemoryUsage() const {
116 return 0;
117 }
118
113 } // namespace cc 119 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/clip_path_display_item.h ('k') | cc/playback/compositing_display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698