From: Hermet Park Date: Fri, 3 Apr 2020 07:09:09 +0000 (+0900) Subject: implement sw engine basic sequence. X-Git-Tag: accepted/tizen/unified/20200806.062539~195 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=701b482131d9a6dbc58b08f9633419bb4ced7b0c;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git implement sw engine basic sequence. Change-Id: Ide27c9b191088109f95e03fcd1c80ad3ecc058cd --- diff --git a/inc/tizenvg.h b/inc/tizenvg.h index aeea75f..c9abb03 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -52,6 +52,14 @@ namespace tvg enum class TIZENVG_EXPORT PathCommand { Close, MoveTo, LineTo, CubicTo }; +class RasterMethod; + +struct Point +{ + float x; + float y; +}; + /** * @class PaintNode @@ -65,7 +73,7 @@ class TIZENVG_EXPORT PaintNode { public: virtual ~PaintNode() {} - virtual int update() = 0; + virtual int update(RasterMethod* engine) = 0; }; @@ -82,14 +90,16 @@ class TIZENVG_EXPORT ShapeNode final : public PaintNode 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 gen(); + static std::unique_ptr gen() noexcept; _TIZENVG_DECLARE_PRIVATE(ShapeNode); }; @@ -108,7 +118,7 @@ class TIZENVG_EXPORT SceneNode final : public PaintNode public: ~SceneNode(); - int update() noexcept override; + int update(RasterMethod* engine) noexcept override; int push(std::unique_ptr shape) noexcept; @@ -134,9 +144,10 @@ public: int push(std::unique_ptr 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; @@ -163,8 +174,10 @@ public: 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 gen() noexcept; diff --git a/src/lib/gl_engine/tvgGlRaster.cpp b/src/lib/gl_engine/tvgGlRaster.cpp index eca8c47..f99205b 100644 --- a/src/lib/gl_engine/tvgGlRaster.cpp +++ b/src/lib/gl_engine/tvgGlRaster.cpp @@ -23,11 +23,11 @@ static GlRaster* pInst = nullptr; -int GlRaster::prepare(ShapeNode *shape) +void* GlRaster::prepare(ShapeNode* shape, void* data) { cout << "GlRaster prepare!!" << endl; - return 0; + return nullptr; } diff --git a/src/lib/gl_engine/tvgGlRaster.h b/src/lib/gl_engine/tvgGlRaster.h index 10c4462..f0db8bf 100644 --- a/src/lib/gl_engine/tvgGlRaster.h +++ b/src/lib/gl_engine/tvgGlRaster.h @@ -23,7 +23,7 @@ namespace tvg 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(); diff --git a/src/lib/sw_engine/meson.build b/src/lib/sw_engine/meson.build index 0a29e22..df72f38 100644 --- a/src/lib/sw_engine/meson.build +++ b/src/lib/sw_engine/meson.build @@ -1,6 +1,8 @@ source_file = [ + 'tvgSwCommon.h', 'tvgSwRaster.h', 'tvgSwRaster.cpp', + 'tvgSwShape.cpp', ] swraster_dep = declare_dependency( diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h new file mode 100644 index 0000000..e77c3fa --- /dev/null +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -0,0 +1,48 @@ +/* + * 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_ */ diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp index fa9a845..88f81b2 100644 --- a/src/lib/sw_engine/tvgSwRaster.cpp +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -17,17 +17,27 @@ #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(data); + if (!sdata) { + sdata = static_cast(calloc(1, sizeof(SwShape))); + assert(sdata); + } - return 0; + bool closed = shapeGenOutline(shape, sdata); + + return sdata; } diff --git a/src/lib/sw_engine/tvgSwRaster.h b/src/lib/sw_engine/tvgSwRaster.h index e79f628..e16837e 100644 --- a/src/lib/sw_engine/tvgSwRaster.h +++ b/src/lib/sw_engine/tvgSwRaster.h @@ -17,13 +17,10 @@ #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(); @@ -33,6 +30,4 @@ private: ~SwRaster(){}; }; -} - #endif /* _TVG_SW_RASTER_H_ */ diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp new file mode 100644 index 0000000..f9826e8 --- /dev/null +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -0,0 +1,159 @@ +/* + * 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(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(realloc(sdata->outline.pts, n * sizeof(SwVector))); + assert(sdata->outline.pts); + sdata->outline.tags = static_cast(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_ */ diff --git a/src/lib/tvgCanvasBase.h b/src/lib/tvgCanvasBase.h index 2a4632e..48fd7bd 100644 --- a/src/lib/tvgCanvasBase.h +++ b/src/lib/tvgCanvasBase.h @@ -62,15 +62,10 @@ struct CanvasBase nodes.push_back(node); - int ret = node->update(); - if (ret) return ret; - if (SceneNode *scene = dynamic_cast(node)) { - //TODO: - } else if (ShapeNode *shape = dynamic_cast(node)) { - return raster->prepare(shape); + return shape->update(raster); } cout << "What type of PaintNode? = " << node << endl; diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 0140cc8..5d7f85c 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -28,20 +28,13 @@ using namespace tvg; 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_ diff --git a/src/lib/tvgGlCanvas.cpp b/src/lib/tvgGlCanvas.cpp index 49828ac..66f5448 100644 --- a/src/lib/tvgGlCanvas.cpp +++ b/src/lib/tvgGlCanvas.cpp @@ -69,4 +69,18 @@ int GlCanvas::clear() noexcept 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_ */ diff --git a/src/lib/tvgSceneNode.cpp b/src/lib/tvgSceneNode.cpp index 68ddbc9..7c4bb58 100644 --- a/src/lib/tvgSceneNode.cpp +++ b/src/lib/tvgSceneNode.cpp @@ -51,13 +51,14 @@ unique_ptr SceneNode::gen() noexcept return unique_ptr(new SceneNode); } + int SceneNode :: push(unique_ptr shape) noexcept { return 0; } -int SceneNode :: update() noexcept +int SceneNode :: update(RasterMethod* engine) noexcept { return 0; diff --git a/src/lib/tvgShapeNode.cpp b/src/lib/tvgShapeNode.cpp index 59b40a7..b3726f0 100644 --- a/src/lib/tvgShapeNode.cpp +++ b/src/lib/tvgShapeNode.cpp @@ -46,12 +46,11 @@ struct ShapeNode::Impl 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() @@ -70,7 +69,6 @@ struct ShapeNode::Impl ShapeNode :: ShapeNode() : pImpl(make_unique()) { - } @@ -80,18 +78,20 @@ ShapeNode :: ~ShapeNode() } -unique_ptr ShapeNode::gen() +unique_ptr ShapeNode::gen() noexcept { return unique_ptr(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; } @@ -104,7 +104,29 @@ int ShapeNode :: clear() noexcept } -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; } diff --git a/src/lib/tvgSwCanvas.cpp b/src/lib/tvgSwCanvas.cpp index 00338ef..82da453 100644 --- a/src/lib/tvgSwCanvas.cpp +++ b/src/lib/tvgSwCanvas.cpp @@ -104,4 +104,18 @@ unique_ptr SwCanvas::gen(uint32_t* buffer, size_t stride, size_t heigh 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_ */