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