1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
11 canvas->reserve(3); //reserve 3 shape nodes (optional)
13 //Prepare Round Rectangle
14 auto shape1 = tvg::Shape::gen();
15 shape1->appendRect(0, 0, 400, 400, 0, 0); //x, y, w, h, rx, ry
18 auto fill = tvg::LinearGradient::gen();
19 fill->linear(0, 0, 400, 400);
21 //Gradient Color Stops
22 tvg::Fill::ColorStop colorStops[2];
23 colorStops[0] = {0, 0, 0, 0, 255};
24 colorStops[1] = {1, 255, 255, 255, 255};
26 fill->colorStops(colorStops, 2);
28 shape1->fill(move(fill));
29 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
32 auto shape2 = tvg::Shape::gen();
33 shape2->appendCircle(400, 400, 200, 200); //cx, cy, radiusW, radiusH
36 auto fill2 = tvg::LinearGradient::gen();
37 fill2->linear(400, 200, 400, 600);
39 //Gradient Color Stops
40 tvg::Fill::ColorStop colorStops2[3];
41 colorStops2[0] = {0, 255, 0, 0, 255};
42 colorStops2[1] = {0.5, 255, 255, 0, 255};
43 colorStops2[2] = {1, 255, 255, 255, 255};
45 fill2->colorStops(colorStops2, 3);
47 shape2->fill(move(fill2));
48 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
52 auto shape3 = tvg::Shape::gen();
53 shape3->appendCircle(600, 600, 150, 100); //cx, cy, radiusW, radiusH
56 auto fill3 = tvg::LinearGradient::gen();
57 fill3->linear(450, 600, 750, 600);
59 //Gradient Color Stops
60 tvg::Fill::ColorStop colorStops3[4];
61 colorStops3[0] = {0, 0, 127, 0, 127};
62 colorStops3[1] = {0.25, 0, 170, 170, 170};
63 colorStops3[2] = {0.5, 200, 0, 200, 200};
64 colorStops3[3] = {1, 255, 255, 255, 255};
66 fill3->colorStops(colorStops3, 4);
68 shape3->fill(move(fill3));
69 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
73 /************************************************************************/
74 /* Sw Engine Test Code */
75 /************************************************************************/
77 static unique_ptr<tvg::SwCanvas> swCanvas;
79 void tvgSwTest(uint32_t* buffer)
82 swCanvas = tvg::SwCanvas::gen();
83 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
85 /* Push the shape into the Canvas drawing list
86 When this shape is into the canvas list, the shape could update & prepare
87 internal data asynchronously for coming rendering.
88 Canvas keeps this shape node unless user call canvas->clear() */
89 tvgDrawCmds(swCanvas.get());
92 void drawSwView(void* data, Eo* obj)
94 if (swCanvas->draw() == tvg::Result::Success) {
100 /************************************************************************/
101 /* GL Engine Test Code */
102 /************************************************************************/
104 static unique_ptr<tvg::GlCanvas> glCanvas;
106 void initGLview(Evas_Object *obj)
108 static constexpr auto BPP = 4;
111 glCanvas = tvg::GlCanvas::gen();
112 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
114 /* Push the shape into the Canvas drawing list
115 When this shape is into the canvas list, the shape could update & prepare
116 internal data asynchronously for coming rendering.
117 Canvas keeps this shape node unless user call canvas->clear() */
118 tvgDrawCmds(glCanvas.get());
121 void drawGLview(Evas_Object *obj)
123 auto gl = elm_glview_gl_api_get(obj);
124 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
125 gl->glClear(GL_COLOR_BUFFER_BIT);
127 if (glCanvas->draw() == tvg::Result::Success) {
133 /************************************************************************/
135 /************************************************************************/
137 int main(int argc, char **argv)
139 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
142 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
145 //Initialize ThorVG Engine
146 if (tvgEngine == tvg::CanvasEngine::Sw) {
147 cout << "tvg engine: software" << endl;
149 cout << "tvg engine: opengl" << endl;
153 auto threads = std::thread::hardware_concurrency();
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;