2 * Copyright (c) 2021 - 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
26 /************************************************************************/
27 /* Drawing Commands */
28 /************************************************************************/
30 static tvg::Picture* pPicture = nullptr;
32 void tvgDrawCmds(tvg::Canvas* canvas)
37 auto picture = tvg::Picture::gen();
39 if (picture->load(EXAMPLE_DIR"/scaleup.png") != tvg::Result::Success) {
40 cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl;
43 if (canvas->push(move(picture)) == tvg::Result::Success) {
44 pPicture = picture.get();
48 void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
50 if (!canvas || !pPicture) return;
54 if (progress > 0.875f) scale = 4.0f;
55 else if (progress > 0.75f) scale = 3.0f;
56 else if (progress > 0.625f) scale = 2.5f;
57 else if (progress > 0.5f) scale = 2.0f;
58 else if (progress > 0.375f) scale = 1.75f;
59 else if (progress > 0.25f) scale = 1.5f;
60 else if (progress > 0.125f) scale = 1.25f;
63 pPicture->scale(scale);
65 canvas->update(pPicture);
68 /************************************************************************/
69 /* Sw Engine Test Code */
70 /************************************************************************/
72 static unique_ptr<tvg::SwCanvas> swCanvas;
74 void tvgSwTest(uint32_t* buffer)
77 swCanvas = tvg::SwCanvas::gen();
78 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
80 /* Push the shape into the Canvas drawing list
81 When this shape is into the canvas list, the shape could update & prepare
82 internal data asynchronously for coming rendering.
83 Canvas keeps this shape node unless user call canvas->clear() */
84 tvgDrawCmds(swCanvas.get());
87 void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
89 tvgUpdateCmds(swCanvas.get(), progress);
92 Eo* img = (Eo*) effect;
93 evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
94 evas_object_image_pixels_dirty_set(img, EINA_TRUE);
97 void drawSwView(void* data, Eo* obj)
99 if (swCanvas->draw() == tvg::Result::Success) {
105 /************************************************************************/
106 /* GL Engine Test Code */
107 /************************************************************************/
109 static unique_ptr<tvg::GlCanvas> glCanvas;
111 void initGLview(Evas_Object *obj)
113 static constexpr auto BPP = 4;
116 glCanvas = tvg::GlCanvas::gen();
117 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
119 /* Push the shape into the Canvas drawing list
120 When this shape is into the canvas list, the shape could update & prepare
121 internal data asynchronously for coming rendering.
122 Canvas keeps this shape node unless user call canvas->clear() */
123 tvgDrawCmds(glCanvas.get());
126 void drawGLview(Evas_Object *obj)
128 auto gl = elm_glview_gl_api_get(obj);
129 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
130 gl->glClear(GL_COLOR_BUFFER_BIT);
132 if (glCanvas->draw() == tvg::Result::Success) {
137 void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
139 tvgUpdateCmds(glCanvas.get(), progress);
140 elm_glview_changed_set((Evas_Object*)effect);
144 /************************************************************************/
146 /************************************************************************/
148 int main(int argc, char **argv)
150 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
153 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
156 //Initialize ThorVG Engine
157 if (tvgEngine == tvg::CanvasEngine::Sw) {
158 cout << "tvg engine: software" << endl;
160 cout << "tvg engine: opengl" << endl;
163 //Initialize ThorVG Engine
164 if (tvg::Initializer::init(tvgEngine, 0) == tvg::Result::Success) {
166 elm_init(argc, argv);
168 Elm_Transit *transit = elm_transit_add();
170 if (tvgEngine == tvg::CanvasEngine::Sw) {
171 auto view = createSwView();
172 elm_transit_effect_add(transit, transitSwCb, view, nullptr);
174 auto view = createGlView();
175 elm_transit_effect_add(transit, transitGlCb, view, nullptr);
178 elm_transit_duration_set(transit, 7);
179 elm_transit_repeat_times_set(transit, -1);
180 elm_transit_auto_reverse_set(transit, EINA_TRUE);
181 elm_transit_go(transit);
186 //Terminate ThorVG Engine
187 tvg::Initializer::term(tvgEngine);
190 cout << "engine is not supported" << endl;