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
)
15 alpha_(SkScalarRoundToInt(opacity
* 255)),
16 disable_image_filtering_(disable_image_filtering
) { }
18 void OpacityFilterCanvas::onFilterPaint(SkPaint
* paint
, Type
) const {
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
;
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());