2 * Copyright (c) 2020 - 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 /************************************************************************/
29 static const char* svg = "<svg height=\"1000\" viewBox=\"0 0 1000 1000\" width=\"1000\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M.10681413.09784845 1000.0527.01592069V1000.0851L.06005738 999.9983Z\" fill=\"#ffffff\" stroke-width=\"3.910218\"/><g fill=\"#252f35\"><g stroke-width=\"3.864492\"><path d=\"M256.61221 100.51736H752.8963V386.99554H256.61221Z\"/><path d=\"M201.875 100.51736H238.366478V386.99554H201.875Z\"/><path d=\"M771.14203 100.51736H807.633508V386.99554H771.14203Z\"/></g><path d=\"M420.82388 380H588.68467V422.805317H420.82388Z\" stroke-width=\"3.227\"/><path d=\"m420.82403 440.7101v63.94623l167.86079 25.5782V440.7101Z\"/><path d=\"M420.82403 523.07258V673.47362L588.68482 612.59701V548.13942Z\"/></g><g fill=\"#222f35\"><path d=\"M420.82403 691.37851 588.68482 630.5019 589 834H421Z\"/><path d=\"m420.82403 852.52249h167.86079v28.64782H420.82403v-28.64782 0 0\"/><path d=\"m439.06977 879.17031c0 0-14.90282 8.49429-18.24574 15.8161-4.3792 9.59153 0 31.63185 0 31.63185h167.86079c0 0 4.3792-22.04032 0-31.63185-3.34292-7.32181-18.24574-15.8161-18.24574-15.8161z\"/></g><g fill=\"#ffffff\"><path d=\"m280 140h15v55l8 10 8-10v-55h15v60l-23 25-23-25z\"/><path d=\"m335 140v80h45v-50h-25v10h10v30h-15v-57h18v-13z\"/></g></svg>";
32 void tvgDrawCmds(tvg::Canvas* canvas)
37 auto shape = tvg::Shape::gen();
38 shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry
39 shape->fill(255, 255, 255, 255); //r, g, b, a
41 if (canvas->push(move(shape)) != tvg::Result::Success) return;
43 auto picture = tvg::Picture::gen();
44 if (picture->load(svg, strlen(svg), "svg") != tvg::Result::Success) return;
46 picture->size(WIDTH, HEIGHT);
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();
133 if (threads > 0) --threads; //Allow the designated main thread capacity
135 //Initialize ThorVG Engine
136 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
138 elm_init(argc, argv);
140 if (tvgEngine == tvg::CanvasEngine::Sw) {
149 //Terminate ThorVG Engine
150 tvg::Initializer::term(tvgEngine);
153 cout << "engine is not supported" << endl;