2 * Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. 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 void tvgDrawCmds(tvg::Canvas* canvas)
34 auto shape = tvg::Shape::gen();
35 shape->appendRect(-100, -100, 200, 200, 0, 0);
36 shape->fill(255, 255, 255, 255);
37 canvas->push(move(shape));
40 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
44 //Explicitly clear all retained paint nodes.
45 if (canvas->clear() != tvg::Result::Success) return;
48 auto shape = tvg::Shape::gen();
49 shape->appendRect(-100, -100, 200, 200, (100 * progress), (100 * progress));
50 shape->fill(rand()%255, rand()%255, rand()%255, 255);
51 shape->translate(800 * progress, 800 * progress);
52 shape->scale(1 - 0.75 * progress);
53 shape->rotate(360 * progress);
55 canvas->push(move(shape));
59 /************************************************************************/
60 /* Sw Engine Test Code */
61 /************************************************************************/
63 static unique_ptr<tvg::SwCanvas> swCanvas;
65 void tvgSwTest(uint32_t* buffer)
68 swCanvas = tvg::SwCanvas::gen();
69 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
71 /* Push the shape into the Canvas drawing list
72 When this shape is into the canvas list, the shape could update & prepare
73 internal data asynchronously for coming rendering.
74 Canvas keeps this shape node unless user call canvas->clear() */
75 tvgDrawCmds(swCanvas.get());
78 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
80 tvgUpdateCmds(swCanvas.get(), progress);
83 Eo* img = (Eo*) effect;
84 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
85 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
88 void drawSwView(void* data, Eo* obj)
90 if (swCanvas->draw() == tvg::Result::Success) {
96 /************************************************************************/
97 /* GL Engine Test Code */
98 /************************************************************************/
100 static unique_ptr<tvg::GlCanvas> glCanvas;
102 void initGLview(Evas_Object *obj)
104 static constexpr auto BPP = 4;
107 glCanvas = tvg::GlCanvas::gen();
108 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
110 /* Push the shape into the Canvas drawing list
111 When this shape is into the canvas list, the shape could update & prepare
112 internal data asynchronously for coming rendering.
113 Canvas keeps this shape node unless user call canvas->clear() */
114 tvgDrawCmds(glCanvas.get());
117 void drawGLview(Evas_Object *obj)
119 auto gl = elm_glview_gl_api_get(obj);
120 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
121 gl->glClear(GL_COLOR_BUFFER_BIT);
123 if (glCanvas->draw() == tvg::Result::Success) {
128 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
130 tvgUpdateCmds(glCanvas.get(), progress);
131 elm_glview_changed_set((Evas_Object*)effect);
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();
156 if (threads > 0) --threads; //Allow the designated main thread capacity
158 //Initialize ThorVG Engine
159 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
161 elm_init(argc, argv);
163 Elm_Transit *transit = elm_transit_add();
165 if (tvgEngine == tvg::CanvasEngine::Sw) {
166 auto view = createSwView();
167 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
169 auto view = createGlView();
170 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
173 elm_transit_duration_set(transit, 2);
174 elm_transit_repeat_times_set(transit, -1);
175 elm_transit_auto_reverse_set(transit, EINA_TRUE);
176 elm_transit_go(transit);
181 //Terminate ThorVG Engine
182 tvg::Initializer::term(tvgEngine);
185 cout << "engine is not supported" << endl;