OLD | NEW |
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" |
| 11 #include "cc/proto/gfx_conversions.h" |
10 #include "skia/ext/refptr.h" | 12 #include "skia/ext/refptr.h" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "third_party/skia/include/core/SkImageFilter.h" | 14 #include "third_party/skia/include/core/SkImageFilter.h" |
13 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
14 #include "third_party/skia/include/core/SkXfermode.h" | 16 #include "third_party/skia/include/core/SkXfermode.h" |
15 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
16 | 18 |
17 namespace cc { | 19 namespace cc { |
18 | 20 |
19 FilterDisplayItem::FilterDisplayItem() { | 21 FilterDisplayItem::FilterDisplayItem() { |
20 } | 22 } |
21 | 23 |
22 FilterDisplayItem::~FilterDisplayItem() { | 24 FilterDisplayItem::~FilterDisplayItem() { |
23 } | 25 } |
24 | 26 |
25 void FilterDisplayItem::SetNew(const FilterOperations& filters, | 27 void FilterDisplayItem::SetNew(const FilterOperations& filters, |
26 const gfx::RectF& bounds) { | 28 const gfx::RectF& bounds) { |
27 filters_ = filters; | 29 filters_ = filters; |
28 bounds_ = bounds; | 30 bounds_ = bounds; |
29 | 31 |
30 // FilterOperations doesn't expose its capacity, but size is probably good | 32 // FilterOperations doesn't expose its capacity, but size is probably good |
31 // enough. | 33 // enough. |
32 size_t external_memory_usage = filters_.size() * sizeof(filters_.at(0)); | 34 size_t external_memory_usage = filters_.size() * sizeof(filters_.at(0)); |
33 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | 35 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, |
34 external_memory_usage); | 36 external_memory_usage); |
35 } | 37 } |
36 | 38 |
| 39 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) { |
| 40 proto->set_type(proto::DisplayItem::Type_Filter); |
| 41 |
| 42 proto::FilterDisplayItem* details = proto->mutable_details_filter(); |
| 43 RectFToProto(bounds_, details->mutable_bounds()); |
| 44 |
| 45 // TODO(dtrainor): Support serializing FilterOperations. |
| 46 } |
| 47 |
| 48 void FilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 49 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type()); |
| 50 |
| 51 const proto::FilterDisplayItem& details = proto.details_filter(); |
| 52 gfx::RectF bounds = ProtoToRectF(details.bounds()); |
| 53 |
| 54 // TODO(dtrainor): Support deserializing FilterOperations. |
| 55 FilterOperations filters; |
| 56 |
| 57 SetNew(filters, bounds); |
| 58 } |
| 59 |
37 void FilterDisplayItem::Raster(SkCanvas* canvas, | 60 void FilterDisplayItem::Raster(SkCanvas* canvas, |
38 const gfx::Rect& canvas_target_playback_rect, | 61 const gfx::Rect& canvas_target_playback_rect, |
39 SkPicture::AbortCallback* callback) const { | 62 SkPicture::AbortCallback* callback) const { |
40 canvas->save(); | 63 canvas->save(); |
41 canvas->translate(bounds_.x(), bounds_.y()); | 64 canvas->translate(bounds_.x(), bounds_.y()); |
42 | 65 |
43 skia::RefPtr<SkImageFilter> image_filter = | 66 skia::RefPtr<SkImageFilter> image_filter = |
44 RenderSurfaceFilters::BuildImageFilter( | 67 RenderSurfaceFilters::BuildImageFilter( |
45 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); | 68 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); |
46 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED | 69 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED |
(...skipping 26 matching lines...) Expand all Loading... |
73 } | 96 } |
74 | 97 |
75 EndFilterDisplayItem::EndFilterDisplayItem() { | 98 EndFilterDisplayItem::EndFilterDisplayItem() { |
76 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 99 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, |
77 0 /* external_memory_usage */); | 100 0 /* external_memory_usage */); |
78 } | 101 } |
79 | 102 |
80 EndFilterDisplayItem::~EndFilterDisplayItem() { | 103 EndFilterDisplayItem::~EndFilterDisplayItem() { |
81 } | 104 } |
82 | 105 |
| 106 void EndFilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) { |
| 107 proto->set_type(proto::DisplayItem::Type_EndFilter); |
| 108 } |
| 109 |
| 110 void EndFilterDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 111 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type()); |
| 112 } |
| 113 |
83 void EndFilterDisplayItem::Raster(SkCanvas* canvas, | 114 void EndFilterDisplayItem::Raster(SkCanvas* canvas, |
84 const gfx::Rect& canvas_target_playback_rect, | 115 const gfx::Rect& canvas_target_playback_rect, |
85 SkPicture::AbortCallback* callback) const { | 116 SkPicture::AbortCallback* callback) const { |
86 canvas->restore(); | 117 canvas->restore(); |
87 canvas->restore(); | 118 canvas->restore(); |
88 } | 119 } |
89 | 120 |
90 void EndFilterDisplayItem::ProcessForBounds( | 121 void EndFilterDisplayItem::ProcessForBounds( |
91 DisplayItemListBoundsCalculator* calculator) const { | 122 DisplayItemListBoundsCalculator* calculator) const { |
92 calculator->Restore(); | 123 calculator->Restore(); |
93 calculator->AddEndingDisplayItem(); | 124 calculator->AddEndingDisplayItem(); |
94 } | 125 } |
95 | 126 |
96 void EndFilterDisplayItem::AsValueInto( | 127 void EndFilterDisplayItem::AsValueInto( |
97 base::trace_event::TracedValue* array) const { | 128 base::trace_event::TracedValue* array) const { |
98 array->AppendString("EndFilterDisplayItem"); | 129 array->AppendString("EndFilterDisplayItem"); |
99 } | 130 } |
100 | 131 |
101 } // namespace cc | 132 } // namespace cc |
OLD | NEW |