aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/sksg
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-01-10 13:36:22 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-11 19:32:45 +0000
commit5f9102f2912ef702e013c48466b5461f2a0b9eb9 (patch)
tree672c92e9267643efa229e5d0c4827d9437daeab2 /experimental/sksg
parent68c3fac8ce26a58bc0795f3d5da443c2a5915e2e (diff)
[skotty,sksg] Initial matte layer support
TBR= Change-Id: I5b689f5d7b0d147fa200cf5bffe476077085cb19 Reviewed-on: https://skia-review.googlesource.com/93300 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental/sksg')
-rw-r--r--experimental/sksg/SkSGNode.h1
-rw-r--r--experimental/sksg/effects/SkSGMaskEffect.cpp51
-rw-r--r--experimental/sksg/effects/SkSGMaskEffect.h44
3 files changed, 96 insertions, 0 deletions
diff --git a/experimental/sksg/SkSGNode.h b/experimental/sksg/SkSGNode.h
index 1ed2a782d2..37139339f2 100644
--- a/experimental/sksg/SkSGNode.h
+++ b/experimental/sksg/SkSGNode.h
@@ -71,6 +71,7 @@ private:
friend class Draw;
friend class EffectNode;
friend class Group;
+ friend class MaskEffect;
friend class Matrix;
friend class Merge;
friend class Stroke;
diff --git a/experimental/sksg/effects/SkSGMaskEffect.cpp b/experimental/sksg/effects/SkSGMaskEffect.cpp
new file mode 100644
index 0000000000..d4ce6df4db
--- /dev/null
+++ b/experimental/sksg/effects/SkSGMaskEffect.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkSGMaskEffect.h"
+
+#include "SkCanvas.h"
+
+namespace sksg {
+
+MaskEffect::MaskEffect(sk_sp<RenderNode> child, sk_sp<RenderNode> mask)
+ : INHERITED(std::move(child))
+ , fMaskNode(std::move(mask)) {
+ fMaskNode->addInvalReceiver(this);
+}
+
+MaskEffect::~MaskEffect() {
+ fMaskNode->removeInvalReceiver(this);
+}
+
+void MaskEffect::onRender(SkCanvas* canvas) const {
+ if (this->bounds().isEmpty())
+ return;
+
+ SkAutoCanvasRestore acr(canvas, false);
+
+ canvas->saveLayer(this->bounds(), nullptr);
+ fMaskNode->render(canvas);
+
+
+ SkPaint p;
+ p.setBlendMode(SkBlendMode::kSrcIn);
+ canvas->saveLayer(this->bounds(), &p);
+
+ this->INHERITED::onRender(canvas);
+}
+
+
+SkRect MaskEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
+ SkASSERT(this->hasInval());
+
+ const auto maskBounds = fMaskNode->revalidate(ic, ctm);
+ auto childBounds = this->INHERITED::onRevalidate(ic, ctm);
+
+ return childBounds.intersect(maskBounds) ? childBounds : SkRect::MakeEmpty();
+}
+
+} // namespace sksg
diff --git a/experimental/sksg/effects/SkSGMaskEffect.h b/experimental/sksg/effects/SkSGMaskEffect.h
new file mode 100644
index 0000000000..aef82b4ef6
--- /dev/null
+++ b/experimental/sksg/effects/SkSGMaskEffect.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSGMaskEffect_DEFINED
+#define SkSGMaskEffect_DEFINED
+
+#include "SkSGEffectNode.h"
+
+namespace sksg {
+
+/**
+ * Concrete Effect node, applying a mask to its descendants.
+ *
+ */
+class MaskEffect final : public EffectNode {
+public:
+ static sk_sp<MaskEffect> Make(sk_sp<RenderNode> child, sk_sp<RenderNode> mask) {
+ return (child && mask)
+ ? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask)))
+ : nullptr;
+ }
+
+ ~MaskEffect() override;
+
+protected:
+ MaskEffect(sk_sp<RenderNode>, sk_sp<RenderNode> mask);
+
+ void onRender(SkCanvas*) const override;
+
+ SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
+
+private:
+ sk_sp<RenderNode> fMaskNode;
+
+ typedef EffectNode INHERITED;
+};
+
+} // namespace sksg
+
+#endif // SkSGMaskEffect_DEFINED