[Do not revert] Roll-back V8 to version 4.4.63.
[chromium-blink-merge.git] / cc / resources / filter_display_item.cc
blobfa6f20fe113b9e9f2422333d4a823730bee32d4a
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"
17 namespace cc {
19 FilterDisplayItem::FilterDisplayItem() {
22 FilterDisplayItem::~FilterDisplayItem() {
25 void FilterDisplayItem::SetNew(const FilterOperations& filters,
26 const gfx::RectF& bounds) {
27 filters_ = filters;
28 bounds_ = bounds;
30 size_t memory_usage =
31 sizeof(skia::RefPtr<SkImageFilter>) + sizeof(gfx::RectF);
32 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */,
33 memory_usage);
36 void FilterDisplayItem::Raster(SkCanvas* canvas,
37 SkDrawPictureCallback* callback) const {
38 canvas->save();
39 canvas->translate(bounds_.x(), bounds_.y());
41 skia::RefPtr<SkImageFilter> image_filter =
42 RenderSurfaceFilters::BuildImageFilter(
43 filters_, gfx::SizeF(bounds_.width(), bounds_.height()));
44 SkRect boundaries;
45 image_filter->computeFastBounds(
46 SkRect::MakeWH(bounds_.width(), bounds_.height()), &boundaries);
48 SkPaint paint;
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 {
72 canvas->restore();
73 canvas->restore();
76 void EndFilterDisplayItem::AsValueInto(
77 base::trace_event::TracedValue* array) const {
78 array->AppendString("EndFilterDisplayItem");
81 } // namespace cc