Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / skia / ext / opacity_filter_canvas.cc
blob11c8135d0e192511460329113a03aec2958c3c12
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->imageInfo().width(), canvas->imageInfo().height()),
15 alpha_(SkScalarRoundToInt(opacity * 255)),
16 disable_image_filtering_(disable_image_filtering) {
17 this->addCanvas(canvas);
20 void OpacityFilterCanvas::onFilterPaint(SkPaint* paint, Type) const {
21 if (alpha_ < 255)
22 paint->setAlpha(alpha_);
24 if (disable_image_filtering_)
25 paint->setFilterQuality(kNone_SkFilterQuality);
28 void OpacityFilterCanvas::onDrawPicture(const SkPicture* picture,
29 const SkMatrix* matrix,
30 const SkPaint* paint) {
31 SkTLazy<SkPaint> filteredPaint;
32 if (paint) {
33 this->onFilterPaint(filteredPaint.set(*paint), kPicture_Type);
36 // Unfurl pictures in order to filter nested paints.
37 this->SkCanvas::onDrawPicture(picture, matrix, filteredPaint.getMaybeNull());
40 } // namespace skia