2 * Copyright (c) 2021 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)
33 canvas->reserve(6); //reserve 6 pictures (optional)
36 auto picture0 = tvg::Picture::gen();
37 if (picture0->load(EXAMPLE_DIR"/test.jpg") == tvg::Result::Success) {
38 picture0->translate(-300,-300);
39 picture0->scale(3.0f);
40 if (canvas->push(move(picture0)) != tvg::Result::Success) return;
44 auto picture1 = tvg::Picture::gen();
45 if (picture1->load(EXAMPLE_DIR"/test.jpg") == tvg::Result::Success) {
46 picture1->translate(-200, -200);
47 if (canvas->push(move(picture1)) != tvg::Result::Success) return;
51 auto picture2 = tvg::Picture::gen();
52 if (picture2->load(EXAMPLE_DIR"/test.jpg") == tvg::Result::Success) {
53 picture2->translate(600, 600);
54 if (canvas->push(move(picture2)) != tvg::Result::Success) return;
58 auto picture3 = tvg::Picture::gen();
59 if (picture3->load(EXAMPLE_DIR"/test.jpg") == tvg::Result::Success) {
60 picture3->translate(-200, 600);
61 if (canvas->push(move(picture3)) != tvg::Result::Success) return;
65 auto picture4 = tvg::Picture::gen();
66 if (picture4->load(EXAMPLE_DIR"/test.jpg") == tvg::Result::Success) {
67 picture4->translate(600, -200);
68 if (canvas->push(move(picture4)) != tvg::Result::Success) return;
72 /************************************************************************/
73 /* Sw Engine Test Code */
74 /************************************************************************/
76 static unique_ptr<tvg::SwCanvas> swCanvas;
78 void tvgSwTest(uint32_t* buffer)
81 swCanvas = tvg::SwCanvas::gen();
82 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
84 /* Push the shape into the Canvas drawing list
85 When this shape is into the canvas list, the shape could update & prepare
86 internal data asynchronously for coming rendering.
87 Canvas keeps this shape node unless user call canvas->clear() */
88 tvgDrawCmds(swCanvas.get());
91 void drawSwView(void* data, Eo* obj)
93 if (swCanvas->draw() == tvg::Result::Success) {
99 /************************************************************************/
100 /* GL Engine Test Code */
101 /************************************************************************/
103 static unique_ptr<tvg::GlCanvas> glCanvas;
105 void initGLview(Evas_Object *obj)
107 static constexpr auto BPP = 4;
110 glCanvas = tvg::GlCanvas::gen();
111 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
113 /* Push the shape into the Canvas drawing list
114 When this shape is into the canvas list, the shape could update & prepare
115 internal data asynchronously for coming rendering.
116 Canvas keeps this shape node unless user call canvas->clear() */
117 tvgDrawCmds(glCanvas.get());
120 void drawGLview(Evas_Object *obj)
122 auto gl = elm_glview_gl_api_get(obj);
123 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
124 gl->glClear(GL_COLOR_BUFFER_BIT);
126 if (glCanvas->draw() == tvg::Result::Success) {
132 /************************************************************************/
134 /************************************************************************/
136 int main(int argc, char **argv)
138 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
141 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
144 //Initialize ThorVG Engine
145 if (tvgEngine == tvg::CanvasEngine::Sw) {
146 cout << "tvg engine: software" << endl;
148 cout << "tvg engine: opengl" << endl;
152 auto threads = std::thread::hardware_concurrency();
153 if (threads > 0) --threads; //Allow the designated main thread capacity
155 //Initialize ThorVG Engine
156 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
158 elm_init(argc, argv);
160 if (tvgEngine == tvg::CanvasEngine::Sw) {
169 //Terminate ThorVG Engine
170 tvg::Initializer::term(tvgEngine);
173 cout << "engine is not supported" << endl;