1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
10 auto shape = tvg::Shape::gen();
11 shape->appendRect(-100, -100, 200, 200, 0, 0);
12 shape->fill(255, 255, 255, 255);
13 canvas->push(move(shape));
16 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
18 //Explicitly clear all retained paint nodes.
19 if (canvas->clear() != tvg::Result::Success) return;
22 auto shape = tvg::Shape::gen();
23 shape->appendRect(-100, -100, 200, 200, (100 * progress), (100 * progress));
24 shape->fill(rand()%255, rand()%255, rand()%255, 255);
25 shape->translate(800 * progress, 800 * progress);
26 shape->scale(1 - 0.75 * progress);
27 shape->rotate(360 * progress);
29 canvas->push(move(shape));
33 /************************************************************************/
34 /* Sw Engine Test Code */
35 /************************************************************************/
37 static unique_ptr<tvg::SwCanvas> swCanvas;
39 void tvgSwTest(uint32_t* buffer)
42 swCanvas = tvg::SwCanvas::gen();
43 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
45 /* Push the shape into the Canvas drawing list
46 When this shape is into the canvas list, the shape could update & prepare
47 internal data asynchronously for coming rendering.
48 Canvas keeps this shape node unless user call canvas->clear() */
49 tvgDrawCmds(swCanvas.get());
52 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
54 tvgUpdateCmds(swCanvas.get(), progress);
57 Eo* img = (Eo*) effect;
58 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
59 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
62 void drawSwView(void* data, Eo* obj)
64 if (swCanvas->draw() == tvg::Result::Success) {
70 /************************************************************************/
71 /* GL Engine Test Code */
72 /************************************************************************/
74 static unique_ptr<tvg::GlCanvas> glCanvas;
76 void initGLview(Evas_Object *obj)
78 static constexpr auto BPP = 4;
81 glCanvas = tvg::GlCanvas::gen();
82 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
84 /* Push the shape into the Canvas drawing list
85 When this shape is into the canvas list, the shape could update & prepare
86 internal data asynchronously for coming rendering.
87 Canvas keeps this shape node unless user call canvas->clear() */
88 tvgDrawCmds(glCanvas.get());
91 void drawGLview(Evas_Object *obj)
93 auto gl = elm_glview_gl_api_get(obj);
95 elm_glview_size_get(obj, &w, &h);
96 gl->glViewport(0, 0, w, h);
97 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
98 gl->glClear(GL_COLOR_BUFFER_BIT);
99 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
100 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
101 gl->glEnable(GL_BLEND);
103 if (glCanvas->draw() == tvg::Result::Success) {
108 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
110 tvgUpdateCmds(glCanvas.get(), progress);
114 /************************************************************************/
116 /************************************************************************/
118 int main(int argc, char **argv)
120 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
123 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
126 //Initialize ThorVG Engine
127 if (tvgEngine == tvg::CanvasEngine::Sw) {
128 cout << "tvg engine: software" << endl;
130 cout << "tvg engine: opengl" << endl;
133 //Initialize ThorVG Engine
134 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
136 elm_init(argc, argv);
138 Elm_Transit *transit = elm_transit_add();
140 if (tvgEngine == tvg::CanvasEngine::Sw) {
141 auto view = createSwView();
142 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
144 auto view = createGlView();
145 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
148 elm_transit_duration_set(transit, 2);
149 elm_transit_repeat_times_set(transit, -1);
150 elm_transit_auto_reverse_set(transit, EINA_TRUE);
151 elm_transit_go(transit);
156 //Terminate ThorVG Engine
157 tvg::Initializer::term(tvgEngine);
160 cout << "engine is not supported" << endl;