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(const FilterOperations
& filters
,
21 : filters_(filters
), bounds_(bounds
) {
24 FilterDisplayItem::~FilterDisplayItem() {
27 void FilterDisplayItem::Raster(SkCanvas
* canvas
,
28 SkDrawPictureCallback
* callback
) const {
30 canvas
->translate(bounds_
.x(), bounds_
.y());
32 skia::RefPtr
<SkImageFilter
> image_filter
=
33 RenderSurfaceFilters::BuildImageFilter(
34 filters_
, gfx::SizeF(bounds_
.width(), bounds_
.height()));
36 image_filter
->computeFastBounds(
37 SkRect::MakeWH(bounds_
.width(), bounds_
.height()), &boundaries
);
40 paint
.setXfermodeMode(SkXfermode::kSrcOver_Mode
);
41 paint
.setImageFilter(image_filter
.get());
42 canvas
->saveLayer(&boundaries
, &paint
);
44 canvas
->translate(-bounds_
.x(), -bounds_
.y());
47 bool FilterDisplayItem::IsSuitableForGpuRasterization() const {
51 int FilterDisplayItem::ApproximateOpCount() const {
55 size_t FilterDisplayItem::PictureMemoryUsage() const {
56 return sizeof(skia::RefPtr
<SkImageFilter
>) + sizeof(gfx::RectF
);
59 void FilterDisplayItem::AsValueInto(
60 base::trace_event::TracedValue
* array
) const {
61 array
->AppendString(base::StringPrintf("FilterDisplayItem bounds: [%s]",
62 bounds_
.ToString().c_str()));
65 EndFilterDisplayItem::EndFilterDisplayItem() {
68 EndFilterDisplayItem::~EndFilterDisplayItem() {
71 void EndFilterDisplayItem::Raster(SkCanvas
* canvas
,
72 SkDrawPictureCallback
* callback
) const {
77 bool EndFilterDisplayItem::IsSuitableForGpuRasterization() const {
81 int EndFilterDisplayItem::ApproximateOpCount() const {
85 size_t EndFilterDisplayItem::PictureMemoryUsage() const {
89 void EndFilterDisplayItem::AsValueInto(
90 base::trace_event::TracedValue
* array
) const {
91 array
->AppendString("EndFilterDisplayItem");