1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
8 static double t1, t2, t3, t4;
9 static unsigned cnt = 0;
11 bool tvgUpdateCmds(tvg::Canvas* canvas)
13 if (!canvas) return false;
15 auto t = ecore_time_get();
17 //Explicitly clear all retained paint nodes.
18 if (canvas->clear() != tvg::Result::Success) {
19 //Logically wrong! Probably, you missed to call sync() before.
24 t2 = ecore_time_get();
26 for (int i = 0; i < COUNT; i++) {
27 auto shape = tvg::Shape::gen();
29 float x = rand() % (WIDTH/2);
30 float y = rand() % (HEIGHT/2);
31 float w = 1 + rand() % (int)(WIDTH * 1.3 / 2);
32 float h = 1 + rand() % (int)(HEIGHT * 1.3 / 2);
34 shape->appendRect(x, y, w, h, 0, 0);
37 auto fill = tvg::LinearGradient::gen();
38 fill->linear(x, y, x + w, y + h);
40 //Gradient Color Stops
41 tvg::Fill::ColorStop colorStops[3];
42 colorStops[0] = {0, uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255};
43 colorStops[1] = {1, uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255};
44 colorStops[2] = {2, uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255};
46 fill->colorStops(colorStops, 3);
47 shape->fill(move(fill));
49 if (canvas->push(move(shape)) != tvg::Result::Success) {
50 //Did you call clear()? Make it sure if canvas is on rendering
55 t3 = ecore_time_get();
61 /************************************************************************/
62 /* Sw Engine Test Code */
63 /************************************************************************/
65 static unique_ptr<tvg::SwCanvas> swCanvas;
67 void tvgSwTest(uint32_t* buffer)
70 swCanvas = tvg::SwCanvas::gen();
71 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
74 Eina_Bool animSwCb(void* data)
76 if (!tvgUpdateCmds(swCanvas.get())) return ECORE_CALLBACK_RENEW;
78 //Drawing task can be performed asynchronously.
79 if (swCanvas->draw() != tvg::Result::Success) return false;
83 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
84 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
86 return ECORE_CALLBACK_RENEW;
89 void drawSwView(void* data, Eo* obj)
91 //Make it guarantee finishing drawing task.
94 t4 = ecore_time_get();
96 printf("[%5d]: total[%fs] = clear[%fs], update[%fs], render[%fs]\n", ++cnt, t4 - t1, t2 - t1, t3 - t2, t4 - t3);
100 /************************************************************************/
101 /* GL Engine Test Code */
102 /************************************************************************/
104 static unique_ptr<tvg::GlCanvas> glCanvas;
106 void initGLview(Evas_Object *obj)
108 static constexpr auto BPP = 4;
111 glCanvas = tvg::GlCanvas::gen();
112 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
115 void drawGLview(Evas_Object *obj)
117 auto gl = elm_glview_gl_api_get(obj);
118 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
119 gl->glClear(GL_COLOR_BUFFER_BIT);
124 Eina_Bool animGlCb(void* data)
126 if (!tvgUpdateCmds(glCanvas.get())) return ECORE_CALLBACK_RENEW;
128 //Drawing task can be performed asynchronously.
131 return ECORE_CALLBACK_RENEW;
135 /************************************************************************/
137 /************************************************************************/
139 int main(int argc, char **argv)
141 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
144 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
147 //Initialize ThorVG Engine
148 if (tvgEngine == tvg::CanvasEngine::Sw) {
149 cout << "tvg engine: software" << endl;
151 cout << "tvg engine: opengl" << endl;
155 auto threads = std::thread::hardware_concurrency();
157 //Initialize ThorVG Engine
158 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
160 elm_init(argc, argv);
162 if (tvgEngine == tvg::CanvasEngine::Sw) {
163 auto view = createSwView();
164 evas_object_image_pixels_get_callback_set(view, drawSwView, nullptr);
165 ecore_animator_add(animSwCb, view);
167 auto view = createGlView();
168 ecore_animator_add(animGlCb, view);
174 //Terminate ThorVG Engine
175 tvg::Initializer::term(tvgEngine);
178 cout << "engine is not supported" << endl;