capi: support c interfaces
[platform/core/graphics/tizenvg.git] / src / bindings / capi / tvgCapi.cpp
1 #include <thorvg.h>
2 #include "thorvg_capi.h"
3
4 using namespace std;
5 using namespace tvg;
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 struct _Tvg_Canvas
12 {
13     //Dummy for Direct Casting
14 };
15
16 struct _Tvg_Paint
17 {
18     //Dummy for Direct Casting
19 };
20
21
22 /************************************************************************/
23 /* Engine API                                                           */
24 /************************************************************************/
25
26 TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method) {
27     Result ret = Result::Success;
28
29     if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
30     if (ret != Result::Success) return (Tvg_Result) ret;
31
32     if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
33     return (Tvg_Result) ret;
34 }
35
36
37 TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method) {
38     Result ret = Result::Success;
39
40     if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
41     if (ret != Result::Success) return (Tvg_Result) ret;
42
43     if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
44     return (Tvg_Result) ret;
45 }
46
47 /************************************************************************/
48 /* Canvas API                                                           */
49 /************************************************************************/
50
51 TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create()
52 {
53     return (Tvg_Canvas*) SwCanvas::gen().release();
54 }
55
56
57 TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
58 {
59     delete(canvas);
60     return TVG_RESULT_SUCCESS;
61 }
62
63
64 TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
65 {
66     return (Tvg_Result) reinterpret_cast<SwCanvas*>(canvas)->target(buffer, stride, w, h);
67 }
68
69
70 TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint)
71 {
72     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->push(unique_ptr<Paint>((Paint*)paint));
73 }
74
75
76 TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n)
77 {
78     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->reserve(n);
79 }
80
81
82 TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas)
83 {
84     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->clear();
85 }
86
87
88 TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas)
89 {
90      return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update();
91 }
92
93
94 TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint)
95 {
96     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update((Paint*) paint);
97 }
98
99
100 TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas, unsigned char async)
101 {
102     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->draw(async);
103 }
104
105
106 TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas)
107 {
108     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->sync();
109 }
110
111
112 /************************************************************************/
113 /* Shape API                                                            */
114 /************************************************************************/
115
116 TVG_EXPORT Tvg_Paint* tvg_shape_new()
117 {
118     return (Tvg_Paint*) Shape::gen().release();
119 }
120
121
122 TVG_EXPORT Tvg_Result tvg_shape_del(Tvg_Paint* paint)
123 {
124     delete(paint);
125     return TVG_RESULT_SUCCESS;
126 }
127
128
129 TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint)
130 {
131     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->reset();
132 }
133
134
135 TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y)
136 {
137     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->moveTo(x, y);
138 }
139
140
141 TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y)
142 {
143     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->lineTo(x, y);
144 }
145
146
147 TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y)
148 {
149     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->cubicTo(cx1, cy1, cx2, cy2, x, y);
150 }
151
152
153 TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint)
154 {
155     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->close();
156 }
157
158
159 TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
160 {
161     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendRect(x, y, w, h, rx, ry);
162 }
163
164
165 TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
166 {
167     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendCircle(cx, cy, rx, ry);
168 }
169
170
171 TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt)
172 {
173     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendPath((PathCommand*)cmds, cmdCnt, (Point*)pts, ptsCnt);
174 }
175
176
177 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
178 {
179     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(width);
180 }
181
182
183 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
184 {
185     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(r, g, b, a);
186 }
187
188
189 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt)
190 {
191     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(dashPattern, cnt);
192 }
193
194
195 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap)
196 {
197     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeCap)cap);
198 }
199
200
201 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join)
202 {
203     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeJoin)join);
204 }
205
206
207 TVG_EXPORT Tvg_Result tvg_shape_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
208 {
209     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
210 }
211
212 #ifdef __cplusplus
213 }
214 #endif