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 "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkImageFilter.h"
9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkXfermode.h"
11 #include "ui/gfx/skia_util.h"
15 FilterDisplayItem::FilterDisplayItem(skia::RefPtr
<SkImageFilter
> filter
,
17 : filter_(filter
), bounds_(bounds
) {
20 FilterDisplayItem::~FilterDisplayItem() {
23 void FilterDisplayItem::Raster(SkCanvas
* canvas
,
24 SkDrawPictureCallback
* callback
) const {
27 filter_
->computeFastBounds(gfx::RectFToSkRect(bounds_
), &boundaries
);
28 canvas
->translate(bounds_
.x(), bounds_
.y());
29 boundaries
.offset(-bounds_
.x(), -bounds_
.y());
32 paint
.setXfermodeMode(SkXfermode::kSrcOver_Mode
);
33 paint
.setImageFilter(filter_
.get());
34 canvas
->saveLayer(&boundaries
, &paint
);
36 canvas
->translate(-bounds_
.x(), -bounds_
.y());
39 bool FilterDisplayItem::IsSuitableForGpuRasterization() const {
43 int FilterDisplayItem::ApproximateOpCount() const {
47 size_t FilterDisplayItem::PictureMemoryUsage() const {
48 return sizeof(skia::RefPtr
<SkImageFilter
>) + sizeof(gfx::RectF
);
51 EndFilterDisplayItem::EndFilterDisplayItem() {
54 EndFilterDisplayItem::~EndFilterDisplayItem() {
57 void EndFilterDisplayItem::Raster(SkCanvas
* canvas
,
58 SkDrawPictureCallback
* callback
) const {
63 bool EndFilterDisplayItem::IsSuitableForGpuRasterization() const {
67 int EndFilterDisplayItem::ApproximateOpCount() const {
71 size_t EndFilterDisplayItem::PictureMemoryUsage() const {