diff --git a/inc/thorvg.h b/inc/thorvg.h index c6fb0373..efeaab1a 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -92,7 +92,7 @@ public: Result transform(const Matrix& m) noexcept; Result bounds(float* x, float* y, float* w, float* h) const noexcept; - virtual std::unique_ptr duplicate() const noexcept = 0; + std::unique_ptr duplicate() const noexcept; _TVG_DECLARE_ACCESSOR(); _TVG_DECLARE_PRIVATE(Paint); @@ -250,7 +250,6 @@ public: StrokeJoin strokeJoin() const noexcept; static std::unique_ptr gen() noexcept; - std::unique_ptr duplicate() const noexcept override; _TVG_DECLARE_PRIVATE(Shape); }; @@ -274,7 +273,6 @@ public: Result viewbox(float* x, float* y, float* w, float* h) const noexcept; static std::unique_ptr gen() noexcept; - std::unique_ptr duplicate() const noexcept override; _TVG_DECLARE_PRIVATE(Picture); }; @@ -297,7 +295,6 @@ public: Result reserve(uint32_t size) noexcept; static std::unique_ptr gen() noexcept; - std::unique_ptr duplicate() const noexcept override; _TVG_DECLARE_PRIVATE(Scene); }; diff --git a/src/lib/tvgLinearGradient.cpp b/src/lib/tvgLinearGradient.cpp index a76239e3..29837c47 100644 --- a/src/lib/tvgLinearGradient.cpp +++ b/src/lib/tvgLinearGradient.cpp @@ -30,7 +30,6 @@ struct LinearGradient::Impl float x1, y1, x2, y2; }; - /************************************************************************/ /* External Class Implementation */ /************************************************************************/ diff --git a/src/lib/tvgPaint.cpp b/src/lib/tvgPaint.cpp index fbbad597..43edcc73 100644 --- a/src/lib/tvgPaint.cpp +++ b/src/lib/tvgPaint.cpp @@ -72,3 +72,8 @@ Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept if (IMPL->bounds(x, y, w, h)) return Result::Success; return Result::InsufficientCondition; } + +unique_ptr Paint::duplicate() const noexcept +{ + return IMPL->duplicate(); +} \ No newline at end of file diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 709a99ac..0fd3a799 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -32,6 +32,7 @@ namespace tvg 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 duplicate() = 0; }; struct Paint::Impl @@ -144,6 +145,11 @@ namespace tvg { return smethod->render(renderer); } + + unique_ptr duplicate() + { + return smethod->duplicate(); + } }; @@ -174,6 +180,11 @@ namespace tvg { return inst->render(renderer); } + + unique_ptr duplicate() override + { + return inst->duplicate(); + } }; } diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index a3676e07..7c20a372 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -62,11 +62,4 @@ Result Picture::viewbox(float* x, float* y, float* w, float* h) const noexcept { if (IMPL->viewbox(x, y, w, h)) return Result::Success; return Result::InsufficientCondition; -} - - -std::unique_ptr Picture::duplicate() const noexcept -{ - //TODO: implement - return nullptr; -} +} \ No newline at end of file diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index d430de49..e98c6b7b 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -104,6 +104,12 @@ struct Picture::Impl if (!loader->read()) return Result::Unknown; return Result::Success; } + + unique_ptr duplicate() + { + //TODO: + return nullptr; + } }; #endif //_TVG_PICTURE_IMPL_H_ \ No newline at end of file diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index 11ccebbe..df7362fb 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -57,11 +57,4 @@ Result Scene::reserve(uint32_t size) noexcept IMPL->paints.reserve(size); return Result::Success; -} - - -std::unique_ptr Scene::duplicate() const noexcept -{ - //TODO: implement - return nullptr; -} +} \ No newline at end of file diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index 68939c3b..4d305926 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -88,6 +88,12 @@ struct Scene::Impl return true; } + + unique_ptr duplicate() + { + //TODO: + return nullptr; + } }; #endif //_TVG_SCENE_IMPL_H_ \ No newline at end of file diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index 9f5aa0d9..92da1d5e 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -49,14 +49,6 @@ unique_ptr Shape::gen() noexcept } -unique_ptr Shape::duplicate() const noexcept -{ - auto shape = Shape::gen(); - if (!shape->pImpl->duplicate(IMPL)) return nullptr; - return shape; -} - - Result Shape::reset() noexcept { IMPL->path->reset(); diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index d7133c31..2281573d 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -38,6 +38,19 @@ struct ShapeStroke 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(malloc(sizeof(float) * dashCnt)); + memcpy(dashPattern, src->dashPattern, sizeof(float) * dashCnt); + } + ~ShapeStroke() { if (dashPattern) free(dashPattern); @@ -163,42 +176,32 @@ struct Shape::Impl return true; } - bool duplicate(Shape::Impl *src) + unique_ptr duplicate() { + auto ret = Shape::gen(); + if (!ret) return nullptr; + + auto dup = ret.get()->pImpl.get(); + //Color - memcpy(color, src->color, sizeof(color)); - flag = RenderUpdateFlag::Color; + memcpy(dup->color, color, sizeof(color)); + dup->flag = RenderUpdateFlag::Color; - //Copy Path - if (src->path) { - path = new ShapePath(); - if (!path) return false; - *path = *src->path; - - path->cmds = static_cast(malloc(sizeof(PathCommand) * path->reservedCmdCnt)); - if (!path->cmds) return false; - memcpy(path->cmds, src->path->cmds, sizeof(PathCommand) * path->cmdCnt); - - path->pts = static_cast(malloc(sizeof(Point) * path->reservedPtsCnt)); - if (!path->pts) return false; - memcpy(path->pts, src->path->pts, sizeof(Point) * path->ptsCnt); - - 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(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; } }; diff --git a/src/lib/tvgShapePath.h b/src/lib/tvgShapePath.h index 19bbe2f7..f3b1f6e7 100644 --- a/src/lib/tvgShapePath.h +++ b/src/lib/tvgShapePath.h @@ -44,6 +44,27 @@ struct ShapePath if (pts) free(pts); } + ShapePath() {} + + ShapePath(const ShapePath* src) + { + cmdCnt = src->cmdCnt; + reservedCmdCnt = src->reservedCmdCnt; + ptsCnt = src->ptsCnt; + reservedPtsCnt = src->reservedPtsCnt; + + cmds = static_cast(malloc(sizeof(PathCommand) * reservedCmdCnt)); + if (!cmds) return; + memcpy(cmds, src->cmds, sizeof(PathCommand) * cmdCnt); + + pts = static_cast(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;