1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
6 tvg::Shape* pShape = nullptr;
8 void tvgDrawCmds(tvg::Canvas* canvas)
13 auto bg = tvg::Shape::gen();
14 bg->appendRect(0, 0, WIDTH, HEIGHT, 0, 0);
16 //fill property will be retained
17 bg->fill(255, 255, 255, 255);
19 if (canvas->push(move(bg)) != tvg::Result::Success) return;
22 auto shape = tvg::Shape::gen();
24 /* Acquire shape pointer to access it again.
25 instead, you should consider not to interrupt this pointer life-cycle. */
28 shape->appendRect(-100, -100, 200, 200, 0, 0);
30 //fill property will be retained
31 shape->fill(127, 255, 255, 255);
32 shape->stroke(0, 0, 255, 255);
35 if (canvas->push(move(shape)) != tvg::Result::Success) return;
38 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
42 /* Update shape directly.
43 You can update only necessary properties of this shape,
44 while retaining other properties. */
47 if (pShape->reset() == tvg::Result::Success) {
48 pShape->appendRect(-100 + (800 * progress), -100 + (800 * progress), 200, 200, (100 * progress), (100 * progress));
49 pShape->stroke(30 * progress);
51 //Update shape for drawing (this may work asynchronously)
52 canvas->update(pShape);
57 /************************************************************************/
58 /* Sw Engine Test Code */
59 /************************************************************************/
61 static unique_ptr<tvg::SwCanvas> swCanvas;
63 void tvgSwTest(uint32_t* buffer)
66 swCanvas = tvg::SwCanvas::gen();
67 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
69 /* Push the shape into the Canvas drawing list
70 When this shape is into the canvas list, the shape could update & prepare
71 internal data asynchronously for coming rendering.
72 Canvas keeps this shape node unless user call canvas->clear() */
73 tvgDrawCmds(swCanvas.get());
76 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
78 tvgUpdateCmds(swCanvas.get(), progress);
81 Eo* img = (Eo*) effect;
82 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
83 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
86 void drawSwView(void* data, Eo* obj)
88 if (swCanvas->draw() == tvg::Result::Success) {
94 /************************************************************************/
95 /* GL Engine Test Code */
96 /************************************************************************/
98 static unique_ptr<tvg::GlCanvas> glCanvas;
100 void initGLview(Evas_Object *obj)
102 static constexpr auto BPP = 4;
105 glCanvas = tvg::GlCanvas::gen();
106 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
108 /* Push the shape into the Canvas drawing list
109 When this shape is into the canvas list, the shape could update & prepare
110 internal data asynchronously for coming rendering.
111 Canvas keeps this shape node unless user call canvas->clear() */
112 tvgDrawCmds(glCanvas.get());
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);
121 if (glCanvas->draw() == tvg::Result::Success) {
126 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
128 tvgUpdateCmds(glCanvas.get(), progress);
132 /************************************************************************/
134 /************************************************************************/
136 int main(int argc, char **argv)
138 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
141 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
144 //Initialize ThorVG Engine
145 if (tvgEngine == tvg::CanvasEngine::Sw) {
146 cout << "tvg engine: software" << endl;
148 cout << "tvg engine: opengl" << endl;
152 auto threads = std::thread::hardware_concurrency();
154 //Initialize ThorVG Engine
155 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
157 elm_init(argc, argv);
159 Elm_Transit *transit = elm_transit_add();
161 if (tvgEngine == tvg::CanvasEngine::Sw) {
162 auto view = createSwView();
163 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
165 auto view = createGlView();
166 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
169 elm_transit_duration_set(transit, 2);
170 elm_transit_repeat_times_set(transit, -1);
171 elm_transit_auto_reverse_set(transit, EINA_TRUE);
172 elm_transit_go(transit);
177 //Terminate ThorVG Engine
178 tvg::Initializer::term(tvgEngine);
181 cout << "engine is not supported" << endl;