Lock video controls' position during fullscreen
[chromium-blink-merge.git] / cc / playback / filter_display_item.cc
blobfbed01509c80ff21641cf5083e9321315af56329
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"
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 // FilterOperations doesn't expose its capacity, but size is probably good
31 // enough.
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 {
40 canvas->save();
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 SkRect boundaries;
47 image_filter->computeFastBounds(
48 SkRect::MakeWH(bounds_.width(), bounds_.height()), &boundaries);
50 SkPaint paint;
51 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
52 paint.setImageFilter(image_filter.get());
53 canvas->saveLayer(&boundaries, &paint);
55 canvas->translate(-bounds_.x(), -bounds_.y());
58 void FilterDisplayItem::AsValueInto(
59 base::trace_event::TracedValue* array) const {
60 array->AppendString(base::StringPrintf("FilterDisplayItem bounds: [%s]",
61 bounds_.ToString().c_str()));
64 EndFilterDisplayItem::EndFilterDisplayItem() {
65 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */,
66 0 /* external_memory_usage */);
69 EndFilterDisplayItem::~EndFilterDisplayItem() {
72 void EndFilterDisplayItem::Raster(SkCanvas* canvas,
73 const gfx::Rect& canvas_target_playback_rect,
74 SkPicture::AbortCallback* callback) const {
75 canvas->restore();
76 canvas->restore();
79 void EndFilterDisplayItem::AsValueInto(
80 base::trace_event::TracedValue* array) const {
81 array->AppendString("EndFilterDisplayItem");
84 } // namespace cc