From: Jean-Philippe Bruyère Date: Sun, 26 Apr 2020 08:55:12 +0000 (+0200) Subject: tests X-Git-Tag: v0.1-alpha~27 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d9de26e25dac93e4563776076e90a94f8723af91;p=jp%2Fvkvg.git tests --- diff --git a/tests/circles.c b/tests/circles.c index a1de285..42af4d9 100644 --- a/tests/circles.c +++ b/tests/circles.c @@ -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; diff --git a/tests/common/test.c b/tests/common/test.c index c03de4c..07be057 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -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); diff --git a/tests/dashes.c b/tests/dashes.c index 2cc0dcf..a0acdb1 100644 --- a/tests/dashes.c +++ b/tests/dashes.c @@ -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 index 0000000..8c1b26a --- /dev/null +++ b/tests/dashes2.c @@ -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; +} diff --git a/tests/fill.c b/tests/fill.c index 612afc5..8813e26 100644 --- a/tests/fill.c +++ b/tests/fill.c @@ -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); } diff --git a/tests/gradient_transform.c b/tests/gradient_transform.c index 196fe9e..6012648 100644 --- a/tests/gradient_transform.c +++ b/tests/gradient_transform.c @@ -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); diff --git a/tests/line_join.c b/tests/line_join.c index 03c9d25..5dd2149 100644 --- a/tests/line_join.c +++ b/tests/line_join.c @@ -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); diff --git a/tests/svg.c b/tests/svg.c index 36df00c..7d14817 100644 --- a/tests/svg.c +++ b/tests/svg.c @@ -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); diff --git a/tests/test1.c b/tests/test1.c index 8036c33..07ca3b0 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -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);