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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
11 #include "cc/output/render_surface_filters.h" | 11 #include "cc/output/render_surface_filters.h" |
| 12 #include "cc/paint/paint_flags.h" |
12 #include "cc/proto/display_item.pb.h" | 13 #include "cc/proto/display_item.pb.h" |
13 #include "cc/proto/gfx_conversions.h" | 14 #include "cc/proto/gfx_conversions.h" |
14 #include "third_party/skia/include/core/SkCanvas.h" | |
15 #include "third_party/skia/include/core/SkImageFilter.h" | 15 #include "third_party/skia/include/core/SkImageFilter.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | |
17 #include "third_party/skia/include/core/SkRefCnt.h" | 16 #include "third_party/skia/include/core/SkRefCnt.h" |
18 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
19 | 18 |
20 namespace cc { | 19 namespace cc { |
21 | 20 |
22 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, | 21 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, |
23 const gfx::RectF& bounds, | 22 const gfx::RectF& bounds, |
24 const gfx::PointF& origin) | 23 const gfx::PointF& origin) |
25 : DisplayItem(FILTER) { | 24 : DisplayItem(FILTER) { |
26 SetNew(filters, bounds, origin); | 25 SetNew(filters, bounds, origin); |
(...skipping 24 matching lines...) Expand all Loading... |
51 | 50 |
52 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 51 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
53 proto->set_type(proto::DisplayItem::Type_Filter); | 52 proto->set_type(proto::DisplayItem::Type_Filter); |
54 | 53 |
55 proto::FilterDisplayItem* details = proto->mutable_filter_item(); | 54 proto::FilterDisplayItem* details = proto->mutable_filter_item(); |
56 RectFToProto(bounds_, details->mutable_bounds()); | 55 RectFToProto(bounds_, details->mutable_bounds()); |
57 | 56 |
58 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321). | 57 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321). |
59 } | 58 } |
60 | 59 |
61 void FilterDisplayItem::Raster(SkCanvas* canvas, | 60 void FilterDisplayItem::Raster(PaintCanvas* canvas, |
62 SkPicture::AbortCallback* callback) const { | 61 PaintRecord::AbortCallback* callback) const { |
63 canvas->save(); | 62 canvas->save(); |
64 canvas->translate(origin_.x(), origin_.y()); | 63 canvas->translate(origin_.x(), origin_.y()); |
65 | 64 |
66 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( | 65 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( |
67 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); | 66 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); |
68 SkRect boundaries = RectFToSkRect(bounds_); | 67 SkRect boundaries = RectFToSkRect(bounds_); |
69 boundaries.offset(-origin_.x(), -origin_.y()); | 68 boundaries.offset(-origin_.x(), -origin_.y()); |
70 | 69 |
71 SkPaint paint; | 70 PaintFlags paint; |
72 paint.setBlendMode(SkBlendMode::kSrcOver); | 71 paint.setBlendMode(SkBlendMode::kSrcOver); |
73 paint.setImageFilter(std::move(image_filter)); | 72 paint.setImageFilter(std::move(image_filter)); |
74 canvas->saveLayer(&boundaries, &paint); | 73 canvas->saveLayer(&boundaries, &paint); |
75 | 74 |
76 canvas->translate(-origin_.x(), -origin_.y()); | 75 canvas->translate(-origin_.x(), -origin_.y()); |
77 } | 76 } |
78 | 77 |
79 void FilterDisplayItem::AsValueInto( | 78 void FilterDisplayItem::AsValueInto( |
80 const gfx::Rect& visual_rect, | 79 const gfx::Rect& visual_rect, |
81 base::trace_event::TracedValue* array) const { | 80 base::trace_event::TracedValue* array) const { |
82 array->AppendString(base::StringPrintf( | 81 array->AppendString(base::StringPrintf( |
83 "FilterDisplayItem bounds: [%s] visualRect: [%s]", | 82 "FilterDisplayItem bounds: [%s] visualRect: [%s]", |
84 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); | 83 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); |
85 } | 84 } |
86 | 85 |
87 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} | 86 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} |
88 | 87 |
89 EndFilterDisplayItem::EndFilterDisplayItem(const proto::DisplayItem& proto) | 88 EndFilterDisplayItem::EndFilterDisplayItem(const proto::DisplayItem& proto) |
90 : DisplayItem(END_FILTER) { | 89 : DisplayItem(END_FILTER) { |
91 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type()); | 90 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type()); |
92 } | 91 } |
93 | 92 |
94 EndFilterDisplayItem::~EndFilterDisplayItem() {} | 93 EndFilterDisplayItem::~EndFilterDisplayItem() {} |
95 | 94 |
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 |
100 void EndFilterDisplayItem::Raster(SkCanvas* canvas, | 99 void EndFilterDisplayItem::Raster(PaintCanvas* canvas, |
101 SkPicture::AbortCallback* callback) const { | 100 PaintRecord::AbortCallback* callback) const { |
102 canvas->restore(); | 101 canvas->restore(); |
103 canvas->restore(); | 102 canvas->restore(); |
104 } | 103 } |
105 | 104 |
106 void EndFilterDisplayItem::AsValueInto( | 105 void EndFilterDisplayItem::AsValueInto( |
107 const gfx::Rect& visual_rect, | 106 const gfx::Rect& visual_rect, |
108 base::trace_event::TracedValue* array) const { | 107 base::trace_event::TracedValue* array) const { |
109 array->AppendString( | 108 array->AppendString( |
110 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", | 109 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", |
111 visual_rect.ToString().c_str())); | 110 visual_rect.ToString().c_str())); |
112 } | 111 } |
113 | 112 |
114 } // namespace cc | 113 } // namespace cc |
OLD | NEW |