1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
11 //Test for Stroke Width
12 for (int i = 0; i < 10; ++i) {
13 auto shape = tvg::Shape::gen();
14 shape->moveTo(50, 50 + (25 * i));
15 shape->lineTo(750, 50 + (25 * i));
16 shape->stroke(255, 255, 255, 255); //color: r, g, b, a
17 shape->stroke(i + 1); //stroke width
18 shape->stroke(tvg::StrokeCap::Round); //default is Square
19 if (canvas->push(move(shape)) != tvg::Result::Success) return;
22 //Test for StrokeJoin & StrokeCap
23 auto shape1 = tvg::Shape::gen();
24 shape1->moveTo(20, 350);
25 shape1->lineTo(250, 350);
26 shape1->lineTo(220, 500);
27 shape1->lineTo(70, 470);
28 shape1->lineTo(70, 330);
29 shape1->stroke(255, 0, 0, 255);
31 shape1->stroke(tvg::StrokeJoin::Round);
32 shape1->stroke(tvg::StrokeCap::Round);
33 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
35 auto shape2 = tvg::Shape::gen();
36 shape2->moveTo(270, 350);
37 shape2->lineTo(500, 350);
38 shape2->lineTo(470, 500);
39 shape2->lineTo(320, 470);
40 shape2->lineTo(320, 330);
41 shape2->stroke(255, 255, 0, 255);
43 shape2->stroke(tvg::StrokeJoin::Bevel);
44 shape2->stroke(tvg::StrokeCap::Square);
45 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
47 auto shape3 = tvg::Shape::gen();
48 shape3->moveTo(520, 350);
49 shape3->lineTo(750, 350);
50 shape3->lineTo(720, 500);
51 shape3->lineTo(570, 470);
52 shape3->lineTo(570, 330);
53 shape3->stroke(0, 255, 0, 255);
55 shape3->stroke(tvg::StrokeJoin::Miter);
56 shape3->stroke(tvg::StrokeCap::Butt);
57 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
59 //Test for Stroke Dash
60 auto shape4 = tvg::Shape::gen();
61 shape4->moveTo(20, 600);
62 shape4->lineTo(250, 600);
63 shape4->lineTo(220, 750);
64 shape4->lineTo(70, 720);
65 shape4->lineTo(70, 580);
66 shape4->stroke(255, 0, 0, 255);
68 shape4->stroke(tvg::StrokeJoin::Round);
69 shape4->stroke(tvg::StrokeCap::Round);
71 float dashPattern1[2] = {10, 10};
72 shape4->stroke(dashPattern1, 2);
73 if (canvas->push(move(shape4)) != tvg::Result::Success) return;
75 auto shape5 = tvg::Shape::gen();
76 shape5->moveTo(270, 600);
77 shape5->lineTo(500, 600);
78 shape5->lineTo(470, 750);
79 shape5->lineTo(320, 720);
80 shape5->lineTo(320, 580);
81 shape5->stroke(255, 255, 0, 255);
83 shape5->stroke(tvg::StrokeJoin::Bevel);
84 shape5->stroke(tvg::StrokeCap::Butt);
86 float dashPattern2[2] = {10, 10};
87 shape5->stroke(dashPattern2, 2);
88 if (canvas->push(move(shape5)) != tvg::Result::Success) return;
90 auto shape6 = tvg::Shape::gen();
91 shape6->moveTo(520, 600);
92 shape6->lineTo(750, 600);
93 shape6->lineTo(720, 750);
94 shape6->lineTo(570, 720);
95 shape6->lineTo(570, 580);
96 shape6->stroke(255, 255, 255, 255);
98 shape6->stroke(tvg::StrokeJoin::Miter);
99 shape6->stroke(tvg::StrokeCap::Square);
101 float dashPattern3[2] = {10, 10};
102 shape6->stroke(dashPattern3, 2);
103 if (canvas->push(move(shape6)) != tvg::Result::Success) return;
107 /************************************************************************/
108 /* Sw Engine Test Code */
109 /************************************************************************/
111 static unique_ptr<tvg::SwCanvas> swCanvas;
113 void tvgSwTest(uint32_t* buffer)
116 swCanvas = tvg::SwCanvas::gen();
117 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
119 /* Push the shape into the Canvas drawing list
120 When this shape is into the canvas list, the shape could update & prepare
121 internal data asynchronously for coming rendering.
122 Canvas keeps this shape node unless user call canvas->clear() */
123 tvgDrawCmds(swCanvas.get());
126 void drawSwView(void* data, Eo* obj)
128 if (swCanvas->draw() == tvg::Result::Success) {
134 /************************************************************************/
135 /* GL Engine Test Code */
136 /************************************************************************/
138 static unique_ptr<tvg::GlCanvas> glCanvas;
140 void initGLview(Evas_Object *obj)
142 static constexpr auto BPP = 4;
145 glCanvas = tvg::GlCanvas::gen();
146 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
148 /* Push the shape into the Canvas drawing list
149 When this shape is into the canvas list, the shape could update & prepare
150 internal data asynchronously for coming rendering.
151 Canvas keeps this shape node unless user call canvas->clear() */
152 tvgDrawCmds(glCanvas.get());
155 void drawGLview(Evas_Object *obj)
157 auto gl = elm_glview_gl_api_get(obj);
158 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
159 gl->glClear(GL_COLOR_BUFFER_BIT);
161 if (glCanvas->draw() == tvg::Result::Success) {
167 /************************************************************************/
169 /************************************************************************/
171 int main(int argc, char **argv)
173 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
176 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
179 //Initialize ThorVG Engine
180 if (tvgEngine == tvg::CanvasEngine::Sw) {
181 cout << "tvg engine: software" << endl;
183 cout << "tvg engine: opengl" << endl;
187 auto threads = std::thread::hardware_concurrency();
189 //Initialize ThorVG Engine
190 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
193 elm_init(argc, argv);
195 if (tvgEngine == tvg::CanvasEngine::Sw) {
204 //Terminate ThorVG Engine
205 tvg::Initializer::term(tvgEngine);
208 cout << "engine is not supported" << endl;