hide engine() interface of shape that's not friendly one by users.
instead canvas would access shape internal data to update/draw it.
Now Paint cannot update itself but has to request to Canvas for it.
Change-Id: Ibafd0864a65c3c33238789d1a3e06c49c4378349
const A& operator=(const A&) = delete; \
A()
+#define _TIZENVG_DECLARE_ACCESSOR(A) \
+ friend A
+
#define _TIZENVG_DISABLE_CTOR(A) \
A() = delete; \
~A() = delete
public:
virtual ~Paint() {}
- virtual int update(RenderMethod*) = 0;
-
virtual int rotate(float degree) = 0;
virtual int scale(float factor) = 0;
virtual int push(std::unique_ptr<Paint> paint) noexcept;
virtual int clear() noexcept;
virtual int update() noexcept;
+ virtual int update(Paint* paint) noexcept;
virtual int draw(bool async = true) noexcept;
virtual int sync() = 0;
public:
~Shape();
- int update(RenderMethod* engine) noexcept override;
int reset() noexcept;
int moveTo(float x, float y) noexcept;
static std::unique_ptr<Shape> gen() noexcept;
- //FIXME: Ugly... Better design?
- void *engine() noexcept;
-
_TIZENVG_DECLARE_PRIVATE(Shape);
+ _TIZENVG_DECLARE_ACCESSOR(Canvas);
};
public:
~Scene();
- int update(RenderMethod* engine) noexcept override;
int push(std::unique_ptr<Shape> shape) noexcept;
int rotate(float degree) noexcept override;
source_file = [
'tvgCommon.h',
'tvgRenderCommon.h',
- 'tvgEngine.cpp',
'tvgShapePath.h',
+ 'tvgShapeImpl.h',
+ 'tvgEngine.cpp',
'tvgCanvas.cpp',
'tvgSwCanvas.cpp',
'tvgGlCanvas.cpp',
#define _TVG_CANVAS_CPP_
#include "tvgCommon.h"
-
+#include "tvgShapeImpl.h"
/************************************************************************/
/* Internal Class Implementation */
struct Canvas::Impl
{
- vector<Paint*> nodes;
- RenderMethod* renderer;
+ vector<Paint*> paints;
+ RenderMethod* renderer;
Impl(RenderMethod* pRenderer):renderer(pRenderer)
{
renderer->unref();
}
- int reserve(size_t n)
+ int push(unique_ptr<Paint> paint)
{
- nodes.reserve(n);
+ Paint* pPaint = paint.release();
+ assert(pPaint);
+ paints.push_back(pPaint);
- return 0;
+ return update(pPaint);
}
- int push(unique_ptr<Paint> paint)
+ int clear()
{
- Paint* node = paint.release();
- assert(node);
- nodes.push_back(node);
- return node->update(renderer);
+ assert(renderer);
+
+ for (auto paint : paints) {
+ if (auto scene = dynamic_cast<Scene*>(paint)) {
+ cout << "TODO: " << scene << endl;
+ } else if (auto shape = dynamic_cast<Shape*>(paint)) {
+ auto p = shape->pImpl.get();
+ assert(p);
+ if (!p->dispose(*shape, *renderer)) return -1;
+ }
+ delete(paint);
+ }
+ paints.clear();
+
+ return 0;
}
- int clear()
+ int update()
{
assert(renderer);
- for (auto node : nodes) {
- if (Scene* scene = dynamic_cast<Scene*>(node)) {
+ for(auto paint: paints) {
+ if (auto scene = dynamic_cast<Scene*>(paint)) {
cout << "TODO: " << scene << endl;
- } else if (Shape *shape = dynamic_cast<Shape*>(node)) {
- if (!renderer->dispose(*shape, shape->engine())) return -1;
+ } else if (auto shape = dynamic_cast<Shape*>(paint)) {
+ auto p = shape->pImpl.get();
+ assert(p);
+ if (!p->update(*shape, *renderer)) return -1;
}
- delete(node);
}
- nodes.clear();
return 0;
}
- int update()
+ int update(Paint* paint)
{
assert(renderer);
- for(auto node: nodes) {
- if (!node->update(renderer)) return -1;
+ if (auto scene = dynamic_cast<Scene*>(paint)) {
+ cout << "TODO: " << scene << endl;
+ } else if (auto shape = dynamic_cast<Shape*>(paint)) {
+ auto p = shape->pImpl.get();
+ assert(p);
+ if (!p->update(*shape, *renderer)) return -1;
}
return 0;
//Clear render target before drawing
if (!renderer->clear()) return -1;
- for(auto node: nodes) {
- if (Scene* scene = dynamic_cast<Scene*>(node)) {
+ for(auto paint: paints) {
+ if (auto scene = dynamic_cast<Scene*>(paint)) {
cout << "TODO: " << scene << endl;
- } else if (Shape *shape = dynamic_cast<Shape*>(node)) {
- if (!renderer->render(*shape, shape->engine())) return -1;
+ } else if (auto shape = dynamic_cast<Shape*>(paint)) {
+ auto p = shape->pImpl.get();
+ assert(p);
+ if(!p->render(*shape, *renderer)) return -1;
}
}
return 0;
{
auto impl = pImpl.get();
assert(impl);
- return impl->reserve(n);
+ impl->paints.reserve(n);
+ return 0;
}
}
-RenderMethod* Canvas::engine() noexcept
+int Canvas::update(Paint* paint) noexcept
{
auto impl = pImpl.get();
assert(impl);
- return impl->renderer;
+ return impl->update(paint);
}
#endif /* _TVG_CANVAS_CPP_ */
}
-int Scene::update(RenderMethod* engine) noexcept
-{
-
- return 0;
-}
-
-
int Scene::scale(float scaleFacator) noexcept
{
return 0;
#define _TVG_SHAPE_CPP_
#include "tvgCommon.h"
-#include "tvgShapePath.h"
+#include "tvgShapeImpl.h"
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
constexpr auto PATH_KAPPA = 0.552284f;
-struct ShapeFill
-{
-};
-
-
-struct ShapeStroke
-{
-};
-
-
-struct Shape::Impl
-{
- ShapeFill *fill = nullptr;
- ShapeStroke *stroke = nullptr;
- ShapePath *path = nullptr;
- uint8_t color[4] = {0, 0, 0, 0}; //r, g, b, a
- float scale = 1;
- float rotate = 0;
- void *edata = nullptr; //engine data
- size_t flag = RenderUpdateFlag::None;
-
- Impl() : path(new ShapePath)
- {
- }
-
- ~Impl()
- {
- if (path) delete(path);
- if (stroke) delete(stroke);
- if (fill) delete(fill);
- }
-};
-
/************************************************************************/
/* External Class Implementation */
}
-void* Shape::engine() noexcept
-{
- auto impl = pImpl.get();
- assert(impl);
- return impl->edata;
-}
-
-
-int Shape::update(RenderMethod* engine) noexcept
-{
- auto impl = pImpl.get();
- assert(impl);
-
- impl->edata = engine->prepare(*this, impl->edata, static_cast<RenderUpdateFlag>(impl->flag));
- impl->flag = RenderUpdateFlag::None;
- if (impl->edata) return 0;
- return -1;
-}
-
-
int Shape::reset() noexcept
{
auto impl = pImpl.get();
--- /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_SHAPE_IMPL_H_
+#define _TVG_SHAPE_IMPL_H_
+
+#include "tvgCommon.h"
+#include "tvgShapePath.h"
+
+/************************************************************************/
+/* Internal Class Implementation */
+/************************************************************************/
+
+struct ShapeFill
+{
+};
+
+
+struct ShapeStroke
+{
+};
+
+
+struct Shape::Impl
+{
+ ShapeFill *fill = nullptr;
+ ShapeStroke *stroke = nullptr;
+ ShapePath *path = nullptr;
+ uint8_t color[4] = {0, 0, 0, 0}; //r, g, b, a
+ float scale = 1;
+ float rotate = 0;
+ void *edata = nullptr; //engine data
+ size_t flag = RenderUpdateFlag::None;
+
+ Impl() : path(new ShapePath)
+ {
+ }
+
+ ~Impl()
+ {
+ if (path) delete(path);
+ if (stroke) delete(stroke);
+ if (fill) delete(fill);
+ }
+
+ bool dispose(Shape& shape, RenderMethod& renderer)
+ {
+ return renderer.dispose(shape, edata);
+ }
+
+ bool render(Shape& shape, RenderMethod& renderer)
+ {
+ return renderer.render(shape, edata);
+ }
+
+ bool update(Shape& shape, RenderMethod& renderer)
+ {
+ edata = renderer.prepare(shape, edata, static_cast<RenderUpdateFlag>(flag));
+ flag = RenderUpdateFlag::None;
+ if (edata) return true;
+ return false;
+ }
+};
+
+#endif //_TVG_SHAPE_IMPL_H_
\ No newline at end of file
pShape->appendRect(-100 + (800 * progress), -100 + (800 * progress), 200, 200, (100 * progress));
//Update shape for drawing (this may work asynchronously)
- pShape->update(canvas->engine());
+ canvas->update(pShape);
//Draw Next frames
canvas->draw();
pShape->rotate(360 * progress);
//Update shape for drawing (this may work asynchronously)
- pShape->update(canvas->engine());
+ canvas->update(pShape);
//Draw Next frames
canvas->draw();