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/playback/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
) {
30 // FilterOperations doesn't expose its capacity, but size is probably good
32 size_t external_memory_usage
= filters_
.size() * sizeof(filters_
.at(0));
33 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
34 external_memory_usage
);
37 void FilterDisplayItem::Raster(SkCanvas
* canvas
,
38 const gfx::Rect
& canvas_target_playback_rect
,
39 SkPicture::AbortCallback
* callback
) const {
41 canvas
->translate(bounds_
.x(), bounds_
.y());
43 skia::RefPtr
<SkImageFilter
> image_filter
=
44 RenderSurfaceFilters::BuildImageFilter(
45 filters_
, gfx::SizeF(bounds_
.width(), bounds_
.height()));
46 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
47 // TODO(senorblanco): remove this once callsites updated (crbug.com/525748)
49 image_filter
->computeFastBounds(
50 SkRect::MakeWH(bounds_
.width(), bounds_
.height()), &boundaries
);
52 SkRect boundaries
= SkRect::MakeWH(bounds_
.width(), bounds_
.height());
56 paint
.setXfermodeMode(SkXfermode::kSrcOver_Mode
);
57 paint
.setImageFilter(image_filter
.get());
58 canvas
->saveLayer(&boundaries
, &paint
);
60 canvas
->translate(-bounds_
.x(), -bounds_
.y());
63 void FilterDisplayItem::AsValueInto(
64 base::trace_event::TracedValue
* array
) const {
65 array
->AppendString(base::StringPrintf("FilterDisplayItem bounds: [%s]",
66 bounds_
.ToString().c_str()));
69 EndFilterDisplayItem::EndFilterDisplayItem() {
70 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
71 0 /* external_memory_usage */);
74 EndFilterDisplayItem::~EndFilterDisplayItem() {
77 void EndFilterDisplayItem::Raster(SkCanvas
* canvas
,
78 const gfx::Rect
& canvas_target_playback_rect
,
79 SkPicture::AbortCallback
* callback
) const {
84 void EndFilterDisplayItem::AsValueInto(
85 base::trace_event::TracedValue
* array
) const {
86 array
->AppendString("EndFilterDisplayItem");