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"
11 OpacityFilterCanvas::OpacityFilterCanvas(SkCanvas
* canvas
,
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 {
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
;
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());