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

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

Issue 1521373005: Revert of cc: Shrink size of display item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/filter_display_item.h ('k') | cc/playback/float_clip_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/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(const FilterOperations& filters, 21 FilterDisplayItem::FilterDisplayItem() {
22 const gfx::RectF& bounds) {
23 SetNew(filters, bounds);
24 } 22 }
25 23
26 FilterDisplayItem::FilterDisplayItem(const proto::DisplayItem& proto) { 24 FilterDisplayItem::~FilterDisplayItem() {
25 }
26
27 void FilterDisplayItem::SetNew(const FilterOperations& filters,
28 const gfx::RectF& bounds) {
29 filters_ = filters;
30 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 }
38
39 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
40 proto->set_type(proto::DisplayItem::Type_Filter);
41
42 proto::FilterDisplayItem* details = proto->mutable_filter_item();
43 RectFToProto(bounds_, details->mutable_bounds());
44
45 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321).
46 }
47
48 void FilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
27 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type()); 49 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type());
28 50
29 const proto::FilterDisplayItem& details = proto.filter_item(); 51 const proto::FilterDisplayItem& details = proto.filter_item();
30 gfx::RectF bounds = ProtoToRectF(details.bounds()); 52 gfx::RectF bounds = ProtoToRectF(details.bounds());
31 53
32 // TODO(dtrainor): Support deserializing FilterOperations (crbug.com/541321). 54 // TODO(dtrainor): Support deserializing FilterOperations (crbug.com/541321).
33 FilterOperations filters; 55 FilterOperations filters;
34 56
35 SetNew(filters, bounds); 57 SetNew(filters, bounds);
36 } 58 }
37 59
38 FilterDisplayItem::~FilterDisplayItem() {}
39
40 void FilterDisplayItem::SetNew(const FilterOperations& filters,
41 const gfx::RectF& bounds) {
42 filters_ = filters;
43 bounds_ = bounds;
44 }
45
46 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
47 proto->set_type(proto::DisplayItem::Type_Filter);
48
49 proto::FilterDisplayItem* details = proto->mutable_filter_item();
50 RectFToProto(bounds_, details->mutable_bounds());
51
52 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321).
53 }
54
55 void FilterDisplayItem::Raster(SkCanvas* canvas, 60 void FilterDisplayItem::Raster(SkCanvas* canvas,
56 const gfx::Rect& canvas_target_playback_rect, 61 const gfx::Rect& canvas_target_playback_rect,
57 SkPicture::AbortCallback* callback) const { 62 SkPicture::AbortCallback* callback) const {
58 canvas->save(); 63 canvas->save();
59 canvas->translate(bounds_.x(), bounds_.y()); 64 canvas->translate(bounds_.x(), bounds_.y());
60 65
61 skia::RefPtr<SkImageFilter> image_filter = 66 skia::RefPtr<SkImageFilter> image_filter =
62 RenderSurfaceFilters::BuildImageFilter( 67 RenderSurfaceFilters::BuildImageFilter(
63 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); 68 filters_, gfx::SizeF(bounds_.width(), bounds_.height()));
64 SkRect boundaries = SkRect::MakeWH(bounds_.width(), bounds_.height()); 69 SkRect boundaries = SkRect::MakeWH(bounds_.width(), bounds_.height());
65 70
66 SkPaint paint; 71 SkPaint paint;
67 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); 72 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
68 paint.setImageFilter(image_filter.get()); 73 paint.setImageFilter(image_filter.get());
69 canvas->saveLayer(&boundaries, &paint); 74 canvas->saveLayer(&boundaries, &paint);
70 75
71 canvas->translate(-bounds_.x(), -bounds_.y()); 76 canvas->translate(-bounds_.x(), -bounds_.y());
72 } 77 }
73 78
74 void FilterDisplayItem::AsValueInto( 79 void FilterDisplayItem::AsValueInto(
75 const gfx::Rect& visual_rect, 80 const gfx::Rect& visual_rect,
76 base::trace_event::TracedValue* array) const { 81 base::trace_event::TracedValue* array) const {
77 array->AppendString(base::StringPrintf( 82 array->AppendString(base::StringPrintf(
78 "FilterDisplayItem bounds: [%s] visualRect: [%s]", 83 "FilterDisplayItem bounds: [%s] visualRect: [%s]",
79 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); 84 bounds_.ToString().c_str(), visual_rect.ToString().c_str()));
80 } 85 }
81 86
82 size_t FilterDisplayItem::ExternalMemoryUsage() const { 87 EndFilterDisplayItem::EndFilterDisplayItem() {
83 // FilterOperations doesn't expose its capacity, but size is probably good 88 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
84 // enough. 89 0 /* external_memory_usage */);
85 return filters_.size() * sizeof(filters_.at(0));
86 } 90 }
87 91
88 EndFilterDisplayItem::EndFilterDisplayItem() {} 92 EndFilterDisplayItem::~EndFilterDisplayItem() {
89
90 EndFilterDisplayItem::EndFilterDisplayItem(const proto::DisplayItem& proto) {
91 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type());
92 } 93 }
93 94
94 EndFilterDisplayItem::~EndFilterDisplayItem() {}
95
96 void EndFilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { 95 void EndFilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const {
97 proto->set_type(proto::DisplayItem::Type_EndFilter); 96 proto->set_type(proto::DisplayItem::Type_EndFilter);
98 } 97 }
99 98
99 void EndFilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
100 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type());
101 }
102
100 void EndFilterDisplayItem::Raster(SkCanvas* canvas, 103 void EndFilterDisplayItem::Raster(SkCanvas* canvas,
101 const gfx::Rect& canvas_target_playback_rect, 104 const gfx::Rect& canvas_target_playback_rect,
102 SkPicture::AbortCallback* callback) const { 105 SkPicture::AbortCallback* callback) const {
103 canvas->restore(); 106 canvas->restore();
104 canvas->restore(); 107 canvas->restore();
105 } 108 }
106 109
107 void EndFilterDisplayItem::AsValueInto( 110 void EndFilterDisplayItem::AsValueInto(
108 const gfx::Rect& visual_rect, 111 const gfx::Rect& visual_rect,
109 base::trace_event::TracedValue* array) const { 112 base::trace_event::TracedValue* array) const {
110 array->AppendString( 113 array->AppendString(
111 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", 114 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]",
112 visual_rect.ToString().c_str())); 115 visual_rect.ToString().c_str()));
113 } 116 }
114 117
115 size_t EndFilterDisplayItem::ExternalMemoryUsage() const {
116 return 0;
117 }
118
119 } // namespace cc 118 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/filter_display_item.h ('k') | cc/playback/float_clip_display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698