]> O.S.I.I.S - jp/vkvg.git/commitdiff
write to png as test option (-w filepath)
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 25 Dec 2021 11:12:22 +0000 (12:12 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 25 Dec 2021 11:12:22 +0000 (12:12 +0100)
tests/common/test.c
tests/text.c

index fc2daa5882c3eb8b897fdb6e29e7189b39ac70d8..47fa8e0e43f3045c7c4823048ff56fd96e2669a9 100644 (file)
@@ -50,6 +50,7 @@ static bool paused = false;
 static VkSampleCountFlags samples = VK_SAMPLE_COUNT_1_BIT;
 static VkPhysicalDeviceType preferedPhysicalDeviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
 static vk_engine_t* e;
+static char* saveToPng = NULL;
 
 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
        if (action != GLFW_PRESS)
@@ -193,6 +194,7 @@ void _print_usage_and_exit () {
        printf("\t-q:\t\tQuiet, don't print measures table head row, usefull for batch tests.\n");
        printf("\t-p:\t\tPrint test details and exit without performing test, usefull to print details in logs.\n");
        printf("\t-vsync:\t\tEnable VSync, disabled by default.\n");
+       printf("\t-w filepath:\t\twrite last image to png.\n");
        printf("\t-h:\t\tThis help message.\n");
        printf("\n");
        exit(-1);
@@ -274,7 +276,12 @@ void _parse_args (int argc, char* argv[]) {
                        default:
                                _print_usage_and_exit();
                        }
-               }
+               }else if (strcmp (argv[i], "-w\0") == 0) {
+                       if (argc -1 < ++i)
+                               _print_usage_and_exit();
+                       saveToPng = argv[i];
+               }else
+                       _print_usage_and_exit();
        }
        if (printTestDetailsAndExit) {
                #ifdef DEBUG
@@ -474,6 +481,9 @@ void perform_test_offscreen (void(*testfunc)(void), const char *testName, int ar
 
        vkDeviceWaitIdle(dev->dev);
 
+       if (saveToPng)
+               vkvg_surface_write_to_png (surf, saveToPng);
+
        vkvg_surface_destroy    (surf);
        vkvg_device_destroy     (device);
 
@@ -591,6 +601,9 @@ void perform_test (void(*testfunc)(void), const char *testName, int argc, char*
                i++;
        }
 
+       if (saveToPng)
+               vkvg_surface_write_to_png (surf, saveToPng);
+
        _print_results (testName, argc, argv, i, run_total, run_time_values);
 
        free (run_time_values);
index 293e63ad86379d40cba99ac50a471dff75ed5961..9b2e952c1fe536518f925ff52628305ef92e7e2b 100644 (file)
@@ -7,6 +7,22 @@ void print(VkvgContext ctx, float penY, uint32_t size) {
        vkvg_move_to(ctx, 10, penY);
        vkvg_show_text (ctx,txt);
 }
+void print_boxed(VkvgContext ctx, const char* text, float penX, float penY, uint32_t size) {
+       vkvg_set_font_size(ctx,size);
+       vkvg_text_extents_t te = {0};
+       vkvg_text_extents(ctx,text,&te);
+       vkvg_font_extents_t fe = {0};
+       vkvg_font_extents(ctx, &fe);
+
+       vkvg_move_to(ctx, penX, penY);
+       vkvg_rectangle(ctx, penX, penY -fe.ascent, te.width, fe.height);
+       vkvg_set_source_rgb(ctx,0.2f,0,0);
+       vkvg_fill(ctx);
+
+       vkvg_move_to(ctx, penX, penY);
+       vkvg_set_source_rgb(ctx,1,1,1);
+       vkvg_show_text (ctx,text);
+}
 
 void test2() {
        VkvgContext ctx = vkvg_create(surf);
@@ -166,7 +182,18 @@ void single_font_and_size () {
        }
        vkvg_destroy(ctx);
 }
+void simple_text () {
+       VkvgContext ctx = vkvg_create(surf);
 
+       vkvg_set_source_rgb             (ctx, 0, 0, 0);
+       vkvg_paint                              (ctx);
+       vkvg_set_source_rgb             (ctx, 1, 1, 1);
+       vkvg_select_font_face   (ctx, "mono");
+       print_boxed                             (ctx, "This is a test string!", 50,20,12);
+       print_boxed                             (ctx, "This is a test string!", 50,50,20);
+       print_boxed                             (ctx, "ANOTHER ONE TO CHECK..", 50,80,20);
+       vkvg_destroy                    (ctx);
+}
 void random_size () {
        VkvgContext ctx = vkvg_create(surf);
        vkvg_clear(ctx);
@@ -208,6 +235,7 @@ void random_font_and_size () {
 int main(int argc, char *argv[]) {
        no_test_size = true;
        //vkvg_log_level = VKVG_LOG_INFO;
+       PERFORM_TEST (simple_text, argc, argv);
        PERFORM_TEST (single_font_and_size, argc, argv);
        PERFORM_TEST (random_size, argc, argv);
        PERFORM_TEST (random_font_and_size, argc, argv);