1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
6 tvg::Scene* pScene1 = nullptr;
7 tvg::Scene* pScene2 = nullptr;
9 void tvgDrawCmds(tvg::Canvas* canvas)
12 auto scene = tvg::Scene::gen();
13 pScene1 = scene.get();
14 scene->reserve(3); //reserve 3 shape nodes (optional)
16 //Prepare Round Rectangle (Scene1)
17 auto shape1 = tvg::Shape::gen();
18 shape1->appendRect(-235, -250, 400, 400, 50, 50); //x, y, w, h, rx, ry
19 shape1->fill(0, 255, 0, 255); //r, g, b, a
20 shape1->stroke(5); //width
21 shape1->stroke(255, 255, 255, 255); //r, g, b, a
22 scene->push(move(shape1));
24 //Prepare Circle (Scene1)
25 auto shape2 = tvg::Shape::gen();
26 shape2->appendCircle(-165, -150, 200, 200); //cx, cy, radiusW, radiusH
27 shape2->fill(255, 255, 0, 255); //r, g, b, a
28 scene->push(move(shape2));
30 //Prepare Ellipse (Scene1)
31 auto shape3 = tvg::Shape::gen();
32 shape3->appendCircle(265, 250, 150, 100); //cx, cy, radiusW, radiusH
33 shape3->fill(0, 255, 255, 255); //r, g, b, a
34 scene->push(move(shape3));
36 scene->translate(350, 350);
40 auto scene2 = tvg::Scene::gen();
41 pScene2 = scene2.get();
42 scene2->reserve(2); //reserve 2 shape nodes (optional)
45 auto shape4 = tvg::Shape::gen();
48 shape4->moveTo(0, -114.5);
49 shape4->lineTo(54, -5.5);
50 shape4->lineTo(175, 11.5);
51 shape4->lineTo(88, 95.5);
52 shape4->lineTo(108, 216.5);
53 shape4->lineTo(0, 160.5);
54 shape4->lineTo(-102, 216.5);
55 shape4->lineTo(-87, 96.5);
56 shape4->lineTo(-173, 12.5);
57 shape4->lineTo(-53, -5.5);
59 shape4->fill(0, 0, 127, 127);
60 shape4->stroke(3); //width
61 shape4->stroke(0, 0, 255, 255); //r, g, b, a
62 scene2->push(move(shape4));
65 auto shape5 = tvg::Shape::gen();
70 auto halfRadius = radius * 0.552284f;
73 shape5->moveTo(cx, cy - radius);
74 shape5->cubicTo(cx + halfRadius, cy - radius, cx + radius, cy - halfRadius, cx + radius, cy);
75 shape5->cubicTo(cx + radius, cy + halfRadius, cx + halfRadius, cy + radius, cx, cy+ radius);
76 shape5->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
77 shape5->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
79 shape5->fill(127, 0, 0, 127);
80 scene2->push(move(shape5));
82 scene2->translate(500, 350);
84 //Push scene2 onto the scene
85 scene->push(move(scene2));
87 //Draw the Scene onto the Canvas
88 canvas->push(move(scene));
91 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
93 /* Update scene directly.
94 You can update only necessary properties of this scene,
95 while retaining other properties. */
97 pScene1->rotate(360 * progress);
98 pScene2->rotate(360 * progress);
100 //Update shape for drawing (this may work asynchronously)
101 canvas->update(pScene1);
105 /************************************************************************/
106 /* Sw Engine Test Code */
107 /************************************************************************/
109 static unique_ptr<tvg::SwCanvas> swCanvas;
111 void tvgSwTest(uint32_t* buffer)
114 swCanvas = tvg::SwCanvas::gen();
115 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
117 /* Push the shape into the Canvas drawing list
118 When this shape is into the canvas list, the shape could update & prepare
119 internal data asynchronously for coming rendering.
120 Canvas keeps this shape node unless user call canvas->clear() */
121 tvgDrawCmds(swCanvas.get());
124 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
126 tvgUpdateCmds(swCanvas.get(), progress);
129 Eo* img = (Eo*) effect;
130 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
131 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
134 void drawSwView(void* data, Eo* obj)
136 if (swCanvas->draw() == tvg::Result::Success) {
142 /************************************************************************/
143 /* GL Engine Test Code */
144 /************************************************************************/
146 static unique_ptr<tvg::GlCanvas> glCanvas;
148 void initGLview(Evas_Object *obj)
150 static constexpr auto BPP = 4;
153 glCanvas = tvg::GlCanvas::gen();
154 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
156 /* Push the shape into the Canvas drawing list
157 When this shape is into the canvas list, the shape could update & prepare
158 internal data asynchronously for coming rendering.
159 Canvas keeps this shape node unless user call canvas->clear() */
160 tvgDrawCmds(glCanvas.get());
163 void drawGLview(Evas_Object *obj)
165 auto gl = elm_glview_gl_api_get(obj);
166 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
167 gl->glClear(GL_COLOR_BUFFER_BIT);
169 if (glCanvas->draw() == tvg::Result::Success) {
174 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
176 tvgUpdateCmds(glCanvas.get(), progress);
180 /************************************************************************/
182 /************************************************************************/
184 int main(int argc, char **argv)
186 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
189 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
192 //Initialize ThorVG Engine
193 if (tvgEngine == tvg::CanvasEngine::Sw) {
194 cout << "tvg engine: software" << endl;
196 cout << "tvg engine: opengl" << endl;
199 //Initialize ThorVG Engine
200 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
202 elm_init(argc, argv);
204 Elm_Transit *transit = elm_transit_add();
206 if (tvgEngine == tvg::CanvasEngine::Sw) {
207 auto view = createSwView();
208 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
210 auto view = createGlView();
211 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
214 elm_transit_duration_set(transit, 2);
215 elm_transit_repeat_times_set(transit, -1);
216 elm_transit_auto_reverse_set(transit, EINA_TRUE);
217 elm_transit_go(transit);
222 //Terminate ThorVG Engine
223 tvg::Initializer::term(tvgEngine);
226 cout << "engine is not supported" << endl;