aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-05-25 12:43:51 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-25 17:11:52 +0000
commit3b526b05d652ad6c310d9c636187b20b51c7648c (patch)
tree6c6fa99f2e80db81e9c3f593fe5883aabdaa442b /experimental
parent59da548b0c4d4239e0ec1855d3f7f77a2bff4b93 (diff)
"Modularize" SkSG
* relocate all SkSG-related files under modules/sksg/ * fix various tidbits to make non-sksg builds possible * drop obsolete SampleSGInval.cpp Change-Id: I54e6c5bb1a09f45030fa8d607b3eb3f7cba78957 Reviewed-on: https://skia-review.googlesource.com/130025 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/sksg/SkSGDraw.cpp50
-rw-r--r--experimental/sksg/SkSGDraw.h48
-rw-r--r--experimental/sksg/SkSGEffectNode.cpp31
-rw-r--r--experimental/sksg/SkSGEffectNode.h38
-rw-r--r--experimental/sksg/SkSGGeometryNode.cpp32
-rw-r--r--experimental/sksg/SkSGGeometryNode.h49
-rw-r--r--experimental/sksg/SkSGGroup.cpp66
-rw-r--r--experimental/sksg/SkSGGroup.h47
-rw-r--r--experimental/sksg/SkSGImage.cpp29
-rw-r--r--experimental/sksg/SkSGImage.h49
-rw-r--r--experimental/sksg/SkSGInvalidationController.cpp32
-rw-r--r--experimental/sksg/SkSGInvalidationController.h43
-rw-r--r--experimental/sksg/SkSGNode.cpp152
-rw-r--r--experimental/sksg/SkSGNode.h107
-rw-r--r--experimental/sksg/SkSGPaintNode.cpp41
-rw-r--r--experimental/sksg/SkSGPaintNode.h60
-rw-r--r--experimental/sksg/SkSGRenderNode.cpp19
-rw-r--r--experimental/sksg/SkSGRenderNode.h36
-rw-r--r--experimental/sksg/SkSGScene.cpp70
-rw-r--r--experimental/sksg/SkSGScene.h85
-rw-r--r--experimental/sksg/effects/SkSGClipEffect.cpp50
-rw-r--r--experimental/sksg/effects/SkSGClipEffect.h50
-rw-r--r--experimental/sksg/effects/SkSGMaskEffect.cpp54
-rw-r--r--experimental/sksg/effects/SkSGMaskEffect.h51
-rw-r--r--experimental/sksg/effects/SkSGOpacityEffect.cpp42
-rw-r--r--experimental/sksg/effects/SkSGOpacityEffect.h42
-rw-r--r--experimental/sksg/effects/SkSGTransform.cpp70
-rw-r--r--experimental/sksg/effects/SkSGTransform.h81
-rw-r--r--experimental/sksg/geometry/SkSGGeometryTransform.cpp53
-rw-r--r--experimental/sksg/geometry/SkSGGeometryTransform.h58
-rw-r--r--experimental/sksg/geometry/SkSGMerge.cpp84
-rw-r--r--experimental/sksg/geometry/SkSGMerge.h64
-rw-r--r--experimental/sksg/geometry/SkSGPath.cpp41
-rw-r--r--experimental/sksg/geometry/SkSGPath.h48
-rw-r--r--experimental/sksg/geometry/SkSGPlane.cpp36
-rw-r--r--experimental/sksg/geometry/SkSGPlane.h40
-rw-r--r--experimental/sksg/geometry/SkSGRect.cpp60
-rw-r--r--experimental/sksg/geometry/SkSGRect.h76
-rw-r--r--experimental/sksg/geometry/SkSGRoundEffect.cpp56
-rw-r--r--experimental/sksg/geometry/SkSGRoundEffect.h50
-rw-r--r--experimental/sksg/geometry/SkSGText.cpp77
-rw-r--r--experimental/sksg/geometry/SkSGText.h69
-rw-r--r--experimental/sksg/geometry/SkSGTrimEffect.cpp56
-rw-r--r--experimental/sksg/geometry/SkSGTrimEffect.h58
-rw-r--r--experimental/sksg/paint/SkSGColor.cpp18
-rw-r--r--experimental/sksg/paint/SkSGColor.h37
-rw-r--r--experimental/sksg/paint/SkSGGradient.cpp60
-rw-r--r--experimental/sksg/paint/SkSGGradient.h105
48 files changed, 0 insertions, 2670 deletions
diff --git a/experimental/sksg/SkSGDraw.cpp b/experimental/sksg/SkSGDraw.cpp
deleted file mode 100644
index b73bf3b577..0000000000
--- a/experimental/sksg/SkSGDraw.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGDraw.h"
-
-#include "SkSGGeometryNode.h"
-#include "SkSGInvalidationController.h"
-#include "SkSGPaintNode.h"
-
-namespace sksg {
-
-Draw::Draw(sk_sp<GeometryNode> geometry, sk_sp<PaintNode> paint)
- : fGeometry(std::move(geometry))
- , fPaint(std::move(paint)) {
- this->observeInval(fGeometry);
- this->observeInval(fPaint);
-}
-
-Draw::~Draw() {
- this->unobserveInval(fGeometry);
- this->unobserveInval(fPaint);
-}
-
-void Draw::onRender(SkCanvas* canvas) const {
- const auto& paint = fPaint->makePaint();
- const auto skipDraw = paint.nothingToDraw() ||
- (paint.getStyle() == SkPaint::kStroke_Style && paint.getStrokeWidth() <= 0);
-
- if (!skipDraw) {
- fGeometry->draw(canvas, paint);
- }
-}
-
-SkRect Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- auto bounds = fGeometry->revalidate(ic, ctm);
- fPaint->revalidate(ic, ctm);
-
- const auto& paint = fPaint->makePaint();
- SkASSERT(paint.canComputeFastBounds());
-
- return paint.computeFastBounds(bounds, &bounds);
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGDraw.h b/experimental/sksg/SkSGDraw.h
deleted file mode 100644
index 20ead3d5f6..0000000000
--- a/experimental/sksg/SkSGDraw.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGDraw_DEFINED
-#define SkSGDraw_DEFINED
-
-#include "SkSGRenderNode.h"
-
-namespace sksg {
-
-class GeometryNode;
-class PaintNode;
-
-/**
- * Concrete rendering node.
- *
- * Wraps and draws a [geometry, paint] tuple.
- *
- * Think Skia SkCanvas::drawFoo(foo, paint) calls.
- */
-class Draw : public RenderNode {
-public:
- static sk_sp<Draw> Make(sk_sp<GeometryNode> geo, sk_sp<PaintNode> paint) {
- return (geo && paint) ? sk_sp<Draw>(new Draw(std::move(geo), std::move(paint))) : nullptr;
- }
-
-protected:
- Draw(sk_sp<GeometryNode>, sk_sp<PaintNode> paint);
- ~Draw() override;
-
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- sk_sp<GeometryNode> fGeometry;
- sk_sp<PaintNode> fPaint;
-
- typedef RenderNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGDraw_DEFINED
diff --git a/experimental/sksg/SkSGEffectNode.cpp b/experimental/sksg/SkSGEffectNode.cpp
deleted file mode 100644
index 70050ccb70..0000000000
--- a/experimental/sksg/SkSGEffectNode.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGEffectNode.h"
-
-namespace sksg {
-
-EffectNode::EffectNode(sk_sp<RenderNode> child)
- : fChild(std::move(child)) {
- this->observeInval(fChild);
-}
-
-EffectNode::~EffectNode() {
- this->unobserveInval(fChild);
-}
-
-void EffectNode::onRender(SkCanvas* canvas) const {
- fChild->render(canvas);
-}
-
-SkRect EffectNode::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- return fChild->revalidate(ic, ctm);
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGEffectNode.h b/experimental/sksg/SkSGEffectNode.h
deleted file mode 100644
index ab0968e96c..0000000000
--- a/experimental/sksg/SkSGEffectNode.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGEffectNode_DEFINED
-#define SkSGEffectNode_DEFINED
-
-#include "SkSGRenderNode.h"
-
-namespace sksg {
-
-/**
- * Base class for nodes which apply some transformation when rendering
- * their descendants.
- *
- * This includes transforms, clipping, filters, etc.
- */
-class EffectNode : public RenderNode {
-protected:
- explicit EffectNode(sk_sp<RenderNode>);
- ~EffectNode() override;
-
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- sk_sp<RenderNode> fChild;
-
- typedef RenderNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGEffectNode_DEFINED
diff --git a/experimental/sksg/SkSGGeometryNode.cpp b/experimental/sksg/SkSGGeometryNode.cpp
deleted file mode 100644
index 6b78c488b7..0000000000
--- a/experimental/sksg/SkSGGeometryNode.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPath.h"
-
-namespace sksg {
-
-// Geometry nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes.
-GeometryNode::GeometryNode() : INHERITED(kBubbleDamage_Trait) {}
-
-void GeometryNode::clip(SkCanvas* canvas, bool aa) const {
- SkASSERT(!this->hasInval());
- this->onClip(canvas, aa);
-}
-
-void GeometryNode::draw(SkCanvas* canvas, const SkPaint& paint) const {
- SkASSERT(!this->hasInval());
- this->onDraw(canvas, paint);
-}
-
-SkPath GeometryNode::asPath() const {
- SkASSERT(!this->hasInval());
- return this->onAsPath();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGGeometryNode.h b/experimental/sksg/SkSGGeometryNode.h
deleted file mode 100644
index 7ce3aa9b79..0000000000
--- a/experimental/sksg/SkSGGeometryNode.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGGeometryNode_DEFINED
-#define SkSGGeometryNode_DEFINED
-
-#include "SkSGNode.h"
-
-class SkCanvas;
-class SkPaint;
-class SkPath;
-
-namespace sksg {
-
-/**
- * Base class for nodes which provide 'geometry' (as opposed to paint)
- * for drawing.
- *
- * Think SkRect, SkPath, etc.
- */
-class GeometryNode : public Node {
-public:
- void clip(SkCanvas*, bool antiAlias) const;
- void draw(SkCanvas*, const SkPaint&) const;
-
- SkPath asPath() const;
-
-protected:
- GeometryNode();
-
- virtual void onClip(SkCanvas*, bool antiAlias) const = 0;
-
- virtual void onDraw(SkCanvas*, const SkPaint&) const = 0;
-
- virtual SkPath onAsPath() const = 0;
-
-private:
- friend class Draw; // wants to know the cached bounds.
-
- typedef Node INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGGeometryNode_DEFINED
diff --git a/experimental/sksg/SkSGGroup.cpp b/experimental/sksg/SkSGGroup.cpp
deleted file mode 100644
index aeccf233f7..0000000000
--- a/experimental/sksg/SkSGGroup.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGGroup.h"
-
-namespace sksg {
-
-Group::Group() {}
-
-Group::~Group() {
- for (const auto& child : fChildren) {
- this->unobserveInval(child);
- }
-}
-
-void Group::addChild(sk_sp<RenderNode> node) {
- // should we allow duplicates?
- for (const auto& child : fChildren) {
- if (child == node) {
- return;
- }
- }
-
- this->observeInval(node);
- fChildren.push_back(std::move(node));
-
- this->invalidate();
-}
-
-void Group::removeChild(const sk_sp<RenderNode>& node) {
- int origCount = fChildren.count();
- for (int i = 0; i < origCount; ++i) {
- if (fChildren[i] == node) {
- fChildren.removeShuffle(i);
- this->unobserveInval(node);
- break;
- }
- }
- SkASSERT(fChildren.count() == origCount - 1);
-
- this->invalidate();
-}
-
-void Group::onRender(SkCanvas* canvas) const {
- for (const auto& child : fChildren) {
- child->render(canvas);
- }
-}
-
-SkRect Group::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- SkRect bounds = SkRect::MakeEmpty();
-
- for (const auto& child : fChildren) {
- bounds.join(child->revalidate(ic, ctm));
- }
-
- return bounds;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGGroup.h b/experimental/sksg/SkSGGroup.h
deleted file mode 100644
index 482f10db8c..0000000000
--- a/experimental/sksg/SkSGGroup.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGGroup_DEFINED
-#define SkSGGroup_DEFINED
-
-#include "SkSGRenderNode.h"
-
-#include "SkTArray.h"
-
-namespace sksg {
-
-/**
- * Concrete node, grouping together multiple descendants.
- */
-class Group : public RenderNode {
-public:
- static sk_sp<Group> Make() {
- return sk_sp<Group>(new Group());
- }
-
- void addChild(sk_sp<RenderNode>);
- void removeChild(const sk_sp<RenderNode>&);
-
- size_t size() const { return SkTo<size_t>(fChildren.count()); }
- bool empty() const { return fChildren.empty(); }
-
-protected:
- Group();
- ~Group() override;
-
- void onRender(SkCanvas*) const override;
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- SkTArray<sk_sp<RenderNode>, true> fChildren;
-
- typedef RenderNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGGroup_DEFINED
diff --git a/experimental/sksg/SkSGImage.cpp b/experimental/sksg/SkSGImage.cpp
deleted file mode 100644
index a0c3a759dc..0000000000
--- a/experimental/sksg/SkSGImage.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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 "SkSGImage.h"
-
-#include "SkCanvas.h"
-#include "SkImage.h"
-
-namespace sksg {
-
-Image::Image(sk_sp<SkImage> image) : fImage(std::move(image)) {}
-
-void Image::onRender(SkCanvas* canvas) const {
- SkPaint paint;
- paint.setAntiAlias(fAntiAlias);
- paint.setFilterQuality(fQuality);
-
- canvas->drawImage(fImage, 0, 0);
-}
-
-SkRect Image::onRevalidate(InvalidationController*, const SkMatrix& ctm) {
- return SkRect::Make(fImage->bounds());
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGImage.h b/experimental/sksg/SkSGImage.h
deleted file mode 100644
index 7d17a50aaa..0000000000
--- a/experimental/sksg/SkSGImage.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 SkSGImage_DEFINED
-#define SkSGImage_DEFINED
-
-#include "SkSGRenderNode.h"
-
-#include "SkFilterQuality.h"
-
-class SkImage;
-
-namespace sksg {
-
-/**
- * Concrete rendering node, wrapping an SkImage.
- *
- */
-class Image final : public RenderNode {
-public:
- static sk_sp<Image> Make(sk_sp<SkImage> image) {
- return image ? sk_sp<Image>(new Image(std::move(image))) : nullptr;
- }
-
- SG_ATTRIBUTE(Quality , SkFilterQuality, fQuality )
- SG_ATTRIBUTE(AntiAlias, bool , fAntiAlias)
-
-protected:
- explicit Image(sk_sp<SkImage>);
-
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- const sk_sp<SkImage> fImage;
- SkFilterQuality fQuality = kLow_SkFilterQuality;
- bool fAntiAlias = true;
-
- typedef RenderNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGImage_DEFINED
diff --git a/experimental/sksg/SkSGInvalidationController.cpp b/experimental/sksg/SkSGInvalidationController.cpp
deleted file mode 100644
index 81a3376bf6..0000000000
--- a/experimental/sksg/SkSGInvalidationController.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGInvalidationController.h"
-
-#include "SkRect.h"
-#include "SkTLazy.h"
-
-namespace sksg {
-
-InvalidationController::InvalidationController() : fBounds(SkRect::MakeEmpty()) {}
-
-void InvalidationController::inval(const SkRect& r, const SkMatrix& ctm) {
- if (r.isEmpty()) {
- return;
- }
-
- SkTCopyOnFirstWrite<SkRect> rect(r);
-
- if (!ctm.isIdentity()) {
- ctm.mapRect(rect.writable());
- }
-
- fRects.push(*rect);
- fBounds.join(*rect);
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGInvalidationController.h b/experimental/sksg/SkSGInvalidationController.h
deleted file mode 100644
index df3857c1fe..0000000000
--- a/experimental/sksg/SkSGInvalidationController.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGInvalidationController_DEFINED
-#define SkSGInvalidationController_DEFINED
-
-#include "SkMatrix.h"
-#include "SkTDArray.h"
-#include "SkTypes.h"
-
-struct SkRect;
-
-namespace sksg {
-
-/**
- * Receiver for invalidation events.
- *
- * Tracks dirty regions for repaint.
- */
-class InvalidationController : public SkNoncopyable {
-public:
- InvalidationController();
-
- void inval(const SkRect&, const SkMatrix& ctm = SkMatrix::I());
-
- const SkRect& bounds() const { return fBounds; }
- const SkRect* begin() const { return fRects.begin(); }
- const SkRect* end() const { return fRects.end(); }
-
-private:
- SkTDArray<SkRect> fRects;
- SkRect fBounds;
-
- typedef SkNoncopyable INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGInvalidationController_DEFINED
diff --git a/experimental/sksg/SkSGNode.cpp b/experimental/sksg/SkSGNode.cpp
deleted file mode 100644
index 35b2640dbb..0000000000
--- a/experimental/sksg/SkSGNode.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkRectPriv.h"
-#include "SkSGNode.h"
-#include "SkSGInvalidationController.h"
-
-namespace sksg {
-
-class Node::ScopedFlag {
-public:
- ScopedFlag(Node* node, uint32_t flag)
- : fNode(node)
- , fFlag(flag)
- , fWasSet(node->fFlags & flag) {
- node->fFlags |= flag;
- }
- ~ScopedFlag() {
- if (!fWasSet) {
- fNode->fFlags &= ~fFlag;;
- }
- }
-
- bool wasSet() const { return fWasSet; }
-
-private:
- Node* fNode;
- uint32_t fFlag;
- bool fWasSet;
-};
-
-#define TRAVERSAL_GUARD \
- ScopedFlag traversal_guard(this, kInTraversal_Flag); \
- if (traversal_guard.wasSet()) \
- return
-
-Node::Node(uint32_t invalTraits)
- : fInvalObserver(nullptr)
- , fBounds(SkRectPriv::MakeLargeS32())
- , fInvalTraits(invalTraits)
- , fFlags(kInvalidated_Flag) {}
-
-Node::~Node() {
- if (fFlags & kObserverArray_Flag) {
- SkASSERT(fInvalObserverArray->isEmpty());
- delete fInvalObserverArray;
- } else {
- SkASSERT(!fInvalObserver);
- }
-}
-
-void Node::observeInval(const sk_sp<Node>& node) {
- SkASSERT(node);
- if (!(node->fFlags & kObserverArray_Flag)) {
- if (!node->fInvalObserver) {
- node->fInvalObserver = this;
- return;
- }
-
- auto observers = new SkTDArray<Node*>();
- observers->setReserve(2);
- observers->push(node->fInvalObserver);
-
- node->fInvalObserverArray = observers;
- node->fFlags |= kObserverArray_Flag;
- }
-
- // No duplicate observers.
- SkASSERT(node->fInvalObserverArray->find(this) < 0);
-
- node->fInvalObserverArray->push(this);
-}
-
-void Node::unobserveInval(const sk_sp<Node>& node) {
- SkASSERT(node);
- if (!(node->fFlags & kObserverArray_Flag)) {
- SkASSERT(node->fInvalObserver == this);
- node->fInvalObserver = nullptr;
- return;
- }
-
- const auto idx = node->fInvalObserverArray->find(this);
- SkASSERT(idx >= 0);
- node->fInvalObserverArray->remove(idx);
-}
-
-template <typename Func>
-void Node::forEachInvalObserver(Func&& func) const {
- if (fFlags & kObserverArray_Flag) {
- for (const auto& parent : *fInvalObserverArray) {
- func(parent);
- }
- return;
- }
-
- if (fInvalObserver) {
- func(fInvalObserver);
- }
-}
-
-void Node::invalidate(bool damageBubbling) {
- TRAVERSAL_GUARD;
-
- if (this->hasInval() && (!damageBubbling || (fFlags & kDamage_Flag))) {
- // All done.
- return;
- }
-
- if (damageBubbling && !(fInvalTraits & kBubbleDamage_Trait)) {
- // Found a damage observer.
- fFlags |= kDamage_Flag;
- damageBubbling = false;
- }
-
- fFlags |= kInvalidated_Flag;
-
- forEachInvalObserver([&](Node* observer) {
- observer->invalidate(damageBubbling);
- });
-}
-
-const SkRect& Node::revalidate(InvalidationController* ic, const SkMatrix& ctm) {
- TRAVERSAL_GUARD fBounds;
-
- if (!this->hasInval()) {
- return fBounds;
- }
-
- SkRect prevBounds;
- if (fFlags & kDamage_Flag) {
- prevBounds = fBounds;
- }
-
- fBounds = this->onRevalidate(ic, ctm);
-
- if (fFlags & kDamage_Flag) {
- ic->inval(prevBounds, ctm);
- if (fBounds != prevBounds) {
- ic->inval(fBounds, ctm);
- }
- }
-
- fFlags &= ~(kInvalidated_Flag | kDamage_Flag);
-
- return fBounds;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGNode.h b/experimental/sksg/SkSGNode.h
deleted file mode 100644
index 17619de485..0000000000
--- a/experimental/sksg/SkSGNode.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGNode_DEFINED
-#define SkSGNode_DEFINED
-
-#include "SkRect.h"
-#include "SkRefCnt.h"
-#include "SkTDArray.h"
-
-class SkCanvas;
-class SkMatrix;
-
-namespace sksg {
-
-class InvalidationController;
-
-/**
- * Base class for all scene graph nodes.
- *
- * Handles ingress edge management for the DAG (i.e. node -> "parent" node mapping),
- * and invalidation.
- *
- * Note: egress edges are only implemented/supported in container subclasses
- * (e.g. Group, Effect, Draw).
- */
-class Node : public SkRefCnt {
-public:
- // Traverse the DAG and revalidate any dependant/invalidated nodes.
- // Returns the bounding box for the DAG fragment.
- const SkRect& revalidate(InvalidationController*, const SkMatrix&);
-
-protected:
- enum InvalTraits {
- // Nodes with this trait never generate direct damage -- instead,
- // the damage bubbles up to ancestors.
- kBubbleDamage_Trait = 1 << 0,
- };
-
- explicit Node(uint32_t invalTraits);
- ~Node() override;
-
- const SkRect& bounds() const {
- SkASSERT(!this->hasInval());
- return fBounds;
- }
-
- // Tag this node for invalidation and optional damage.
- void invalidate(bool damage = true);
- bool hasInval() const { return fFlags & kInvalidated_Flag; }
-
- // Dispatched on revalidation. Subclasses are expected to recompute/cache their properties
- // and return their bounding box in local coordinates.
- virtual SkRect onRevalidate(InvalidationController*, const SkMatrix& ctm) = 0;
-
- // Register/unregister |this| to receive invalidation events from a descendant.
- void observeInval(const sk_sp<Node>&);
- void unobserveInval(const sk_sp<Node>&);
-
-private:
- enum Flags {
- kInvalidated_Flag = 1 << 0, // the node or its descendants require revalidation
- kDamage_Flag = 1 << 1, // the node contributes damage during revalidation
- kObserverArray_Flag = 1 << 2, // the node has more than one inval observer
- kInTraversal_Flag = 1 << 3, // the node is part of a traversal (cycle detection)
- };
-
- template <typename Func>
- void forEachInvalObserver(Func&&) const;
-
- class ScopedFlag;
-
- union {
- Node* fInvalObserver;
- SkTDArray<Node*>* fInvalObserverArray;
- };
- SkRect fBounds;
- const uint32_t fInvalTraits : 16;
- uint32_t fFlags : 16;
-
- typedef SkRefCnt INHERITED;
-};
-
-// Helper for defining attribute getters/setters in subclasses.
-#define SG_ATTRIBUTE(attr_name, attr_type, attr_container) \
- const attr_type& get##attr_name() const { return attr_container; } \
- void set##attr_name(const attr_type& v) { \
- if (attr_container == v) return; \
- attr_container = v; \
- this->invalidate(); \
- }
-
-#define SG_MAPPED_ATTRIBUTE(attr_name, attr_type, attr_container) \
- attr_type get##attr_name() const { return attr_container.get##attr_name(); } \
- void set##attr_name(const attr_type& v) { \
- if (attr_container.get##attr_name() == v) return; \
- attr_container.set##attr_name(v); \
- this->invalidate(); \
- }
-
-} // namespace sksg
-
-#endif // SkSGNode_DEFINED
diff --git a/experimental/sksg/SkSGPaintNode.cpp b/experimental/sksg/SkSGPaintNode.cpp
deleted file mode 100644
index 9220b0f0af..0000000000
--- a/experimental/sksg/SkSGPaintNode.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGPaintNode.h"
-
-namespace sksg {
-
-// Paint nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes.
-PaintNode::PaintNode() : INHERITED(kBubbleDamage_Trait) {}
-
-const SkPaint& PaintNode::makePaint() {
- SkASSERT(!this->hasInval());
-
- return fPaint;
-}
-
-SkRect PaintNode::onRevalidate(InvalidationController*, const SkMatrix&) {
- SkASSERT(this->hasInval());
-
- fPaint.reset();
- fPaint.setAntiAlias(fAntiAlias);
- fPaint.setBlendMode(fBlendMode);
- fPaint.setStyle(fStyle);
- fPaint.setStrokeWidth(fStrokeWidth);
- fPaint.setStrokeMiter(fStrokeMiter);
- fPaint.setStrokeJoin(fStrokeJoin);
- fPaint.setStrokeCap(fStrokeCap);
-
- this->onApplyToPaint(&fPaint);
-
- // Compose opacity on top of the subclass value.
- fPaint.setAlpha(SkScalarRoundToInt(fPaint.getAlpha() * SkTPin<SkScalar>(fOpacity, 0, 1)));
-
- return SkRect::MakeEmpty();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGPaintNode.h b/experimental/sksg/SkSGPaintNode.h
deleted file mode 100644
index 5c9563b3a6..0000000000
--- a/experimental/sksg/SkSGPaintNode.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGPaintNode_DEFINED
-#define SkSGPaintNode_DEFINED
-
-#include "SkSGNode.h"
-
-#include "SkPaint.h"
-
-namespace sksg {
-
-/**
- * Base class for nodes which provide a 'paint' (as opposed to geometry) for
- * drawing (e.g. colors, gradients, patterns).
- *
- * Roughly equivalent to Skia's SkPaint.
- */
-class PaintNode : public Node {
-public:
- const SkPaint& makePaint();
-
- SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
- SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
- SG_ATTRIBUTE(BlendMode , SkBlendMode , fBlendMode )
- SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
- SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
- SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
- SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
- SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
-
-protected:
- PaintNode();
-
- virtual void onApplyToPaint(SkPaint*) const = 0;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) final;
-
-private:
- SkPaint fPaint;
-
- SkScalar fOpacity = 1,
- fStrokeWidth = 1,
- fStrokeMiter = 4;
- bool fAntiAlias = false;
- SkBlendMode fBlendMode = SkBlendMode::kSrcOver;
- SkPaint::Style fStyle = SkPaint::kFill_Style;
- SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
- SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
-
- typedef Node INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGGeometryNode_DEFINED
diff --git a/experimental/sksg/SkSGRenderNode.cpp b/experimental/sksg/SkSGRenderNode.cpp
deleted file mode 100644
index e952c69f20..0000000000
--- a/experimental/sksg/SkSGRenderNode.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGRenderNode.h"
-
-namespace sksg {
-
-RenderNode::RenderNode() : INHERITED(0) {}
-
-void RenderNode::render(SkCanvas* canvas) const {
- SkASSERT(!this->hasInval());
- this->onRender(canvas);
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGRenderNode.h b/experimental/sksg/SkSGRenderNode.h
deleted file mode 100644
index 4ca1aec616..0000000000
--- a/experimental/sksg/SkSGRenderNode.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGRenderNode_DEFINED
-#define SkSGRenderNode_DEFINED
-
-#include "SkSGNode.h"
-
-class SkCanvas;
-
-namespace sksg {
-
-/**
- * Base class for nodes which can render to a canvas.
- */
-class RenderNode : public Node {
-public:
- // Render the node and its descendants to the canvas.
- void render(SkCanvas*) const;
-
-protected:
- RenderNode();
-
- virtual void onRender(SkCanvas*) const = 0;
-
-private:
- typedef Node INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGRenderNode_DEFINED
diff --git a/experimental/sksg/SkSGScene.cpp b/experimental/sksg/SkSGScene.cpp
deleted file mode 100644
index 8d7e0b369b..0000000000
--- a/experimental/sksg/SkSGScene.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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 "SkSGScene.h"
-
-#include "SkCanvas.h"
-#include "SkMatrix.h"
-#include "SkPaint.h"
-#include "SkSGInvalidationController.h"
-#include "SkSGRenderNode.h"
-
-namespace sksg {
-
-Animator::Animator() = default;
-Animator::~Animator() = default;
-
-void Animator::tick(float t) {
- this->onTick(t);
-}
-
-GroupAnimator::GroupAnimator(AnimatorList&& animators)
- : fAnimators(std::move(animators)) {}
-
-void GroupAnimator::onTick(float t) {
- for (const auto& a : fAnimators) {
- a->tick(t);
- }
-}
-
-std::unique_ptr<Scene> Scene::Make(sk_sp<RenderNode> root, AnimatorList&& anims) {
- return root ? std::unique_ptr<Scene>(new Scene(std::move(root), std::move(anims))) : nullptr;
-}
-
-Scene::Scene(sk_sp<RenderNode> root, AnimatorList&& animators)
- : fRoot(std::move(root))
- , fAnimators(std::move(animators)) {}
-
-Scene::~Scene() = default;
-
-void Scene::render(SkCanvas* canvas) const {
- InvalidationController ic;
- fRoot->revalidate(&ic, SkMatrix::I());
- fRoot->render(canvas);
-
- if (fShowInval) {
- SkPaint fill, stroke;
- fill.setAntiAlias(true);
- fill.setColor(0x40ff0000);
- stroke.setAntiAlias(true);
- stroke.setColor(0xffff0000);
- stroke.setStyle(SkPaint::kStroke_Style);
-
- for (const auto& r : ic) {
- canvas->drawRect(r, fill);
- canvas->drawRect(r, stroke);
- }
- }
-}
-
-void Scene::animate(float t) {
- for (const auto& anim : fAnimators) {
- anim->tick(t);
- }
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/SkSGScene.h b/experimental/sksg/SkSGScene.h
deleted file mode 100644
index 2081c1d747..0000000000
--- a/experimental/sksg/SkSGScene.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 SkSGScene_DEFINED
-#define SkSGScene_DEFINED
-
-#include "SkRefCnt.h"
-#include "SkTypes.h"
-
-#include <memory>
-#include <vector>
-
-class SkCanvas;
-
-namespace sksg {
-
-class RenderNode;
-
-/**
- * Base class for animators.
- *
- */
-class Animator : public SkNoncopyable {
-public:
- virtual ~Animator();
-
- void tick(float t);
-
-protected:
- Animator();
-
- virtual void onTick(float t) = 0;
-
-private:
- using INHERITED = SkNoncopyable;
-};
-
-using AnimatorList = std::vector<std::unique_ptr<Animator>>;
-
-class GroupAnimator : public Animator {
-protected:
- explicit GroupAnimator(AnimatorList&&);
-
- void onTick(float t) override;
-
-private:
- const AnimatorList fAnimators;
-
- using INHERITED = Animator;
-};
-
-/**
- * Holds a scene root and a list of animators.
- *
- * Provides high-level mehods for driving rendering and animations.
- *
- */
-class Scene final : SkNoncopyable {
-public:
- static std::unique_ptr<Scene> Make(sk_sp<RenderNode> root, AnimatorList&& animators);
- ~Scene();
-
- void render(SkCanvas*) const;
- void animate(float t);
-
- void setShowInval(bool show) { fShowInval = show; }
-
-private:
- Scene(sk_sp<RenderNode> root, AnimatorList&& animators);
-
- const sk_sp<RenderNode> fRoot;
- const AnimatorList fAnimators;
-
- bool fShowInval = false;
-
- using INHERITED = SkNoncopyable;
-};
-
-} // namespace sksg
-
-#endif // SkSGScene_DEFINED
diff --git a/experimental/sksg/effects/SkSGClipEffect.cpp b/experimental/sksg/effects/SkSGClipEffect.cpp
deleted file mode 100644
index b2d68fc8cf..0000000000
--- a/experimental/sksg/effects/SkSGClipEffect.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 "SkSGClipEffect.h"
-
-#include "SkCanvas.h"
-#include "SkPath.h"
-#include "SkSGGeometryNode.h"
-
-namespace sksg {
-
-ClipEffect::ClipEffect(sk_sp<RenderNode> child, sk_sp<GeometryNode> clip, bool aa)
- : INHERITED(std::move(child))
- , fClipNode(std::move(clip))
- , fAntiAlias(aa) {
- this->observeInval(fClipNode);
-}
-
-ClipEffect::~ClipEffect() {
- this->unobserveInval(fClipNode);
-}
-
-void ClipEffect::onRender(SkCanvas* canvas) const {
- if (this->bounds().isEmpty())
- return;
-
- SkAutoCanvasRestore acr(canvas, !fNoop);
- if (!fNoop) {
- fClipNode->clip(canvas, fAntiAlias);
- }
-
- this->INHERITED::onRender(canvas);
-}
-
-SkRect ClipEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- const auto clipBounds = fClipNode->revalidate(ic, ctm);
- auto childBounds = this->INHERITED::onRevalidate(ic, ctm);
-
- fNoop = fClipNode->asPath().conservativelyContainsRect(childBounds);
-
- return childBounds.intersect(clipBounds) ? childBounds : SkRect::MakeEmpty();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/effects/SkSGClipEffect.h b/experimental/sksg/effects/SkSGClipEffect.h
deleted file mode 100644
index 674edb2b5c..0000000000
--- a/experimental/sksg/effects/SkSGClipEffect.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 SkSGClipEffect_DEFINED
-#define SkSGClipEffect_DEFINED
-
-#include "SkSGEffectNode.h"
-
-namespace sksg {
-
-class GeometryNode;
-
-/**
- * Concrete Effect node, applying a clip to its descendants.
- *
- */
-class ClipEffect final : public EffectNode {
-public:
- static sk_sp<ClipEffect> Make(sk_sp<RenderNode> child, sk_sp<GeometryNode> clip,
- bool aa = false) {
- return (child && clip)
- ? sk_sp<ClipEffect>(new ClipEffect(std::move(child), std::move(clip), aa))
- : nullptr;
- }
-
- ~ClipEffect() override;
-
-protected:
- ClipEffect(sk_sp<RenderNode>, sk_sp<GeometryNode>, bool aa);
-
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- const sk_sp<GeometryNode> fClipNode;
- const bool fAntiAlias;
-
- bool fNoop = false;
-
- typedef EffectNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGClipEffect_DEFINED
diff --git a/experimental/sksg/effects/SkSGMaskEffect.cpp b/experimental/sksg/effects/SkSGMaskEffect.cpp
deleted file mode 100644
index 16e4c0dd8d..0000000000
--- a/experimental/sksg/effects/SkSGMaskEffect.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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, Mode mode)
- : INHERITED(std::move(child))
- , fMaskNode(std::move(mask))
- , fMaskMode(mode) {
- this->observeInval(fMaskNode);
-}
-
-MaskEffect::~MaskEffect() {
- this->unobserveInval(fMaskNode);
-}
-
-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(fMaskMode == Mode::kNormal ? SkBlendMode::kSrcIn : SkBlendMode::kSrcOut);
- 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 (fMaskMode == Mode::kInvert || childBounds.intersect(maskBounds))
- ? childBounds
- : SkRect::MakeEmpty();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/effects/SkSGMaskEffect.h b/experimental/sksg/effects/SkSGMaskEffect.h
deleted file mode 100644
index c4fd0120e5..0000000000
--- a/experimental/sksg/effects/SkSGMaskEffect.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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:
- enum class Mode {
- kNormal,
- kInvert
- };
-
- static sk_sp<MaskEffect> Make(sk_sp<RenderNode> child, sk_sp<RenderNode> mask,
- Mode mode = Mode::kNormal) {
- return (child && mask)
- ? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask), mode))
- : nullptr;
- }
-
- ~MaskEffect() override;
-
-protected:
- MaskEffect(sk_sp<RenderNode>, sk_sp<RenderNode> mask, Mode);
-
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- const sk_sp<RenderNode> fMaskNode;
- const Mode fMaskMode;
-
- typedef EffectNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGMaskEffect_DEFINED
diff --git a/experimental/sksg/effects/SkSGOpacityEffect.cpp b/experimental/sksg/effects/SkSGOpacityEffect.cpp
deleted file mode 100644
index b1ff10d217..0000000000
--- a/experimental/sksg/effects/SkSGOpacityEffect.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 "SkSGOpacityEffect.h"
-
-#include "SkCanvas.h"
-
-#include <math.h>
-
-namespace sksg {
-
-OpacityEffect::OpacityEffect(sk_sp<RenderNode> child, float opacity)
- : INHERITED(std::move(child))
- , fOpacity(opacity) {}
-
-void OpacityEffect::onRender(SkCanvas* canvas) const {
- // opacity <= 0 disables rendering
- if (fOpacity <= 0)
- return;
-
- // TODO: we could avoid savelayer if there is no more than one drawing primitive
- // in the sub-DAG.
- SkAutoCanvasRestore acr(canvas, false);
- if (fOpacity < 1) {
- canvas->saveLayerAlpha(&this->bounds(), roundf(fOpacity * 255));
- }
-
- this->INHERITED::onRender(canvas);
-}
-
-SkRect OpacityEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- // opacity <= 0 disables rendering AND revalidation for the sub-DAG
- return fOpacity > 0 ? this->INHERITED::onRevalidate(ic, ctm) : SkRect::MakeEmpty();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/effects/SkSGOpacityEffect.h b/experimental/sksg/effects/SkSGOpacityEffect.h
deleted file mode 100644
index d906775b44..0000000000
--- a/experimental/sksg/effects/SkSGOpacityEffect.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 SkSGOpacityEffect_DEFINED
-#define SkSGOpacityEffect_DEFINED
-
-#include "SkSGEffectNode.h"
-
-namespace sksg {
-
-/**
- * Concrete Effect node, applying opacity to its descendants.
- *
- */
-class OpacityEffect final : public EffectNode {
-public:
- static sk_sp<OpacityEffect> Make(sk_sp<RenderNode> child, float opacity = 1) {
- return child ? sk_sp<OpacityEffect>(new OpacityEffect(std::move(child), opacity)) : nullptr;
- }
-
- SG_ATTRIBUTE(Opacity, float, fOpacity)
-
-protected:
- OpacityEffect(sk_sp<RenderNode>, float);
-
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- float fOpacity;
-
- typedef EffectNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGOpacityEffect_DEFINED
diff --git a/experimental/sksg/effects/SkSGTransform.cpp b/experimental/sksg/effects/SkSGTransform.cpp
deleted file mode 100644
index 6a985a971e..0000000000
--- a/experimental/sksg/effects/SkSGTransform.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGTransform.h"
-
-#include "SkCanvas.h"
-
-namespace sksg {
-// Matrix nodes don't generate damage on their own, but via aggregation ancestor Transform nodes.
-Matrix::Matrix(const SkMatrix& m, sk_sp<Matrix> parent)
- : INHERITED(kBubbleDamage_Trait)
- , fParent(std::move(parent))
- , fLocalMatrix(m) {
- if (fParent) {
- this->observeInval(fParent);
- }
-}
-
-Matrix::~Matrix() {
- if (fParent) {
- this->unobserveInval(fParent);
- }
-}
-
-SkRect Matrix::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- fTotalMatrix = fLocalMatrix;
-
- if (fParent) {
- fParent->revalidate(ic, ctm);
- fTotalMatrix.postConcat(fParent->getTotalMatrix());
- }
-
- return SkRect::MakeEmpty();
-}
-
-Transform::Transform(sk_sp<RenderNode> child, sk_sp<Matrix> matrix)
- : INHERITED(std::move(child))
- , fMatrix(std::move(matrix)) {
- this->observeInval(fMatrix);
-}
-
-Transform::~Transform() {
- this->unobserveInval(fMatrix);
-}
-
-void Transform::onRender(SkCanvas* canvas) const {
- const auto& m = fMatrix->getTotalMatrix();
- SkAutoCanvasRestore acr(canvas, !m.isIdentity());
- canvas->concat(m);
- this->INHERITED::onRender(canvas);
-}
-
-SkRect Transform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- // We don't care about matrix reval results.
- fMatrix->revalidate(ic, ctm);
-
- const auto& m = fMatrix->getTotalMatrix();
- auto bounds = this->INHERITED::onRevalidate(ic, SkMatrix::Concat(ctm, m));
- m.mapRect(&bounds);
-
- return bounds;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/effects/SkSGTransform.h b/experimental/sksg/effects/SkSGTransform.h
deleted file mode 100644
index 6b7fbc010b..0000000000
--- a/experimental/sksg/effects/SkSGTransform.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGTransform_DEFINED
-#define SkSGTransform_DEFINED
-
-#include "SkSGEffectNode.h"
-
-#include "SkMatrix.h"
-
-namespace sksg {
-
-/**
- * Concrete node, wrapping an SkMatrix, with an optional parent Matrix (to allow chaining):
- *
- * M' = parent x M
- */
-class Matrix : public Node {
-public:
- static sk_sp<Matrix> Make(const SkMatrix& m, sk_sp<Matrix> parent = nullptr) {
- return sk_sp<Matrix>(new Matrix(m, std::move(parent)));
- }
-
- ~Matrix() override;
-
- SG_ATTRIBUTE(Matrix, SkMatrix, fLocalMatrix)
-
- const SkMatrix& getTotalMatrix() const { return fTotalMatrix; }
-
-protected:
- Matrix(const SkMatrix&, sk_sp<Matrix>);
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- sk_sp<Matrix> fParent;
- SkMatrix fLocalMatrix,
- fTotalMatrix; // cached during revalidation
-
- typedef Node INHERITED;
-};
-
-/**
- * Concrete Effect node, binding a Matrix to a RenderNode.
- */
-class Transform final : public EffectNode {
-public:
- static sk_sp<Transform> Make(sk_sp<RenderNode> child, sk_sp<Matrix> matrix) {
- return child && matrix
- ? sk_sp<Transform>(new Transform(std::move(child), std::move(matrix)))
- : nullptr;
- }
-
- static sk_sp<Transform> Make(sk_sp<RenderNode> child, const SkMatrix& m) {
- return Make(std::move(child), Matrix::Make(m));
- }
-
- ~Transform() override;
-
- const sk_sp<Matrix>& getMatrix() const { return fMatrix; }
-
-protected:
- void onRender(SkCanvas*) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
-
-private:
- Transform(sk_sp<RenderNode>, sk_sp<Matrix>);
-
- const sk_sp<Matrix> fMatrix;
-
- typedef EffectNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGTransform_DEFINED
diff --git a/experimental/sksg/geometry/SkSGGeometryTransform.cpp b/experimental/sksg/geometry/SkSGGeometryTransform.cpp
deleted file mode 100644
index 5b366b9620..0000000000
--- a/experimental/sksg/geometry/SkSGGeometryTransform.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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 "SkSGGeometryTransform.h"
-
-#include "SkCanvas.h"
-
-namespace sksg {
-
-GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix)
- : fChild(std::move(child))
- , fMatrix(std::move(matrix)) {
- this->observeInval(fChild);
- this->observeInval(fMatrix);
-}
-
-GeometryTransform::~GeometryTransform() {
- this->unobserveInval(fChild);
- this->unobserveInval(fMatrix);
-}
-
-void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipPath(fTransformed, SkClipOp::kIntersect, antiAlias);
-}
-
-void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawPath(fTransformed, paint);
-}
-
-SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- // We don't care about matrix reval results.
- fMatrix->revalidate(ic, ctm);
- const auto& m = fMatrix->getMatrix();
-
- auto bounds = fChild->revalidate(ic, ctm);
- fTransformed = fChild->asPath();
- fTransformed.transform(m);
-
- m.mapRect(&bounds);
- return bounds;
-}
-
-SkPath GeometryTransform::onAsPath() const {
- return fTransformed;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGGeometryTransform.h b/experimental/sksg/geometry/SkSGGeometryTransform.h
deleted file mode 100644
index fe7e026031..0000000000
--- a/experimental/sksg/geometry/SkSGGeometryTransform.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 SkSGGeometryTransform_DEFINED
-#define SkSGGeometryTransform_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPath.h"
-#include "SkSGTransform.h"
-
-class SkMatrix;
-
-namespace sksg {
-
-/**
- * Concrete Effect node, binding a Matrix to a GeometryNode.
- */
-class GeometryTransform final : public GeometryNode {
-public:
- static sk_sp<GeometryTransform> Make(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix) {
- return child && matrix
- ? sk_sp<GeometryTransform>(new GeometryTransform(std::move(child), std::move(matrix)))
- : nullptr;
- }
-
- static sk_sp<GeometryTransform> Make(sk_sp<GeometryNode> child, const SkMatrix& m) {
- return Make(std::move(child), Matrix::Make(m));
- }
-
- ~GeometryTransform() override;
-
- const sk_sp<Matrix>& getMatrix() const { return fMatrix; }
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- GeometryTransform(sk_sp<GeometryNode>, sk_sp<Matrix>);
-
- const sk_sp<GeometryNode> fChild;
- const sk_sp<Matrix> fMatrix;
- SkPath fTransformed;
-
- using INHERITED = GeometryNode;
-};
-
-}
-
-#endif // SkSGGeometryTransform_DEFINED
diff --git a/experimental/sksg/geometry/SkSGMerge.cpp b/experimental/sksg/geometry/SkSGMerge.cpp
deleted file mode 100644
index be1ff4123a..0000000000
--- a/experimental/sksg/geometry/SkSGMerge.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGMerge.h"
-
-#include "SkCanvas.h"
-#include "SkPathOps.h"
-
-namespace sksg {
-
-Merge::Merge(std::vector<sk_sp<GeometryNode>>&& geos, Mode mode)
- : fGeos(std::move(geos))
- , fMode(mode) {
- for (const auto& geo : fGeos) {
- this->observeInval(geo);
- }
-}
-
-Merge::~Merge() {
- for (const auto& geo : fGeos) {
- this->unobserveInval(geo);
- }
-}
-
-void Merge::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipPath(fMerged, SkClipOp::kIntersect, antiAlias);
-}
-
-void Merge::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawPath(fMerged, paint);
-}
-
-SkPath Merge::onAsPath() const {
- return fMerged;
-}
-
-static SkPathOp mode_to_op(Merge::Mode mode) {
- switch (mode) {
- case Merge::Mode::kUnion:
- return kUnion_SkPathOp;
- case Merge::Mode::kIntersect:
- return kIntersect_SkPathOp;
- case Merge::Mode::kDifference:
- return kDifference_SkPathOp;
- case Merge::Mode::kReverseDifference:
- return kReverseDifference_SkPathOp;
- case Merge::Mode::kXOR:
- return kXOR_SkPathOp;
- default:
- break;
- }
-
- return kUnion_SkPathOp;
-}
-
-SkRect Merge::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- const auto op = mode_to_op(fMode);
- SkOpBuilder builder;
-
- fMerged.reset();
-
- for (const auto& geo : fGeos) {
- geo->revalidate(ic, ctm);
- if (fMode == Mode::kMerge) {
- fMerged.addPath(geo->asPath());
- } else {
- builder.add(geo->asPath(), geo == fGeos.front() ? kUnion_SkPathOp : op);
- }
- }
-
- if (fMode != Mode::kMerge) {
- builder.resolve(&fMerged);
- }
-
- return fMerged.computeTightBounds();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGMerge.h b/experimental/sksg/geometry/SkSGMerge.h
deleted file mode 100644
index 54924d6475..0000000000
--- a/experimental/sksg/geometry/SkSGMerge.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGMerge_DEFINED
-#define SkSGMerge_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPath.h"
-
-#include <vector>
-
-class SkCanvas;
-class SkPaint;
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, combining other geometries based on Mode.
- */
-class Merge final : public GeometryNode {
-public:
- enum class Mode {
- // Append path mode.
- kMerge,
-
- // SkPathOp ops.
- kUnion,
- kIntersect,
- kDifference,
- kReverseDifference,
- kXOR,
- };
-
- static sk_sp<Merge> Make(std::vector<sk_sp<GeometryNode>>&& geos, Mode mode) {
- return sk_sp<Merge>(new Merge(std::move(geos), mode));
- }
-
- ~Merge() override;
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- Merge(std::vector<sk_sp<GeometryNode>>&& geos, Mode);
-
- std::vector<sk_sp<GeometryNode>> fGeos;
- SkPath fMerged;
- Mode fMode;
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGMerge_DEFINED
diff --git a/experimental/sksg/geometry/SkSGPath.cpp b/experimental/sksg/geometry/SkSGPath.cpp
deleted file mode 100644
index 230442d409..0000000000
--- a/experimental/sksg/geometry/SkSGPath.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGPath.h"
-
-#include "SkCanvas.h"
-#include "SkPaint.h"
-#include "SkRectPriv.h"
-
-namespace sksg {
-
-Path::Path(const SkPath& path) : fPath(path) {}
-
-void Path::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipPath(fPath, SkClipOp::kIntersect, antiAlias);
-}
-
-void Path::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawPath(fPath, paint);
-}
-
-SkRect Path::onRevalidate(InvalidationController*, const SkMatrix&) {
- SkASSERT(this->hasInval());
-
- const auto ft = fPath.getFillType();
- return (ft == SkPath::kWinding_FillType || ft == SkPath::kEvenOdd_FillType)
- // "Containing" fills have finite bounds.
- ? fPath.computeTightBounds()
- // Inverse fills are "infinite".
- : SkRectPriv::MakeLargeS32();
-}
-
-SkPath Path::onAsPath() const {
- return fPath;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGPath.h b/experimental/sksg/geometry/SkSGPath.h
deleted file mode 100644
index 1a8718868d..0000000000
--- a/experimental/sksg/geometry/SkSGPath.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGPath_DEFINED
-#define SkSGPath_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPath.h"
-
-class SkCanvas;
-class SkPaint;
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, wrapping an SkPath.
- */
-class Path : public GeometryNode {
-public:
- static sk_sp<Path> Make() { return sk_sp<Path>(new Path(SkPath())); }
- static sk_sp<Path> Make(const SkPath& r) { return sk_sp<Path>(new Path(r)); }
-
- SG_ATTRIBUTE(Path, SkPath, fPath)
- SG_MAPPED_ATTRIBUTE(FillType, SkPath::FillType, fPath)
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- explicit Path(const SkPath&);
-
- SkPath fPath;
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGPath_DEFINED
diff --git a/experimental/sksg/geometry/SkSGPlane.cpp b/experimental/sksg/geometry/SkSGPlane.cpp
deleted file mode 100644
index 806fcc7d29..0000000000
--- a/experimental/sksg/geometry/SkSGPlane.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 "SkSGPlane.h"
-
-#include "SkCanvas.h"
-#include "SkPath.h"
-
-namespace sksg {
-
-Plane::Plane() = default;
-
-void Plane::onClip(SkCanvas*, bool) const {}
-
-void Plane::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawPaint(paint);
-}
-
-SkRect Plane::onRevalidate(InvalidationController*, const SkMatrix&) {
- SkASSERT(this->hasInval());
-
- return SkRect::MakeLTRB(SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax);
-}
-
-SkPath Plane::onAsPath() const {
- SkPath path;
- path.setFillType(SkPath::kInverseWinding_FillType);
-
- return path;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGPlane.h b/experimental/sksg/geometry/SkSGPlane.h
deleted file mode 100644
index c0a26375b2..0000000000
--- a/experimental/sksg/geometry/SkSGPlane.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 SkSGPlane_DEFINED
-#define SkSGPlane_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-class SkCanvas;
-class SkPaint;
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, representing the whole canvas.
- */
-class Plane final : public GeometryNode {
-public:
- static sk_sp<Plane> Make() { return sk_sp<Plane>(new Plane()); }
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- Plane();
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGPlane_DEFINED
diff --git a/experimental/sksg/geometry/SkSGRect.cpp b/experimental/sksg/geometry/SkSGRect.cpp
deleted file mode 100644
index 16f0a6f1e1..0000000000
--- a/experimental/sksg/geometry/SkSGRect.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGRect.h"
-
-#include "SkCanvas.h"
-#include "SkPaint.h"
-#include "SkPath.h"
-
-namespace sksg {
-
-Rect::Rect(const SkRect& rect) : fRect(rect) {}
-
-void Rect::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipRect(fRect, SkClipOp::kIntersect, antiAlias);
-}
-
-void Rect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawRect(fRect, paint);
-}
-
-SkRect Rect::onRevalidate(InvalidationController*, const SkMatrix&) {
- SkASSERT(this->hasInval());
-
- return fRect;
-}
-
-SkPath Rect::onAsPath() const {
- SkPath path;
- path.addRect(fRect);
- return path;
-}
-
-RRect::RRect(const SkRRect& rr) : fRRect(rr) {}
-
-void RRect::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipRRect(fRRect, SkClipOp::kIntersect, antiAlias);
-}
-
-void RRect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawRRect(fRRect, paint);
-}
-
-SkRect RRect::onRevalidate(InvalidationController*, const SkMatrix&) {
- SkASSERT(this->hasInval());
-
- return fRRect.getBounds();
-}
-
-SkPath RRect::onAsPath() const {
- SkPath path;
- path.addRRect(fRRect);
- return path;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGRect.h b/experimental/sksg/geometry/SkSGRect.h
deleted file mode 100644
index f5fcb962c6..0000000000
--- a/experimental/sksg/geometry/SkSGRect.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGRect_DEFINED
-#define SkSGRect_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkRect.h"
-#include "SkRRect.h"
-
-class SkCanvas;
-class SkPaint;
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, wrapping an SkRect.
- */
-class Rect final : public GeometryNode {
-public:
- static sk_sp<Rect> Make() { return sk_sp<Rect>(new Rect(SkRect::MakeEmpty())); }
- static sk_sp<Rect> Make(const SkRect& r) { return sk_sp<Rect>(new Rect(r)); }
-
- SG_ATTRIBUTE(L, SkScalar, fRect.fLeft )
- SG_ATTRIBUTE(T, SkScalar, fRect.fTop )
- SG_ATTRIBUTE(R, SkScalar, fRect.fRight )
- SG_ATTRIBUTE(B, SkScalar, fRect.fBottom)
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- explicit Rect(const SkRect&);
-
- SkRect fRect;
-
- using INHERITED = GeometryNode;
-};
-
-/**
- * Concrete Geometry node, wrapping an SkRRect.
- */
-class RRect final : public GeometryNode {
-public:
- static sk_sp<RRect> Make() { return sk_sp<RRect>(new RRect(SkRRect())); }
- static sk_sp<RRect> Make(const SkRRect& rr) { return sk_sp<RRect>(new RRect(rr)); }
-
- SG_ATTRIBUTE(RRect, SkRRect, fRRect)
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- explicit RRect(const SkRRect&);
-
- SkRRect fRRect;
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGRect_DEFINED
diff --git a/experimental/sksg/geometry/SkSGRoundEffect.cpp b/experimental/sksg/geometry/SkSGRoundEffect.cpp
deleted file mode 100644
index 8cf9068f65..0000000000
--- a/experimental/sksg/geometry/SkSGRoundEffect.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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 "SkSGRoundEffect.h"
-
-#include "SkCanvas.h"
-#include "SkCornerPathEffect.h"
-#include "SkStrokeRec.h"
-
-namespace sksg {
-
-RoundEffect::RoundEffect(sk_sp<GeometryNode> child)
- : fChild(std::move(child)) {
- this->observeInval(fChild);
-}
-
-RoundEffect::~RoundEffect() {
- this->unobserveInval(fChild);
-}
-
-void RoundEffect::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipPath(fRoundedPath, SkClipOp::kIntersect, antiAlias);
-}
-
-void RoundEffect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- SkASSERT(!paint.getPathEffect());
-
- canvas->drawPath(fRoundedPath, paint);
-}
-
-SkPath RoundEffect::onAsPath() const {
- return fRoundedPath;
-}
-
-SkRect RoundEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- const auto childbounds = fChild->revalidate(ic, ctm);
- const auto path = fChild->asPath();
-
- if (auto round = SkCornerPathEffect::Make(fRadius)) {
- fRoundedPath.reset();
- SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
- SkAssertResult(round->filterPath(&fRoundedPath, path, &rec, &childbounds));
- } else {
- fRoundedPath = path;
- }
-
- return fRoundedPath.computeTightBounds();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGRoundEffect.h b/experimental/sksg/geometry/SkSGRoundEffect.h
deleted file mode 100644
index 67124ca072..0000000000
--- a/experimental/sksg/geometry/SkSGRoundEffect.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 SkSGRoundEffect_DEFINED
-#define SkSGRoundEffect_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPath.h"
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, applying a rounded-corner effect to its child.
- */
-class RoundEffect final : public GeometryNode {
-public:
- static sk_sp<RoundEffect> Make(sk_sp<GeometryNode> child) {
- return child ? sk_sp<RoundEffect>(new RoundEffect(std::move(child))) : nullptr;
- }
-
- ~RoundEffect() override;
-
- SG_ATTRIBUTE(Radius, SkScalar, fRadius)
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- explicit RoundEffect(sk_sp<GeometryNode>);
-
- const sk_sp<GeometryNode> fChild;
-
- SkPath fRoundedPath;
- SkScalar fRadius = 0;
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGRoundEffect_DEFINED
diff --git a/experimental/sksg/geometry/SkSGText.cpp b/experimental/sksg/geometry/SkSGText.cpp
deleted file mode 100644
index c149390023..0000000000
--- a/experimental/sksg/geometry/SkSGText.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 "SkSGText.h"
-
-#include "SkCanvas.h"
-#include "SkPaint.h"
-#include "SkPath.h"
-#include "SkTArray.h"
-#include "SkTextBlob.h"
-#include "SkTypeface.h"
-
-namespace sksg {
-
-sk_sp<Text> Text::Make(sk_sp<SkTypeface> tf, const SkString& text) {
- return sk_sp<Text>(new Text(std::move(tf), text));
-}
-
-Text::Text(sk_sp<SkTypeface> tf, const SkString& text)
- : fTypeface(std::move(tf))
- , fText(text) {}
-
-Text::~Text() = default;
-
-SkRect Text::onRevalidate(InvalidationController*, const SkMatrix&) {
- // TODO: we could potentially track invals which don't require rebuilding the blob.
-
- SkPaint font;
- font.setFlags(fFlags);
- font.setTypeface(fTypeface);
- font.setTextSize(fSize);
- font.setTextScaleX(fScaleX);
- font.setTextSkewX(fSkewX);
- font.setTextAlign(fAlign);
- font.setHinting(fHinting);
-
- // First, convert to glyphIDs.
- font.setTextEncoding(SkPaint::kUTF8_TextEncoding);
- SkSTArray<256, SkGlyphID, true> glyphs;
- glyphs.reset(font.textToGlyphs(fText.c_str(), fText.size(), nullptr));
- SkAssertResult(font.textToGlyphs(fText.c_str(), fText.size(), glyphs.begin()) == glyphs.count());
- font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-
- // Next, build the cached blob.
- SkTextBlobBuilder builder;
- const auto& buf = builder.allocRun(font, glyphs.count(), 0, 0, nullptr);
- if (!buf.glyphs) {
- fBlob.reset();
- return SkRect::MakeEmpty();
- }
-
- memcpy(buf.glyphs, glyphs.begin(), glyphs.count() * sizeof(SkGlyphID));
-
- fBlob = builder.make();
- return fBlob
- ? fBlob->bounds().makeOffset(fPosition.x(), fPosition.y())
- : SkRect::MakeEmpty();
-}
-
-void Text::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- canvas->drawTextBlob(fBlob, fPosition.x(), fPosition.y(), paint);
-}
-
-SkPath Text::onAsPath() const {
- // TODO
- return SkPath();
-}
-
-void Text::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipPath(this->asPath(), antiAlias);
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGText.h b/experimental/sksg/geometry/SkSGText.h
deleted file mode 100644
index eb43337a10..0000000000
--- a/experimental/sksg/geometry/SkSGText.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 SkSGText_DEFINED
-#define SkSGText_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPaintDefaults.h"
-#include "SkPoint.h"
-#include "SkString.h"
-
-class SkCanvas;
-class SkPaint;
-class SkTextBlob;
-class SkTypeface;
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, wrapping a (shaped) SkTextBlob.
- */
-class Text final : public GeometryNode {
-public:
- static sk_sp<Text> Make(sk_sp<SkTypeface> tf, const SkString& text);
- ~Text() override;
-
- SG_ATTRIBUTE(Text , SkString , fText )
- SG_ATTRIBUTE(Flags , uint32_t , fFlags )
- SG_ATTRIBUTE(Position, SkPoint , fPosition)
- SG_ATTRIBUTE(Size , SkScalar , fSize )
- SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX )
- SG_ATTRIBUTE(SkewX , SkScalar , fSkewX )
- SG_ATTRIBUTE(Align , SkPaint::Align, fAlign )
-
- // TODO: add shaping functionality.
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- explicit Text(sk_sp<SkTypeface>, const SkString&);
-
- const sk_sp<SkTypeface> fTypeface;
- SkString fText;
- uint32_t fFlags = SkPaintDefaults_Flags;
- SkPoint fPosition = SkPoint::Make(0, 0);
- SkScalar fSize = SkPaintDefaults_TextSize;
- SkScalar fScaleX = 1;
- SkScalar fSkewX = 0;
- SkPaint::Align fAlign = SkPaint::kLeft_Align;
- SkPaint::Hinting fHinting = SkPaintDefaults_Hinting;
-
- sk_sp<SkTextBlob> fBlob; // cached text blob
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGText_DEFINED
diff --git a/experimental/sksg/geometry/SkSGTrimEffect.cpp b/experimental/sksg/geometry/SkSGTrimEffect.cpp
deleted file mode 100644
index b8c59bcfe8..0000000000
--- a/experimental/sksg/geometry/SkSGTrimEffect.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGTrimEffect.h"
-
-#include "SkCanvas.h"
-#include "SkStrokeRec.h"
-#include "SkTrimPathEffect.h"
-
-namespace sksg {
-
-TrimEffect::TrimEffect(sk_sp<GeometryNode> child)
- : fChild(std::move(child)) {
- this->observeInval(fChild);
-}
-
-TrimEffect::~TrimEffect() {
- this->unobserveInval(fChild);
-}
-
-void TrimEffect::onClip(SkCanvas* canvas, bool antiAlias) const {
- canvas->clipPath(fTrimmedPath, SkClipOp::kIntersect, antiAlias);
-}
-
-void TrimEffect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
- SkASSERT(!paint.getPathEffect());
-
- canvas->drawPath(fTrimmedPath, paint);
-}
-
-SkPath TrimEffect::onAsPath() const {
- return fTrimmedPath;
-}
-
-SkRect TrimEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- SkASSERT(this->hasInval());
-
- const auto childbounds = fChild->revalidate(ic, ctm);
- const auto path = fChild->asPath();
-
- if (auto trim = SkTrimPathEffect::Make(fStart, fStop, fMode)) {
- fTrimmedPath.reset();
- SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
- SkAssertResult(trim->filterPath(&fTrimmedPath, path, &rec, &childbounds));
- } else {
- fTrimmedPath = path;
- }
-
- return fTrimmedPath.computeTightBounds();
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGTrimEffect.h b/experimental/sksg/geometry/SkSGTrimEffect.h
deleted file mode 100644
index 18f15921e7..0000000000
--- a/experimental/sksg/geometry/SkSGTrimEffect.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGTrimEffect_DEFINED
-#define SkSGTrimEffect_DEFINED
-
-#include "SkSGGeometryNode.h"
-
-#include "SkPath.h"
-#include "SkTrimPathEffect.h"
-
-class SkCanvas;
-class SkPaint;
-
-namespace sksg {
-
-/**
- * Concrete Geometry node, applying a trim effect to its child.
- */
-class TrimEffect final : public GeometryNode {
-public:
- static sk_sp<TrimEffect> Make(sk_sp<GeometryNode> child) {
- return child ? sk_sp<TrimEffect>(new TrimEffect(std::move(child))) : nullptr;
- }
-
- ~TrimEffect() override;
-
- SG_ATTRIBUTE(Start , SkScalar , fStart )
- SG_ATTRIBUTE(Stop , SkScalar , fStop )
- SG_ATTRIBUTE(Mode , SkTrimPathEffect::Mode, fMode )
-
-protected:
- void onClip(SkCanvas*, bool antiAlias) const override;
- void onDraw(SkCanvas*, const SkPaint&) const override;
-
- SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
- SkPath onAsPath() const override;
-
-private:
- explicit TrimEffect(sk_sp<GeometryNode>);
-
- const sk_sp<GeometryNode> fChild;
-
- SkPath fTrimmedPath;
- SkScalar fStart = 0,
- fStop = 1;
- SkTrimPathEffect::Mode fMode = SkTrimPathEffect::Mode::kNormal;
-
- using INHERITED = GeometryNode;
-};
-
-} // namespace sksg
-
-#endif // SkSGTrimEffect_DEFINED
diff --git a/experimental/sksg/paint/SkSGColor.cpp b/experimental/sksg/paint/SkSGColor.cpp
deleted file mode 100644
index d5d4d1ce62..0000000000
--- a/experimental/sksg/paint/SkSGColor.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGColor.h"
-
-namespace sksg {
-
-Color::Color(SkColor c) : fColor(c) {}
-
-void Color::onApplyToPaint(SkPaint* paint) const {
- paint->setColor(fColor);
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/paint/SkSGColor.h b/experimental/sksg/paint/SkSGColor.h
deleted file mode 100644
index a19921cfd3..0000000000
--- a/experimental/sksg/paint/SkSGColor.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGColor_DEFINED
-#define SkSGColor_DEFINED
-
-#include "SkSGPaintNode.h"
-
-#include "SkColor.h"
-
-namespace sksg {
-
-/**
- * Concrete Paint node, wrapping an SkColor.
- */
-class Color : public PaintNode {
-public:
- static sk_sp<Color> Make(SkColor c) { return sk_sp<Color>(new Color(c)); }
-
- SG_ATTRIBUTE(Color, SkColor, fColor)
-
-protected:
- void onApplyToPaint(SkPaint*) const override;
-
-private:
- explicit Color(SkColor);
-
- SkColor fColor;
-};
-
-} // namespace sksg
-
-#endif // SkSGColor_DEFINED
diff --git a/experimental/sksg/paint/SkSGGradient.cpp b/experimental/sksg/paint/SkSGGradient.cpp
deleted file mode 100644
index 98e7f395f8..0000000000
--- a/experimental/sksg/paint/SkSGGradient.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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 "SkSGGradient.h"
-
-#include "SkGradientShader.h"
-#include "SkPaint.h"
-
-namespace sksg {
-
-void Gradient::onApplyToPaint(SkPaint* paint) const {
- if (fColorStops.empty()) {
- paint->setShader(nullptr);
- return;
- }
-
- std::vector<SkColor> colors;
- std::vector<SkScalar> positions;
- colors.reserve(fColorStops.size());
- positions.reserve(fColorStops.size());
-
- SkScalar position = 0;
- for (const auto& stop : fColorStops) {
- colors.push_back(stop.fColor);
- position = SkTPin(stop.fPosition, position, 1.0f);
- positions.push_back(position);
- }
-
- // TODO: detect even stop distributions, pass null for positions.
- paint->setShader(this->onMakeShader(colors, positions));
-}
-
-sk_sp<SkShader> LinearGradient::onMakeShader(const std::vector<SkColor>& colors,
- const std::vector<SkScalar>& positions) const {
- SkASSERT(colors.size() == positions.size());
-
- const SkPoint pts[] = { fStartPoint, fEndPoint };
- return SkGradientShader::MakeLinear(pts, colors.data(), positions.data(), colors.size(),
- this->getTileMode());
-}
-
-sk_sp<SkShader> RadialGradient::onMakeShader(const std::vector<SkColor>& colors,
- const std::vector<SkScalar>& positions) const {
- SkASSERT(colors.size() == positions.size());
-
- return (fStartRadius <= 0 && fStartCenter == fEndCenter)
- ? SkGradientShader::MakeRadial(fEndCenter, fEndRadius,
- colors.data(), positions.data(), colors.size(),
- this->getTileMode())
- : SkGradientShader::MakeTwoPointConical(fStartCenter, fStartRadius,
- fEndCenter, fEndRadius,
- colors.data(), positions.data(), colors.size(),
- this->getTileMode());
-}
-
-} //namespace sksg
diff --git a/experimental/sksg/paint/SkSGGradient.h b/experimental/sksg/paint/SkSGGradient.h
deleted file mode 100644
index d69cb1495c..0000000000
--- a/experimental/sksg/paint/SkSGGradient.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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 SkSGGradient_DEFINED
-#define SkSGGradient_DEFINED
-
-#include "SkSGPaintNode.h"
-
-#include "SkColor.h"
-#include "SkPoint.h"
-#include "SkScalar.h"
-#include "SkShader.h"
-
-#include <vector>
-
-namespace sksg {
-
-/**
- * Gradient base class.
- */
-class Gradient : public PaintNode {
-public:
- struct ColorStop {
- SkScalar fPosition;
- SkColor fColor;
-
- bool operator==(const ColorStop& other) const {
- return fPosition == other.fPosition && fColor == other.fColor;
- }
- };
-
- SG_ATTRIBUTE(ColorStops, std::vector<ColorStop>, fColorStops)
- SG_ATTRIBUTE(TileMode , SkShader::TileMode , fTileMode )
-
-protected:
- void onApplyToPaint(SkPaint*) const final;
-
- virtual sk_sp<SkShader> onMakeShader(const std::vector<SkColor>& colors,
- const std::vector<SkScalar>& positions) const = 0;
-
-protected:
- Gradient() = default;
-
-private:
- std::vector<ColorStop> fColorStops;
- SkShader::TileMode fTileMode = SkShader::kClamp_TileMode;
-
- using INHERITED = PaintNode;
-};
-
-class LinearGradient final : public Gradient {
-public:
- static sk_sp<LinearGradient> Make() {
- return sk_sp<LinearGradient>(new LinearGradient());
- }
-
- SG_ATTRIBUTE(StartPoint, SkPoint, fStartPoint)
- SG_ATTRIBUTE(EndPoint , SkPoint, fEndPoint )
-
-protected:
- sk_sp<SkShader> onMakeShader(const std::vector<SkColor>& colors,
- const std::vector<SkScalar>& positions) const override;
-
-private:
- LinearGradient() = default;
-
- SkPoint fStartPoint = SkPoint::Make(0, 0),
- fEndPoint = SkPoint::Make(0, 0);
-
- using INHERITED = Gradient;
-};
-
-class RadialGradient final : public Gradient {
-public:
- static sk_sp<RadialGradient> Make() {
- return sk_sp<RadialGradient>(new RadialGradient());
- }
-
- SG_ATTRIBUTE(StartCenter, SkPoint , fStartCenter)
- SG_ATTRIBUTE(EndCenter , SkPoint , fEndCenter )
- SG_ATTRIBUTE(StartRadius, SkScalar, fStartRadius)
- SG_ATTRIBUTE(EndRadius , SkScalar, fEndRadius )
-
-protected:
- sk_sp<SkShader> onMakeShader(const std::vector<SkColor>& colors,
- const std::vector<SkScalar>& positions) const override;
-
-private:
- RadialGradient() = default;
-
- SkPoint fStartCenter = SkPoint::Make(0, 0),
- fEndCenter = SkPoint::Make(0, 0);
- SkScalar fStartRadius = 0,
- fEndRadius = 0;
-
- using INHERITED = Gradient;
-};
-
-} // namespace sksg
-
-#endif // SkSGGradient_DEFINED