From: Hermet Park Date: Mon, 21 Sep 2020 10:20:51 +0000 (+0900) Subject: common fill: implement duplicate() method. X-Git-Tag: accepted/tizen/6.0/unified/20201030.120901~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5272050a828a7a9a87e086bee5cc8467e245836;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git common fill: implement duplicate() method. Change-Id: Ia47a13d4a124d91f84bd5ed755b831ea5c35e3ff --- diff --git a/inc/thorvg.h b/inc/thorvg.h index 7d5062c..e4f45a7 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -91,7 +91,7 @@ public: Result translate(float x, float y) noexcept; Result transform(const Matrix& m) noexcept; Result bounds(float* x, float* y, float* w, float* h) const noexcept; - std::unique_ptr duplicate() const noexcept; + Paint* duplicate() const noexcept; _TVG_DECLARE_ACCESSOR(); _TVG_DECLARE_PRIVATE(Paint); @@ -122,6 +122,7 @@ public: uint32_t colorStops(const ColorStop** colorStops) const noexcept; FillSpread spread() const noexcept; + std::unique_ptr duplicate() const noexcept; _TVG_DECALRE_IDENTIFIER(); _TVG_DECLARE_PRIVATE(Fill); diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 03ee907..b58f0ff 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -166,7 +166,7 @@ TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m) TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint) { if (!paint) return NULL; - return (Tvg_Paint*) reinterpret_cast(paint)->duplicate().release(); + return (Tvg_Paint*) reinterpret_cast(paint)->duplicate(); } diff --git a/src/lib/meson.build b/src/lib/meson.build index bc0d959..0b1b90a 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -14,6 +14,7 @@ source_file = [ 'tvgCanvasImpl.h', 'tvgCommon.h', 'tvgBezier.h', + 'tvgFill.h', 'tvgLoader.h', 'tvgLoaderMgr.h', 'tvgPictureImpl.h', diff --git a/src/lib/tvgCanvasImpl.h b/src/lib/tvgCanvasImpl.h index ebac74d..8131284 100644 --- a/src/lib/tvgCanvasImpl.h +++ b/src/lib/tvgCanvasImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_CANVAS_IMPL_H_ #define _TVG_CANVAS_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 3ed4544..ecacc82 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -46,7 +46,6 @@ using namespace tvg; #include "tvgLoader.h" #include "tvgLoaderMgr.h" #include "tvgRender.h" -#include "tvgPaint.h" #include "tvgTaskScheduler.h" #endif //_TVG_COMMON_H_ diff --git a/src/lib/tvgFill.cpp b/src/lib/tvgFill.cpp index 4594e84..c9d3f1c 100644 --- a/src/lib/tvgFill.cpp +++ b/src/lib/tvgFill.cpp @@ -19,25 +19,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" - +#include "tvgFill.h" /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ -struct Fill::Impl -{ - ColorStop* colorStops = nullptr; - uint32_t cnt = 0; - FillSpread spread; - - ~Impl() - { - if (colorStops) free(colorStops); - } -}; - /************************************************************************/ /* External Class Implementation */ @@ -95,4 +82,10 @@ Result Fill::spread(FillSpread s) noexcept FillSpread Fill::spread() const noexcept { return pImpl->spread; -} \ No newline at end of file +} + + +unique_ptr Fill::duplicate() const noexcept +{ + return pImpl->duplicate(); +} diff --git a/src/lib/tvgFill.h b/src/lib/tvgFill.h new file mode 100644 index 0000000..07af49c --- /dev/null +++ b/src/lib/tvgFill.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef _TVG_FILL_H_ +#define _TVG_FILL_H_ + +#include "tvgCommon.h" + +template +struct DuplicateMethod +{ + virtual ~DuplicateMethod(){} + virtual unique_ptr duplicate() = 0; +}; + +template +struct FillDup : DuplicateMethod +{ + T* inst = nullptr; + + FillDup(T* _inst) : inst(_inst) {} + ~FillDup(){} + + unique_ptr duplicate() override + { + return inst->duplicate(); + } +}; + +struct Fill::Impl +{ + ColorStop* colorStops = nullptr; + uint32_t cnt = 0; + FillSpread spread; + DuplicateMethod* dup = nullptr; + + ~Impl() + { + if (dup) delete(dup); + if (colorStops) free(colorStops); + } + + void method(DuplicateMethod* dup) + { + this->dup = dup; + } + + unique_ptr duplicate() + { + auto ret = dup->duplicate(); + if (!ret) return nullptr; + + ret->pImpl->cnt = cnt; + ret->pImpl->spread = spread; + ret->pImpl->colorStops = static_cast(malloc(sizeof(ColorStop) * cnt)); + memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt); + + return ret; + } +}; + +#endif //_TVG_FILL_H_ \ No newline at end of file diff --git a/src/lib/tvgLinearGradient.cpp b/src/lib/tvgLinearGradient.cpp index 1d67c17..5258b33 100644 --- a/src/lib/tvgLinearGradient.cpp +++ b/src/lib/tvgLinearGradient.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgFill.h" /************************************************************************/ /* Internal Class Implementation */ @@ -31,6 +31,19 @@ struct LinearGradient::Impl float y1 = 0; float x2 = 0; float y2 = 0; + + unique_ptr duplicate() + { + auto ret = LinearGradient::gen(); + if (!ret) return nullptr; + + ret->pImpl->x1 = x1; + ret->pImpl->y1 = y1; + ret->pImpl->x2 = x2; + ret->pImpl->y2 = y2; + + return ret; + } }; /************************************************************************/ @@ -40,6 +53,7 @@ struct LinearGradient::Impl LinearGradient::LinearGradient():pImpl(new Impl()) { _id = FILL_ID_LINEAR; + Fill::pImpl->method(new FillDup(pImpl)); } diff --git a/src/lib/tvgPaint.cpp b/src/lib/tvgPaint.cpp index 55e0d75..7c490ba 100644 --- a/src/lib/tvgPaint.cpp +++ b/src/lib/tvgPaint.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ @@ -74,7 +74,7 @@ Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept return Result::InsufficientCondition; } -unique_ptr Paint::duplicate() const noexcept +Paint* Paint::duplicate() const noexcept { return pImpl->duplicate(); } \ No newline at end of file diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 0fd3a79..63c0849 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -22,6 +22,8 @@ #ifndef _TVG_PAINT_H_ #define _TVG_PAINT_H_ +#include "tvgCommon.h" + namespace tvg { struct StrategyMethod @@ -146,9 +148,9 @@ namespace tvg return smethod->render(renderer); } - unique_ptr duplicate() + Paint* duplicate() { - return smethod->duplicate(); + return smethod->duplicate().release(); } }; diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index a4ac3ee..0860ff4 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -19,6 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + #include "tvgPictureImpl.h" /************************************************************************/ diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index e96384d..b1e4fb1 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_PICTURE_IMPL_H_ #define _TVG_PICTURE_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgRadialGradient.cpp b/src/lib/tvgRadialGradient.cpp index d91ebba..d02d2e0 100644 --- a/src/lib/tvgRadialGradient.cpp +++ b/src/lib/tvgRadialGradient.cpp @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "tvgCommon.h" +#include "tvgFill.h" /************************************************************************/ /* Internal Class Implementation */ @@ -30,6 +30,18 @@ struct RadialGradient::Impl float cx = 0; float cy = 0; float radius = 0; + + unique_ptr duplicate() + { + auto ret = RadialGradient::gen(); + if (!ret) return nullptr; + + ret->pImpl->cx = cx; + ret->pImpl->cy = cy; + ret->pImpl->radius = radius; + + return ret; + } }; @@ -40,6 +52,7 @@ struct RadialGradient::Impl RadialGradient::RadialGradient():pImpl(new Impl()) { _id = FILL_ID_RADIAL; + Fill::pImpl->method(new FillDup(pImpl)); } diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index b1b2898..00f2ccc 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_SCENE_IMPL_H_ #define _TVG_SCENE_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" /************************************************************************/ /* Internal Class Implementation */ diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index d9481a2..5186003 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -22,7 +22,7 @@ #ifndef _TVG_SHAPE_IMPL_H_ #define _TVG_SHAPE_IMPL_H_ -#include "tvgCommon.h" +#include "tvgPaint.h" #include "tvgShapePath.h" /************************************************************************/ @@ -199,7 +199,10 @@ struct Shape::Impl dup->flag |= RenderUpdateFlag::Stroke; } - //TODO: Fill + if (fill) { + dup->fill = fill->duplicate().release(); + dup->flag |= RenderUpdateFlag::Gradient; + } return ret; }