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

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