• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
OpacityEffect(sk_sp<RenderNode> child,float opacity)12 OpacityEffect::OpacityEffect(sk_sp<RenderNode> child, float opacity)
13     : INHERITED(std::move(child))
14     , fOpacity(opacity) {}
15 
onRender(SkCanvas * canvas,const RenderContext * ctx) const16 void OpacityEffect::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
17     // opacity <= 0 disables rendering
18     if (fOpacity <= 0)
19         return;
20 
21     // opacity >= 1 has no effect
22     if (fOpacity >= 1) {
23         this->INHERITED::onRender(canvas, ctx);
24         return;
25     }
26 
27     const auto local_context = ScopedRenderContext(canvas, ctx).modulateOpacity(fOpacity);
28 
29     this->INHERITED::onRender(canvas, local_context);
30 }
31 
onNodeAt(const SkPoint & p) const32 const RenderNode* OpacityEffect::onNodeAt(const SkPoint& p) const {
33     return (fOpacity > 0) ? this->INHERITED::onNodeAt(p) : nullptr;
34 }
35 
onRevalidate(InvalidationController * ic,const SkMatrix & ctm)36 SkRect OpacityEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
37     SkASSERT(this->hasInval());
38 
39     // opacity <= 0 disables rendering AND revalidation for the sub-DAG
40     return fOpacity > 0 ? this->INHERITED::onRevalidate(ic, ctm) : SkRect::MakeEmpty();
41 }
42 
43 } // namespace sksg
44