1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
6 tvg::Shape* pShape = nullptr;
8 void tvgDrawCmds(tvg::Canvas* canvas)
13 auto shape = tvg::Shape::gen();
15 /* Acquire shape pointer to access it again.
16 instead, you should consider not to interrupt this pointer life-cycle. */
19 shape->appendRect(-100, -100, 200, 200, 0, 0);
21 //fill property will be retained
22 shape->fill(127, 255, 255, 255);
23 shape->stroke(0, 0, 255, 255);
26 if (canvas->push(move(shape)) != tvg::Result::Success) return;
29 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
33 /* Update shape directly.
34 You can update only necessary properties of this shape,
35 while retaining other properties. */
38 if (pShape->reset() == tvg::Result::Success) {
39 pShape->appendRect(-100 + (800 * progress), -100 + (800 * progress), 200, 200, (100 * progress), (100 * progress));
40 pShape->stroke(30 * progress);
42 //Update shape for drawing (this may work asynchronously)
43 canvas->update(pShape);
48 /************************************************************************/
49 /* Sw Engine Test Code */
50 /************************************************************************/
52 static unique_ptr<tvg::SwCanvas> swCanvas;
54 void tvgSwTest(uint32_t* buffer)
57 swCanvas = tvg::SwCanvas::gen();
58 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
60 /* Push the shape into the Canvas drawing list
61 When this shape is into the canvas list, the shape could update & prepare
62 internal data asynchronously for coming rendering.
63 Canvas keeps this shape node unless user call canvas->clear() */
64 tvgDrawCmds(swCanvas.get());
67 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
69 tvgUpdateCmds(swCanvas.get(), progress);
72 Eo* img = (Eo*) effect;
73 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
74 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
77 void drawSwView(void* data, Eo* obj)
79 if (swCanvas->draw() == tvg::Result::Success) {
85 /************************************************************************/
86 /* GL Engine Test Code */
87 /************************************************************************/
89 static unique_ptr<tvg::GlCanvas> glCanvas;
91 void initGLview(Evas_Object *obj)
93 static constexpr auto BPP = 4;
96 glCanvas = tvg::GlCanvas::gen();
97 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
99 /* Push the shape into the Canvas drawing list
100 When this shape is into the canvas list, the shape could update & prepare
101 internal data asynchronously for coming rendering.
102 Canvas keeps this shape node unless user call canvas->clear() */
103 tvgDrawCmds(glCanvas.get());
106 void drawGLview(Evas_Object *obj)
108 auto gl = elm_glview_gl_api_get(obj);
109 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
110 gl->glClear(GL_COLOR_BUFFER_BIT);
112 if (glCanvas->draw() == tvg::Result::Success) {
117 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
119 tvgUpdateCmds(glCanvas.get(), progress);
123 /************************************************************************/
125 /************************************************************************/
127 int main(int argc, char **argv)
129 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
132 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
135 //Initialize ThorVG Engine
136 if (tvgEngine == tvg::CanvasEngine::Sw) {
137 cout << "tvg engine: software" << endl;
139 cout << "tvg engine: opengl" << endl;
143 auto threads = std::thread::hardware_concurrency();
145 //Initialize ThorVG Engine
146 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
148 elm_init(argc, argv);
150 Elm_Transit *transit = elm_transit_add();
152 if (tvgEngine == tvg::CanvasEngine::Sw) {
153 auto view = createSwView();
154 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
156 auto view = createGlView();
157 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
160 elm_transit_duration_set(transit, 2);
161 elm_transit_repeat_times_set(transit, -1);
162 elm_transit_auto_reverse_set(transit, EINA_TRUE);
163 elm_transit_go(transit);
168 //Terminate ThorVG Engine
169 tvg::Initializer::term(tvgEngine);
172 cout << "engine is not supported" << endl;