1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
11 //Prepare first shape, which will not be drawn
12 auto shape1 = tvg::Shape::gen();
13 shape1->appendRect(10, 10, 200, 200, 0, 0);
14 shape1->appendRect(220, 10, 100, 100, 0, 0);
17 shape1->stroke(0, 255, 0, 255);
19 float dashPattern[2] = {4, 4};
20 shape1->stroke(dashPattern, 2);
21 shape1->fill(255, 0, 0, 255);
23 //Create second shape and duplicate parameters
24 auto shape2 = shape1->duplicate();
26 //Create third shape, duplicate from first and add some new parameters
27 auto shape3 = shape1->duplicate();
29 //Get access to valid derived class type
30 tvg::Shape* shapePtr = reinterpret_cast<tvg::Shape*>(shape3.get());
32 //move shape3 to new postion to don't cover second shape
33 shape3->translate(0, 220);
36 shapePtr->appendRect(340, 10, 100, 100, 0, 0);
37 shapePtr->fill(0, 0, 255, 255);
40 canvas->push(move(shape2));
41 canvas->push(move(shape3));
45 /************************************************************************/
46 /* Sw Engine Test Code */
47 /************************************************************************/
49 static unique_ptr<tvg::SwCanvas> swCanvas;
51 void tvgSwTest(uint32_t* buffer)
54 swCanvas = tvg::SwCanvas::gen();
55 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
57 /* Push the shape into the Canvas drawing list
58 When this shape is into the canvas list, the shape could update & prepare
59 internal data asynchronously for coming rendering.
60 Canvas keeps this shape node unless user call canvas->clear() */
61 tvgDrawCmds(swCanvas.get());
64 void drawSwView(void* data, Eo* obj)
66 if (swCanvas->draw() == tvg::Result::Success) {
72 /************************************************************************/
73 /* GL Engine Test Code */
74 /************************************************************************/
76 static unique_ptr<tvg::GlCanvas> glCanvas;
78 void initGLview(Evas_Object *obj)
80 static constexpr auto BPP = 4;
83 glCanvas = tvg::GlCanvas::gen();
84 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
86 /* Push the shape into the Canvas drawing list
87 When this shape is into the canvas list, the shape could update & prepare
88 internal data asynchronously for coming rendering.
89 Canvas keeps this shape node unless user call canvas->clear() */
90 tvgDrawCmds(glCanvas.get());
93 void drawGLview(Evas_Object *obj)
95 auto gl = elm_glview_gl_api_get(obj);
96 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
97 gl->glClear(GL_COLOR_BUFFER_BIT);
99 if (glCanvas->draw() == tvg::Result::Success) {
105 /************************************************************************/
107 /************************************************************************/
109 int main(int argc, char **argv)
111 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
114 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
117 //Initialize ThorVG Engine
118 if (tvgEngine == tvg::CanvasEngine::Sw) {
119 cout << "tvg engine: software" << endl;
121 cout << "tvg engine: opengl" << endl;
125 auto threads = std::thread::hardware_concurrency();
127 //Initialize ThorVG Engine
128 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
130 elm_init(argc, argv);
132 if (tvgEngine == tvg::CanvasEngine::Sw) {
141 //Terminate ThorVG Engine
142 tvg::Initializer::term(tvgEngine);
145 cout << "engine is not supported" << endl;