| 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 "modules/sksg/include/SkSGOpacityEffect.h" |
| 9 | |
| 10 | namespace sksg { |
| 11 | |
| 12 | OpacityEffect::OpacityEffect(sk_sp<RenderNode> child, float opacity) |
| 13 | : INHERITED(std::move(child)) |
| 14 | , fOpacity(opacity) {} |
| 15 | |
| 16 | void OpacityEffect::onRender(SkCanvas* canvas, const RenderContext* ctx) const { |
| 17 | // opacity <= 0 disables rendering |
| 18 | if (fOpacity <= 0) |
| 19 | return; |
| 20 | |
| 21 | const auto local_context = ScopedRenderContext(canvas, ctx).modulateOpacity(fOpacity); |
| 22 | |
| 23 | this->INHERITED::onRender(canvas, local_context); |
| 24 | } |
| 25 | |
| 26 | const RenderNode* OpacityEffect::onNodeAt(const SkPoint& p) const { |
| 27 | return (fOpacity > 0) ? this->INHERITED::onNodeAt(p) : nullptr; |
| 28 | } |
| 29 | |
| 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 |
| 38 |