common taskscheduler: revise functionalities.
[platform/core/graphics/tizenvg.git] / test / testCustomTransform.cpp
index cc0c8bb..50033f9 100644 (file)
@@ -1,20 +1,13 @@
-#include <tizenvg.h>
-#include <Elementary.h>
+#include "testCommon.h"
 
-using namespace std;
-
-#define WIDTH 800
-#define HEIGHT 800
-
-static uint32_t buffer[WIDTH * HEIGHT];
-unique_ptr<tvg::SwCanvas> canvas = nullptr;
+/************************************************************************/
+/* Drawing Commands                                                     */
+/************************************************************************/
 tvg::Shape* pShape = nullptr;
 
-void tvgtest()
+void tvgDrawCmds(tvg::Canvas* canvas)
 {
-    //Create a Canvas
-    canvas = tvg::SwCanvas::gen();
-    canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
+    if (!canvas) return;
 
     //Shape1
     auto shape = tvg::Shape::gen();
@@ -35,15 +28,15 @@ void tvgtest()
     shape->lineTo(-53, -5.5);
     shape->close();
     shape->fill(0, 0, 255, 255);
-    canvas->push(move(shape));
-
-    //Draw first frame
-    canvas->draw();
-    canvas->sync();
+    shape->stroke(3);
+    shape->stroke(255, 255, 255, 255);
+    if (canvas->push(move(shape)) != tvg::Result::Success) return;
 }
 
-void transit_cb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
+void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
 {
+    if (!canvas) return;
+
     /* Update shape directly.
        You can update only necessary properties of this shape,
        while retaining other properties. */
@@ -68,72 +61,152 @@ void transit_cb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progres
     auto t12 = m.e11 * -sinVal + m.e12 * cosVal;
     auto t21 = m.e21 * cosVal + m.e22 * sinVal;
     auto t22 = m.e21 * -sinVal + m.e22 * cosVal;
-    auto t31 = m.e31 * cosVal + m.e32 * sinVal;
-    auto t32 = m.e31 * -sinVal + m.e32 * cosVal;
+    auto t13 = m.e31 * cosVal + m.e32 * sinVal;
+    auto t23 = m.e31 * -sinVal + m.e32 * cosVal;
 
     m.e11 = t11;
     m.e12 = t12;
     m.e21 = t21;
     m.e22 = t22;
-    m.e31 = t31;
-    m.e32 = t32;
+    m.e13 = t13;
+    m.e23 = t23;
 
     //translate
-    m.e31 = progress * 300.0f + 300.0f;
-    m.e32 = progress * -100.0f + 300.0f;
+    m.e13 = progress * 300.0f + 300.0f;
+    m.e23 = progress * -100.0f + 300.0f;
 
     pShape->transform(m);
 
     //Update shape for drawing (this may work asynchronously)
     canvas->update(pShape);
+}
+
 
-    //Draw Next frames
-    canvas->draw();
-    canvas->sync();
+/************************************************************************/
+/* Sw Engine Test Code                                                  */
+/************************************************************************/
+
+static unique_ptr<tvg::SwCanvas> swCanvas;
+
+void tvgSwTest(uint32_t* buffer)
+{
+    //Create a Canvas
+    swCanvas = tvg::SwCanvas::gen();
+    swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
+
+    /* 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() */
+    tvgDrawCmds(swCanvas.get());
+}
+
+void transitSwCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
+{
+    tvgUpdateCmds(swCanvas.get(), progress);
 
     //Update Efl Canvas
     Eo* img = (Eo*) effect;
     evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
+    evas_object_image_pixels_dirty_set(img, EINA_TRUE);
+}
+
+void drawSwView(void* data, Eo* obj)
+{
+    if (swCanvas->draw() == tvg::Result::Success) {
+        swCanvas->sync();
+    }
 }
 
-void win_del(void *data, Evas_Object *o, void *ev)
+
+/************************************************************************/
+/* GL Engine Test Code                                                  */
+/************************************************************************/
+
+static unique_ptr<tvg::GlCanvas> glCanvas;
+
+void initGLview(Evas_Object *obj)
 {
-    elm_exit();
+    static constexpr auto BPP = 4;
+
+    //Create a Canvas
+    glCanvas = tvg::GlCanvas::gen();
+    glCanvas->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() */
+    tvgDrawCmds(glCanvas.get());
+}
+
+void drawGLview(Evas_Object *obj)
+{
+    auto gl = elm_glview_gl_api_get(obj);
+    gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+    gl->glClear(GL_COLOR_BUFFER_BIT);
+
+    if (glCanvas->draw() == tvg::Result::Success) {
+        glCanvas->sync();
+    }
 }
 
+void transitGlCb(Elm_Transit_Effect *effect, Elm_Transit* transit, double progress)
+{
+    tvgUpdateCmds(glCanvas.get(), progress);
+}
+
+
+/************************************************************************/
+/* Main Code                                                            */
+/************************************************************************/
+
 int main(int argc, char **argv)
 {
-    //Initialize TizenVG Engine
-    tvg::Initializer::init(tvg::CanvasEngine::Sw);
+    tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
+
+    if (argc > 1) {
+        if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
+    }
+
+    //Initialize ThorVG Engine
+    if (tvgEngine == tvg::CanvasEngine::Sw) {
+        cout << "tvg engine: software" << endl;
+    } else {
+        cout << "tvg engine: opengl" << endl;
+    }
+
+    //Threads Count
+    auto threads = std::thread::hardware_concurrency();
 
-    tvgtest();
+    //Initialize ThorVG Engine
+    if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
 
-    //Show the result using EFL...
-    elm_init(argc, argv);
+        elm_init(argc, argv);
 
-    Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test");
-    evas_object_smart_callback_add(win, "delete,request", win_del, 0);
+        Elm_Transit *transit = elm_transit_add();
 
-    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);
+        if (tvgEngine == tvg::CanvasEngine::Sw) {
+            auto view = createSwView();
+            elm_transit_effect_add(transit, transitSwCb, view, nullptr);
+        } else {
+            auto view = createGlView();
+            elm_transit_effect_add(transit, transitGlCb, view, nullptr);
+        }
 
-    elm_win_resize_object_add(win, img);
-    evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
-    evas_object_show(win);
+        elm_transit_duration_set(transit, 2);
+        elm_transit_repeat_times_set(transit, -1);
+        elm_transit_auto_reverse_set(transit, EINA_TRUE);
+        elm_transit_go(transit);
 
-    Elm_Transit *transit = elm_transit_add();
-    elm_transit_effect_add(transit, transit_cb, img, nullptr);
-    elm_transit_duration_set(transit, 2);
-    elm_transit_repeat_times_set(transit, -1);
-    elm_transit_auto_reverse_set(transit, EINA_TRUE);
-    elm_transit_go(transit);
+        elm_run();
+        elm_shutdown();
 
-    elm_run();
-    elm_shutdown();
+        //Terminate ThorVG Engine
+        tvg::Initializer::term(tvgEngine);
 
-    //Terminate TizenVG Engine
-    tvg::Initializer::term(tvg::CanvasEngine::Sw);
+    } else {
+        cout << "engine is not supported" << endl;
+    }
+    return 0;
 }