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 tvgUpdateCmds(tvg::Canvas* canvas, float progress)
33 if (canvas->clear() != tvg::Result::Success) return;
36 auto shape = tvg::Shape::gen();
38 shape->moveTo(0, -114.5);
39 shape->lineTo(54, -5.5);
40 shape->lineTo(175, 11.5);
41 shape->lineTo(88, 95.5);
42 shape->lineTo(108, 216.5);
43 shape->lineTo(0, 160.5);
44 shape->lineTo(-102, 216.5);
45 shape->lineTo(-87, 96.5);
46 shape->lineTo(-173, 12.5);
47 shape->lineTo(-53, -5.5);
49 shape->fill(0, 0, 255, 255);
51 shape->stroke(255, 255, 255, 255);
54 tvg::Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1};
57 m.e11 = 1 - (progress * 0.5f);
60 m.e22 = 1 + (progress * 2.0f);
63 constexpr auto PI = 3.141592f;
65 auto radian = degree / 180.0f * PI;
66 auto cosVal = cosf(radian);
67 auto sinVal = sinf(radian);
69 auto t11 = m.e11 * cosVal + m.e12 * sinVal;
70 auto t12 = m.e11 * -sinVal + m.e12 * cosVal;
71 auto t21 = m.e21 * cosVal + m.e22 * sinVal;
72 auto t22 = m.e21 * -sinVal + m.e22 * cosVal;
73 auto t13 = m.e31 * cosVal + m.e32 * sinVal;
74 auto t23 = m.e31 * -sinVal + m.e32 * cosVal;
84 m.e13 = progress * 300.0f + 300.0f;
85 m.e23 = progress * -100.0f + 300.0f;
89 canvas->push(move(shape));
93 /************************************************************************/
94 /* Sw Engine Test Code */
95 /************************************************************************/
97 static unique_ptr<tvg::SwCanvas> swCanvas;
99 void tvgSwTest(uint32_t* buffer)
102 swCanvas = tvg::SwCanvas::gen();
103 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
105 /* Push the shape into the Canvas drawing list
106 When this shape is into the canvas list, the shape could update & prepare
107 internal data asynchronously for coming rendering.
108 Canvas keeps this shape node unless user call canvas->clear() */
109 tvgUpdateCmds(swCanvas.get(), 0);
112 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
114 tvgUpdateCmds(swCanvas.get(), progress);
117 Eo* img = (Eo*) effect;
118 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
119 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
122 void drawSwView(void* data, Eo* obj)
124 if (swCanvas->draw() == tvg::Result::Success) {
130 /************************************************************************/
131 /* GL Engine Test Code */
132 /************************************************************************/
134 static unique_ptr<tvg::GlCanvas> glCanvas;
136 void initGLview(Evas_Object *obj)
138 static constexpr auto BPP = 4;
141 glCanvas = tvg::GlCanvas::gen();
142 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
144 /* Push the shape into the Canvas drawing list
145 When this shape is into the canvas list, the shape could update & prepare
146 internal data asynchronously for coming rendering.
147 Canvas keeps this shape node unless user call canvas->clear() */
148 tvgUpdateCmds(glCanvas.get(), 0);
151 void drawGLview(Evas_Object *obj)
153 auto gl = elm_glview_gl_api_get(obj);
154 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
155 gl->glClear(GL_COLOR_BUFFER_BIT);
157 if (glCanvas->draw() == tvg::Result::Success) {
162 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
164 tvgUpdateCmds(glCanvas.get(), progress);
165 elm_glview_changed_set((Evas_Object*)effect);
169 /************************************************************************/
171 /************************************************************************/
173 int main(int argc, char **argv)
175 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
178 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
181 //Initialize ThorVG Engine
182 if (tvgEngine == tvg::CanvasEngine::Sw) {
183 cout << "tvg engine: software" << endl;
185 cout << "tvg engine: opengl" << endl;
189 auto threads = std::thread::hardware_concurrency();
190 if (threads > 0) --threads; //Allow the designated main thread capacity
192 //Initialize ThorVG Engine
193 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
195 elm_init(argc, argv);
197 Elm_Transit *transit = elm_transit_add();
199 if (tvgEngine == tvg::CanvasEngine::Sw) {
200 auto view = createSwView();
201 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
203 auto view = createGlView();
204 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
207 elm_transit_duration_set(transit, 2);
208 elm_transit_repeat_times_set(transit, -1);
209 elm_transit_auto_reverse_set(transit, EINA_TRUE);
210 elm_transit_go(transit);
215 //Terminate ThorVG Engine
216 tvg::Initializer::term(tvgEngine);
219 cout << "engine is not supported" << endl;