]> O.S.I.I.S - jp/vkvg.git/commitdiff
more samples dev
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 19 Aug 2025 08:07:59 +0000 (10:07 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 19 Aug 2025 08:07:59 +0000 (10:07 +0200)
samples/tests/colinear.cpp [new file with mode: 0644]
samples/tests/compositing.cpp
samples/tests/context.cpp [new file with mode: 0644]
samples/tests/fill_and_stroke.cpp [new file with mode: 0644]
samples/tests/gradient.cpp
samples/tests/recording.cpp [new file with mode: 0644]
samples/tests/save_restore.cpp [new file with mode: 0644]
samples/tests/stroke.cpp [new file with mode: 0644]
samples/tests/surface.cpp [new file with mode: 0644]
samples/tests/svg.cpp [new file with mode: 0644]
tests/CMakeLists.txt

diff --git a/samples/tests/colinear.cpp b/samples/tests/colinear.cpp
new file mode 100644 (file)
index 0000000..300c744
--- /dev/null
@@ -0,0 +1,19 @@
+#include "VkvgTest.hpp"
+
+TEST(colinear_line_to) {
+    VkvgContext ctx = vkvg_create(test->surf);
+
+    vkvg_set_source_rgba(ctx, 0.7f, 0.7f, 0.7f, 1);
+    vkvg_paint(ctx);
+
+    vkvg_set_source_rgba(ctx, 0, 1, 0, 1);
+    vkvg_set_line_width(ctx, 10);
+
+    vkvg_move_to(ctx, 100, 100);
+    vkvg_line_to(ctx, 100, 200);
+    vkvg_line_to(ctx, 100, 300);
+    vkvg_stroke(ctx);
+
+    vkvg_destroy(ctx);
+}
+
index 6ef062e68cbe13db3bee8c7fae965379ab323244..d122912e17426b27b95a45db3db133114a50af3d 100644 (file)
@@ -1,7 +1,7 @@
 #include "VkvgTest.hpp"
-
 TEST(compositing) {
     VkvgContext ctx = vkvg_create(test->surf);
+    vkvg_clear(ctx);
 
     vkvg_set_source_rgba(ctx, 1, 0, 0, 0.5f);
     vkvg_rectangle(ctx, 100, 100, 200, 200);
@@ -13,9 +13,9 @@ TEST(compositing) {
 
     vkvg_destroy(ctx);
 }
-
 TEST(opacity) {
     VkvgContext ctx = vkvg_create(test->surf);
+    vkvg_clear(ctx);
 
     vkvg_set_source_rgba(ctx, 1, 0, 0, 1.0f);
     vkvg_rectangle(ctx, 100, 100, 200, 200);
diff --git a/samples/tests/context.cpp b/samples/tests/context.cpp
new file mode 100644 (file)
index 0000000..157fbc3
--- /dev/null
@@ -0,0 +1,15 @@
+#include "VkvgTest.hpp"
+
+TEST(context_create_destroy_multi) {
+    VkvgContext* ctxs = (VkvgContext*)malloc(sizeof(VkvgContext) * test->app->testSize);
+    for (uint32_t i = 0; i < test->app->testSize; i++)
+        ctxs[i] = vkvg_create(test->surf);
+    for (uint32_t i = 0; i < test->app->testSize; i++)
+        vkvg_destroy(ctxs[i]);
+    free(ctxs);
+}
+
+TEST(context_create_destroy_single) {
+    VkvgContext ctx = vkvg_create(test->surf);
+    vkvg_destroy(ctx);
+}
diff --git a/samples/tests/fill_and_stroke.cpp b/samples/tests/fill_and_stroke.cpp
new file mode 100644 (file)
index 0000000..cfc6706
--- /dev/null
@@ -0,0 +1,47 @@
+#include "VkvgTest.hpp"
+TEST(fill_and_stroke) {
+    VkvgContext ctx = vkvg_create(test->surf);
+
+    vkvg_move_to(ctx, 100, 100);
+    vkvg_rel_line_to(ctx, 50, -80);
+    vkvg_rel_line_to(ctx, 50, 80);
+    vkvg_close_path(ctx);
+
+    vkvg_move_to(ctx, 300, 100);
+    vkvg_rel_line_to(ctx, 50, -80);
+    vkvg_rel_line_to(ctx, 50, 80);
+    vkvg_close_path(ctx);
+
+    vkvg_set_line_width(ctx, 10.0);
+    vkvg_set_source_rgb(ctx, 0, 0, 1);
+    vkvg_fill_preserve(ctx);
+    // vkvg_fill(ctx);
+    vkvg_set_source_rgb(ctx, 1, 0, 0);
+    vkvg_stroke(ctx);
+
+    vkvg_destroy(ctx);
+}
+TEST(fill_non_zero) {
+    VkvgContext ctx = vkvg_create(test->surf);
+    vkvg_save(ctx);
+    vkvg_set_line_width(ctx, 30);
+    vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
+
+    vkvg_set_source_rgba(ctx, 0.1f, 0.9f, 0.1f, 1.0f);
+    vkvg_move_to(ctx, 100, 100);
+    vkvg_rel_line_to(ctx, 200, 0);
+    vkvg_rel_line_to(ctx, 0, 150);
+    vkvg_rel_line_to(ctx, -200, 0);
+    vkvg_close_path(ctx);
+
+    vkvg_move_to(ctx, 150, 150);
+    vkvg_rel_line_to(ctx, 0, 50);
+    vkvg_rel_line_to(ctx, 100, 0);
+    vkvg_rel_line_to(ctx, 0, -50);
+    vkvg_close_path(ctx);
+
+    vkvg_fill(ctx);
+
+    vkvg_destroy(ctx);
+}
+
index 2af598d96c92cfd156e04ff6d3ef81f4853bf270..37379b395e35b6e4379f5dbe9633b63b637d68d9 100644 (file)
@@ -158,3 +158,17 @@ TEST(gradient_alpha) {
 
     vkvg_destroy(ctx);
 }
+
+TEST(gradient_radial) {
+    VkvgContext ctx = vkvg_create(test->surf);
+
+    VkvgPattern radial = vkvg_pattern_create_radial(250.0f, 250.0f, 0, 300, 300, 260.0f);
+    vkvg_pattern_add_color_stop(radial, 0.0, 1, 0, 0, 1);
+    vkvg_pattern_add_color_stop(radial, 0.5, 0, 1, 0, 1);
+    vkvg_pattern_add_color_stop(radial, 1.0, 0, 0, 0, 1);
+    vkvg_set_source(ctx, radial);
+    vkvg_paint(ctx);
+    vkvg_pattern_destroy(radial);
+
+    vkvg_destroy(ctx);
+}
diff --git a/samples/tests/recording.cpp b/samples/tests/recording.cpp
new file mode 100644 (file)
index 0000000..2abb48d
--- /dev/null
@@ -0,0 +1,41 @@
+#include "VkvgTest.hpp"
+
+#if VKVG_RECORDING
+TEST(recording) {
+    VkvgContext ctx = vkvg_create(test->surf);
+
+    vkvg_scale(ctx, 0.5, 0.5);
+    vkvg_start_recording(ctx);
+
+    vkvg_set_source_rgba(ctx, 0.1f, 0.9f, 0.1f, 1.0f);
+    vkvg_move_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, -10, -100);
+    vkvg_rel_line_to(ctx, -190, -50);
+    vkvg_rel_line_to(ctx, 300, 50);
+    vkvg_rel_line_to(ctx, 50, 0);
+    vkvg_rel_line_to(ctx, 0, 50);
+    vkvg_rel_line_to(ctx, 50, 0);
+    vkvg_rel_line_to(ctx, 0, 50);
+    vkvg_rel_line_to(ctx, 50, 0);
+    vkvg_rel_line_to(ctx, 0, 50);
+    vkvg_rel_line_to(ctx, 50, 0);
+    vkvg_rel_line_to(ctx, 0, 50);
+    vkvg_close_path(ctx);
+
+    vkvg_stroke_preserve(ctx);
+    vkvg_fill(ctx);
+
+    VkvgRecording rec = vkvg_stop_recording(ctx);
+
+    vkvg_translate(ctx, 400, 0);
+    vkvg_replay(ctx, rec);
+
+    vkvg_destroy(ctx);
+    vkvg_recording_destroy(rec);
+}
+#endif
+
diff --git a/samples/tests/save_restore.cpp b/samples/tests/save_restore.cpp
new file mode 100644 (file)
index 0000000..48833e3
--- /dev/null
@@ -0,0 +1,30 @@
+#include "VkvgTest.hpp"
+
+void recurse_draw(VkvgContext ctx, int depth) {
+    depth++;
+    vkvg_save(ctx);
+
+    vkvg_translate(ctx, 5, 5);
+    vkvg_rectangle(ctx, (float)depth, (float)depth, 200, 200);
+    /*vkvg_clip_preserve(ctx);
+    vkvg_set_source_rgb(ctx, 1.f/depth, 1.f / depth, 1.f / depth);
+    vkvg_fill_preserve(ctx);*/
+    vkvg_set_source_rgb(ctx, 0, 1, 0);
+    vkvg_stroke(ctx);
+
+    if (depth < 20)
+        recurse_draw(ctx, depth);
+
+    vkvg_restore(ctx);
+}
+
+TEST(save_restrore) {
+    VkvgContext ctx = vkvg_create(test->surf);
+    recurse_draw(ctx, 0);
+    vkvg_destroy(ctx);
+}
+
+
+
+
+
diff --git a/samples/tests/stroke.cpp b/samples/tests/stroke.cpp
new file mode 100644 (file)
index 0000000..7f9f8ab
--- /dev/null
@@ -0,0 +1,54 @@
+#include "VkvgTest.hpp"
+TEST(stroke) {
+    VkvgContext ctx = vkvg_create(test->surf);
+
+    vkvg_set_line_width(ctx, 1);
+    vkvg_set_source_rgba(ctx, 1, 0, 0, 1);
+    vkvg_move_to(ctx, 200.5f, 200.5f);
+    vkvg_line_to(ctx, 400.5f, 200.5f);
+    vkvg_line_to(ctx, 400.5f, 400.5f);
+    vkvg_line_to(ctx, 200.5f, 400.5f);
+    vkvg_close_path(ctx);
+    vkvg_stroke(ctx);
+
+    vkvg_set_source_rgba(ctx, 0, 1, 0, 1);
+    vkvg_move_to(ctx, 300.5f, 300.5f);
+    vkvg_line_to(ctx, 500.5f, 300.5f);
+    vkvg_line_to(ctx, 500.5f, 500.5f);
+    vkvg_line_to(ctx, 300.5f, 500.5f);
+    vkvg_stroke(ctx);
+
+    // vkvg_set_source_rgba(ctx,0,0.2,0.35,1);
+    // vkvg_fill(ctx);
+
+    vkvg_set_source_rgba(ctx, 0.5f, 1, 0, 1);
+    vkvg_move_to(ctx, 320.5f, 320.5f);
+    vkvg_line_to(ctx, 520.5f, 320.5f);
+    vkvg_line_to(ctx, 520.5f, 520.5f);
+    vkvg_line_to(ctx, 320.5f, 520.5f);
+    // vkvg_close_path(ctx);
+    vkvg_stroke(ctx);
+    vkvg_set_line_width(ctx, 40);
+    vkvg_set_source_rgba(ctx, 0.5f, 0.6f, 1, 1.0f);
+    vkvg_move_to(ctx, 700, 475);
+    vkvg_line_to(ctx, 400, 475);
+    vkvg_stroke(ctx);
+    vkvg_set_source_rgba(ctx, 0, 0.5f, 0.5f, 0.5f);
+    vkvg_move_to(ctx, 300, 200);
+    vkvg_arc(ctx, 200, 200, 100, 0, M_PIF);
+    vkvg_stroke(ctx);
+
+    vkvg_set_line_width(ctx, 20);
+    vkvg_set_source_rgba(ctx, 0.1f, 0.1f, 0.1f, 0.5f);
+    vkvg_move_to(ctx, 100, 60);
+    vkvg_line_to(ctx, 400, 600);
+    vkvg_stroke(ctx);
+
+    vkvg_set_source_rgba(ctx, 1, 1, 1, 1);
+    vkvg_set_line_width(ctx, 1);
+    vkvg_rectangle(ctx, 600.5f, 200.5f, 100, 60);
+    vkvg_stroke(ctx);
+
+    vkvg_destroy(ctx);
+}
+
diff --git a/samples/tests/surface.cpp b/samples/tests/surface.cpp
new file mode 100644 (file)
index 0000000..e82d176
--- /dev/null
@@ -0,0 +1,15 @@
+#include "VkvgTest.hpp"
+TEST(surface_create_destroy_multi_512) {
+    VkvgSurface* surfs = (VkvgSurface*)malloc(sizeof(VkvgSurface) * test->app->testSize);
+    for (uint32_t i = 0; i < test->app->testSize; i++)
+        surfs[i] = vkvg_surface_create(test->device, 512, 512);
+    for (uint32_t i = 0; i < test->app->testSize; i++)
+        vkvg_surface_destroy(surfs[i]);
+    free(surfs);
+}
+
+TEST(surface_create_destroy_single_512) {
+    VkvgSurface s = vkvg_surface_create(test->device, 512, 512);
+    vkvg_surface_destroy(s);
+}
+
diff --git a/samples/tests/svg.cpp b/samples/tests/svg.cpp
new file mode 100644 (file)
index 0000000..12f2895
--- /dev/null
@@ -0,0 +1,45 @@
+#include "VkvgTest.hpp"
+
+#include "vkvg-svg.h"
+
+static float       rotation   = 0.f;
+
+TEST(svg_surface_create_from_svg) {
+    VkvgSurface svgSurf = vkvg_surface_create_from_svg(test->device, test->app->width, test->app->height, GET_PATH("tiger.svg"));
+    VkvgContext ctx = vkvg_create(test->surf);
+
+    vkvg_set_source_rgb(ctx, 1, 1, 1);
+    vkvg_paint(ctx);
+
+    vkvg_set_source_surface(ctx, svgSurf, 0, 0);
+    vkvg_paint(ctx);
+
+    vkvg_destroy(ctx);
+    vkvg_surface_destroy(svgSurf);
+}
+TEST(svg_load_render) {
+    VkvgSvg  svg = vkvg_svg_load(GET_PATH("tiger.svg"));
+    uint32_t w, h;
+    vkvg_svg_get_dimensions(svg, &w, &h);
+    VkvgContext ctx = vkvg_create(test->surf);
+    vkvg_clear(ctx);
+
+    vkvg_svg_render(svg, ctx, NULL);
+
+    vkvg_destroy(ctx);
+    vkvg_svg_destroy(svg);
+}
+TEST(svg_load_render_sub) {
+    VkvgSvg  svg = vkvg_svg_load(GET_PATH("checkbox.svg"));
+    uint32_t w, h;
+    vkvg_svg_get_dimensions(svg, &w, &h);
+    VkvgContext ctx = vkvg_create(test->surf);
+    vkvg_clear(ctx);
+
+    vkvg_svg_render(svg, ctx, "#True");
+    vkvg_translate(ctx, 200, 0);
+    vkvg_svg_render(svg, ctx, "#False");
+
+    vkvg_destroy(ctx);
+    vkvg_svg_destroy(svg);
+}
index d148dbed37b469644469878404afe2a70b7b5f44..20124e94a6009fe857305a6941f4a613e2ae6014 100644 (file)
@@ -8,7 +8,7 @@ IF (VKVG_TEST_OFFSCREEN)
        ADD_DEFINITIONS (-DVKVG_TEST_OFFSCREEN)
 ENDIF ()
 
-set(TESTS_DATA_ROOT "${CMAKE_SOURCE_DIR}/tests/data/" CACHE STRING "Data path for tests")
+SET(TESTS_DATA_ROOT "${CMAKE_SOURCE_DIR}/tests/data/" CACHE STRING "Data path for tests")
 
 FUNCTION (buildtest TEST_FILE)
        GET_FILENAME_COMPONENT(TEST_NAME ${TEST_FILE} NAME_WE)