]> O.S.I.I.S - jp/vkvg.git/commitdiff
tests
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 26 Apr 2020 08:55:12 +0000 (10:55 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 5 May 2020 20:14:27 +0000 (22:14 +0200)
tests/circles.c
tests/common/test.c
tests/dashes.c
tests/dashes2.c [new file with mode: 0644]
tests/fill.c
tests/gradient_transform.c
tests/line_join.c
tests/svg.c
tests/test1.c

index a1de285a41c3575ba68aff37503904605a7b960f..42af4d9e5b1b0a825a47845efb1b53c14d4073e3 100644 (file)
@@ -3,15 +3,19 @@
 void test(){
     VkvgContext ctx = vkvg_create(surf);
 
+
     vkvg_set_line_width(ctx, 1);
     vkvg_set_source_rgb   (ctx, 1,1,1);
     vkvg_paint(ctx);
     vkvg_set_source_rgb   (ctx, 0,0,0);
 
+    vkvg_scale(ctx,10.0f,10.0f);
+    //vkvg_scale(ctx,2.0f,2.0f);
+
     float x = 10;
     float r = 1;
     while (x < 600){
-        vkvg_arc(ctx, x, 300,   r, 0, M_PI*2);
+        vkvg_arc(ctx, x+0.5f, 10.5f,   r, 0, M_PI*2);
         x += r;
         r ++;
         x += r + 5;
index c03de4ced92a366702ddb19799aa268405aa50e3..07be05748ed827549c6a2c49b18f4bcf72a8c904 100644 (file)
@@ -33,7 +33,7 @@ VkvgDevice device = NULL;
 VkvgSurface surf = NULL;
 
 uint32_t test_size = 100;  // items drawn in one run, or complexity
-int iterations = 10000;   // repeat test n times
+int iterations = 40000;   // repeat test n times
 
 static bool paused = false;
 static VkSampleCountFlags samples = VK_SAMPLE_COUNT_8_BIT;
@@ -187,15 +187,15 @@ void run_test_func (void(*testfunc)(void),uint32_t width, uint32_t height) {
         i++;
     }
 
-    double avg_run_time = run_total / (double)iterations;
-    double med_run_time = median_run_time (run_time_values, iterations);
-    double standard_dev = standard_deviation (run_time_values, iterations, avg_run_time);
+    double avg_run_time = run_total / (double)i;
+    double med_run_time = median_run_time (run_time_values, i);
+    double standard_dev = standard_deviation (run_time_values, i, avg_run_time);
     double avg_frames_per_second = (1.0 / avg_run_time);
     avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999;
 
     free (run_time_values);
 
-    printf ("size:%d iter:%d  avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, iterations, avg_frames_per_second, avg_run_time, med_run_time, standard_dev);
+    printf ("size:%d iter:%d  avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev);
 }
 void clear_test () {
     vkDeviceWaitIdle(e->dev->dev);
@@ -299,15 +299,15 @@ void perform_test (void(*testfunc)(void),uint32_t width, uint32_t height) {
         i++;
     }
 
-    double avg_run_time = run_total / (double)iterations;
-    double med_run_time = median_run_time (run_time_values, iterations);
-    double standard_dev = standard_deviation (run_time_values, iterations, avg_run_time);
+    double avg_run_time = run_total / (double)i;
+    double med_run_time = median_run_time (run_time_values, i);
+    double standard_dev = standard_deviation (run_time_values, i, avg_run_time);
     double avg_frames_per_second = (1.0 / avg_run_time);
     avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999;
 
     free (run_time_values);
 
-    printf ("size:%d iter:%d  avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, iterations, avg_frames_per_second, avg_run_time, med_run_time, standard_dev);
+    printf ("size:%d iter:%d  avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, i, avg_frames_per_second, avg_run_time, med_run_time, standard_dev);
 
     vkDeviceWaitIdle(e->dev->dev);
 
index 2cc0dcfe6029664fc8a3b5a682e92608184ed94c..a0acdb15ce42c6a82c7aeeb983b5f9ad96a62c09 100644 (file)
@@ -6,22 +6,37 @@ void test(){
 
     VkvgContext ctx = vkvg_create(surf);
     //const float dashes[] = {160.0f, 80};
-    //const float dashes[] = {160.0f, 30};
-    const float dashes[] = {50, 40};
+    float dashes[] = {700.0f, 30};
+    //const float dashes[] = {50, 40};
     vkvg_set_line_cap(ctx, VKVG_LINE_CAP_ROUND);
     vkvg_set_dash(ctx, dashes, 2, offset);
     vkvg_set_line_width(ctx, 20);
     vkvg_set_source_rgb(ctx, 0, 0, 1);
 
-    vkvg_move_to (ctx, 50, 50);
+    vkvg_move_to (ctx, 150, 50);
     vkvg_rel_line_to (ctx, 500, 0);
-    vkvg_rel_line_to (ctx, 0, 500);
-    vkvg_rel_line_to (ctx, 200, 0);
     vkvg_rel_line_to (ctx, 0, 200);
+    vkvg_rel_line_to (ctx, 200, 0);
+    vkvg_rel_line_to (ctx, 0, 500);
     vkvg_rel_line_to (ctx, -700, 0);
     vkvg_close_path(ctx);
     vkvg_stroke (ctx);
 
+    dashes[0] = 0;
+    dashes[1] = 30;
+    vkvg_set_dash(ctx, dashes, 2, offset);
+
+    vkvg_set_source_rgb(ctx, 0, 1, 0);
+
+    vkvg_move_to (ctx, 200, 100);
+    vkvg_rel_line_to (ctx, 400, 0);
+    vkvg_rel_line_to (ctx, 0, 200);
+    vkvg_rel_line_to (ctx, 200, 0);
+    vkvg_rel_line_to (ctx, 0, 400);
+    vkvg_rel_line_to (ctx, -600, 0);
+    vkvg_close_path(ctx);
+    vkvg_stroke (ctx);
+
     vkvg_destroy(ctx);
 }
 
diff --git a/tests/dashes2.c b/tests/dashes2.c
new file mode 100644 (file)
index 0000000..8c1b26a
--- /dev/null
@@ -0,0 +1,31 @@
+#include "test.h"
+
+void test(){
+    VkvgContext ctx = vkvg_create(surf);
+
+    const float dashes[] = {0, 8};
+    vkvg_set_line_cap(ctx, VKVG_LINE_CAP_ROUND);
+    vkvg_set_dash(ctx, dashes, 2, 0);
+    vkvg_set_line_width(ctx, 4);
+
+    vkvg_move_to    (ctx, 100, 400);
+    vkvg_curve_to   (ctx, 100, 100, 600, 700, 600, 400);
+    vkvg_curve_to   (ctx, 1000, 100, 100, 800, 1000, 800);
+    vkvg_curve_to   (ctx, 1000, 500, 700, 500, 700, 100);
+    //vkvg_close_path(ctx);
+
+    //vkvg_set_source_rgba   (ctx, 0.5,0.0,1.0,0.5);
+    //vkvg_fill_preserve(ctx);
+
+    vkvg_set_source_rgba   (ctx, 1,0,0,1);
+    vkvg_stroke(ctx);
+
+    vkvg_destroy(ctx);
+}
+
+int main(int argc, char *argv[]) {
+
+    perform_test (test, 1024, 768);
+
+    return 0;
+}
index 612afc5ef0b6bef441b8daec72e55c81973efa70..8813e262d63cf74b013b3869e2bc41992011ca32 100644 (file)
@@ -2,17 +2,20 @@
 
 void test(){
     VkvgContext ctx = vkvg_create(surf);
+    vkvg_set_line_width(ctx,30);
+    vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND);
 
     vkvg_set_source_rgba(ctx,0.1,0.9,0.1,1.0);
     vkvg_move_to(ctx,100,100);
-    vkvg_rel_line_to(ctx,100,100);
-    vkvg_rel_line_to(ctx,100,-100);
+    vkvg_rel_line_to(ctx,50,200);
+    vkvg_rel_line_to(ctx,150,-100);
     vkvg_rel_line_to(ctx,100,200);
     vkvg_rel_line_to(ctx,-100,100);
-    vkvg_rel_line_to(ctx,-100,-100);
-    vkvg_rel_line_to(ctx,-100,-50);
-    //vkvg_close_path(ctx);
-    vkvg_fill(ctx);
+    vkvg_rel_line_to(ctx,-10,-100);
+    vkvg_rel_line_to(ctx,-190,-50);
+    vkvg_close_path(ctx);
+
+    vkvg_stroke(ctx);
 
     vkvg_destroy(ctx);
 }
index 196fe9eff9793f444f6ccf41d000d932f3715a0f..6012648bd917b7c5c0b83d081f8b2e597f6bc429 100644 (file)
@@ -5,19 +5,21 @@ void test(){
 
     //vkvg_translate(ctx,-100,-100);
 
-    vkvg_translate(ctx,100,100);
+    vkvg_translate(ctx,200,100);
     vkvg_rotate(ctx,0.5);
 
-    vkvg_scale(ctx,2,2);
-    VkvgPattern pat = vkvg_pattern_create_linear(0,0,200,0);
+    //vkvg_scale(ctx,2,2);
+    VkvgPattern pat = vkvg_pattern_create_linear(0,0,400,0);
+    vkvg_pattern_set_extend(pat, VKVG_EXTEND_NONE);
     vkvg_set_line_width(ctx, 20);
     vkvg_pattern_add_color_stop(pat, 0, 1, 0, 0, 1);
     vkvg_pattern_add_color_stop(pat, 0.5, 0, 1, 0, 1);
     vkvg_pattern_add_color_stop(pat, 1, 0, 0, 1, 1);
     vkvg_set_source (ctx, pat);
-    vkvg_rectangle(ctx,0,0,200,200);
-    vkvg_fill (ctx);
-    //vkvg_stroke (ctx);
+    vkvg_rectangle(ctx,0,0,400,200);
+    //vkvg_fill (ctx);
+    vkvg_stroke (ctx);
+    //vkvg_paint(ctx);
     vkvg_pattern_destroy (pat);
 
     vkvg_destroy(ctx);
index 03c9d258d3f9fbc963a66bebd3f4aa6afc65cea6..5dd2149812e4e594c91cc581951c9e49125441d5 100644 (file)
@@ -3,18 +3,22 @@
 void test(){
     VkvgContext ctx = vkvg_create(surf);
 
-    float x = 50, y = 150, dx = 150, dy = 140;
+    float x = 250, y = 150, dx = 150, dy = 140;
 
-    vkvg_scale(ctx,2,2);
+    //vkvg_scale(ctx,2,2);
 
-    vkvg_set_line_width(ctx,40);
-    vkvg_set_source_rgba(ctx,0,0,0,1);
+    vkvg_set_line_width(ctx,100);
+    vkvg_set_source_rgba(ctx,0,1,0,1);
 
 
     vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND);
     //vkvg_rectangle(ctx,x,y,dx,dy);
 
     vkvg_move_to(ctx,x,y);
+    vkvg_rel_line_to(ctx,-50,30);
+    vkvg_rel_line_to(ctx,0,60);
+    vkvg_rel_line_to(ctx,50,30);
+    /*
     vkvg_rel_line_to(ctx,50,-30);
     vkvg_rel_line_to(ctx,50,0);
     vkvg_rel_line_to(ctx,50,30);
@@ -33,11 +37,12 @@ void test(){
     vkvg_rel_line_to(ctx,0,-60);
     vkvg_rel_line_to(ctx,-50,-30);
     vkvg_rel_line_to(ctx,-50,0);
-    vkvg_rel_line_to(ctx,-50,30);
+    vkvg_rel_line_to(ctx,-50,30);*/
     vkvg_close_path(ctx);
     vkvg_stroke(ctx);
 
-    vkvg_move_to(ctx,x,y);
+    vkvg_set_source_rgba(ctx,0,0,1,1);
+    vkvg_move_to(ctx,x+250,y);
     vkvg_rel_line_to(ctx,50,-30);
     vkvg_rel_line_to(ctx,50,0);
     vkvg_rel_line_to(ctx,50,30);
index 36df00ce5728dd23627cf6acccae36f461108076..7d148179f688ed85bbe772af2b5a08896c0e85e0 100644 (file)
@@ -4,14 +4,6 @@
 //#define NANOSVG_IMPLEMENTATION       // Expands implementation
 #include "nanosvg.h"
 
-/*void _svg_set_color (VkvgContext ctx, uint32_t c, float alpha) {
-    float a = (c >> 24 & 255) / 255.f;
-    float b = (c >> 16 & 255) / 255.f;
-    float g = (c >> 8 & 255) / 255.f;
-    float r = (c & 255) / 255.f;
-    vkvg_set_source_rgba(ctx,r,g,b,a*alpha);
-}*/
-
 static float rotation = 0.f;
 static const char* path = "data/tiger.svg";
 //static const char* path = "data/vkvg.svg";
@@ -42,6 +34,7 @@ void test_nsvg() {
 
     vkvg_scale(ctx,1.0f,1.0f);
     //vkvg_render_svg(ctx, svg, "wq");
+
     vkvg_render_svg(ctx, svg, NULL);
 
     vkvg_destroy(ctx);
@@ -49,88 +42,6 @@ void test_nsvg() {
     nsvg_destroy(svg);
 }
 
-void test_svg () {
-    rotation+=0.01f;
-
-    vkvg_matrix_t mat;
-    vkvg_matrix_init_translate (&mat, 512,400);
-    vkvg_matrix_rotate(&mat,rotation);
-    vkvg_matrix_translate(&mat,-512,-400);
-
-    VkvgContext ctx = vkvg_create(surf);
-    vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD);
-    vkvg_set_source_rgba(ctx,1.0,1.0,1.0,1);
-    vkvg_paint(ctx);
-
-    vkvg_set_matrix(ctx,&mat);
-
-    NSVGimage* svg;
-    NSVGshape* shape;
-    NSVGpath* path;
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/tux.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/world.svg", "px", 96);
-    svg = nsvgParseFromFile("data/tiger.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/koch_curve.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/diamond1.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/diamond2.svg", "px", 96);
-    //svg = nsvgParseFromFile("/home/jp/yahweh-protosinaitic.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/WMD-biological.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/Skull_and_crossbones.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/IconAlerte.svg", "px", 96);
-    //svg = nsvgParseFromFile("/mnt/data/images/svg/Svg_example4.svg", "px", 96);
-
-    //vkvg_scale(ctx, 3,3);
-    vkvg_set_source_rgba(ctx,0.0,0.0,0.0,1);
-
-    for (shape = svg->shapes; shape != NULL; shape = shape->next) {
-        vkvg_new_path(ctx);
-
-        float o = shape->opacity;
-
-        vkvg_set_line_width(ctx, shape->strokeWidth);
-
-        for (path = shape->paths; path != NULL; path = path->next) {
-            float* p = path->pts;
-            vkvg_move_to(ctx, p[0],p[1]);
-            for (int i = 1; i < path->npts-2; i += 3) {
-                p = &path->pts[i*2];
-                vkvg_curve_to(ctx, p[0],p[1], p[2],p[3], p[4],p[5]);
-            }
-            if (path->closed)
-                vkvg_close_path(ctx);
-        }
-
-        if (shape->fill.type == NSVG_PAINT_COLOR)
-            _svg_set_color(ctx, shape->fill.color, o);
-        else if (shape->fill.type == NSVG_PAINT_LINEAR_GRADIENT){
-            NSVGgradient* g = shape->fill.gradient;
-            _svg_set_color(ctx, g->stops[0].color, o);
-        }
-
-        if (shape->fill.type != NSVG_PAINT_NONE){
-            if (shape->stroke.type == NSVG_PAINT_NONE){
-                vkvg_fill(ctx);
-                continue;
-            }
-            vkvg_fill_preserve (ctx);
-        }
-
-        if (shape->stroke.type == NSVG_PAINT_COLOR)
-            _svg_set_color(ctx, shape->stroke.color, o);
-        else if (shape->stroke.type == NSVG_PAINT_LINEAR_GRADIENT){
-            NSVGgradient* g = shape->stroke.gradient;
-            _svg_set_color(ctx, g->stops[0].color, o);
-        }
-
-        vkvg_stroke(ctx);
-    }
-
-    nsvgDelete(svg);
-
-
-    vkvg_destroy(ctx);
-}
-
 int main(int argc, char *argv[]) {
 
     perform_test (test_nsvg, 1024, 800);
index 8036c3385fae87ad5c16dd6f8e1d327bd8401958..07ca3b0d2b6ea08a7a4d1abb4edcb4a497f72a0c 100644 (file)
@@ -61,12 +61,16 @@ void cairo_test_fill_rule (VkvgContext cr){
 }
 void cairo_test_text (VkvgContext cr) {
     vkvg_text_extents_t extents;
+    vkvg_font_extents_t ft;
 
-    const char *utf8 = "vkvg";
+    //vkvg_set_fill_rule(cr, VKVG_FILL_RULE_NON_ZERO);
+    const char *utf8 = "vkvg|Ãp";
     float x,y;
 
-    vkvg_select_font_face (cr, "times");
-    vkvg_set_font_size (cr, 100.0);
+    //vkvg_select_font_face (cr, "times");
+    vkvg_select_font_face (cr, "linux biolinum keyboard");
+    vkvg_set_font_size (cr, 50);
+    vkvg_font_extents(cr, &ft);
     vkvg_text_extents (cr, utf8, &extents);
     vkvg_set_source_rgb(cr,0,0,0);
 
@@ -77,15 +81,36 @@ void cairo_test_text (VkvgContext cr) {
     vkvg_show_text (cr, utf8);
 
     /* draw helping lines */
-    vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
-    vkvg_set_line_width (cr, 6.0);
+    vkvg_set_source_rgba (cr, 0, 0.2, 0.2, 0.6);
+    vkvg_set_line_width (cr, 1.0);
     vkvg_new_path(cr);
     vkvg_arc (cr, x, y, 10.0, 0, 2*M_PI);
     vkvg_fill (cr);
     vkvg_move_to (cr, x,y);
-    vkvg_rel_line_to (cr, 0, -extents.height);
+    //vkvg_rel_line_to (cr, 0, -30);
+    vkvg_rel_line_to (cr, 0, -ft.ascent);
     vkvg_rel_line_to (cr, extents.width, 0);
     vkvg_rel_line_to (cr, extents.x_bearing, -extents.y_bearing);
+
+    vkvg_stroke (cr);
+
+    vkvg_move_to (cr, x,y);
+    vkvg_rel_line_to (cr, extents.width, 0);
+    vkvg_set_source_rgba (cr, 0.0, 0.0, 0.9, 0.6);
+
+    vkvg_stroke (cr);
+
+    vkvg_move_to (cr, x,y);
+    vkvg_rel_line_to (cr, 0, -ft.descent);
+    vkvg_rel_line_to (cr, extents.width, 0);
+    vkvg_set_source_rgba (cr, 0.9, 0.0, 0.0, 0.6);
+
+    vkvg_stroke (cr);
+
+    vkvg_move_to (cr, x-10,y-ft.ascent);
+    vkvg_rel_line_to (cr, 0, ft.height);
+    vkvg_set_source_rgba (cr, 0.0, 0.1, 0.0, 0.6);
+
     vkvg_stroke (cr);
 }
 void cairo_test_clip (VkvgContext cr){
@@ -300,7 +325,7 @@ void cairo_print_arc (VkvgContext cr) {
 static float rotation = 0.f;
 
 void cairo_tests () {
-    rotation+=0.01f;
+    rotation+=0.002f;
 
     vkvg_matrix_t mat;
     vkvg_matrix_init_translate (&mat, 512,400);
@@ -314,7 +339,7 @@ void cairo_tests () {
     vkvg_set_source_rgba(ctx,1.0f,1.0f,1.0f,1);
     vkvg_paint(ctx);
 
-    vkvg_set_matrix(ctx,&mat);
+    //vkvg_set_matrix(ctx,&mat);
 
     cairo_print_arc(ctx);