Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / skia / ext / opacity_filter_canvas.cc
blob53d3580069c33b521d0a12fc03d40fe5daff8af5
1 // Copyright 2015 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 "skia/ext/opacity_filter_canvas.h"
6 #include "third_party/skia/include/core/SkPaint.h"
7 #include "third_party/skia/include/core/SkTLazy.h"
9 namespace skia {
11 OpacityFilterCanvas::OpacityFilterCanvas(SkCanvas* canvas,
12 float opacity,
13 bool disable_image_filtering)
14 : INHERITED(canvas),
15 alpha_(SkScalarRoundToInt(opacity * 255)),
16 disable_image_filtering_(disable_image_filtering) { }
18 void OpacityFilterCanvas::onFilterPaint(SkPaint* paint, Type) const {
19 if (alpha_ < 255)
20 paint->setAlpha(alpha_);
22 if (disable_image_filtering_)
23 paint->setFilterQuality(kNone_SkFilterQuality);
26 void OpacityFilterCanvas::onDrawPicture(const SkPicture* picture,
27 const SkMatrix* matrix,
28 const SkPaint* paint) {
29 SkTLazy<SkPaint> filteredPaint;
30 if (paint) {
31 this->onFilterPaint(filteredPaint.set(*paint), kPicture_Type);
34 // Unfurl pictures in order to filter nested paints.
35 this->SkCanvas::onDrawPicture(picture, matrix, filteredPaint.getMaybeNull());
38 } // namespace skia