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<Paint> duplicate() const noexcept;
+ Paint* duplicate() const noexcept;
_TVG_DECLARE_ACCESSOR();
_TVG_DECLARE_PRIVATE(Paint);
uint32_t colorStops(const ColorStop** colorStops) const noexcept;
FillSpread spread() const noexcept;
+ std::unique_ptr<Fill> duplicate() const noexcept;
_TVG_DECALRE_IDENTIFIER();
_TVG_DECLARE_PRIVATE(Fill);
TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint)
{
if (!paint) return NULL;
- return (Tvg_Paint*) reinterpret_cast<Paint*>(paint)->duplicate().release();
+ return (Tvg_Paint*) reinterpret_cast<Paint*>(paint)->duplicate();
}
'tvgCanvasImpl.h',
'tvgCommon.h',
'tvgBezier.h',
+ 'tvgFill.h',
'tvgLoader.h',
'tvgLoaderMgr.h',
'tvgPictureImpl.h',
#ifndef _TVG_CANVAS_IMPL_H_
#define _TVG_CANVAS_IMPL_H_
-#include "tvgCommon.h"
+#include "tvgPaint.h"
/************************************************************************/
/* Internal Class Implementation */
#include "tvgLoader.h"
#include "tvgLoaderMgr.h"
#include "tvgRender.h"
-#include "tvgPaint.h"
#include "tvgTaskScheduler.h"
#endif //_TVG_COMMON_H_
* 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 */
FillSpread Fill::spread() const noexcept
{
return pImpl->spread;
-}
\ No newline at end of file
+}
+
+
+unique_ptr<Fill> Fill::duplicate() const noexcept
+{
+ return pImpl->duplicate();
+}
--- /dev/null
+/*
+ * 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<typename T>
+struct DuplicateMethod
+{
+ virtual ~DuplicateMethod(){}
+ virtual unique_ptr<T> duplicate() = 0;
+};
+
+template<class T>
+struct FillDup : DuplicateMethod<Fill>
+{
+ T* inst = nullptr;
+
+ FillDup(T* _inst) : inst(_inst) {}
+ ~FillDup(){}
+
+ unique_ptr<Fill> duplicate() override
+ {
+ return inst->duplicate();
+ }
+};
+
+struct Fill::Impl
+{
+ ColorStop* colorStops = nullptr;
+ uint32_t cnt = 0;
+ FillSpread spread;
+ DuplicateMethod<Fill>* dup = nullptr;
+
+ ~Impl()
+ {
+ if (dup) delete(dup);
+ if (colorStops) free(colorStops);
+ }
+
+ void method(DuplicateMethod<Fill>* dup)
+ {
+ this->dup = dup;
+ }
+
+ unique_ptr<Fill> duplicate()
+ {
+ auto ret = dup->duplicate();
+ if (!ret) return nullptr;
+
+ ret->pImpl->cnt = cnt;
+ ret->pImpl->spread = spread;
+ ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
+ memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
+
+ return ret;
+ }
+};
+
+#endif //_TVG_FILL_H_
\ No newline at end of file
* 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 */
float y1 = 0;
float x2 = 0;
float y2 = 0;
+
+ unique_ptr<Fill> 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;
+ }
};
/************************************************************************/
LinearGradient::LinearGradient():pImpl(new Impl())
{
_id = FILL_ID_LINEAR;
+ Fill::pImpl->method(new FillDup<LinearGradient::Impl>(pImpl));
}
* 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 */
return Result::InsufficientCondition;
}
-unique_ptr<Paint> Paint::duplicate() const noexcept
+Paint* Paint::duplicate() const noexcept
{
return pImpl->duplicate();
}
\ No newline at end of file
#ifndef _TVG_PAINT_H_
#define _TVG_PAINT_H_
+#include "tvgCommon.h"
+
namespace tvg
{
struct StrategyMethod
return smethod->render(renderer);
}
- unique_ptr<Paint> duplicate()
+ Paint* duplicate()
{
- return smethod->duplicate();
+ return smethod->duplicate().release();
}
};
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+
#include "tvgPictureImpl.h"
/************************************************************************/
#ifndef _TVG_PICTURE_IMPL_H_
#define _TVG_PICTURE_IMPL_H_
-#include "tvgCommon.h"
+#include "tvgPaint.h"
/************************************************************************/
/* Internal Class Implementation */
* 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 */
float cx = 0;
float cy = 0;
float radius = 0;
+
+ unique_ptr<Fill> duplicate()
+ {
+ auto ret = RadialGradient::gen();
+ if (!ret) return nullptr;
+
+ ret->pImpl->cx = cx;
+ ret->pImpl->cy = cy;
+ ret->pImpl->radius = radius;
+
+ return ret;
+ }
};
RadialGradient::RadialGradient():pImpl(new Impl())
{
_id = FILL_ID_RADIAL;
+ Fill::pImpl->method(new FillDup<RadialGradient::Impl>(pImpl));
}
#ifndef _TVG_SCENE_IMPL_H_
#define _TVG_SCENE_IMPL_H_
-#include "tvgCommon.h"
+#include "tvgPaint.h"
/************************************************************************/
/* Internal Class Implementation */
#ifndef _TVG_SHAPE_IMPL_H_
#define _TVG_SHAPE_IMPL_H_
-#include "tvgCommon.h"
+#include "tvgPaint.h"
#include "tvgShapePath.h"
/************************************************************************/
dup->flag |= RenderUpdateFlag::Stroke;
}
- //TODO: Fill
+ if (fill) {
+ dup->fill = fill->duplicate().release();
+ dup->flag |= RenderUpdateFlag::Gradient;
+ }
return ret;
}