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)
35 //Prepare Path Commands
36 tvg::PathCommand cmds[11];
37 cmds[0] = tvg::PathCommand::MoveTo;
38 cmds[1] = tvg::PathCommand::LineTo;
39 cmds[2] = tvg::PathCommand::LineTo;
40 cmds[3] = tvg::PathCommand::LineTo;
41 cmds[4] = tvg::PathCommand::LineTo;
42 cmds[5] = tvg::PathCommand::LineTo;
43 cmds[6] = tvg::PathCommand::LineTo;
44 cmds[7] = tvg::PathCommand::LineTo;
45 cmds[8] = tvg::PathCommand::LineTo;
46 cmds[9] = tvg::PathCommand::LineTo;
47 cmds[10] = tvg::PathCommand::Close;
51 pts[0] = {199, 34}; //MoveTo
52 pts[1] = {253, 143}; //LineTo
53 pts[2] = {374, 160}; //LineTo
54 pts[3] = {287, 244}; //LineTo
55 pts[4] = {307, 365}; //LineTo
56 pts[5] = {199, 309}; //LineTo
57 pts[6] = {97, 365}; //LineTo
58 pts[7] = {112, 245}; //LineTo
59 pts[8] = {26, 161}; //LineTo
60 pts[9] = {146, 143}; //LineTo
62 auto shape1 = tvg::Shape::gen();
63 shape1->appendPath(cmds, 11, pts, 10); //copy path data
64 shape1->fill(0, 255, 0, 255);
65 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
71 auto halfRadius = radius * 0.552284f;
73 //Prepare Path Commands
74 tvg::PathCommand cmds2[6];
75 cmds2[0] = tvg::PathCommand::MoveTo;
76 cmds2[1] = tvg::PathCommand::CubicTo;
77 cmds2[2] = tvg::PathCommand::CubicTo;
78 cmds2[3] = tvg::PathCommand::CubicTo;
79 cmds2[4] = tvg::PathCommand::CubicTo;
80 cmds2[5] = tvg::PathCommand::Close;
84 pts2[0] = {cx, cy - radius}; //MoveTo
86 pts2[1] = {cx + halfRadius, cy - radius}; //Ctrl1
87 pts2[2] = {cx + radius, cy - halfRadius}; //Ctrl2
88 pts2[3] = {cx + radius, cy}; //To
90 pts2[4] = {cx + radius, cy + halfRadius}; //Ctrl1
91 pts2[5] = {cx + halfRadius, cy + radius}; //Ctrl2
92 pts2[6] = {cx, cy+ radius}; //To
94 pts2[7] = {cx - halfRadius, cy + radius}; //Ctrl1
95 pts2[8] = {cx - radius, cy + halfRadius}; //Ctrl2
96 pts2[9] = {cx - radius, cy}; //To
98 pts2[10] = {cx - radius, cy - halfRadius}; //Ctrl1
99 pts2[11] = {cx - halfRadius, cy - radius}; //Ctrl2
100 pts2[12] = {cx, cy - radius}; //To
102 auto shape2 = tvg::Shape::gen();
103 shape2->appendPath(cmds2, 6, pts2, 13); //copy path data
104 shape2->fill(255, 255, 0, 255);
105 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
109 /************************************************************************/
110 /* Sw Engine Test Code */
111 /************************************************************************/
113 static unique_ptr<tvg::SwCanvas> swCanvas;
115 void tvgSwTest(uint32_t* buffer)
118 swCanvas = tvg::SwCanvas::gen();
119 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
121 /* Push the shape into the Canvas drawing list
122 When this shape is into the canvas list, the shape could update & prepare
123 internal data asynchronously for coming rendering.
124 Canvas keeps this shape node unless user call canvas->clear() */
125 tvgDrawCmds(swCanvas.get());
128 void drawSwView(void* data, Eo* obj)
130 if (swCanvas->draw() == tvg::Result::Success) {
136 /************************************************************************/
137 /* GL Engine Test Code */
138 /************************************************************************/
140 static unique_ptr<tvg::GlCanvas> glCanvas;
142 void initGLview(Evas_Object *obj)
144 static constexpr auto BPP = 4;
147 glCanvas = tvg::GlCanvas::gen();
148 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
150 /* Push the shape into the Canvas drawing list
151 When this shape is into the canvas list, the shape could update & prepare
152 internal data asynchronously for coming rendering.
153 Canvas keeps this shape node unless user call canvas->clear() */
154 tvgDrawCmds(glCanvas.get());
157 void drawGLview(Evas_Object *obj)
159 auto gl = elm_glview_gl_api_get(obj);
160 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
161 gl->glClear(GL_COLOR_BUFFER_BIT);
163 if (glCanvas->draw() == tvg::Result::Success) {
169 /************************************************************************/
171 /************************************************************************/
173 int main(int argc, char **argv)
175 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
178 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
181 //Initialize ThorVG Engine
182 if (tvgEngine == tvg::CanvasEngine::Sw) {
183 cout << "tvg engine: software" << endl;
185 cout << "tvg engine: opengl" << endl;
189 auto threads = std::thread::hardware_concurrency();
190 if (threads > 0) --threads; //Allow the designated main thread capacity
192 //Initialize ThorVG Engine
193 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
195 elm_init(argc, argv);
197 if (tvgEngine == tvg::CanvasEngine::Sw) {
206 //Terminate ThorVG Engine
207 tvg::Initializer::term(tvgEngine);
210 cout << "engine is not supported" << endl;