mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
common: code refactoring.
introduce Canvas class to replace the CanvasBase. now, SwCanvas, GlCanvas inherits this Canvas for polymorphism and remove duplicated interfaces. Change-Id: I65a87e3aa2289d04997930a54aeccd14f57dd73a
This commit is contained in:
parent
6be53b0779
commit
0e6faa9276
5 changed files with 136 additions and 140 deletions
|
@ -72,7 +72,33 @@ class TIZENVG_EXPORT PaintNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~PaintNode() {}
|
virtual ~PaintNode() {}
|
||||||
virtual int update(RenderMethod* engine) = 0;
|
virtual int update(RenderMethod*) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class Canvas
|
||||||
|
*
|
||||||
|
* @ingroup TizenVG
|
||||||
|
*
|
||||||
|
* @brief description...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class TIZENVG_EXPORT Canvas
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Canvas(RenderMethod*);
|
||||||
|
virtual ~Canvas();
|
||||||
|
|
||||||
|
virtual int push(std::unique_ptr<PaintNode> paint) noexcept;
|
||||||
|
virtual int clear() noexcept;
|
||||||
|
virtual int update() noexcept;
|
||||||
|
virtual int draw(bool async = true) noexcept;
|
||||||
|
virtual int sync() = 0;
|
||||||
|
|
||||||
|
RenderMethod* engine() noexcept;
|
||||||
|
|
||||||
|
_TIZENVG_DECLARE_PRIVATE(Canvas);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,21 +167,13 @@ public:
|
||||||
@brief description...
|
@brief description...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class TIZENVG_EXPORT SwCanvas final
|
class TIZENVG_EXPORT SwCanvas final : public Canvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~SwCanvas();
|
~SwCanvas();
|
||||||
|
|
||||||
int push(std::unique_ptr<PaintNode> paint) noexcept;
|
|
||||||
int clear() noexcept;
|
|
||||||
|
|
||||||
int update() noexcept;
|
|
||||||
int draw(bool async = true) noexcept;
|
|
||||||
int sync() noexcept;
|
|
||||||
RenderMethod* engine() noexcept;
|
|
||||||
|
|
||||||
int target(uint32_t* buffer, size_t stride, size_t height) noexcept;
|
int target(uint32_t* buffer, size_t stride, size_t height) noexcept;
|
||||||
|
int sync() noexcept override;
|
||||||
static std::unique_ptr<SwCanvas> gen(uint32_t* buffer = nullptr, size_t stride = 0, size_t height = 0) noexcept;
|
static std::unique_ptr<SwCanvas> gen(uint32_t* buffer = nullptr, size_t stride = 0, size_t height = 0) noexcept;
|
||||||
|
|
||||||
_TIZENVG_DECLARE_PRIVATE(SwCanvas);
|
_TIZENVG_DECLARE_PRIVATE(SwCanvas);
|
||||||
|
@ -170,20 +188,14 @@ public:
|
||||||
* @brief description...
|
* @brief description...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class TIZENVG_EXPORT GlCanvas final
|
class TIZENVG_EXPORT GlCanvas final : public Canvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~GlCanvas();
|
~GlCanvas();
|
||||||
|
|
||||||
int push(std::unique_ptr<PaintNode> paint) noexcept;
|
|
||||||
int clear() noexcept;
|
|
||||||
|
|
||||||
//TODO: Gl Specific methods. Need gl backend configuration methods as well.
|
//TODO: Gl Specific methods. Need gl backend configuration methods as well.
|
||||||
int update() noexcept;
|
|
||||||
int draw(bool async = true) noexcept;
|
|
||||||
int sync() noexcept { return 0; }
|
|
||||||
RenderMethod* engine() noexcept;
|
|
||||||
|
|
||||||
|
int sync() noexcept override;
|
||||||
static std::unique_ptr<GlCanvas> gen() noexcept;
|
static std::unique_ptr<GlCanvas> gen() noexcept;
|
||||||
|
|
||||||
_TIZENVG_DECLARE_PRIVATE(GlCanvas);
|
_TIZENVG_DECLARE_PRIVATE(GlCanvas);
|
||||||
|
|
|
@ -5,8 +5,8 @@ source_file = [
|
||||||
'tvgCommon.h',
|
'tvgCommon.h',
|
||||||
'tvgRenderCommon.h',
|
'tvgRenderCommon.h',
|
||||||
'tvgEngine.cpp',
|
'tvgEngine.cpp',
|
||||||
'tvgCanvasBase.h',
|
|
||||||
'tvgShapePath.h',
|
'tvgShapePath.h',
|
||||||
|
'tvgCanvas.cpp',
|
||||||
'tvgSwCanvas.cpp',
|
'tvgSwCanvas.cpp',
|
||||||
'tvgGlCanvas.cpp',
|
'tvgGlCanvas.cpp',
|
||||||
'tvgSceneNode.cpp',
|
'tvgSceneNode.cpp',
|
||||||
|
|
|
@ -14,23 +14,27 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef _TVG_CANVAS_BASE_CPP_
|
#ifndef _TVG_CANVAS_CPP_
|
||||||
#define _TVG_CANVAS_BASE_CPP_
|
#define _TVG_CANVAS_CPP_
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
|
|
||||||
|
|
||||||
struct CanvasBase
|
/************************************************************************/
|
||||||
|
/* Internal Class Implementation */
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
struct Canvas::Impl
|
||||||
{
|
{
|
||||||
vector<PaintNode*> nodes;
|
vector<PaintNode*> nodes;
|
||||||
RenderMethod* renderer;
|
RenderMethod* renderer;
|
||||||
|
|
||||||
CanvasBase(RenderMethod *pRenderer):renderer(pRenderer)
|
Impl(RenderMethod *pRenderer):renderer(pRenderer)
|
||||||
{
|
{
|
||||||
renderer->ref();
|
renderer->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
~CanvasBase()
|
~Impl()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
renderer->unref();
|
renderer->unref();
|
||||||
|
@ -43,6 +47,14 @@ struct CanvasBase
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int push(unique_ptr<PaintNode> paint)
|
||||||
|
{
|
||||||
|
PaintNode *node = paint.release();
|
||||||
|
assert(node);
|
||||||
|
nodes.push_back(node);
|
||||||
|
return node->update(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
int clear()
|
int clear()
|
||||||
{
|
{
|
||||||
assert(renderer);
|
assert(renderer);
|
||||||
|
@ -75,14 +87,6 @@ struct CanvasBase
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int push(unique_ptr<PaintNode> paint)
|
|
||||||
{
|
|
||||||
PaintNode *node = paint.release();
|
|
||||||
assert(node);
|
|
||||||
nodes.push_back(node);
|
|
||||||
return node->update(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
int draw()
|
int draw()
|
||||||
{
|
{
|
||||||
assert(renderer);
|
assert(renderer);
|
||||||
|
@ -101,4 +105,59 @@ struct CanvasBase
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _TVG_CANVAS_BASE_CPP_ */
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* External Class Implementation */
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
Canvas::Canvas(RenderMethod *pRenderer):pImpl(make_unique<Impl>(pRenderer))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Canvas::~Canvas()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Canvas::push(unique_ptr<PaintNode> paint) noexcept
|
||||||
|
{
|
||||||
|
auto impl = pImpl.get();
|
||||||
|
assert(impl);
|
||||||
|
|
||||||
|
return impl->push(move(paint));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Canvas::clear() noexcept
|
||||||
|
{
|
||||||
|
auto impl = pImpl.get();
|
||||||
|
assert(impl);
|
||||||
|
return impl->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Canvas::draw(bool async) noexcept
|
||||||
|
{
|
||||||
|
auto impl = pImpl.get();
|
||||||
|
assert(impl);
|
||||||
|
return impl->draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Canvas::update() noexcept
|
||||||
|
{
|
||||||
|
auto impl = pImpl.get();
|
||||||
|
assert(impl);
|
||||||
|
return impl->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RenderMethod* Canvas::engine() noexcept
|
||||||
|
{
|
||||||
|
auto impl = pImpl.get();
|
||||||
|
assert(impl);
|
||||||
|
return impl->renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _TVG_CANVAS_CPP_ */
|
|
@ -18,16 +18,15 @@
|
||||||
#define _TVG_GLCANVAS_CPP_
|
#define _TVG_GLCANVAS_CPP_
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgCanvasBase.h"
|
|
||||||
#include "tvgGlRenderer.h"
|
#include "tvgGlRenderer.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
struct GlCanvas::Impl : CanvasBase
|
struct GlCanvas::Impl
|
||||||
{
|
{
|
||||||
Impl() : CanvasBase(GlRenderer::inst()) {}
|
Impl() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ struct GlCanvas::Impl : CanvasBase
|
||||||
/* External Class Implementation */
|
/* External Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
GlCanvas::GlCanvas() : pImpl(make_unique<Impl>())
|
GlCanvas::GlCanvas() : Canvas(GlRenderer::inst()), pImpl(make_unique<Impl>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +44,12 @@ GlCanvas::~GlCanvas()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GlCanvas::sync() noexcept
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unique_ptr<GlCanvas> GlCanvas::gen() noexcept
|
unique_ptr<GlCanvas> GlCanvas::gen() noexcept
|
||||||
{
|
{
|
||||||
auto canvas = unique_ptr<GlCanvas>(new GlCanvas);
|
auto canvas = unique_ptr<GlCanvas>(new GlCanvas);
|
||||||
|
@ -54,42 +59,4 @@ unique_ptr<GlCanvas> GlCanvas::gen() noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int GlCanvas::push(unique_ptr<PaintNode> paint) noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->push(move(paint));
|
|
||||||
}
|
|
||||||
|
|
||||||
int GlCanvas::clear() noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int GlCanvas::update() noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
RenderMethod* GlCanvas::engine() noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int GlCanvas::draw(bool async) noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _TVG_GLCANVAS_CPP_ */
|
#endif /* _TVG_GLCANVAS_CPP_ */
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#define _TVG_SWCANVAS_CPP_
|
#define _TVG_SWCANVAS_CPP_
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgCanvasBase.h"
|
|
||||||
#include "tvgSwRenderer.h"
|
#include "tvgSwRenderer.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,9 +25,9 @@
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
struct SwCanvas::Impl : CanvasBase
|
struct SwCanvas::Impl
|
||||||
{
|
{
|
||||||
Impl() : CanvasBase(SwRenderer::inst()) {}
|
Impl() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,49 +35,7 @@ struct SwCanvas::Impl : CanvasBase
|
||||||
/* External Class Implementation */
|
/* External Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
int SwCanvas::target(uint32_t* buffer, size_t stride, size_t height) noexcept
|
SwCanvas::SwCanvas() : Canvas(SwRenderer::inst()), pImpl(make_unique<Impl>())
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
|
|
||||||
dynamic_cast<SwRenderer*>(impl->renderer)->target(buffer, stride, height);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int SwCanvas::draw(bool async) noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int SwCanvas::sync() noexcept
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int SwCanvas::push(unique_ptr<PaintNode> paint) noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
|
|
||||||
return impl->push(move(paint));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int SwCanvas::clear() noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SwCanvas::SwCanvas() : pImpl(make_unique<Impl>())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +45,23 @@ SwCanvas::~SwCanvas()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SwCanvas::target(uint32_t* buffer, size_t stride, size_t height) noexcept
|
||||||
|
{
|
||||||
|
auto renderer = dynamic_cast<SwRenderer*>(engine());
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
|
if (!renderer->target(buffer, stride, height)) return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SwCanvas::sync() noexcept
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unique_ptr<SwCanvas> SwCanvas::gen(uint32_t* buffer, size_t stride, size_t height) noexcept
|
unique_ptr<SwCanvas> SwCanvas::gen(uint32_t* buffer, size_t stride, size_t height) noexcept
|
||||||
{
|
{
|
||||||
auto canvas = unique_ptr<SwCanvas>(new SwCanvas);
|
auto canvas = unique_ptr<SwCanvas>(new SwCanvas);
|
||||||
|
@ -99,20 +73,4 @@ unique_ptr<SwCanvas> SwCanvas::gen(uint32_t* buffer, size_t stride, size_t heigh
|
||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SwCanvas::update() noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
RenderMethod* SwCanvas::engine() noexcept
|
|
||||||
{
|
|
||||||
auto impl = pImpl.get();
|
|
||||||
assert(impl);
|
|
||||||
return impl->renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _TVG_SWCANVAS_CPP_ */
|
#endif /* _TVG_SWCANVAS_CPP_ */
|
||||||
|
|
Loading…
Add table
Reference in a new issue