[skottie,sksg] Improved shape group semantics
* paints also apply to preceding nested geometries
* path effects also apply to preceding nested geometries
TBR=
Change-Id: Ic72f8d032fb5823f506ff688630b786a23219f20
Reviewed-on: https://skia-review.googlesource.com/97222
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/experimental/sksg/geometry/SkSGGeometryTransform.cpp b/experimental/sksg/geometry/SkSGGeometryTransform.cpp
new file mode 100644
index 0000000..14c37d9
--- /dev/null
+++ b/experimental/sksg/geometry/SkSGGeometryTransform.cpp
@@ -0,0 +1,49 @@
+/*
+ * 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)) {
+ fChild->addInvalReceiver(this);
+ fMatrix->addInvalReceiver(this);
+}
+
+GeometryTransform::~GeometryTransform() {
+ fChild->removeInvalReceiver(this);
+ fMatrix->removeInvalReceiver(this);
+}
+
+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;
+}
+
+void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
+ canvas->drawPath(fTransformed, paint);
+}
+
+} // namespace sksg