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/filter_display_item.cc

Issue 1494223003: cc: Shrink size of display item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make SetNew private 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
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/filter_display_item.h" 5 #include "cc/playback/filter_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/output/render_surface_filters.h" 9 #include "cc/output/render_surface_filters.h"
10 #include "cc/proto/display_item.pb.h" 10 #include "cc/proto/display_item.pb.h"
11 #include "cc/proto/gfx_conversions.h" 11 #include "cc/proto/gfx_conversions.h"
12 #include "skia/ext/refptr.h" 12 #include "skia/ext/refptr.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkImageFilter.h" 14 #include "third_party/skia/include/core/SkImageFilter.h"
15 #include "third_party/skia/include/core/SkPaint.h" 15 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkXfermode.h" 16 #include "third_party/skia/include/core/SkXfermode.h"
17 #include "ui/gfx/skia_util.h" 17 #include "ui/gfx/skia_util.h"
18 18
19 namespace cc { 19 namespace cc {
20 20
21 FilterDisplayItem::FilterDisplayItem() { 21 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters,
22 const gfx::RectF& bounds) {
23 SetNew(filters, bounds);
22 } 24 }
23 25
24 FilterDisplayItem::~FilterDisplayItem() { 26 FilterDisplayItem::FilterDisplayItem(const proto::DisplayItem& proto) {
27 FromProtobuf(proto);
25 } 28 }
26 29
30 FilterDisplayItem::~FilterDisplayItem() {}
31
27 void FilterDisplayItem::SetNew(const FilterOperations& filters, 32 void FilterDisplayItem::SetNew(const FilterOperations& filters,
28 const gfx::RectF& bounds) { 33 const gfx::RectF& bounds) {
29 filters_ = filters; 34 filters_ = filters;
30 bounds_ = bounds; 35 bounds_ = bounds;
31
32 // FilterOperations doesn't expose its capacity, but size is probably good
33 // enough.
34 size_t external_memory_usage = filters_.size() * sizeof(filters_.at(0));
35 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
36 external_memory_usage);
37 } 36 }
38 37
39 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 38 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
40 proto->set_type(proto::DisplayItem::Type_Filter); 39 proto->set_type(proto::DisplayItem::Type_Filter);
41 40
42 proto::FilterDisplayItem* details = proto->mutable_filter_item(); 41 proto::FilterDisplayItem* details = proto->mutable_filter_item();
43 RectFToProto(bounds_, details->mutable_bounds()); 42 RectFToProto(bounds_, details->mutable_bounds());
44 43
45 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321). 44 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321).
46 } 45 }
47 46
48 void FilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { 47 void FilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
49 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type()); 48 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type());
50 49
51 const proto::FilterDisplayItem& details = proto.filter_item(); 50 const proto::FilterDisplayItem& details = proto.filter_item();
52 gfx::RectF bounds = ProtoToRectF(details.bounds()); 51 gfx::RectF bounds = ProtoToRectF(details.bounds());
53 52
54 // TODO(dtrainor): Support deserializing FilterOperations (crbug.com/541321). 53 // TODO(dtrainor): Support deserializing FilterOperations
danakj 2015/12/08 19:18:16 random comment wrapping?
54 // (crbug.com/541321).
55 FilterOperations filters; 55 FilterOperations filters;
56 56
57 SetNew(filters, bounds); 57 SetNew(filters, bounds);
58 } 58 }
59 59
60 void FilterDisplayItem::Raster(SkCanvas* canvas, 60 void FilterDisplayItem::Raster(SkCanvas* canvas,
61 const gfx::Rect& canvas_target_playback_rect, 61 const gfx::Rect& canvas_target_playback_rect,
62 SkPicture::AbortCallback* callback) const { 62 SkPicture::AbortCallback* callback) const {
63 canvas->save(); 63 canvas->save();
64 canvas->translate(bounds_.x(), bounds_.y()); 64 canvas->translate(bounds_.x(), bounds_.y());
(...skipping 12 matching lines...) Expand all
77 } 77 }
78 78
79 void FilterDisplayItem::AsValueInto( 79 void FilterDisplayItem::AsValueInto(
80 const gfx::Rect& visual_rect, 80 const gfx::Rect& visual_rect,
81 base::trace_event::TracedValue* array) const { 81 base::trace_event::TracedValue* array) const {
82 array->AppendString(base::StringPrintf( 82 array->AppendString(base::StringPrintf(
83 "FilterDisplayItem bounds: [%s] visualRect: [%s]", 83 "FilterDisplayItem bounds: [%s] visualRect: [%s]",
84 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); 84 bounds_.ToString().c_str(), visual_rect.ToString().c_str()));
85 } 85 }
86 86
87 EndFilterDisplayItem::EndFilterDisplayItem() { 87 size_t FilterDisplayItem::ExternalMemoryUsage() const {
88 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, 88 // FilterOperations doesn't expose its capacity, but size is probably good
89 0 /* external_memory_usage */); 89 // enough.
90 return filters_.size() * sizeof(filters_.at(0));
90 } 91 }
91 92
92 EndFilterDisplayItem::~EndFilterDisplayItem() { 93 EndFilterDisplayItem::EndFilterDisplayItem() {}
94
95 EndFilterDisplayItem::EndFilterDisplayItem(const proto::DisplayItem& proto) {
96 FromProtobuf(proto);
93 } 97 }
94 98
99 EndFilterDisplayItem::~EndFilterDisplayItem() {}
100
95 void EndFilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 101 void EndFilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
96 proto->set_type(proto::DisplayItem::Type_EndFilter); 102 proto->set_type(proto::DisplayItem::Type_EndFilter);
97 } 103 }
98 104
99 void EndFilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { 105 void EndFilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
100 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type()); 106 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type());
101 } 107 }
102 108
103 void EndFilterDisplayItem::Raster(SkCanvas* canvas, 109 void EndFilterDisplayItem::Raster(SkCanvas* canvas,
104 const gfx::Rect& canvas_target_playback_rect, 110 const gfx::Rect& canvas_target_playback_rect,
105 SkPicture::AbortCallback* callback) const { 111 SkPicture::AbortCallback* callback) const {
106 canvas->restore(); 112 canvas->restore();
107 canvas->restore(); 113 canvas->restore();
108 } 114 }
109 115
110 void EndFilterDisplayItem::AsValueInto( 116 void EndFilterDisplayItem::AsValueInto(
111 const gfx::Rect& visual_rect, 117 const gfx::Rect& visual_rect,
112 base::trace_event::TracedValue* array) const { 118 base::trace_event::TracedValue* array) const {
113 array->AppendString( 119 array->AppendString(
114 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", 120 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]",
115 visual_rect.ToString().c_str())); 121 visual_rect.ToString().c_str()));
116 } 122 }
117 123
124 size_t EndFilterDisplayItem::ExternalMemoryUsage() const {
125 return 0;
126 }
127
118 } // namespace cc 128 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698