revise duplicate() approach with stategy pattern.
Change-Id: Id829e6ed5bad481ed317f036ee82991a01faa1c1
Result transform(const Matrix& m) noexcept;
Result bounds(float* x, float* y, float* w, float* h) const noexcept;
- virtual std::unique_ptr<Paint> duplicate() const noexcept = 0;
+ std::unique_ptr<Paint> duplicate() const noexcept;
_TVG_DECLARE_ACCESSOR();
_TVG_DECLARE_PRIVATE(Paint);
StrokeJoin strokeJoin() const noexcept;
static std::unique_ptr<Shape> gen() noexcept;
- std::unique_ptr<Paint> duplicate() const noexcept override;
_TVG_DECLARE_PRIVATE(Shape);
};
Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
static std::unique_ptr<Picture> gen() noexcept;
- std::unique_ptr<Paint> duplicate() const noexcept override;
_TVG_DECLARE_PRIVATE(Picture);
};
Result reserve(uint32_t size) noexcept;
static std::unique_ptr<Scene> gen() noexcept;
- std::unique_ptr<Paint> duplicate() const noexcept override;
_TVG_DECLARE_PRIVATE(Scene);
};
float x1, y1, x2, y2;
};
-
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
if (IMPL->bounds(x, y, w, h)) return Result::Success;
return Result::InsufficientCondition;
}
+
+unique_ptr<Paint> Paint::duplicate() const noexcept
+{
+ return IMPL->duplicate();
+}
\ No newline at end of file
virtual bool update(RenderMethod& renderer, const RenderTransform* transform, RenderUpdateFlag pFlag) = 0;
virtual bool render(RenderMethod& renderer) = 0;
virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
+ virtual unique_ptr<Paint> duplicate() = 0;
};
struct Paint::Impl
{
return smethod->render(renderer);
}
+
+ unique_ptr<Paint> duplicate()
+ {
+ return smethod->duplicate();
+ }
};
{
return inst->render(renderer);
}
+
+ unique_ptr<Paint> duplicate() override
+ {
+ return inst->duplicate();
+ }
};
}
{
if (IMPL->viewbox(x, y, w, h)) return Result::Success;
return Result::InsufficientCondition;
-}
-
-
-std::unique_ptr<Paint> Picture::duplicate() const noexcept
-{
- //TODO: implement
- return nullptr;
-}
+}
\ No newline at end of file
if (!loader->read()) return Result::Unknown;
return Result::Success;
}
+
+ unique_ptr<Paint> duplicate()
+ {
+ //TODO:
+ return nullptr;
+ }
};
#endif //_TVG_PICTURE_IMPL_H_
\ No newline at end of file
IMPL->paints.reserve(size);
return Result::Success;
-}
-
-
-std::unique_ptr<Paint> Scene::duplicate() const noexcept
-{
- //TODO: implement
- return nullptr;
-}
+}
\ No newline at end of file
return true;
}
+
+ unique_ptr<Paint> duplicate()
+ {
+ //TODO:
+ return nullptr;
+ }
};
#endif //_TVG_SCENE_IMPL_H_
\ No newline at end of file
}
-unique_ptr<Paint> Shape::duplicate() const noexcept
-{
- auto shape = Shape::gen();
- if (!shape->pImpl->duplicate(IMPL)) return nullptr;
- return shape;
-}
-
-
Result Shape::reset() noexcept
{
IMPL->path->reset();
StrokeCap cap = StrokeCap::Square;
StrokeJoin join = StrokeJoin::Bevel;
+ ShapeStroke() {}
+
+ ShapeStroke(const ShapeStroke* src)
+ {
+ width = src->width;
+ dashCnt = src->dashCnt;
+ cap = src->cap;
+ join = src->join;
+ memcpy(color, src->color, sizeof(color));
+ dashPattern = static_cast<float*>(malloc(sizeof(float) * dashCnt));
+ memcpy(dashPattern, src->dashPattern, sizeof(float) * dashCnt);
+ }
+
~ShapeStroke()
{
if (dashPattern) free(dashPattern);
return true;
}
- bool duplicate(Shape::Impl *src)
+ unique_ptr<Paint> duplicate()
{
- //Color
- memcpy(color, src->color, sizeof(color));
- flag = RenderUpdateFlag::Color;
-
- //Copy Path
- if (src->path) {
- path = new ShapePath();
- if (!path) return false;
- *path = *src->path;
+ auto ret = Shape::gen();
+ if (!ret) return nullptr;
- path->cmds = static_cast<PathCommand*>(malloc(sizeof(PathCommand) * path->reservedCmdCnt));
- if (!path->cmds) return false;
- memcpy(path->cmds, src->path->cmds, sizeof(PathCommand) * path->cmdCnt);
+ auto dup = ret.get()->pImpl.get();
- path->pts = static_cast<Point*>(malloc(sizeof(Point) * path->reservedPtsCnt));
- if (!path->pts) return false;
- memcpy(path->pts, src->path->pts, sizeof(Point) * path->ptsCnt);
+ //Color
+ memcpy(dup->color, color, sizeof(color));
+ dup->flag = RenderUpdateFlag::Color;
- flag |= RenderUpdateFlag::Path;
+ //Path
+ if (path) {
+ dup->path = new ShapePath(path);
+ dup->flag |= RenderUpdateFlag::Path;
}
- //Copy Stroke
- if (src->stroke) {
- stroke = new ShapeStroke();
- if (!stroke) return false;
- *stroke = *src->stroke;
- stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * stroke->dashCnt));
- memcpy(stroke->dashPattern, src->stroke->dashPattern, sizeof(float) * stroke->dashCnt);
- flag |= RenderUpdateFlag::Stroke;
+ //Stroke
+ if (stroke) {
+ dup->stroke = new ShapeStroke(stroke);
+ dup->flag |= RenderUpdateFlag::Stroke;
}
- //TODO: Copy Fill
+ //TODO: Fill
- return true;
+ return ret;
}
};
if (pts) free(pts);
}
+ ShapePath() {}
+
+ ShapePath(const ShapePath* src)
+ {
+ cmdCnt = src->cmdCnt;
+ reservedCmdCnt = src->reservedCmdCnt;
+ ptsCnt = src->ptsCnt;
+ reservedPtsCnt = src->reservedPtsCnt;
+
+ cmds = static_cast<PathCommand*>(malloc(sizeof(PathCommand) * reservedCmdCnt));
+ if (!cmds) return;
+ memcpy(cmds, src->cmds, sizeof(PathCommand) * cmdCnt);
+
+ pts = static_cast<Point*>(malloc(sizeof(Point) * reservedPtsCnt));
+ if (!pts) {
+ free(cmds);
+ return;
+ }
+ memcpy(pts, src->pts, sizeof(Point) * ptsCnt);
+ }
+
void reserveCmd(uint32_t cmdCnt)
{
if (cmdCnt <= reservedCmdCnt) return;