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.
5 #include "cc/resources/filter_display_item.h"
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"
19 FilterDisplayItem::FilterDisplayItem() {
22 FilterDisplayItem::~FilterDisplayItem() {
25 void FilterDisplayItem::SetNew(const FilterOperations
& filters
,
26 const gfx::RectF
& bounds
) {
31 sizeof(skia::RefPtr
<SkImageFilter
>) + sizeof(gfx::RectF
);
32 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
36 void FilterDisplayItem::Raster(SkCanvas
* canvas
,
37 SkDrawPictureCallback
* callback
) const {
39 canvas
->translate(bounds_
.x(), bounds_
.y());
41 skia::RefPtr
<SkImageFilter
> image_filter
=
42 RenderSurfaceFilters::BuildImageFilter(
43 filters_
, gfx::SizeF(bounds_
.width(), bounds_
.height()));
45 image_filter
->computeFastBounds(
46 SkRect::MakeWH(bounds_
.width(), bounds_
.height()), &boundaries
);
49 paint
.setXfermodeMode(SkXfermode::kSrcOver_Mode
);
50 paint
.setImageFilter(image_filter
.get());
51 canvas
->saveLayer(&boundaries
, &paint
);
53 canvas
->translate(-bounds_
.x(), -bounds_
.y());
56 void FilterDisplayItem::AsValueInto(
57 base::trace_event::TracedValue
* array
) const {
58 array
->AppendString(base::StringPrintf("FilterDisplayItem bounds: [%s]",
59 bounds_
.ToString().c_str()));
62 EndFilterDisplayItem::EndFilterDisplayItem() {
63 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
64 0 /* memory_usage */);
67 EndFilterDisplayItem::~EndFilterDisplayItem() {
70 void EndFilterDisplayItem::Raster(SkCanvas
* canvas
,
71 SkDrawPictureCallback
* callback
) const {
76 void EndFilterDisplayItem::AsValueInto(
77 base::trace_event::TracedValue
* array
) const {
78 array
->AppendString("EndFilterDisplayItem");