Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkSGOpacityEffect.h" |
| 9 | |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 10 | namespace sksg { |
| 11 | |
| 12 | OpacityEffect::OpacityEffect(sk_sp<RenderNode> child, float opacity) |
| 13 | : INHERITED(std::move(child)) |
| 14 | , fOpacity(opacity) {} |
| 15 | |
Florin Malita | c0132ff | 2018-08-09 07:40:01 -0400 | [diff] [blame] | 16 | void OpacityEffect::onRender(SkCanvas* canvas, const RenderContext* ctx) const { |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 17 | // opacity <= 0 disables rendering |
| 18 | if (fOpacity <= 0) |
| 19 | return; |
| 20 | |
Florin Malita | c0132ff | 2018-08-09 07:40:01 -0400 | [diff] [blame] | 21 | const auto local_context = ScopedRenderContext(canvas, ctx).modulateOpacity(fOpacity); |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 22 | |
Florin Malita | c0132ff | 2018-08-09 07:40:01 -0400 | [diff] [blame] | 23 | this->INHERITED::onRender(canvas, local_context); |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 24 | } |
| 25 | |
Florin Malita | eb46bd8 | 2019-02-12 09:33:21 -0500 | [diff] [blame] | 26 | const RenderNode* OpacityEffect::onNodeAt(const SkPoint& p) const { |
| 27 | return (fOpacity > 0) ? this->INHERITED::onNodeAt(p) : nullptr; |
| 28 | } |
| 29 | |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 30 | SkRect OpacityEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
| 31 | SkASSERT(this->hasInval()); |
| 32 | |
| 33 | // opacity <= 0 disables rendering AND revalidation for the sub-DAG |
| 34 | return fOpacity > 0 ? this->INHERITED::onRevalidate(ic, ctm) : SkRect::MakeEmpty(); |
| 35 | } |
| 36 | |
| 37 | } // namespace sksg |