From 639cf2f0cefde91ed5b2b017c575c854c44ad970 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 14 Jun 2021 09:51:44 +0200 Subject: [PATCH] split select font face/path, preferedPhysicalDeviceType in test.c --- appveyor.yml | 2 +- include/vkvg.h | 15 +++++++++++---- src/vkvg_context.c | 3 +++ src/vkvg_context_internal.c | 2 +- src/vkvg_context_internal.h | 2 +- src/vkvg_fonts.c | 17 ++++++++++------- src/vkvg_fonts.h | 1 + tests/common/test.c | 9 +++++---- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index cf6d16f..79edab0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ for: VCPKG_DEFAULT_TRIPLET: x64-windows VULKAN_SDK: C:/VulkanSDK/1.1.130.0 APPVEYOR_SAVE_CACHE_ON_ERROR: true - APPVEYOR_CACHE_SKIP_RESTORE: true + APPVEYOR_CACHE_SKIP_RESTORE: false cache: - VulkanSDK.exe - c:\tools\vcpkg\installed\ diff --git a/include/vkvg.h b/include/vkvg.h index 156c148..1846c17 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -1237,22 +1237,29 @@ void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix); vkvg_public void vkvg_get_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix); /** - * @brief + * @brief Reset the current transformation matrix of the provided context to the identity matrix. * * @param ctx a valid vkvg #context */ vkvg_public void vkvg_identity_matrix (VkvgContext ctx); -//text /** - * @brief + * @brief Try find font with the specified name using the FontConfig library. * * @param ctx a valid vkvg #context - * @param name + * @param name A name to be recognized by the FontConfig library */ vkvg_public void vkvg_select_font_face (VkvgContext ctx, const char* name); +/** + * @brief Select a new font by providing its file path. + * + * @param ctx a valid vkvg #context + * @param name A valid font file path. + */ +vkvg_public +void vkvg_select_font_path (VkvgContext ctx, const char* path); /** * @brief * diff --git a/src/vkvg_context.c b/src/vkvg_context.c index e9df71e..33e4c4b 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -896,6 +896,9 @@ VkvgPattern vkvg_get_source (VkvgContext ctx){ void vkvg_select_font_face (VkvgContext ctx, const char* name){ _select_font_face (ctx, name); } +void vkvg_select_font_path (VkvgContext ctx, const char* path){ + _select_font_path (ctx, path); +} void vkvg_set_font_size (VkvgContext ctx, uint32_t size){ _set_font_size (ctx,size); } diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index d3df56b..025b63e 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -1056,7 +1056,7 @@ void _poly_fill (VkvgContext ctx){ _end_render_pass(ctx); _flush_vertices_caches(ctx); vkh_cmd_end(ctx->cmd); - _wait_and_submit_cmd(ctx); + _wait_and_submit_cmd(ctx);//the extra wait here is not useful. if (ctx->vertCount + ctx->pointCount > ctx->sizeVBO){ //_resize_vertex_cache(ctx, ctx->vertCount + ctx->pointCount); _resize_vbo(ctx, ctx->vertCount + ctx->pointCount); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 4f65868..1b302ba 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -127,7 +127,7 @@ typedef struct _vkvg_context_t { //vk buffers, holds data until flush vkvg_buff indices; //index buffer with persistent map memory - uint32_t sizeIBO; //size of vk ibo size + uint32_t sizeIBO; //size of vk ibo uint32_t sizeIndices; //reserved size uint32_t indCount; //current indice count diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c index 2255754..3cd9cf1 100644 --- a/src/vkvg_fonts.c +++ b/src/vkvg_fonts.c @@ -220,7 +220,7 @@ void _dump_glyphs (FT_Face face){ //flush font stagging buffer to cache texture array void _flush_chars_to_tex (VkvgDevice dev, _vkvg_font_t* f) { _font_cache_t* cache = dev->fontCache; - if (cache->stagingX == 0) + if (cache->stagingX == 0)//no char in stagging buff to flush return; LOG(VKVG_LOG_INFO, "_flush_chars_to_tex pen(%d, %d)\n",f->curLine.penX, f->curLine.penY); @@ -321,6 +321,12 @@ void _set_font_size (VkvgContext ctx, uint32_t size){ ctx->selectedFont.charSize = size << 6; ctx->currentFont = NULL; } + +void _select_font_path (VkvgContext ctx, const char* fontFile){ + memset (ctx->selectedFont.fontFile, 0, FONT_FILE_NAME_MAX_SIZE); + memcpy (ctx->selectedFont.fontFile, fontFile, FONT_FILE_NAME_MAX_SIZE); + ctx->currentFont = NULL; +} //select current font for context void _select_font_face (VkvgContext ctx, const char* name){ _font_cache_t* cache = (_font_cache_t*)ctx->pSurf->dev->fontCache; @@ -336,16 +342,13 @@ void _select_font_face (VkvgContext ctx, const char* name){ FcPattern* font = FcFontMatch(cache->config, pat, &result); if (font) { - if (FcPatternGetString(font, FC_FILE, 0, (FcChar8 **)&fontFile) == FcResultMatch){ - memset (ctx->selectedFont.fontFile, 0, FONT_FILE_NAME_MAX_SIZE); - memcpy (ctx->selectedFont.fontFile, fontFile, FONT_FILE_NAME_MAX_SIZE); - } + if (FcPatternGetString(font, FC_FILE, 0, (FcChar8 **)&fontFile) == FcResultMatch) + _select_font_path (ctx, fontFile); } FcPatternDestroy(pat); FcPatternDestroy(font); - - ctx->currentFont = NULL; } + //try to find font in cache with same font file path and font size as selected in context. _vkvg_font_t* _tryFindVkvgFont (VkvgContext ctx){ _font_cache_t* cache = (_font_cache_t*)ctx->pSurf->dev->fontCache; diff --git a/src/vkvg_fonts.h b/src/vkvg_fonts.h index d6bd37e..4f5211d 100644 --- a/src/vkvg_fonts.h +++ b/src/vkvg_fonts.h @@ -116,6 +116,7 @@ void _init_fonts_cache (VkvgDevice dev); void _destroy_font_cache (VkvgDevice dev); //Select current font for context from font name, create new font entry in cache if required void _select_font_face (VkvgContext ctx, const char* name); +void _select_font_path (VkvgContext ctx, const char* fontFile); //Set current font size for context void _set_font_size (VkvgContext ctx, uint32_t size); //Draw text diff --git a/tests/common/test.c b/tests/common/test.c index c64f002..0bec4d9 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -48,6 +48,7 @@ int single_test = -1; //if not < 0, contains the index of the single test to ru 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 void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { @@ -136,9 +137,9 @@ double standard_deviation (const double data[], int n, double mean) void init_test (uint32_t width, uint32_t height){ if (test_vsync) - e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, width, height); + e = vkengine_create (preferedPhysicalDeviceType, VK_PRESENT_MODE_FIFO_KHR, width, height); else - e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, width, height); + e = vkengine_create (preferedPhysicalDeviceType, VK_PRESENT_MODE_MAILBOX_KHR, width, height); VkhPresenter r = e->renderer; vkengine_set_key_callback (e, key_callback); @@ -416,9 +417,9 @@ void perform_test (void(*testfunc)(void), const char *testName, int argc, char* } if (test_vsync) - e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, test_width, test_height); + e = vkengine_create (preferedPhysicalDeviceType, VK_PRESENT_MODE_FIFO_KHR, test_width, test_height); else - e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, test_width, test_height); + e = vkengine_create (preferedPhysicalDeviceType, VK_PRESENT_MODE_MAILBOX_KHR, test_width, test_height); VkhPresenter r = e->renderer; vkengine_set_key_callback (e, key_callback); -- 2.47.3