/*
- * 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.
- *
+ * 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.
*/
#include <thorvg.h>
//Dummy for Direct Casting
};
+struct _Tvg_Gradient
+{
+ //Dummy for Direct Casting
+};
+
/************************************************************************/
/* Engine API */
/************************************************************************/
-TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method) {
+TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method, unsigned threads) {
Result ret = Result::Success;
- if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
+ if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw, threads);
if (ret != Result::Success) return (Tvg_Result) ret;
- if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
+ if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl, threads);
return (Tvg_Result) ret;
}
TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method) {
Result ret = Result::Success;
- if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
+ if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::term(tvg::CanvasEngine::Sw);
if (ret != Result::Success) return (Tvg_Result) ret;
- if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
+ if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::term(tvg::CanvasEngine::Gl);
return (Tvg_Result) ret;
}
}
-TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
+TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs)
{
- return (Tvg_Result) reinterpret_cast<SwCanvas*>(canvas)->target(buffer, stride, w, h);
+ return (Tvg_Result) reinterpret_cast<SwCanvas*>(canvas)->target(buffer, stride, w, h, static_cast<SwCanvas::Colorspace>(cs));
}
TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas)
{
- return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update();
+ return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update(nullptr);
}
}
-TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas, unsigned char async)
+TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas)
{
- return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->draw(async);
+ return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->draw();
}
/************************************************************************/
-/* Shape API */
+/* Paint API */
/************************************************************************/
-TVG_EXPORT Tvg_Paint* tvg_shape_new()
+TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint)
{
- return (Tvg_Paint*) Shape::gen().release();
+ delete(paint);
+ return TVG_RESULT_SUCCESS;
}
-TVG_EXPORT Tvg_Result tvg_shape_del(Tvg_Paint* paint)
+TVG_EXPORT Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor)
{
- delete(paint);
- return TVG_RESULT_SUCCESS;
+ return (Tvg_Result) reinterpret_cast<Paint*>(paint)->scale(factor);
+}
+
+
+TVG_EXPORT Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree)
+{
+ return (Tvg_Result) reinterpret_cast<Paint*>(paint)->rotate(degree);
+}
+
+
+TVG_EXPORT Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y)
+{
+ return (Tvg_Result) reinterpret_cast<Paint*>(paint)->translate(x, y);
+}
+
+
+TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m)
+{
+ return (Tvg_Result) reinterpret_cast<Paint*>(paint)->transform(*(reinterpret_cast<const Matrix*>(m)));
+}
+
+
+/************************************************************************/
+/* Shape API */
+/************************************************************************/
+
+TVG_EXPORT Tvg_Paint* tvg_shape_new()
+{
+ return (Tvg_Paint*) Shape::gen().release();
}
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendRect(x, y, w, h, rx, ry);
}
+TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie)
+{
+ return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendArc(cx, cy, radius, startAngle, sweep, pie);
+}
TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
{
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
}
-TVG_EXPORT Tvg_Result tvg_shape_scale(Tvg_Paint* paint, float factor)
+
+TVG_EXPORT Tvg_Result tvg_shape_linear_gradient_set(Tvg_Paint* paint, Tvg_Gradient *gradient)
+{
+ return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(unique_ptr<LinearGradient>((LinearGradient*)(gradient)));
+}
+
+
+TVG_EXPORT Tvg_Result tvg_shape_radial_gradient_set(Tvg_Paint* paint, Tvg_Gradient *gradient)
{
- return (Tvg_Result) reinterpret_cast<Shape*>(paint)->scale(factor);
+ return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(unique_ptr<RadialGradient>((RadialGradient*)(gradient)));
}
+
+/************************************************************************/
+/* Picture API */
+/************************************************************************/
+
+TVG_EXPORT Tvg_Paint* tvg_picture_new()
+{
+ return (Tvg_Paint*) Picture::gen().release();
+}
+
+
+TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path)
+{
+ return (Tvg_Result) reinterpret_cast<Picture*>(paint)->load(path);
+}
+
+
+TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(Tvg_Paint* paint, float* x, float* y, float* w, float* h)
+{
+ return (Tvg_Result) reinterpret_cast<Picture*>(paint)->viewbox(x, y, w, h);
+}
+
+
+/************************************************************************/
+/* Gradient API */
+/************************************************************************/
+TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new()
+{
+ return (Tvg_Gradient*)LinearGradient::gen().release();
+}
+
+TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new()
+{
+ return (Tvg_Gradient*)RadialGradient::gen().release();
+
+}
+
+TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad)
+{
+ delete(grad);
+ return TVG_RESULT_SUCCESS;
+}
+
+TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2)
+{
+ return (Tvg_Result) reinterpret_cast<LinearGradient*>(grad)->linear(x1, y1, x2, y2);
+}
+
+TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius)
+{
+ return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
+}
+
+TVG_EXPORT Tvg_Result tvg_gradient_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
+{
+ return (Tvg_Result) reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop*>(color_stop), cnt);
+}
+
+TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
+{
+ return (Tvg_Result) reinterpret_cast<Fill*>(grad)->spread((FillSpread)spread);
+}
+
+
#ifdef __cplusplus
}
-#endif
\ No newline at end of file
+#endif