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/resources/filter_display_item.h" | 5 #include "cc/resources/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" |
| 10 #include "skia/ext/refptr.h" |
9 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
10 #include "third_party/skia/include/core/SkImageFilter.h" | 12 #include "third_party/skia/include/core/SkImageFilter.h" |
11 #include "third_party/skia/include/core/SkPaint.h" | 13 #include "third_party/skia/include/core/SkPaint.h" |
12 #include "third_party/skia/include/core/SkXfermode.h" | 14 #include "third_party/skia/include/core/SkXfermode.h" |
13 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
14 | 16 |
15 namespace cc { | 17 namespace cc { |
16 | 18 |
17 FilterDisplayItem::FilterDisplayItem(skia::RefPtr<SkImageFilter> filter, | 19 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, |
18 gfx::RectF bounds) | 20 gfx::RectF bounds) |
19 : filter_(filter), bounds_(bounds) { | 21 : filters_(filters), bounds_(bounds) { |
20 } | 22 } |
21 | 23 |
22 FilterDisplayItem::~FilterDisplayItem() { | 24 FilterDisplayItem::~FilterDisplayItem() { |
23 } | 25 } |
24 | 26 |
25 void FilterDisplayItem::Raster(SkCanvas* canvas, | 27 void FilterDisplayItem::Raster(SkCanvas* canvas, |
26 SkDrawPictureCallback* callback) const { | 28 SkDrawPictureCallback* callback) const { |
27 canvas->save(); | 29 canvas->save(); |
| 30 canvas->translate(bounds_.x(), bounds_.y()); |
| 31 |
| 32 skia::RefPtr<SkImageFilter> image_filter = |
| 33 RenderSurfaceFilters::BuildImageFilter( |
| 34 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); |
28 SkRect boundaries; | 35 SkRect boundaries; |
29 filter_->computeFastBounds(gfx::RectFToSkRect(bounds_), &boundaries); | 36 image_filter->computeFastBounds( |
30 canvas->translate(bounds_.x(), bounds_.y()); | 37 SkRect::MakeWH(bounds_.width(), bounds_.height()), &boundaries); |
31 boundaries.offset(-bounds_.x(), -bounds_.y()); | |
32 | 38 |
33 SkPaint paint; | 39 SkPaint paint; |
34 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 40 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
35 paint.setImageFilter(filter_.get()); | 41 paint.setImageFilter(image_filter.get()); |
36 canvas->saveLayer(&boundaries, &paint); | 42 canvas->saveLayer(&boundaries, &paint); |
37 | 43 |
38 canvas->translate(-bounds_.x(), -bounds_.y()); | 44 canvas->translate(-bounds_.x(), -bounds_.y()); |
39 } | 45 } |
40 | 46 |
41 bool FilterDisplayItem::IsSuitableForGpuRasterization() const { | 47 bool FilterDisplayItem::IsSuitableForGpuRasterization() const { |
42 return true; | 48 return true; |
43 } | 49 } |
44 | 50 |
45 int FilterDisplayItem::ApproximateOpCount() const { | 51 int FilterDisplayItem::ApproximateOpCount() const { |
46 return 1; | 52 return 1; |
47 } | 53 } |
48 | 54 |
49 size_t FilterDisplayItem::PictureMemoryUsage() const { | 55 size_t FilterDisplayItem::PictureMemoryUsage() const { |
50 return sizeof(skia::RefPtr<SkImageFilter>) + sizeof(gfx::RectF); | 56 return sizeof(skia::RefPtr<SkImageFilter>) + sizeof(gfx::RectF); |
51 } | 57 } |
52 | 58 |
53 void FilterDisplayItem::AsValueInto(base::debug::TracedValue* array) const { | 59 void FilterDisplayItem::AsValueInto( |
| 60 base::trace_event::TracedValue* array) const { |
54 array->AppendString(base::StringPrintf("FilterDisplayItem bounds: [%s]", | 61 array->AppendString(base::StringPrintf("FilterDisplayItem bounds: [%s]", |
55 bounds_.ToString().c_str())); | 62 bounds_.ToString().c_str())); |
56 } | 63 } |
57 | 64 |
58 EndFilterDisplayItem::EndFilterDisplayItem() { | 65 EndFilterDisplayItem::EndFilterDisplayItem() { |
59 } | 66 } |
60 | 67 |
61 EndFilterDisplayItem::~EndFilterDisplayItem() { | 68 EndFilterDisplayItem::~EndFilterDisplayItem() { |
62 } | 69 } |
63 | 70 |
64 void EndFilterDisplayItem::Raster(SkCanvas* canvas, | 71 void EndFilterDisplayItem::Raster(SkCanvas* canvas, |
65 SkDrawPictureCallback* callback) const { | 72 SkDrawPictureCallback* callback) const { |
66 canvas->restore(); | 73 canvas->restore(); |
67 canvas->restore(); | 74 canvas->restore(); |
68 } | 75 } |
69 | 76 |
70 bool EndFilterDisplayItem::IsSuitableForGpuRasterization() const { | 77 bool EndFilterDisplayItem::IsSuitableForGpuRasterization() const { |
71 return true; | 78 return true; |
72 } | 79 } |
73 | 80 |
74 int EndFilterDisplayItem::ApproximateOpCount() const { | 81 int EndFilterDisplayItem::ApproximateOpCount() const { |
75 return 0; | 82 return 0; |
76 } | 83 } |
77 | 84 |
78 size_t EndFilterDisplayItem::PictureMemoryUsage() const { | 85 size_t EndFilterDisplayItem::PictureMemoryUsage() const { |
79 return 0; | 86 return 0; |
80 } | 87 } |
81 | 88 |
82 void EndFilterDisplayItem::AsValueInto(base::debug::TracedValue* array) const { | 89 void EndFilterDisplayItem::AsValueInto( |
| 90 base::trace_event::TracedValue* array) const { |
83 array->AppendString("EndFilterDisplayItem"); | 91 array->AppendString("EndFilterDisplayItem"); |
84 } | 92 } |
85 | 93 |
86 } // namespace cc | 94 } // namespace cc |
OLD | NEW |