From: Jean-Philippe Bruyère Date: Sat, 25 Dec 2021 11:12:22 +0000 (+0100) Subject: write to png as test option (-w filepath) X-Git-Tag: v0.3.0-beta~69 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=697de125a5812c14134d30fcd933a4ca2c9b29c9;p=jp%2Fvkvg.git write to png as test option (-w filepath) --- diff --git a/tests/common/test.c b/tests/common/test.c index fc2daa5..47fa8e0 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -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); diff --git a/tests/text.c b/tests/text.c index 293e63a..9b2e952 100644 --- a/tests/text.c +++ b/tests/text.c @@ -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);