enum class TIZENVG_EXPORT PathCommand { Close, MoveTo, LineTo, CubicTo };
+class RasterMethod;
+
+struct Point
+{
+ float x;
+ float y;
+};
+
/**
* @class PaintNode
{
public:
virtual ~PaintNode() {}
- virtual int update() = 0;
+ virtual int update(RasterMethod* engine) = 0;
};
public:
~ShapeNode();
- int update() noexcept override;
+ int update(RasterMethod* engine) noexcept override;
int appendRect(float x, float y, float w, float h, float radius) noexcept;
int appendCircle(float cx, float cy, float radius) noexcept;
int fill(uint32_t r, uint32_t g, uint32_t b, uint32_t a) noexcept;
int clear() noexcept;
+ int pathCommands(const PathCommand** cmds) noexcept;
+ int pathCoords(const Point** pts) noexcept;
- static std::unique_ptr<ShapeNode> gen();
+ static std::unique_ptr<ShapeNode> gen() noexcept;
_TIZENVG_DECLARE_PRIVATE(ShapeNode);
};
public:
~SceneNode();
- int update() noexcept override;
+ int update(RasterMethod* engine) noexcept override;
int push(std::unique_ptr<ShapeNode> shape) noexcept;
int push(std::unique_ptr<PaintNode> paint) noexcept;
int clear() noexcept;
- int update(PaintNode* node) noexcept;
+ int update() noexcept;
int draw(bool async = true) noexcept;
int sync() noexcept;
+ RasterMethod* engine() noexcept;
int target(uint32_t* buffer, size_t stride, size_t height) noexcept;
int clear() noexcept;
//TODO: Gl Specific methods. Need gl backend configuration methods as well.
+ int update() noexcept;
int draw(bool async = true) noexcept { return 0; }
int sync() noexcept { return 0; }
+ RasterMethod* engine() noexcept;
static std::unique_ptr<GlCanvas> gen() noexcept;
static GlRaster* pInst = nullptr;
-int GlRaster::prepare(ShapeNode *shape)
+void* GlRaster::prepare(ShapeNode* shape, void* data)
{
cout << "GlRaster prepare!!" << endl;
- return 0;
+ return nullptr;
}
class GlRaster : public RasterMethod
{
public:
- int prepare(ShapeNode *shape) override;
+ void* prepare(ShapeNode* shape, void* data) override;
static GlRaster* inst();
static int init();
static int term();
source_file = [
+ 'tvgSwCommon.h',
'tvgSwRaster.h',
'tvgSwRaster.cpp',
+ 'tvgSwShape.cpp',
]
swraster_dep = declare_dependency(
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef _TVG_SW_COMMON_H_
+#define _TVG_SW_COMMON_H_
+
+#include "tvgCommon.h"
+
+using namespace tvg;
+using SwPos = signed long;
+
+struct SwVector
+{
+ SwPos x;
+ SwPos y;
+};
+
+struct SwOutline
+{
+ short* cntrs; /* the contour end points */
+ short cntrsCnt; /* number of contours in glyph */
+ SwVector* pts; /* the outline's points */
+ short ptsCnt; /* number of points in the glyph */
+ char* tags; /* the points flags */
+ int flags; /* outline masks */
+};
+
+struct SwShape
+{
+ SwOutline outline;
+};
+
+bool shapeGenOutline(ShapeNode *shape, SwShape* sdata);
+
+#endif /* _TVG_SW_COMMON_H_ */
#ifndef _TVG_SW_RASTER_CPP_
#define _TVG_SW_RASTER_CPP_
-#include "tvgCommon.h"
+#include "tvgSwCommon.h"
#include "tvgSwRaster.h"
+/************************************************************************/
+/* Internal Class Implementation */
+/************************************************************************/
static SwRaster* pInst = nullptr;
-int SwRaster::prepare(ShapeNode *shape)
+
+void* SwRaster::prepare(ShapeNode *shape, void* data)
{
- cout << "SWRaster prepare!!" << endl;
+ SwShape *sdata = static_cast<SwShape*>(data);
+ if (!sdata) {
+ sdata = static_cast<SwShape*>(calloc(1, sizeof(SwShape)));
+ assert(sdata);
+ }
- return 0;
+ bool closed = shapeGenOutline(shape, sdata);
+
+ return sdata;
}
#ifndef _TVG_SW_RASTER_H_
#define _TVG_SW_RASTER_H_
-namespace tvg
-{
-
class SwRaster : public RasterMethod
{
public:
- int prepare(ShapeNode *shape) override;
+ void* prepare(ShapeNode* shape, void* data) override;
static SwRaster* inst();
static int init();
static int term();
~SwRaster(){};
};
-}
-
#endif /* _TVG_SW_RASTER_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef _TVG_SW_SHAPE_H_
+#define _TVG_SW_SHAPE_H_
+
+#include "tvgSwCommon.h"
+
+static void growOutlineContour(SwShape *sdata, size_t n)
+{
+ sdata->outline.cntrsCnt = n;
+
+ if (n == 0) {
+ free(sdata->outline.cntrs);
+ sdata->outline.cntrs = nullptr;
+ return;
+ }
+ sdata->outline.cntrs = static_cast<short *>(realloc(sdata->outline.cntrs, n * sizeof(short)));
+ assert(sdata->outline.cntrs);
+}
+
+
+static void growOutlinePoint(SwShape *sdata, size_t n)
+{
+ sdata->outline.ptsCnt = n;
+
+ if (n == 0) {
+ free(sdata->outline.pts);
+ sdata->outline.pts = nullptr;
+ free(sdata->outline.tags);
+ sdata->outline.tags = nullptr;
+ return;
+ }
+
+ sdata->outline.pts = static_cast<SwVector *>(realloc(sdata->outline.pts, n * sizeof(SwVector)));
+ assert(sdata->outline.pts);
+ sdata->outline.tags = static_cast<char*>(realloc(sdata->outline.tags, n * sizeof(char)));
+ assert(sdata->outline.tags);
+}
+
+
+static void outlineEnd(SwShape* sdata)
+{
+ //grow contour 1
+}
+
+
+static void outlineMoveTo(SwShape* sdata, const Point* pt)
+{
+ //grow pts 1,
+ //grow contour 1
+}
+
+
+static void outlineLineTo(SwShape* sdata, const Point* pt)
+{
+ //grow pts 1
+}
+
+
+static void outlineCubicTo(SwShape* sdata, const Point* ctrl1, const Point* ctrl2, const Point* pt)
+{
+ //grow pts 3
+}
+
+
+static void outlineClose(SwShape* sdata)
+{
+ //grow pts 1
+}
+
+
+bool shapeGenOutline(ShapeNode *shape, SwShape* sdata)
+{
+ bool closed = false;
+
+ const PathCommand* cmds = nullptr;
+ auto cmdCnt = shape->pathCommands(&cmds);
+
+ const Point* pts = nullptr;
+ shape->pathCoords(&pts);
+
+ //reservation
+ auto outlinePtsCnt = 0;
+ auto outlineCntrsCnt = 0;
+
+ for (auto i = 0; i < cmdCnt; ++i) {
+ switch(*cmds) {
+ case PathCommand::Close: {
+ ++outlinePtsCnt;
+ break;
+ }
+ case PathCommand::MoveTo: {
+ ++outlineCntrsCnt;
+ ++outlinePtsCnt;
+ break;
+ }
+ case PathCommand::LineTo: {
+ ++outlinePtsCnt;
+ break;
+ }
+ case PathCommand::CubicTo: {
+ outlinePtsCnt += 3;
+ break;
+ }
+ }
+ }
+
+ ++outlinePtsCnt; //for close
+
+ growOutlinePoint(sdata, outlinePtsCnt);
+ growOutlineContour(sdata, outlineCntrsCnt);
+
+ //Generate Outlines
+ while (cmdCnt-- > 0) {
+ switch(*cmds) {
+ case PathCommand::Close: {
+ outlineClose(sdata);
+ break;
+ }
+ case PathCommand::MoveTo: {
+ outlineMoveTo(sdata, pts);
+ ++pts;
+ break;
+ }
+ case PathCommand::LineTo: {
+ outlineLineTo(sdata, pts);
+ ++pts;
+ break;
+ }
+ case PathCommand::CubicTo: {
+ outlineCubicTo(sdata, pts, pts + 1, pts + 2);
+ pts += 3;
+ break;
+ }
+ }
+ ++cmds;
+ }
+
+ outlineEnd(sdata);
+
+ return closed;
+}
+
+
+#endif /* _TVG_SW_SHAPE_H_ */
nodes.push_back(node);
- int ret = node->update();
- if (ret) return ret;
-
if (SceneNode *scene = dynamic_cast<SceneNode *>(node)) {
- //TODO:
-
} else if (ShapeNode *shape = dynamic_cast<ShapeNode *>(node)) {
- return raster->prepare(shape);
+ return shape->update(raster);
}
cout << "What type of PaintNode? = " << node << endl;
namespace tvg
{
-struct Point
-{
- float x, y;
-};
-
class RasterMethod
{
public:
virtual ~RasterMethod() {}
- virtual int prepare(ShapeNode *shape) = 0;
+ virtual void* prepare(ShapeNode* shape, void* data) = 0;
};
-
}
-
#endif //_TVG_COMMON_H_
return impl->clear();
}
+
+int GlCanvas::update() noexcept
+{
+ return 0;
+}
+
+
+RasterMethod* GlCanvas::engine() noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl);
+ return impl->raster;
+}
+
#endif /* _TVG_GLCANVAS_CPP_ */
return unique_ptr<SceneNode>(new SceneNode);
}
+
int SceneNode :: push(unique_ptr<ShapeNode> shape) noexcept
{
return 0;
}
-int SceneNode :: update() noexcept
+int SceneNode :: update(RasterMethod* engine) noexcept
{
return 0;
ShapeFill *fill = nullptr;
ShapeStroke *stroke = nullptr;
ShapePath *path = nullptr;
-
uint8_t color[4] = {0, 0, 0, 0}; //r, g, b, a
+ void *edata = nullptr; //engine data
Impl() : path(new ShapePath)
{
-
}
~Impl()
ShapeNode :: ShapeNode() : pImpl(make_unique<Impl>())
{
-
}
}
-unique_ptr<ShapeNode> ShapeNode::gen()
+unique_ptr<ShapeNode> ShapeNode::gen() noexcept
{
return unique_ptr<ShapeNode>(new ShapeNode);
}
-int ShapeNode :: update() noexcept
+int ShapeNode :: update(RasterMethod* engine) noexcept
{
auto impl = pImpl.get();
assert(impl);
- return 0;
+ impl->edata = engine->prepare(this, impl->edata);
+ if (impl->edata) return 0;
+ return - 1;
}
}
-int ShapeNode ::appendCircle(float cx, float cy, float radius) noexcept
+int ShapeNode :: pathCommands(const PathCommand** cmds) noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl && cmds);
+
+ *cmds = impl->path->cmds;
+
+ return impl->path->cmdCnt;
+}
+
+
+int ShapeNode :: pathCoords(const Point** pts) noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl && pts);
+
+ *pts = impl->path->pts;
+
+ return impl->path->ptsCnt;
+}
+
+
+int ShapeNode :: appendCircle(float cx, float cy, float radius) noexcept
{
return 0;
}
return canvas;
}
+
+int SwCanvas::update() noexcept
+{
+ return 0;
+}
+
+
+RasterMethod* SwCanvas::engine() noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl);
+ return impl->raster;
+}
+
#endif /* _TVG_SWCANVAS_CPP_ */