test shape: unify sw/gl test code. 22/237322/1
authorHermet Park <chuneon.park@samsung.com>
Mon, 29 Jun 2020 05:59:01 +0000 (14:59 +0900)
committerHermet Park <chuneon.park@samsung.com>
Mon, 29 Jun 2020 05:59:01 +0000 (14:59 +0900)
default is sw engine, please run sample app with "gl" argument

$./testShape gl

Change-Id: Iff7da624ff17827df957919341737b9f129f502e

.gitignore
test/makefile
test/testGlShape.cpp [deleted file]
test/testShape.cpp

index f6c52c5..9a64520 100644 (file)
@@ -19,5 +19,4 @@ testLinearGradient
 testRadialGradient
 testGradientTransform
 testSvg
-testGlShape
 testAsync
index 33eb7d9..6455a0a 100644 (file)
@@ -17,5 +17,4 @@ all:
        gcc -o testRadialGradient testRadialGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg`
        gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg`
        gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg`
-       gcc -o testGlShape testGlShape.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg`
        gcc -o testAsync testAsync.cpp -g -lstdc++ `pkg-config --cflags --libs elementary thorvg`
diff --git a/test/testGlShape.cpp b/test/testGlShape.cpp
deleted file mode 100644 (file)
index c488091..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <thorvg.h>
-#include <Elementary.h>
-
-using namespace std;
-
-#define WIDTH   800
-#define HEIGHT  800
-#define BPP     4
-static Evas_GL_API *glapi;
-static unique_ptr<tvg::GlCanvas> canvas;
-
-void tvgtest()
-{
-    //Create a Canvas
-    canvas = tvg::GlCanvas::gen();
-    canvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
-
-    //Prepare a Shape (Rectangle + Rectangle + Circle + Circle)
-    auto shape1 = tvg::Shape::gen();
-    shape1->appendRect(0, 0, 200, 200, 0);          //x, y, w, h, cornerRadius
-    shape1->appendRect(100, 100, 300, 300, 100);    //x, y, w, h, cornerRadius
-    shape1->appendCircle(400, 400, 100, 100);       //cx, cy, radiusW, radiusH
-    shape1->appendCircle(400, 500, 170, 100);       //cx, cy, radiusW, radiusH
-    shape1->fill(255, 255, 0, 255);                 //r, g, b, a
-    shape1->stroke(255, 0, 0, 255);                 //r, g, b, a
-    shape1->stroke(10.0f);
-
-    /* Push the shape into the Canvas drawing list
-       When this shape is into the canvas list, the shape could update & prepare
-       internal data asynchronously for coming rendering.
-       Canvas keeps this shape node unless user call canvas->clear() */
-    canvas->push(move(shape1));
-}
-
-void init_gl(Evas_Object *obj)
-{
-    //Initialize ThorVG Engine
-    tvg::Initializer::init(tvg::CanvasEngine::Gl);
-
-    tvgtest();
-}
-
-void del_gl(Evas_Object *obj)
-{
-    //Terminate ThorVG Engine
-    tvg::Initializer::term(tvg::CanvasEngine::Gl);
-}
-
-void draw_gl(Evas_Object *obj)
-{
-    Evas_GL_API *gl = elm_glview_gl_api_get(obj);
-    int w, h;
-    elm_glview_size_get(obj, &w, &h);
-    gl->glViewport(0, 0, w, h);
-    gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-    gl->glClear(GL_COLOR_BUFFER_BIT);
-    gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
-    gl->glEnable(GL_BLEND);
-
-    canvas->draw();
-    canvas->sync();
-}
-
-void win_del(void *data, Evas_Object *o, void *ev)
-{
-    elm_exit();
-}
-
-int main(int argc, char **argv)
-{
-    //Show the result using EFL...
-    elm_init(argc, argv);
-
-    elm_config_accel_preference_set("gl");
-
-    Eo* win = elm_win_util_standard_add(nullptr, "ThorVG Test");
-    evas_object_smart_callback_add(win, "delete,request", win_del, 0);
-
-    //Create a new glview object
-    Eo* gl = elm_glview_add(win);
-    glapi = elm_glview_gl_api_get(gl);
-    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
-    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-
-    elm_glview_mode_set(gl, ELM_GLVIEW_ALPHA);
-    elm_glview_resize_policy_set(gl, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
-    elm_glview_render_policy_set(gl, ELM_GLVIEW_RENDER_POLICY_ON_DEMAND);
-
-    evas_object_resize(gl, WIDTH, HEIGHT);
-
-    //Initialize callback function gets registered here
-    elm_glview_init_func_set(gl, init_gl);
-    //Delete callback function gets registered here
-    elm_glview_del_func_set(gl, del_gl);
-    elm_glview_render_func_set(gl, draw_gl);
-
-    evas_object_show(gl);
-
-    evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
-    evas_object_show(win);
-
-    elm_run();
-    elm_shutdown();
-
-    return 0;
-}
index a79c770..e32142f 100644 (file)
@@ -6,17 +6,8 @@ using namespace std;
 #define WIDTH 800
 #define HEIGHT 800
 
-static uint32_t buffer[WIDTH * HEIGHT];
-
-void tvgtest()
+unique_ptr<tvg::Paint> tvgDrawCmds()
 {
-    //Initialize ThorVG Engine
-    tvg::Initializer::init(tvg::CanvasEngine::Sw);
-
-    //Create a Canvas
-    auto canvas = tvg::SwCanvas::gen();
-    canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
-
     //Prepare a Shape (Rectangle + Rectangle + Circle + Circle)
     auto shape1 = tvg::Shape::gen();
     shape1->appendRect(0, 0, 200, 200, 0);          //x, y, w, h, cornerRadius
@@ -25,12 +16,27 @@ void tvgtest()
     shape1->appendCircle(400, 500, 170, 100);       //cx, cy, radiusW, radiusH
     shape1->fill(255, 255, 0, 255);                 //r, g, b, a
 
+    return move(shape1);
+}
+
+/************************************************************************/
+/* Sw Engine Test Code                                                  */
+/************************************************************************/
+
+void tvgSwTest(uint32_t* buffer)
+{
+    //Initialize ThorVG Engine
+    tvg::Initializer::init(tvg::CanvasEngine::Sw);
+
+    //Create a Canvas
+    auto canvas = tvg::SwCanvas::gen();
+    canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
+
     /* Push the shape into the Canvas drawing list
        When this shape is into the canvas list, the shape could update & prepare
        internal data asynchronously for coming rendering.
        Canvas keeps this shape node unless user call canvas->clear() */
-    canvas->push(move(shape1));
-
+    canvas->push(tvgDrawCmds());
     canvas->draw();
     canvas->sync();
 
@@ -38,29 +44,101 @@ void tvgtest()
     tvg::Initializer::term(tvg::CanvasEngine::Sw);
 }
 
+/************************************************************************/
+/* GL Engine Test Code                                                  */
+/************************************************************************/
+
+static unique_ptr<tvg::GlCanvas> canvas;
+
+void initGLview(Evas_Object *obj)
+{
+    static constexpr auto BPP = 4;
+
+    //Initialize ThorVG Engine
+    tvg::Initializer::init(tvg::CanvasEngine::Gl);
+
+    //Create a Canvas
+    canvas = tvg::GlCanvas::gen();
+    canvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
+
+    /* Push the shape into the Canvas drawing list
+       When this shape is into the canvas list, the shape could update & prepare
+       internal data asynchronously for coming rendering.
+       Canvas keeps this shape node unless user call canvas->clear() */
+    canvas->push(tvgDrawCmds());
+}
+
+void delGLview(Evas_Object *obj)
+{
+    //Terminate ThorVG Engine
+    tvg::Initializer::term(tvg::CanvasEngine::Gl);
+}
+
+void drawGLview(Evas_Object *obj)
+{
+    auto gl = elm_glview_gl_api_get(obj);
+    int w, h;
+    elm_glview_size_get(obj, &w, &h);
+    gl->glViewport(0, 0, w, h);
+    gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+    gl->glClear(GL_COLOR_BUFFER_BIT);
+    gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
+    gl->glEnable(GL_BLEND);
+
+    canvas->draw();
+    canvas->sync();
+}
+
+/************************************************************************/
+/* Common Infrastructure Code                                           */
+/************************************************************************/
+
 void win_del(void *data, Evas_Object *o, void *ev)
 {
    elm_exit();
 }
 
-
 int main(int argc, char **argv)
 {
-    tvgtest();
+    bool swEngine = true;
+
+    if (argc > 1) {
+        if (!strcmp(argv[1], "gl")) swEngine = false;
+    }
 
-    //Show the result using EFL...
     elm_init(argc, argv);
 
+    //Show the result using EFL...
+    elm_config_accel_preference_set("gl");
+
     Eo* win = elm_win_util_standard_add(NULL, "ThorVG Test");
     evas_object_smart_callback_add(win, "delete,request", win_del, 0);
 
-    Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
-    evas_object_image_size_set(img, WIDTH, HEIGHT);
-    evas_object_image_data_set(img, buffer);
-    evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-    evas_object_show(img);
-
-    elm_win_resize_object_add(win, img);
+    Eo* viewer;
+
+    if (swEngine) {
+        static uint32_t buffer[WIDTH * HEIGHT];
+        viewer = evas_object_image_filled_add(evas_object_evas_get(win));
+        evas_object_image_size_set(viewer, WIDTH, HEIGHT);
+        evas_object_image_data_set(viewer, buffer);
+        evas_object_size_hint_weight_set(viewer, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+        evas_object_show(viewer);
+        tvgSwTest(buffer);
+    //GlEngine
+    } else {
+        viewer = elm_glview_add(win);
+        evas_object_size_hint_weight_set(viewer, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+        elm_glview_mode_set(viewer, ELM_GLVIEW_ALPHA);
+        elm_glview_resize_policy_set(viewer, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
+        elm_glview_render_policy_set(viewer, ELM_GLVIEW_RENDER_POLICY_ON_DEMAND);
+        elm_glview_init_func_set(viewer, initGLview);
+        elm_glview_del_func_set(viewer, delGLview);
+        elm_glview_render_func_set(viewer, drawGLview);
+        evas_object_show(viewer);
+    }
+
+    elm_win_resize_object_add(win, viewer);
     evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
     evas_object_show(win);