test: add stress test for performance profiling. 02/237002/2
authorHermet Park <chuneon.park@samsung.com>
Wed, 24 Jun 2020 04:31:09 +0000 (13:31 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 24 Jun 2020 04:38:13 +0000 (13:38 +0900)
Change-Id: I4a1556c107ba59b7c972375ab8bfd22c777a5503

.gitignore
test/makefile
test/testStress.cpp [new file with mode: 0644]

index c2b9a6c..c8da1b2 100644 (file)
@@ -20,3 +20,4 @@ testRadialGradient
 testGradientTransform
 testSvg
 testGlShape
+testStress
index f6624fc..9f77648 100644 (file)
@@ -18,3 +18,4 @@ all:
        gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
        gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
        gcc -o testGlShape testGlShape.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
+       gcc -o testStress testStress.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
diff --git a/test/testStress.cpp b/test/testStress.cpp
new file mode 100644 (file)
index 0000000..2c1020e
--- /dev/null
@@ -0,0 +1,117 @@
+#include <tizenvg.h>
+#include <Elementary.h>
+
+using namespace std;
+
+#define WIDTH 800
+#define HEIGHT 800
+#define COUNT 50
+
+static uint32_t buffer[WIDTH * HEIGHT];
+unique_ptr<tvg::SwCanvas> canvas = nullptr;
+
+void tvgtest()
+{
+    //Create a Canvas
+    canvas = tvg::SwCanvas::gen();
+    canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
+}
+
+Eina_Bool anim_cb(void *data)
+{
+    static unsigned cnt = 0;
+
+    //Explicitly clear all retained paint nodes.
+    double t1 = ecore_time_get();
+    canvas->clear();
+    double t2 = ecore_time_get();
+
+    for (int i = 0; i < COUNT; i++) {
+        auto shape = tvg::Shape::gen();
+
+        float x = rand() % 400;
+        float y = rand() % 400;
+        float w = 1 + rand() % 600;
+        float h = 1 + rand() % 600;
+
+        shape->appendRect(x, y, w, h, rand() % 400);
+
+        if (rand() % 2) {
+            //LinearGradient
+            auto fill = tvg::LinearGradient::gen();
+            fill->linear(x, y, x + w, y + h);
+
+            //Gradient Color Stops
+            tvg::Fill::ColorStop colorStops[3];
+            colorStops[0] = {0, uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255};
+            colorStops[1] = {1, uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255};
+            colorStops[2] = {2, uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255};
+
+            fill->colorStops(colorStops, 3);
+            shape->fill(move(fill));
+        } else {
+            shape->fill(uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255);
+        }
+#if 0
+        if (rand() % 2) {
+           shape->stroke(float(rand() % 10));
+           shape->stroke(uint8_t(rand() % 255), uint8_t(rand() % 255), uint8_t(rand() % 255), 255);
+        }
+#endif
+        canvas->push(move(shape));
+    }
+
+    double t3 = ecore_time_get();
+
+    //Draw Next frames
+    canvas->draw();
+    canvas->sync();
+
+    double t4 = ecore_time_get();
+
+    printf("[%5d]: total[%fms] = clear[%fms] + update[%fms] + render[%fms]\n", ++cnt, t4 - t1, t2 - t1, t3 - t2, t4 - t3);
+
+    //Update Efl Canvas
+    Eo* img = (Eo*) data;
+    evas_object_image_data_update_add(img, 0, 0, WIDTH, HEIGHT);
+
+    return ECORE_CALLBACK_RENEW;
+}
+
+void
+win_del(void *data, Evas_Object *o, void *ev)
+{
+    elm_exit();
+}
+
+int main(int argc, char **argv)
+{
+    //Initialize TizenVG Engine
+    tvg::Initializer::init(tvg::CanvasEngine::Sw);
+
+    tvgtest();
+
+    //Show the result using EFL...
+    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);
+
+    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);
+    evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
+    evas_object_show(win);
+
+    ecore_animator_add(anim_cb, img);
+
+    elm_run();
+    elm_shutdown();
+
+    //Terminate TizenVG Engine
+    tvg::Initializer::term(tvg::CanvasEngine::Sw);
+}