mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
implement sw engine basic sequence.
Change-Id: Ide27c9b191088109f95e03fcd1c80ad3ecc058cd
This commit is contained in:
parent
02b2d812e4
commit
701b482131
14 changed files with 307 additions and 41 deletions
|
@ -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<ShapeNode> gen();
|
||||
static std::unique_ptr<ShapeNode> 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<ShapeNode> shape) noexcept;
|
||||
|
||||
|
@ -134,9 +144,10 @@ public:
|
|||
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;
|
||||
|
||||
|
@ -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<GlCanvas> gen() noexcept;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
source_file = [
|
||||
'tvgSwCommon.h',
|
||||
'tvgSwRaster.h',
|
||||
'tvgSwRaster.cpp',
|
||||
'tvgSwShape.cpp',
|
||||
]
|
||||
|
||||
swraster_dep = declare_dependency(
|
||||
|
|
48
src/lib/sw_engine/tvgSwCommon.h
Normal file
48
src/lib/sw_engine/tvgSwCommon.h
Normal file
|
@ -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_ */
|
|
@ -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)
|
||||
{
|
||||
cout << "SWRaster prepare!!" << endl;
|
||||
|
||||
return 0;
|
||||
void* SwRaster::prepare(ShapeNode *shape, void* data)
|
||||
{
|
||||
SwShape *sdata = static_cast<SwShape*>(data);
|
||||
if (!sdata) {
|
||||
sdata = static_cast<SwShape*>(calloc(1, sizeof(SwShape)));
|
||||
assert(sdata);
|
||||
}
|
||||
|
||||
bool closed = shapeGenOutline(shape, sdata);
|
||||
|
||||
return sdata;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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_ */
|
||||
|
|
159
src/lib/sw_engine/tvgSwShape.cpp
Normal file
159
src/lib/sw_engine/tvgSwShape.cpp
Normal file
|
@ -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<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_ */
|
|
@ -62,15 +62,10 @@ struct CanvasBase
|
|||
|
||||
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;
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -51,13 +51,14 @@ unique_ptr<SceneNode> SceneNode::gen() noexcept
|
|||
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;
|
||||
|
|
|
@ -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<Impl>())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,18 +78,20 @@ ShapeNode :: ~ShapeNode()
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -104,4 +104,18 @@ unique_ptr<SwCanvas> 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_ */
|
||||
|
|
Loading…
Add table
Reference in a new issue