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 shape1 = tvg::Shape::gen();
35 shape1->moveTo(205, 35);
36 shape1->lineTo(330, 355);
37 shape1->lineTo(25, 150);
38 shape1->lineTo(385, 150);
39 shape1->lineTo(80, 355);
41 shape1->fill(255, 255, 255, 255);
42 shape1->fill(tvg::FillRule::Winding); //Fill all winding shapes
44 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
47 auto shape2 = tvg::Shape::gen();
48 shape2->moveTo(535, 335);
49 shape2->lineTo(660, 655);
50 shape2->lineTo(355, 450);
51 shape2->lineTo(715, 450);
52 shape2->lineTo(410, 655);
54 shape2->fill(255, 255, 255, 255);
55 shape2->fill(tvg::FillRule::EvenOdd); //Fill polygons with even odd pattern
57 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
60 /************************************************************************/
61 /* Sw Engine Test Code */
62 /************************************************************************/
64 static unique_ptr<tvg::SwCanvas> swCanvas;
66 void tvgSwTest(uint32_t* buffer)
69 swCanvas = tvg::SwCanvas::gen();
70 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
72 /* Push the shape into the Canvas drawing list
73 When this shape is into the canvas list, the shape could update & prepare
74 internal data asynchronously for coming rendering.
75 Canvas keeps this shape node unless user call canvas->clear() */
76 tvgDrawCmds(swCanvas.get());
79 void drawSwView(void* data, Eo* obj)
81 if (swCanvas->draw() == tvg::Result::Success) {
87 /************************************************************************/
88 /* GL Engine Test Code */
89 /************************************************************************/
91 static unique_ptr<tvg::GlCanvas> glCanvas;
93 void initGLview(Evas_Object *obj)
95 static constexpr auto BPP = 4;
98 glCanvas = tvg::GlCanvas::gen();
99 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
101 /* Push the shape into the Canvas drawing list
102 When this shape is into the canvas list, the shape could update & prepare
103 internal data asynchronously for coming rendering.
104 Canvas keeps this shape node unless user call canvas->clear() */
105 tvgDrawCmds(glCanvas.get());
108 void drawGLview(Evas_Object *obj)
110 auto gl = elm_glview_gl_api_get(obj);
111 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
112 gl->glClear(GL_COLOR_BUFFER_BIT);
114 if (glCanvas->draw() == tvg::Result::Success) {
120 /************************************************************************/
122 /************************************************************************/
124 int main(int argc, char **argv)
126 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
129 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
132 //Initialize ThorVG Engine
133 if (tvgEngine == tvg::CanvasEngine::Sw) {
134 cout << "tvg engine: software" << endl;
136 cout << "tvg engine: opengl" << endl;
140 auto threads = std::thread::hardware_concurrency();
141 if (threads > 0) --threads; //Allow the designated main thread capacity
143 //Initialize ThorVG Engine
144 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
146 elm_init(argc, argv);
148 if (tvgEngine == tvg::CanvasEngine::Sw) {
157 //Terminate ThorVG Engine
158 tvg::Initializer::term(tvgEngine);
161 cout << "engine is not supported" << endl;