introduce Canvas class to replace the CanvasBase.
now, SwCanvas, GlCanvas inherits this Canvas for polymorphism
and remove duplicated interfaces.
Change-Id: I65a87e3aa2289d04997930a54aeccd14f57dd73a
{
public:
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);
};
@brief description...
*
*/
-class TIZENVG_EXPORT SwCanvas final
+class TIZENVG_EXPORT SwCanvas final : public Canvas
{
public:
~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 sync() noexcept override;
static std::unique_ptr<SwCanvas> gen(uint32_t* buffer = nullptr, size_t stride = 0, size_t height = 0) noexcept;
_TIZENVG_DECLARE_PRIVATE(SwCanvas);
* @brief description...
*
*/
-class TIZENVG_EXPORT GlCanvas final
+class TIZENVG_EXPORT GlCanvas final : public Canvas
{
public:
~GlCanvas();
- int push(std::unique_ptr<PaintNode> paint) noexcept;
- int clear() noexcept;
-
//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;
_TIZENVG_DECLARE_PRIVATE(GlCanvas);
'tvgCommon.h',
'tvgRenderCommon.h',
'tvgEngine.cpp',
- 'tvgCanvasBase.h',
'tvgShapePath.h',
+ 'tvgCanvas.cpp',
'tvgSwCanvas.cpp',
'tvgGlCanvas.cpp',
'tvgSceneNode.cpp',
--- /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_CANVAS_CPP_
+#define _TVG_CANVAS_CPP_
+
+#include "tvgCommon.h"
+
+
+/************************************************************************/
+/* Internal Class Implementation */
+/************************************************************************/
+
+struct Canvas::Impl
+{
+ vector<PaintNode*> nodes;
+ RenderMethod* renderer;
+
+ Impl(RenderMethod *pRenderer):renderer(pRenderer)
+ {
+ renderer->ref();
+ }
+
+ ~Impl()
+ {
+ clear();
+ renderer->unref();
+ }
+
+ int reserve(size_t n)
+ {
+ nodes.reserve(n);
+
+ return 0;
+ }
+
+ int push(unique_ptr<PaintNode> paint)
+ {
+ PaintNode *node = paint.release();
+ assert(node);
+ nodes.push_back(node);
+ return node->update(renderer);
+ }
+
+ int clear()
+ {
+ assert(renderer);
+
+ auto ret = 0;
+
+ for (auto node : nodes) {
+ if (SceneNode *scene = dynamic_cast<SceneNode *>(node)) {
+ cout << "TODO: " << scene << endl;
+ } else if (ShapeNode *shape = dynamic_cast<ShapeNode *>(node)) {
+ ret |= renderer->dispose(*shape, shape->engine());
+ }
+ delete(node);
+ }
+ nodes.clear();
+
+ return ret;
+ }
+
+ int update()
+ {
+ assert(renderer);
+
+ auto ret = 0;
+
+ for(auto node: nodes) {
+ ret |= node->update(renderer);
+ }
+
+ return ret;
+ }
+
+ int draw()
+ {
+ assert(renderer);
+
+ auto ret = 0;
+
+ for(auto node: nodes) {
+ if (SceneNode *scene = dynamic_cast<SceneNode *>(node)) {
+ cout << "TODO: " << scene << endl;
+ } else if (ShapeNode *shape = dynamic_cast<ShapeNode *>(node)) {
+ ret |= renderer->render(*shape, shape->engine());
+ }
+ }
+ return ret;
+ }
+
+};
+
+
+/************************************************************************/
+/* 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_ */
+++ /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_CANVAS_BASE_CPP_
-#define _TVG_CANVAS_BASE_CPP_
-
-#include "tvgCommon.h"
-
-
-struct CanvasBase
-{
- vector<PaintNode*> nodes;
- RenderMethod* renderer;
-
- CanvasBase(RenderMethod *pRenderer):renderer(pRenderer)
- {
- renderer->ref();
- }
-
- ~CanvasBase()
- {
- clear();
- renderer->unref();
- }
-
- int reserve(size_t n)
- {
- nodes.reserve(n);
-
- return 0;
- }
-
- int clear()
- {
- assert(renderer);
-
- auto ret = 0;
-
- for (auto node : nodes) {
- if (SceneNode *scene = dynamic_cast<SceneNode *>(node)) {
- cout << "TODO: " << scene << endl;
- } else if (ShapeNode *shape = dynamic_cast<ShapeNode *>(node)) {
- ret |= renderer->dispose(*shape, shape->engine());
- }
- delete(node);
- }
- nodes.clear();
-
- return ret;
- }
-
- int update()
- {
- assert(renderer);
-
- auto ret = 0;
-
- for(auto node: nodes) {
- ret |= node->update(renderer);
- }
-
- return ret;
- }
-
- int push(unique_ptr<PaintNode> paint)
- {
- PaintNode *node = paint.release();
- assert(node);
- nodes.push_back(node);
- return node->update(renderer);
- }
-
- int draw()
- {
- assert(renderer);
-
- auto ret = 0;
-
- for(auto node: nodes) {
- if (SceneNode *scene = dynamic_cast<SceneNode *>(node)) {
- cout << "TODO: " << scene << endl;
- } else if (ShapeNode *shape = dynamic_cast<ShapeNode *>(node)) {
- ret |= renderer->render(*shape, shape->engine());
- }
- }
- return ret;
- }
-
-};
-
-#endif /* _TVG_CANVAS_BASE_CPP_ */
#define _TVG_GLCANVAS_CPP_
#include "tvgCommon.h"
-#include "tvgCanvasBase.h"
#include "tvgGlRenderer.h"
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
-struct GlCanvas::Impl : CanvasBase
+struct GlCanvas::Impl
{
- Impl() : CanvasBase(GlRenderer::inst()) {}
+ Impl() {}
};
/* External Class Implementation */
/************************************************************************/
-GlCanvas::GlCanvas() : pImpl(make_unique<Impl>())
+GlCanvas::GlCanvas() : Canvas(GlRenderer::inst()), pImpl(make_unique<Impl>())
{
}
}
-unique_ptr<GlCanvas> GlCanvas::gen() noexcept
-{
- auto canvas = unique_ptr<GlCanvas>(new GlCanvas);
- assert(canvas);
-
- return canvas;
-}
-
-
-int GlCanvas::push(unique_ptr<PaintNode> paint) noexcept
-{
- auto impl = pImpl.get();
- assert(impl);
- return impl->push(move(paint));
-}
-
-int GlCanvas::clear() noexcept
+int GlCanvas::sync() noexcept
{
- auto impl = pImpl.get();
- assert(impl);
- return impl->clear();
+ return 0;
}
-int GlCanvas::update() noexcept
+unique_ptr<GlCanvas> GlCanvas::gen() noexcept
{
- auto impl = pImpl.get();
- assert(impl);
- return impl->update();
-}
-
+ auto canvas = unique_ptr<GlCanvas>(new GlCanvas);
+ assert(canvas);
-RenderMethod* GlCanvas::engine() noexcept
-{
- auto impl = pImpl.get();
- assert(impl);
- return impl->renderer;
+ return canvas;
}
-int GlCanvas::draw(bool async) noexcept
-{
- auto impl = pImpl.get();
- assert(impl);
- return impl->draw();
-}
-
#endif /* _TVG_GLCANVAS_CPP_ */
#define _TVG_SWCANVAS_CPP_
#include "tvgCommon.h"
-#include "tvgCanvasBase.h"
#include "tvgSwRenderer.h"
/* Internal Class Implementation */
/************************************************************************/
-struct SwCanvas::Impl : CanvasBase
+struct SwCanvas::Impl
{
- Impl() : CanvasBase(SwRenderer::inst()) {}
+ Impl() {}
};
/* External Class Implementation */
/************************************************************************/
-int SwCanvas::target(uint32_t* buffer, size_t stride, size_t height) noexcept
-{
- auto impl = pImpl.get();
- assert(impl);
-
- dynamic_cast<SwRenderer*>(impl->renderer)->target(buffer, stride, height);
-
- return 0;
-}
-
-
-int SwCanvas::draw(bool async) noexcept
+SwCanvas::SwCanvas() : Canvas(SwRenderer::inst()), pImpl(make_unique<Impl>())
{
- auto impl = pImpl.get();
- assert(impl);
- return impl->draw();
}
-int SwCanvas::sync() noexcept
-{
- return 0;
-}
-
-
-int SwCanvas::push(unique_ptr<PaintNode> paint) noexcept
+SwCanvas::~SwCanvas()
{
- auto impl = pImpl.get();
- assert(impl);
-
- return impl->push(move(paint));
}
-int SwCanvas::clear() noexcept
+int SwCanvas::target(uint32_t* buffer, size_t stride, size_t height) noexcept
{
- auto impl = pImpl.get();
- assert(impl);
- return impl->clear();
-}
+ auto renderer = dynamic_cast<SwRenderer*>(engine());
+ assert(renderer);
+ if (!renderer->target(buffer, stride, height)) return -1;
-SwCanvas::SwCanvas() : pImpl(make_unique<Impl>())
-{
+ return 0;
}
-SwCanvas::~SwCanvas()
+int SwCanvas::sync() noexcept
{
+ return 0;
}
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_ */