1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
6 tvg::Scene* pScene1 = nullptr;
7 tvg::Scene* pScene2 = nullptr;
9 void tvgDrawCmds(tvg::Canvas* canvas)
14 auto scene = tvg::Scene::gen();
15 pScene1 = scene.get();
16 scene->reserve(3); //reserve 3 shape nodes (optional)
18 //Prepare Round Rectangle (Scene1)
19 auto shape1 = tvg::Shape::gen();
20 shape1->appendRect(-235, -250, 400, 400, 50, 50); //x, y, w, h, rx, ry
21 shape1->fill(0, 255, 0, 255); //r, g, b, a
22 shape1->stroke(5); //width
23 shape1->stroke(255, 255, 255, 255); //r, g, b, a
24 scene->push(move(shape1));
26 //Prepare Circle (Scene1)
27 auto shape2 = tvg::Shape::gen();
28 shape2->appendCircle(-165, -150, 200, 200); //cx, cy, radiusW, radiusH
29 shape2->fill(255, 255, 0, 255); //r, g, b, a
30 scene->push(move(shape2));
32 //Prepare Ellipse (Scene1)
33 auto shape3 = tvg::Shape::gen();
34 shape3->appendCircle(265, 250, 150, 100); //cx, cy, radiusW, radiusH
35 shape3->fill(0, 255, 255, 255); //r, g, b, a
36 scene->push(move(shape3));
38 scene->translate(350, 350);
42 auto scene2 = tvg::Scene::gen();
43 pScene2 = scene2.get();
44 scene2->reserve(2); //reserve 2 shape nodes (optional)
47 auto shape4 = tvg::Shape::gen();
50 shape4->moveTo(0, -114.5);
51 shape4->lineTo(54, -5.5);
52 shape4->lineTo(175, 11.5);
53 shape4->lineTo(88, 95.5);
54 shape4->lineTo(108, 216.5);
55 shape4->lineTo(0, 160.5);
56 shape4->lineTo(-102, 216.5);
57 shape4->lineTo(-87, 96.5);
58 shape4->lineTo(-173, 12.5);
59 shape4->lineTo(-53, -5.5);
61 shape4->fill(0, 0, 255, 127);
62 shape4->stroke(3); //width
63 shape4->stroke(0, 0, 255, 255); //r, g, b, a
64 scene2->push(move(shape4));
67 auto shape5 = tvg::Shape::gen();
72 auto halfRadius = radius * 0.552284f;
75 shape5->moveTo(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);
78 shape5->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
79 shape5->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
81 shape5->fill(255, 0, 0, 127);
82 scene2->push(move(shape5));
84 scene2->translate(500, 350);
86 //Push scene2 onto the scene
87 scene->push(move(scene2));
89 //Draw the Scene onto the Canvas
90 canvas->push(move(scene));
93 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
97 /* Update scene directly.
98 You can update only necessary properties of this scene,
99 while retaining other properties. */
101 pScene1->rotate(360 * progress);
102 pScene2->rotate(360 * progress);
104 //Update shape for drawing (this may work asynchronously)
105 canvas->update(pScene1);
109 /************************************************************************/
110 /* Sw Engine Test Code */
111 /************************************************************************/
113 static unique_ptr<tvg::SwCanvas> swCanvas;
115 void tvgSwTest(uint32_t* buffer)
118 swCanvas = tvg::SwCanvas::gen();
119 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
121 /* Push the shape into the Canvas drawing list
122 When this shape is into the canvas list, the shape could update & prepare
123 internal data asynchronously for coming rendering.
124 Canvas keeps this shape node unless user call canvas->clear() */
125 tvgDrawCmds(swCanvas.get());
128 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
130 tvgUpdateCmds(swCanvas.get(), progress);
133 Eo* img = (Eo*) effect;
134 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
135 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
138 void drawSwView(void* data, Eo* obj)
140 if (swCanvas->draw() == tvg::Result::Success) {
146 /************************************************************************/
147 /* GL Engine Test Code */
148 /************************************************************************/
150 static unique_ptr<tvg::GlCanvas> glCanvas;
152 void initGLview(Evas_Object *obj)
154 static constexpr auto BPP = 4;
157 glCanvas = tvg::GlCanvas::gen();
158 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
160 /* Push the shape into the Canvas drawing list
161 When this shape is into the canvas list, the shape could update & prepare
162 internal data asynchronously for coming rendering.
163 Canvas keeps this shape node unless user call canvas->clear() */
164 tvgDrawCmds(glCanvas.get());
167 void drawGLview(Evas_Object *obj)
169 auto gl = elm_glview_gl_api_get(obj);
170 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
171 gl->glClear(GL_COLOR_BUFFER_BIT);
173 if (glCanvas->draw() == tvg::Result::Success) {
178 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
180 tvgUpdateCmds(glCanvas.get(), progress);
184 /************************************************************************/
186 /************************************************************************/
188 int main(int argc, char **argv)
190 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
193 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
196 //Initialize ThorVG Engine
197 if (tvgEngine == tvg::CanvasEngine::Sw) {
198 cout << "tvg engine: software" << endl;
200 cout << "tvg engine: opengl" << endl;
203 //Initialize ThorVG Engine
204 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
206 elm_init(argc, argv);
208 Elm_Transit *transit = elm_transit_add();
210 if (tvgEngine == tvg::CanvasEngine::Sw) {
211 auto view = createSwView();
212 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
214 auto view = createGlView();
215 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
218 elm_transit_duration_set(transit, 2);
219 elm_transit_repeat_times_set(transit, -1);
220 elm_transit_auto_reverse_set(transit, EINA_TRUE);
221 elm_transit_go(transit);
226 //Terminate ThorVG Engine
227 tvg::Initializer::term(tvgEngine);
230 cout << "engine is not supported" << endl;