starter sample for playing with SG.
will flesh out more over time.
Bug: skia:
Change-Id: If5eaf0a7c404b9209b93871eb3ac3d74da8c65dd
Reviewed-on: https://skia-review.googlesource.com/c/191003
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index bfad8d5..f56e407 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1723,6 +1723,7 @@
":experimental_svg_model",
":flags",
":xml",
+ "modules/sksg",
"modules/skshaper",
]
diff --git a/gn/samples.gni b/gn/samples.gni
index 05862d2..d1b7904 100644
--- a/gn/samples.gni
+++ b/gn/samples.gni
@@ -76,6 +76,7 @@
"$_samplecode/SampleRectanizer.cpp",
"$_samplecode/SampleRegion.cpp",
"$_samplecode/SampleRepeatTile.cpp",
+ "$_samplecode/SampleSG.cpp",
"$_samplecode/SampleShaders.cpp",
"$_samplecode/SampleShadowColor.cpp",
"$_samplecode/SampleShadowReference.cpp",
diff --git a/modules/sksg/include/SkSGDraw.h b/modules/sksg/include/SkSGDraw.h
index 570ba72..3aff62d 100644
--- a/modules/sksg/include/SkSGDraw.h
+++ b/modules/sksg/include/SkSGDraw.h
@@ -8,13 +8,12 @@
#ifndef SkSGDraw_DEFINED
#define SkSGDraw_DEFINED
+#include "SkSGGeometryNode.h"
+#include "SkSGPaintNode.h"
#include "SkSGRenderNode.h"
namespace sksg {
-class GeometryNode;
-class PaintNode;
-
/**
* Concrete rendering node.
*
diff --git a/samplecode/SampleSG.cpp b/samplecode/SampleSG.cpp
new file mode 100644
index 0000000..186f8c0
--- /dev/null
+++ b/samplecode/SampleSG.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2019 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Sample.h"
+#include "SkCanvas.h"
+#include "SkFont.h"
+#include "SkFontMetrics.h"
+#include "SkPath.h"
+
+#include "SkSGDraw.h"
+#include "SkSGColor.h"
+#include "SkSGGroup.h"
+#include "SkSGRect.h"
+#include "SkSGScene.h"
+
+class SampleSG : public Sample {
+ sk_sp<sksg::Group> fGroup;
+ std::unique_ptr<sksg::Scene> fScene;
+public:
+ SampleSG() {
+ fGroup = sksg::Group::Make();
+
+ fScene = sksg::Scene::Make(fGroup, sksg::AnimatorList());
+
+ auto r = sksg::Rect::Make({20, 20, 400, 300});
+ auto p = sksg::Color::Make(SK_ColorRED);
+ auto d = sksg::Draw::Make(r, p);
+ fGroup->addChild(d);
+
+ r = sksg::Rect::Make({60, 70, 300, 400});
+ p = sksg::Color::Make(SK_ColorBLUE);
+ d = sksg::Draw::Make(r, p);
+ fGroup->addChild(d);
+ }
+
+protected:
+ bool onQuery(Sample::Event* evt) override {
+ if (Sample::TitleQ(*evt)) {
+ Sample::TitleR(evt, "SceneGraph");
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ void onDrawContent(SkCanvas* canvas) override {
+ fScene->render(canvas);
+ }
+
+ virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y,
+ unsigned modi) override {
+ return this->INHERITED::onFindClickHandler(x, y, modi);
+ }
+
+ bool onClick(Click* click) override {
+ return false;
+ }
+
+private:
+
+ typedef Sample INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_SAMPLE( return new SampleSG(); )