1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
12 auto shape = tvg::Shape::gen();
13 shape->appendRect(-100, -100, 200, 200, 0, 0);
14 shape->fill(255, 255, 255, 255);
15 canvas->push(move(shape));
18 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
22 //Explicitly clear all retained paint nodes.
23 if (canvas->clear() != tvg::Result::Success) return;
26 auto shape = tvg::Shape::gen();
27 shape->appendRect(-100, -100, 200, 200, (100 * progress), (100 * progress));
28 shape->fill(rand()%255, rand()%255, rand()%255, 255);
29 shape->translate(800 * progress, 800 * progress);
30 shape->scale(1 - 0.75 * progress);
31 shape->rotate(360 * progress);
33 canvas->push(move(shape));
37 /************************************************************************/
38 /* Sw Engine Test Code */
39 /************************************************************************/
41 static unique_ptr<tvg::SwCanvas> swCanvas;
43 void tvgSwTest(uint32_t* buffer)
46 swCanvas = tvg::SwCanvas::gen();
47 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
49 /* Push the shape into the Canvas drawing list
50 When this shape is into the canvas list, the shape could update & prepare
51 internal data asynchronously for coming rendering.
52 Canvas keeps this shape node unless user call canvas->clear() */
53 tvgDrawCmds(swCanvas.get());
56 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
58 tvgUpdateCmds(swCanvas.get(), progress);
61 Eo* img = (Eo*) effect;
62 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
63 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
66 void drawSwView(void* data, Eo* obj)
68 if (swCanvas->draw() == tvg::Result::Success) {
74 /************************************************************************/
75 /* GL Engine Test Code */
76 /************************************************************************/
78 static unique_ptr<tvg::GlCanvas> glCanvas;
80 void initGLview(Evas_Object *obj)
82 static constexpr auto BPP = 4;
85 glCanvas = tvg::GlCanvas::gen();
86 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
88 /* Push the shape into the Canvas drawing list
89 When this shape is into the canvas list, the shape could update & prepare
90 internal data asynchronously for coming rendering.
91 Canvas keeps this shape node unless user call canvas->clear() */
92 tvgDrawCmds(glCanvas.get());
95 void drawGLview(Evas_Object *obj)
97 auto gl = elm_glview_gl_api_get(obj);
98 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
99 gl->glClear(GL_COLOR_BUFFER_BIT);
101 if (glCanvas->draw() == tvg::Result::Success) {
106 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
108 tvgUpdateCmds(glCanvas.get(), progress);
112 /************************************************************************/
114 /************************************************************************/
116 int main(int argc, char **argv)
118 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
121 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
124 //Initialize ThorVG Engine
125 if (tvgEngine == tvg::CanvasEngine::Sw) {
126 cout << "tvg engine: software" << endl;
128 cout << "tvg engine: opengl" << endl;
132 auto threads = std::thread::hardware_concurrency();
134 //Initialize ThorVG Engine
135 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
137 elm_init(argc, argv);
139 Elm_Transit *transit = elm_transit_add();
141 if (tvgEngine == tvg::CanvasEngine::Sw) {
142 auto view = createSwView();
143 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
145 auto view = createGlView();
146 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
149 elm_transit_duration_set(transit, 2);
150 elm_transit_repeat_times_set(transit, -1);
151 elm_transit_auto_reverse_set(transit, EINA_TRUE);
152 elm_transit_go(transit);
157 //Terminate ThorVG Engine
158 tvg::Initializer::term(tvgEngine);
161 cout << "engine is not supported" << endl;