1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
6 tvg::Shape* pShape = nullptr;
8 void tvgDrawCmds(tvg::Canvas* canvas)
13 auto shape = tvg::Shape::gen();
15 /* Acquire shape pointer to access it again.
16 instead, you should consider not to interrupt this pointer life-cycle. */
19 shape->moveTo(0, -114.5);
20 shape->lineTo(54, -5.5);
21 shape->lineTo(175, 11.5);
22 shape->lineTo(88, 95.5);
23 shape->lineTo(108, 216.5);
24 shape->lineTo(0, 160.5);
25 shape->lineTo(-102, 216.5);
26 shape->lineTo(-87, 96.5);
27 shape->lineTo(-173, 12.5);
28 shape->lineTo(-53, -5.5);
30 shape->fill(0, 0, 255, 255);
32 shape->stroke(255, 255, 255, 255);
33 if (canvas->push(move(shape)) != tvg::Result::Success) return;
36 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
40 /* Update shape directly.
41 You can update only necessary properties of this shape,
42 while retaining other properties. */
45 tvg::Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1};
48 m.e11 = 1 - (progress * 0.5f);
51 m.e22 = 1 + (progress * 2.0f);
54 constexpr auto PI = 3.141592f;
56 auto radian = degree / 180.0f * PI;
57 auto cosVal = cosf(radian);
58 auto sinVal = sinf(radian);
60 auto t11 = m.e11 * cosVal + m.e12 * sinVal;
61 auto t12 = m.e11 * -sinVal + m.e12 * cosVal;
62 auto t21 = m.e21 * cosVal + m.e22 * sinVal;
63 auto t22 = m.e21 * -sinVal + m.e22 * cosVal;
64 auto t13 = m.e31 * cosVal + m.e32 * sinVal;
65 auto t23 = m.e31 * -sinVal + m.e32 * cosVal;
75 m.e13 = progress * 300.0f + 300.0f;
76 m.e23 = progress * -100.0f + 300.0f;
80 //Update shape for drawing (this may work asynchronously)
81 canvas->update(pShape);
85 /************************************************************************/
86 /* Sw Engine Test Code */
87 /************************************************************************/
89 static unique_ptr<tvg::SwCanvas> swCanvas;
91 void tvgSwTest(uint32_t* buffer)
94 swCanvas = tvg::SwCanvas::gen();
95 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
97 /* Push the shape into the Canvas drawing list
98 When this shape is into the canvas list, the shape could update & prepare
99 internal data asynchronously for coming rendering.
100 Canvas keeps this shape node unless user call canvas->clear() */
101 tvgDrawCmds(swCanvas.get());
104 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
106 tvgUpdateCmds(swCanvas.get(), progress);
109 Eo* img = (Eo*) effect;
110 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
111 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
114 void drawSwView(void* data, Eo* obj)
116 if (swCanvas->draw() == tvg::Result::Success) {
122 /************************************************************************/
123 /* GL Engine Test Code */
124 /************************************************************************/
126 static unique_ptr<tvg::GlCanvas> glCanvas;
128 void initGLview(Evas_Object *obj)
130 static constexpr auto BPP = 4;
133 glCanvas = tvg::GlCanvas::gen();
134 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
136 /* Push the shape into the Canvas drawing list
137 When this shape is into the canvas list, the shape could update & prepare
138 internal data asynchronously for coming rendering.
139 Canvas keeps this shape node unless user call canvas->clear() */
140 tvgDrawCmds(glCanvas.get());
143 void drawGLview(Evas_Object *obj)
145 auto gl = elm_glview_gl_api_get(obj);
146 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
147 gl->glClear(GL_COLOR_BUFFER_BIT);
149 if (glCanvas->draw() == tvg::Result::Success) {
154 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
156 tvgUpdateCmds(glCanvas.get(), progress);
160 /************************************************************************/
162 /************************************************************************/
164 int main(int argc, char **argv)
166 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
169 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
172 //Initialize ThorVG Engine
173 if (tvgEngine == tvg::CanvasEngine::Sw) {
174 cout << "tvg engine: software" << endl;
176 cout << "tvg engine: opengl" << endl;
179 //Initialize ThorVG Engine
180 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
182 elm_init(argc, argv);
184 Elm_Transit *transit = elm_transit_add();
186 if (tvgEngine == tvg::CanvasEngine::Sw) {
187 auto view = createSwView();
188 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
190 auto view = createGlView();
191 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
194 elm_transit_duration_set(transit, 2);
195 elm_transit_repeat_times_set(transit, -1);
196 elm_transit_auto_reverse_set(transit, EINA_TRUE);
197 elm_transit_go(transit);
202 //Terminate ThorVG Engine
203 tvg::Initializer::term(tvgEngine);
206 cout << "engine is not supported" << endl;