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 /************************************************************************/
30 void tvgDrawCmds(tvg::Canvas* canvas)
35 auto picture = tvg::Picture::gen();
36 if (picture->load(EXAMPLE_DIR"/test.tvg") != tvg::Result::Success) {
37 cout << "TVG is not supported. Did you enable TVG Loader?" << endl;
42 picture->size(&w, &h);
43 cout << "default tvg view size = " << w << " x " << h << endl;
45 picture->translate(w * 0.1f, h * 0.1f);
46 picture->size(w * 0.8f, h * 0.8f);
48 canvas->push(move(picture));
52 /************************************************************************/
53 /* Sw Engine Test Code */
54 /************************************************************************/
56 static unique_ptr<tvg::SwCanvas> swCanvas;
58 void tvgSwTest(uint32_t* buffer)
61 swCanvas = tvg::SwCanvas::gen();
62 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
64 /* Push the shape into the Canvas drawing list
65 When this shape is into the canvas list, the shape could update & prepare
66 internal data asynchronously for coming rendering.
67 Canvas keeps this shape node unless user call canvas->clear() */
68 tvgDrawCmds(swCanvas.get());
71 void drawSwView(void* data, Eo* obj)
73 if (swCanvas->draw() == tvg::Result::Success) {
79 /************************************************************************/
80 /* GL Engine Test Code */
81 /************************************************************************/
83 static unique_ptr<tvg::GlCanvas> glCanvas;
85 void initGLview(Evas_Object *obj)
87 static constexpr auto BPP = 4;
90 glCanvas = tvg::GlCanvas::gen();
91 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
93 /* Push the shape into the Canvas drawing list
94 When this shape is into the canvas list, the shape could update & prepare
95 internal data asynchronously for coming rendering.
96 Canvas keeps this shape node unless user call canvas->clear() */
97 tvgDrawCmds(glCanvas.get());
100 void drawGLview(Evas_Object *obj)
102 auto gl = elm_glview_gl_api_get(obj);
103 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
104 gl->glClear(GL_COLOR_BUFFER_BIT);
106 if (glCanvas->draw() == tvg::Result::Success) {
112 /************************************************************************/
114 /************************************************************************/
116 int main(int argc, char **argv)
118 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
121 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
124 //Initialize ThorVG Engine
125 if (tvgEngine == tvg::CanvasEngine::Sw) {
126 cout << "tvg engine: software" << endl;
128 cout << "tvg engine: opengl" << endl;
132 auto threads = std::thread::hardware_concurrency();
134 //Initialize ThorVG Engine
135 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
137 elm_init(argc, argv);
139 if (tvgEngine == tvg::CanvasEngine::Sw) {
148 //Terminate ThorVG Engine
149 tvg::Initializer::term(tvgEngine);
152 cout << "engine is not supported" << endl;