2 * Copyright (c) 2021 - 2023 the ThorVG project. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 /************************************************************************/
26 /* Drawing Commands */
27 /************************************************************************/
29 static tvg::Picture* pPicture = nullptr;
30 static double updateTime = 0;
31 static double accumulateTime = 0;
32 static uint32_t cnt = 0;
34 void tvgDrawCmds(tvg::Canvas* canvas)
38 auto picture = tvg::Picture::gen();
40 picture->load(EXAMPLE_DIR"/tiger.svg");
41 picture->size(WIDTH, HEIGHT);
42 pPicture = picture.get();
43 canvas->push(move(picture));
46 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
50 pPicture->translate(WIDTH * progress * 0.05f, HEIGHT * progress * 0.05f);
52 auto before = ecore_time_get();
54 canvas->update(pPicture);
56 auto after = ecore_time_get();
58 updateTime = after - before;
62 /************************************************************************/
63 /* Sw Engine Test Code */
64 /************************************************************************/
66 static unique_ptr<tvg::SwCanvas> swCanvas;
68 void tvgSwTest(uint32_t* buffer)
71 swCanvas = tvg::SwCanvas::gen();
72 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
74 /* Push the shape into the Canvas drawing list
75 When this shape is into the canvas list, the shape could update & prepare
76 internal data asynchronously for coming rendering.
77 Canvas keeps this shape node unless user call canvas->clear() */
78 tvgDrawCmds(swCanvas.get());
81 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
83 tvgUpdateCmds(swCanvas.get(), progress);
86 Eo* img = (Eo*) effect;
87 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
88 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
91 void drawSwView(void* data, Eo* obj)
93 auto before = ecore_time_get();
95 if (swCanvas->draw() == tvg::Result::Success) {
99 auto after = ecore_time_get();
101 auto rasterTime = after - before;
105 accumulateTime += (updateTime + rasterTime);
107 printf("[%5d]: rendering = %fs, average = %fs\n", cnt, updateTime + rasterTime, accumulateTime / cnt);
111 /************************************************************************/
112 /* GL Engine Test Code */
113 /************************************************************************/
115 static unique_ptr<tvg::GlCanvas> glCanvas;
117 void initGLview(Evas_Object *obj)
119 static constexpr auto BPP = 4;
122 glCanvas = tvg::GlCanvas::gen();
123 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
125 /* Push the shape into the Canvas drawing list
126 When this shape is into the canvas list, the shape could update & prepare
127 internal data asynchronously for coming rendering.
128 Canvas keeps this shape node unless user call canvas->clear() */
129 tvgDrawCmds(glCanvas.get());
132 void drawGLview(Evas_Object *obj)
134 auto gl = elm_glview_gl_api_get(obj);
135 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
136 gl->glClear(GL_COLOR_BUFFER_BIT);
138 if (glCanvas->draw() == tvg::Result::Success) {
143 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
145 tvgUpdateCmds(glCanvas.get(), progress);
146 elm_glview_changed_set((Evas_Object*)effect);
150 /************************************************************************/
152 /************************************************************************/
154 int main(int argc, char **argv)
156 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
159 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
162 //Initialize ThorVG Engine
163 if (tvgEngine == tvg::CanvasEngine::Sw) {
164 cout << "tvg engine: software" << endl;
166 cout << "tvg engine: opengl" << endl;
169 //Initialize ThorVG Engine
170 if (tvg::Initializer::init(tvgEngine, 0) == tvg::Result::Success) {
172 elm_init(argc, argv);
174 Elm_Transit *transit = elm_transit_add();
176 if (tvgEngine == tvg::CanvasEngine::Sw) {
177 auto view = createSwView();
178 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
180 auto view = createGlView();
181 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
184 elm_transit_duration_set(transit, 2);
185 elm_transit_repeat_times_set(transit, -1);
186 elm_transit_auto_reverse_set(transit, EINA_TRUE);
187 elm_transit_go(transit);
192 //Terminate ThorVG Engine
193 tvg::Initializer::term(tvgEngine);
196 cout << "engine is not supported" << endl;