diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-10-22 00:37:36 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-10-22 00:37:36 +0200 |
| commit | c92b15f3cafb24ae55404b27d67031f0031f1740 (patch) | |
| tree | bc5b26b0dc26ba30a74c95f6ba3bc9b52348c985 | |
| parent | 745160b4e258f9f09797086f3839184ceef7d24c (diff) | |
debug, code clean up, wip
| -rw-r--r-- | gunit_tests/context.cpp | 1 | ||||
| -rw-r--r-- | gunit_tests/drawTestBase.cpp | 2 | ||||
| -rw-r--r-- | gunit_tests/textDraw.cpp | 13 | ||||
| -rw-r--r-- | samples/tests/text.cpp | 44 | ||||
| -rw-r--r-- | src/array.h | 5 | ||||
| -rw-r--r-- | src/cross_os.h | 24 | ||||
| -rw-r--r-- | src/vectors.h | 24 | ||||
| -rw-r--r-- | src/vkvg_context.c | 43 | ||||
| -rw-r--r-- | src/vkvg_context_internal.c | 65 | ||||
| -rw-r--r-- | src/vkvg_device.c | 55 | ||||
| -rw-r--r-- | src/vkvg_device_internal.c | 26 | ||||
| -rw-r--r-- | src/vkvg_device_internal.h | 35 | ||||
| -rw-r--r-- | src/vkvg_experimental.c | 24 | ||||
| -rw-r--r-- | src/vkvg_experimental.h | 24 | ||||
| -rw-r--r-- | src/vkvg_fonts.c | 60 | ||||
| -rw-r--r-- | src/vkvg_internal.h | 24 | ||||
| -rw-r--r-- | src/vkvg_matrix.c | 24 | ||||
| -rw-r--r-- | src/vkvg_matrix.h | 24 | ||||
| -rw-r--r-- | src/vkvg_pattern.c | 4 | ||||
| -rw-r--r-- | src/vkvg_surface.c | 37 | ||||
| -rw-r--r-- | src/vkvg_surface_internal.c | 40 | ||||
| -rw-r--r-- | src/vkvg_surface_internal.h | 24 | ||||
| -rw-r--r-- | tests/text.c | 18 | ||||
| -rw-r--r-- | tests/vkvg-svg/svg-viewer.c | 2 | ||||
| m--------- | vkh | 0 |
25 files changed, 231 insertions, 411 deletions
diff --git a/gunit_tests/context.cpp b/gunit_tests/context.cpp index 9f68a6b..6b9a107 100644 --- a/gunit_tests/context.cpp +++ b/gunit_tests/context.cpp @@ -164,7 +164,6 @@ TEST_F(ContextTest, CtxDrawBasicNullContext) { EXPECT_NO_FATAL_FAILURE(vkvg_select_font_face(ctx, NULL)); EXPECT_NO_FATAL_FAILURE(vkvg_load_font_from_path(ctx, NULL, NULL)); - EXPECT_NO_FATAL_FAILURE(vkvg_load_font_from_memory(ctx, NULL, 0, NULL)); EXPECT_NO_FATAL_FAILURE(vkvg_set_font_size(ctx, 0)); EXPECT_NO_FATAL_FAILURE(vkvg_show_text(ctx, NULL)); EXPECT_NO_FATAL_FAILURE(vkvg_text_extents(ctx, NULL, NULL)); diff --git a/gunit_tests/drawTestBase.cpp b/gunit_tests/drawTestBase.cpp index a4bdc20..b05710a 100644 --- a/gunit_tests/drawTestBase.cpp +++ b/gunit_tests/drawTestBase.cpp @@ -25,7 +25,7 @@ DrawTestBase::DrawTestBase() { info.samples = VK_SAMPLE_COUNT_4_BIT; fs::path fontDir = fs::path(GTEST_DATA_ROOT) / "fonts"; info.fontsDirectories = fontDir.c_str(); - dev = vkvg_device_create(&info); + dev = vkvg_device_create(&info); } DrawTestBase::~DrawTestBase() { vkvg_device_destroy(dev); } diff --git a/gunit_tests/textDraw.cpp b/gunit_tests/textDraw.cpp index d543ed7..a226a99 100644 --- a/gunit_tests/textDraw.cpp +++ b/gunit_tests/textDraw.cpp @@ -78,10 +78,23 @@ TEST_F(TextDrawTest, ShowText) { vkvg_show_text(ctx, "いろはにほへと ちりぬるを わかよたれそ つねならむ"); vkvg_font_extents(ctx, &fe); penY += fe.height; + vkvg_set_text_direction(ctx, VKVG_VERTICAL); vkvg_move_to(ctx, 20, 60); vkvg_show_text(ctx, "石英に刺激され、白ウサギはカラスたちのために、赤ギツネの上に飛び乗った。"); + vkvg_font_destroy(font); + + vkvg_set_text_direction(ctx, VKVG_HORIZONTAL); + font = vkvg_font_create(surf, "Roboto:bold", 30); + vkvg_set_font(ctx, font); + vkvg_move_to(ctx, 40, penY); + vkvg_show_text(ctx, "Galvanized by the quartz, The white rabbit just jumped on the red fox for the sake of the crows"); + vkvg_font_extents(ctx, &fe); + penY += fe.height; + + + vkvg_destroy(ctx); diff --git a/samples/tests/text.cpp b/samples/tests/text.cpp index 4f54094..3c64586 100644 --- a/samples/tests/text.cpp +++ b/samples/tests/text.cpp @@ -269,6 +269,50 @@ TEST(text_random_font_and_size) { } vkvg_destroy(ctx); } +TEST(text) { + VkvgContext ctx = vkvg_create(test->surf); + vkvg_paint(ctx); + VkvgFont font = vkvg_font_create(test->surf, "times", 30); + vkvg_set_font(ctx, font); + vkvg_font_extents_t fe = {0}; + vkvg_font_extents(ctx, &fe); + vkvg_set_source_rgb(ctx,1,1,1); + float penY = fe.ascent; + vkvg_move_to(ctx, 40, penY); + vkvg_show_text(ctx, "Galvanized by the quartz, the white rabbit just jumped on the red fox for the sake of the crows"); + penY += fe.height; + + vkvg_font_destroy(font); + + font = vkvg_font_create(test->surf, "noto sans jp", 30); + vkvg_set_font(ctx, font); + vkvg_move_to(ctx, 40, penY); + vkvg_show_text(ctx, "Galvanized by the quartz, The white rabbit just jumped on the red fox for the sake of the crows"); + vkvg_font_extents(ctx, &fe); + penY += fe.height; + + vkvg_move_to(ctx, 40, penY); + vkvg_show_text(ctx, "いろはにほへと ちりぬるを わかよたれそ つねならむ"); + vkvg_font_extents(ctx, &fe); + penY += fe.height; + + vkvg_set_text_direction(ctx, VKVG_VERTICAL); + vkvg_move_to(ctx, 20, 60); + vkvg_show_text(ctx, "石英に刺激され、白ウサギはカラスたちのために、赤ギツネの上に飛び乗った。"); + + vkvg_font_destroy(font); + + vkvg_set_text_direction(ctx, VKVG_HORIZONTAL); + font = vkvg_font_create(test->surf, "Roboto:bold", 30); + vkvg_set_font(ctx, font); + vkvg_move_to(ctx, 40, penY); + vkvg_show_text(ctx, "Galvanized by the quartz, The white rabbit just jumped on the red fox for the sake of the crows"); + vkvg_font_extents(ctx, &fe); + +// vkvg_font_destroy(font); + + vkvg_destroy(ctx); +} TEST(text_proto_sinaitic) { VkvgContext ctx = vkvg_create(test->surf); vkvg_clear(ctx); diff --git a/src/array.h b/src/array.h index 041d05f..e8ba5d9 100644 --- a/src/array.h +++ b/src/array.h @@ -1,4 +1,7 @@ -#ifndef ARRAY_H_INCLUDED +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +#ifndef ARRAY_H_INCLUDED #define ARRAY_H_INCLUDED #include <stddef.h> diff --git a/src/cross_os.h b/src/cross_os.h index 43b5206..8752870 100644 --- a/src/cross_os.h +++ b/src/cross_os.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #pragma once #include <stddef.h> diff --git a/src/vectors.h b/src/vectors.h index f67882d..a84a238 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #ifndef VKVG_VECTORS_H #define VKVG_VECTORS_H diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 9d0ad2c..09e0718 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -137,12 +137,11 @@ VkvgContext vkvg_create(VkvgSurface surf) { _init_ctx(ctx); - VkhDevice vkhd = (VkhDevice)&dev->vkDev; // for context to be thread safe, command pool and descriptor pool have to be created in the thread of the context. - ctx->cmdPool = vkh_cmd_pool_create(vkhd, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + ctx->cmdPool = vkh_cmd_pool_create(dev->vkhDev, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); #ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE - ctx->flushFence = vkh_fence_create_signaled((VkhDevice)&ctx->dev->vkDev); + ctx->flushFence = vkh_fence_create_signaled(dev->vkhDev); #endif _create_vertices_buff(ctx); @@ -160,14 +159,14 @@ VkvgContext vkvg_create(VkvgSurface surf) { ctx->sizeIBO); #if defined(DEBUG) && defined(VKVG_DBG_UTILS) - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_COMMAND_POOL, (uint64_t)ctx->cmdPool, "CTX Cmd Pool"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)ctx->cmdBuffers[0], "CTX Cmd Buff A"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)ctx->cmdBuffers[1], "CTX Cmd Buff B"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_COMMAND_POOL, (uint64_t)ctx->cmdPool, "CTX Cmd Pool"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)ctx->cmdBuffers[0], "CTX Cmd Buff A"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)ctx->cmdBuffers[1], "CTX Cmd Buff B"); #ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_FENCE, (uint64_t)ctx->flushFence, "CTX Flush Fence"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_FENCE, (uint64_t)ctx->flushFence, "CTX Flush Fence"); #endif - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->indices.buffer, "CTX Index Buff"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->vertices.buffer, "CTX Vertex Buff"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->indices.buffer, "CTX Index Buff"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->vertices.buffer, "CTX Vertex Buff"); #endif return ctx; @@ -1171,8 +1170,10 @@ VkvgPattern vkvg_get_source(VkvgContext ctx) { void vkvg_set_font (VkvgContext ctx, VkvgFont font) { if (ctx->currentFont == font) return; - if (ctx->currentFont) + if (ctx->currentFont) { + _flush_cmd_buff(ctx); vkvg_font_destroy(ctx->currentFont); + } ctx->currentFont = font; vkvg_font_reference (font); } @@ -1191,22 +1192,7 @@ void vkvg_load_font_from_path(VkvgContext ctx, const char* path, const char* nam if (vkvg_status(ctx)) return; RECORD(ctx, VKVG_CMD_SET_FONT_PATH, name); - /*vkvg_font_face_t* fid = _font_cache_add_font_identity(ctx, path, name); - if (!_font_cache_load_font_file_in_memory(fid)) { - ctx->status = VKVG_STATUS_FILE_NOT_FOUND; - return; - } - _select_font_face(ctx, name);*/ -} -void vkvg_load_font_from_memory(VkvgContext ctx, unsigned char* fontBuffer, long fontBufferByteSize, const char* name) { - if (vkvg_status(ctx)) - return; - // RECORD(ctx, VKVG_CMD_SET_FONT_PATH, name); - /*vkvg_font_face_t* fid = _font_cache_add_font_identity(ctx, NULL, name); - fid->fontBuffer = fontBuffer; - fid->fontBufSize = fontBufferByteSize;*/ - - //_select_font_face(ctx, name); + vkvg_set_font(ctx, vkvg_font_create_from_file(ctx->pSurf, path, 0, 12)); } void vkvg_set_font_size(VkvgContext ctx, uint32_t size) { if (vkvg_status(ctx)) @@ -1245,9 +1231,8 @@ void vkvg_show_text(VkvgContext ctx, const char* text) { return; RECORD(ctx, VKVG_CMD_SHOW_TEXT, text); LOG(VKVG_LOG_INFO_CMD, "CMD: show_text:\n"); - //_ensure_renderpass_is_started(ctx); + _ensure_renderpass_is_started(ctx); _font_cache_show_text(ctx, text); - //_flush_undrawn_vertices (ctx); } VkvgText vkvg_text_create(VkvgContext ctx, const char* text) { @@ -1348,7 +1333,7 @@ void vkvg_save(VkvgContext ctx) { } ctx->savedStencils = savedStencilsPtr; VkhImage savStencil = vkh_image_ms_create( - (VkhDevice)&ctx->dev->vkDev, dev->stencilFormat, ctx->pSurf->surfClass->samples, ctx->pSurf->width, ctx->pSurf->height, + ctx->dev->vkhDev, dev->stencilFormat, ctx->pSurf->surfClass->samples, ctx->pSurf->width, ctx->pSurf->height, VKH_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); ctx->savedStencils[curSaveStencil - 1] = savStencil; diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index bab2a0b..92b804c 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) // credits for bezier algorithms to: // Anti-Grain Geometry (AGG) - Version 2.5 @@ -250,9 +232,9 @@ float _get_arc_step(VkvgContext ctx, float radius) { return fminf(M_PIF / 3.f, M_PIF / (r * 0.4f)); } void _create_vertices_buff(VkvgContext ctx) { - vkh_buffer_init((VkhDevice)&ctx->dev->vkDev, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, + vkh_buffer_init(ctx->dev->vkhDev, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, ctx->sizeVBO * sizeof(Vertex), &ctx->vertices, true); - vkh_buffer_init((VkhDevice)&ctx->dev->vkDev, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, + vkh_buffer_init(ctx->dev->vkhDev, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, ctx->sizeIBO * sizeof(VKVG_IBO_INDEX_TYPE), &ctx->indices, true); } void _resize_vbo(VkvgContext ctx, uint32_t new_size) { @@ -392,10 +374,10 @@ void _ensure_renderpass_is_started(VkvgContext ctx) { _update_push_constants(ctx); } void _create_cmd_buff(VkvgContext ctx) { - vkh_cmd_buffs_create((VkhDevice)&ctx->dev->vkDev, ctx->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 2, + vkh_cmd_buffs_create(ctx->dev->vkhDev, ctx->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 2, ctx->cmdBuffers); #if defined(DEBUG) && defined(ENABLE_VALIDATION) - vkh_device_set_object_name((VkhDevice)&ctx->pSurf->dev->vkDev, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, + vkh_device_set_object_name(ctx->dev->vkhDev, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)ctx->cmd, "vkvgCtxCmd"); #endif } @@ -404,7 +386,7 @@ void _clear_attachment(VkvgContext ctx) {} bool _wait_ctx_flush_end(VkvgContext ctx) { LOG(VKVG_LOG_INFO, "CTX: _wait_flush_fence\n"); #ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE - if (vkh_timeline_wait((VkhDevice)&ctx->dev->vkDev, ctx->pSurf->timeline, ctx->timelineStep) == VK_SUCCESS) + if (vkh_timeline_wait(ctx->dev->vkhDev, ctx->pSurf->timeline, ctx->timelineStep) == VK_SUCCESS) return true; #else if (WaitForFences(ctx->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT) == VK_SUCCESS) @@ -424,7 +406,7 @@ bool _wait_and_submit_cmd(VkvgContext ctx) { #ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE VkvgSurface surf = ctx->pSurf; VkvgDevice dev = surf->dev; - // vkh_timeline_wait ((VkhDevice)&dev->vkDev, surf->timeline, ct->timelineStep); + // vkh_timeline_wait (dev->vkhDev, surf->timeline, ct->timelineStep); if (ctx->pattern && ctx->pattern->type == VKVG_PATTERN_TYPE_SURFACE) { // add source surface timeline sync. VkvgSurface source = (VkvgSurface)ctx->pattern->data; @@ -688,29 +670,32 @@ void _update_cur_pattern(VkvgContext ctx, VkvgPattern pat) { } else newPatternType = pat->type; - if (lastPat && lastPat->type == VKVG_PATTERN_TYPE_SURFACE) { - //if lastpat has only one ref, descriptorSet would be destroyed, so flush context - if (vkvg_pattern_get_reference_count(lastPat) == 1) - vkvg_flush(ctx); - } - - ctx->pattern = pat; - - switch (newPatternType) { - case VKVG_PATTERN_TYPE_SOLID: { - if (ctx->cmdStarted && lastPat) { + if (lastPat) { + if (ctx->cmdStarted) { switch (lastPat->type) { case VKVG_PATTERN_TYPE_SURFACE: - CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + //if lastpat has only one ref, descriptorSet would be destroyed, so flush context + if (vkvg_pattern_get_reference_count(lastPat) == 1) + vkvg_flush(ctx); + if (newPatternType != VKVG_PATTERN_TYPE_SURFACE) + CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout, 1, 1, &ctx->dev->dummySrcSet, 0, NULL); break; case VKVG_PATTERN_TYPE_LINEAR: case VKVG_PATTERN_TYPE_RADIAL: - CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + if (newPatternType != VKVG_PATTERN_TYPE_LINEAR && + newPatternType != VKVG_PATTERN_TYPE_RADIAL) + CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout, 2, 1, &ctx->dev->dummyGradSet, 0, NULL); break; } } + } + + ctx->pattern = pat; + + switch (newPatternType) { + case VKVG_PATTERN_TYPE_SOLID: { break; } case VKVG_PATTERN_TYPE_SURFACE: { diff --git a/src/vkvg_device.c b/src/vkvg_device.c index fc5bb4f..5f780bf 100644 --- a/src/vkvg_device.c +++ b/src/vkvg_device.c @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2025 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #include "vkvg_device_internal.h" #include "vkvg_context_internal.h" @@ -82,8 +64,6 @@ void _device_init(VkvgDevice dev, const vkvg_device_create_info_t* info) { if (dev->status != VKVG_STATUS_SUCCESS) return; - VkhDevice vkhd = (VkhDevice)&dev->vkDev; - if (!_device_init_function_pointers(dev)) { dev->status = VKVG_STATUS_NULL_POINTER; return; @@ -92,7 +72,7 @@ void _device_init(VkvgDevice dev, const vkvg_device_create_info_t* info) { VkhPhyInfo phyInfos = vkh_phyinfo_create(dev->phy, NULL); dev->phyMemProps = phyInfos->memProps; - dev->gQueue = vkh_queue_create(vkhd, info->qFamIdx, info->qIndex); + dev->gQueue = vkh_queue_create(dev->vkhDev, info->qFamIdx, info->qIndex); // mtx_init (&dev->gQMutex, mtx_plain); vkh_phyinfo_destroy(phyInfos); @@ -102,9 +82,9 @@ void _device_init(VkvgDevice dev, const vkvg_device_create_info_t* info) { vmaCreateAllocator(&allocatorInfo, (VmaAllocator*)&dev->allocator); #endif - dev->cmdPool = vkh_cmd_pool_create(vkhd, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); - dev->cmd = vkh_cmd_buff_create(vkhd, dev->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY); - dev->fence = vkh_fence_create_signaled(vkhd); + dev->cmdPool = vkh_cmd_pool_create(dev->vkhDev, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + dev->cmd = vkh_cmd_buff_create(dev->vkhDev, dev->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY); + dev->fence = vkh_fence_create_signaled(dev->vkhDev); //_device_create_pipeline_cache(dev); _device_createDescriptorSetLayout (dev); @@ -122,14 +102,14 @@ void _device_init(VkvgDevice dev, const vkvg_device_create_info_t* info) { _linux_register_error_handler(); #endif #ifdef VKVG_DBG_UTILS - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_COMMAND_POOL, (uint64_t)dev->cmdPool, "Device Cmd Pool"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)dev->cmd, "Device Cmd Buff"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_FENCE, (uint64_t)dev->fence, "Device Fence"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_COMMAND_POOL, (uint64_t)dev->cmdPool, "Device Cmd Pool"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)dev->cmd, "Device Cmd Buff"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_FENCE, (uint64_t)dev->fence, "Device Fence"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t)dev->dslSrc, "DSLayout SOURCE"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t)dev->dslFont, "DSLayout FONT"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t)dev->dslGrad, "DSLayout GRADIENT"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_PIPELINE_LAYOUT, (uint64_t)dev->pipelineLayout, "PLLayout dev"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t)dev->dslSrc, "DSLayout SOURCE"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t)dev->dslFont, "DSLayout FONT"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (uint64_t)dev->dslGrad, "DSLayout GRADIENT"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_PIPELINE_LAYOUT, (uint64_t)dev->pipelineLayout, "PLLayout dev"); #endif #endif dev->status = VKVG_STATUS_SUCCESS; @@ -345,7 +325,8 @@ VkvgDevice vkvg_device_create(vkvg_device_create_info_t* info) { .ppEnabledExtensionNames = enabledExts, .pEnabledFeatures = &enabledFeatures, .pNext = pNext}; - dev->vkhDev = vkh_device_create(app, pi, &device_info); + dev->vkhDev = vkh_device_create(app, pi, &device_info); + dev->holdVkhDev = true; info->inst = vkh_app_get_inst(app); info->phy = vkh_device_get_phy(dev->vkhDev); @@ -354,6 +335,8 @@ VkvgDevice vkvg_device_create(vkvg_device_create_info_t* info) { info->qIndex = 0; vkh_app_free_phyinfos(phyCount, phys); + } else { + dev->vkhDev = vkh_device_import(info->inst, info->phy, info->vkdev); } _device_init(dev, info); @@ -424,7 +407,7 @@ void vkvg_device_destroy(VkvgDevice dev) { mtx_destroy(&dev->fontCache->mutex); } - if (dev->vkhDev) { + if (dev->holdVkhDev) { VkhApp app = vkh_device_get_app(dev->vkhDev); vkh_device_destroy(dev->vkhDev); vkh_app_destroy(app); diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 1fdffdd..79b94eb 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #define GetInstProcAddress(inst, func) (PFN_##func) vkGetInstanceProcAddr(inst, #func); @@ -219,7 +201,7 @@ bool _device_init_function_pointers(VkvgDevice dev) { LOGE("vkvg create device failed: 'VK_EXT_debug_utils' has to be loaded for Debug build\n"); return false; } - vkh_device_init_debug_utils((VkhDevice)&dev->vkDev); + vkh_device_init_debug_utils(dev->vkhDev); #endif CmdBindPipeline = GetVkProcAddress(dev->vkDev, dev->instance, vkCmdBindPipeline); CmdBindDescriptorSets = GetVkProcAddress(dev->vkDev, dev->instance, vkCmdBindDescriptorSets); diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h index 0ea8a5b..f273b8a 100644 --- a/src/vkvg_device_internal.h +++ b/src/vkvg_device_internal.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #ifndef VKVG_DEVICE_INTERNAL_H #define VKVG_DEVICE_INTERNAL_H @@ -64,14 +46,14 @@ CTOR_ARRAY(SurfaceClass) ARRAY_DEL_ELT(SurfaceClass) typedef struct _vkvg_device_t { + vkvg_status_t status; /**< Current status of device, affected by last operation */ VkDevice vkDev; /**< Vulkan Logical Device */ - VkPhysicalDeviceMemoryProperties phyMemProps; /**< Vulkan Physical device memory properties */ VkPhysicalDevice phy; /**< Vulkan Physical device */ VkInstance instance; /**< Vulkan instance */ + VkPhysicalDeviceMemoryProperties phyMemProps; /**< Vulkan Physical device memory properties */ #ifdef VKH_USE_VMA void* allocator; /**< Vulkan Memory allocator */ #endif - vkvg_status_t status; /**< Current status of device, affected by last operation */ VkImageTiling supportedTiling; /**< Supported image tiling for surface, 0xFF=no support */ VkFormat stencilFormat; /**< Supported vulkan image format for stencil */ @@ -102,11 +84,12 @@ typedef struct _vkvg_device_t { VkDescriptorSet dummyGradSet; - VkhDevice vkhDev; /**< old VkhDev created during vulkan context creation by @ref vkvg_device_create. */ + VkhDevice vkhDev; + bool holdVkhDev; /**< vkhDevice should be destroyed */ - bool deferredResolve; /**< if true, resolve only on context destruction and set as source */ + bool deferredResolve; /**< if true, resolve only on context destruction and set as source */ - font_cache_t* fontCache; /**< Store everything relative to common font caching system */ + font_cache_t* fontCache; /**< Store everything relative to common font caching system */ VkvgContext lastCtx; /**< last element of double linked list of context, used to trigger font caching system update on all contexts*/ diff --git a/src/vkvg_experimental.c b/src/vkvg_experimental.c index 31679c0..4633301 100644 --- a/src/vkvg_experimental.c +++ b/src/vkvg_experimental.c @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #include <string.h> #include "vkvg_experimental.h" diff --git a/src/vkvg_experimental.h b/src/vkvg_experimental.h index 3439151..7ee8fdf 100644 --- a/src/vkvg_experimental.h +++ b/src/vkvg_experimental.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #ifndef VKVG_EXPERIMENTAL_H #define VKVG_EXPERIMENTAL_H diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c index f943316..186930d 100644 --- a/src/vkvg_fonts.c +++ b/src/vkvg_fonts.c @@ -8,6 +8,7 @@ #include "vkh.h" +#include <stdlib.h> #include <locale.h> #include <string.h> #include <wchar.h> @@ -109,6 +110,12 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { return; } if (fontDirs) { + const char* minimal_blank_config = + "<?xml version=\"1.0\"?>" + "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">" + "<fontconfig>" + " <cachedir>/tmp/vkvg-fc-cache</cachedir>" + "</fontconfig>"; cache->config = FcConfigCreate(); if (!cache->config) { LOGE("Failed to create custom Fontconfig configuration.\n"); @@ -116,6 +123,14 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { free(cache); return; } + if (!FcConfigParseAndLoadFromMemory(cache->config, (const FcChar8*)minimal_blank_config, FcTrue)) { + LOGE ("Error: Failed to scan fonts in directory.\n"); + FcConfigDestroy(cache->config); + dev->status = VKVG_STATUS_DEVICE_ERROR; + free(cache); + return; + } + const char *start = fontDirs; const char *end; char fontDir[1024]; @@ -124,12 +139,21 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { end = strchr(start, ','); size_t len = end ? (size_t)(end - start) : strlen(start); strncpy(fontDir, start, len); + fontDir[len] = '\0'; if (!FcConfigAppFontAddDir(cache->config, (FcChar8*)fontDir)) LOG(VKVG_LOG_DEBUG, "Failed to add '%s' to Fontconfig configuration.\n", fontDir); start = end ? end + 1 : NULL; } + if (!FcConfigBuildFonts(cache->config)) { + LOGE ("Error: Failed to scan fonts in directory.\n"); + FcConfigDestroy(cache->config); + dev->status = VKVG_STATUS_DEVICE_ERROR; + free(cache); + return; + } + FcConfigSetCurrent(cache->config); } else { cache->config = FcConfigGetCurrent(); @@ -158,19 +182,17 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { cache->texPixelSize = 1; #endif - VkhDevice vkhd = (VkhDevice)&dev->vkDev; - cache->texPages = array_create_tex_page_t(FONT_CACHE_INIT_LAYERS); for (int i = 0; i < FONT_CACHE_INIT_LAYERS; ++i) { array_add_tex_page_t(&cache->texPages, (tex_page_t){array_create_TexRef(10), 0.f}); } cache->texture = vkh_tex2d_array_create( - vkhd, cache->texFormat, FONT_PAGE_SIZE, FONT_PAGE_SIZE, FONT_CACHE_INIT_LAYERS, VKH_MEMORY_USAGE_GPU_ONLY, + dev->vkhDev, cache->texFormat, FONT_PAGE_SIZE, FONT_PAGE_SIZE, FONT_CACHE_INIT_LAYERS, VKH_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); vkh_image_create_view (cache->texture, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_COLOR_BIT); - cache->uploadFence = vkh_fence_create(vkhd); + cache->uploadFence = vkh_fence_create(dev->vkhDev); const VkDescriptorPoolSize descriptorPoolSize = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}; VkDescriptorPoolCreateInfo descriptorPoolCreateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, @@ -190,10 +212,10 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { const uint32_t buffLength = FONT_PAGE_SIZE * FONT_PAGE_SIZE * cache->texPixelSize; - vkh_buffer_init(vkhd, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, buffLength, &cache->buff, + vkh_buffer_init(dev->vkhDev, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, buffLength, &cache->buff, true); - cache->cmd = vkh_cmd_buff_create(vkhd, dev->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY); + cache->cmd = vkh_cmd_buff_create(dev->vkhDev, dev->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY); // Set texture cache initial layout to shaderReadOnly to prevent error msg if cache is not fill const VkImageSubresourceRange subres = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, FONT_CACHE_INIT_LAYERS}; @@ -209,9 +231,9 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { cache->fontBuffers = array_create_FontBuffer(4); #if defined(DEBUG) && defined(VKVG_DBG_UTILS) - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)cache->descriptorPool, + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)cache->descriptorPool, "Font cache Descriptor Pool"); - vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)cache->dsFont, "Cache DescSet FONT"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)cache->dsFont, "Cache DescSet FONT"); #endif } void _font_buffer_destroy (font_cache_t* cache, FontBuffer fontBuffer) { @@ -253,7 +275,8 @@ void _font_cache_destroy(VkvgDevice dev) { for (int j = 0; j < buffs[i]->faces.count; ++j) { VkvgFont *fonts = faces[j]->sizes.elements; for (int k = 0; k < faces[j]->sizes.count; ++k) { - vkvg_font_destroy(fonts[k]); + //while (vkvg_font_get_reference_count(fonts[k]) > 0) + vkvg_font_destroy(fonts[k]); } } } @@ -315,7 +338,7 @@ void _increase_font_tex_array(VkvgDevice dev) { uint8_t newSize = cache->texPages.count; VkhImage newImg = vkh_tex2d_array_create( - (VkhDevice)&dev->vkDev, cache->texFormat, FONT_PAGE_SIZE, FONT_PAGE_SIZE, newSize, VKH_MEMORY_USAGE_GPU_ONLY, + dev->vkhDev, cache->texFormat, FONT_PAGE_SIZE, FONT_PAGE_SIZE, newSize, VKH_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); vkh_image_create_view(newImg, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_COLOR_BIT); @@ -671,8 +694,8 @@ bool try_get_or_create_font_face_from_query (VkvgDevice dev, const char* querySt //FcPatternAddBool(request, FC_SCALABLE, FcTrue); //FcPatternAddString(request, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); - //FcConfigSubstitute(cache->config, request, FcMatchPattern); - //FcDefaultSubstitute(request); + FcConfigSubstitute(cache->config, request, FcMatchPattern); + FcDefaultSubstitute(request); FcResult result; FcPattern* font = FcFontMatch(cache->config, request, &result); @@ -746,13 +769,13 @@ bool try_get_font_size (FontFace face, uint32_t pt26_6, signed long* coords, Vkv for (int i = 0; i < face->sizes.count; ++i) { VkvgFont f = face->sizes.elements[i]; if (f->charSize == pt26_6) { - if (!coords) - return true; - for (int axe = 0; axe < face->numAxis; ++axe) { - if (f->coords[axe] != coords[axe]) - return false; + if (coords) { + for (int axe = 0; axe < face->numAxis; ++axe) { + if (f->coords[axe] != coords[axe]) + return false; + } + free(coords);//coords matche, free new coords } - free(coords);//coords matche, free new coords *font = f; return true; } @@ -995,7 +1018,6 @@ void text_run_render(VkvgText tr, VkvgContext ctx) { _add_point(ctx, pen.x, pen.y); _flush_chars_to_tex(tr->font); UNLOCK_FONTCACHE(ctx->dev) - /*if (ctx->fontCacheImg != ctx->dev->fontCache->texture) { vkvg_flush(ctx); _font_cache_update_context_descset(ctx); diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index c7f5c0e..ff7c883 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2025 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #pragma once // disable warning on iostream functions on windows diff --git a/src/vkvg_matrix.c b/src/vkvg_matrix.c index e15007a..da633f7 100644 --- a/src/vkvg_matrix.c +++ b/src/vkvg_matrix.c @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) // most of the matrix logic is grabbed from cairo, so here is the // licence: diff --git a/src/vkvg_matrix.h b/src/vkvg_matrix.h index 66db350..69f963a 100644 --- a/src/vkvg_matrix.h +++ b/src/vkvg_matrix.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #ifndef VKVG_MATRICES_H #define VKVG_MATRICES_H diff --git a/src/vkvg_pattern.c b/src/vkvg_pattern.c index d1ea604..07a72e6 100644 --- a/src/vkvg_pattern.c +++ b/src/vkvg_pattern.c @@ -47,9 +47,9 @@ void _surface_pattern_init (VkvgDevice dev, surface_pattern_t* pat) { VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &pat->dsSource)); #if defined(DEBUG) && defined(VKVG_DBG_UTILS) - vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)pat->descPool, + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)pat->descPool, "Pattern Descriptor Pool"); - vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)pat->dsSource, "Pattern DescSet"); + vkh_device_set_object_name(dev->vkhDev, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)pat->dsSource, "Pattern DescSet"); #endif } void _create_sampler(surface_pattern_t* pat) { diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index 1d8ab57..a09eb32 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -1,28 +1,9 @@ -/* - * Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #include "vkvg_surface_internal.h" #include "vkvg_device_internal.h" -#include "vkvg_context_internal.h" #define STBI_ASSERT(x) ((void)0) #define STBIW_ASSERT(x) ((void)0) @@ -104,12 +85,12 @@ VkvgSurface vkvg_surface_create_from_bitmap(VkvgDevice dev, unsigned char* img, uint32_t imgSize = width * height * 4; VkImageSubresourceLayers imgSubResLayers = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; // original format image - VkhImage stagImg = vkh_image_create((VkhDevice)&surf->dev->vkDev, VK_FORMAT_R8G8B8A8_UNORM, surf->width, + VkhImage stagImg = vkh_image_create(dev->vkhDev, VK_FORMAT_R8G8B8A8_UNORM, surf->width, surf->height, VK_IMAGE_TILING_LINEAR, VKH_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); // staging buffer vkh_buffer_t buff = {0}; - vkh_buffer_init((VkhDevice)&dev->vkDev, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, imgSize, + vkh_buffer_init(dev->vkhDev, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, imgSize, &buff, true); memcpy(vkh_buffer_get_mapped_pointer(&buff), img, imgSize); @@ -318,11 +299,11 @@ vkvg_status_t vkvg_surface_write_to_png(VkvgSurface surf, const char* path) { VkhImage stagImg; if (dev->pngStagTiling == VK_IMAGE_TILING_LINEAR) - stagImg = vkh_image_create((VkhDevice)&surf->dev->vkDev, dev->pngStagFormat, surf->width, surf->height, + stagImg = vkh_image_create(dev->vkhDev, dev->pngStagFormat, surf->width, surf->height, dev->pngStagTiling, VKH_MEMORY_USAGE_GPU_TO_CPU, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); else - stagImg = vkh_image_create((VkhDevice)&surf->dev->vkDev, dev->pngStagFormat, surf->width, surf->height, + stagImg = vkh_image_create(dev->vkhDev, dev->pngStagFormat, surf->width, surf->height, dev->pngStagTiling, VKH_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); @@ -351,7 +332,7 @@ vkvg_status_t vkvg_surface_write_to_png(VkvgSurface surf, const char* path) { VkhImage stagImgLinear = stagImg; if (dev->pngStagTiling == VK_IMAGE_TILING_OPTIMAL) { - stagImgLinear = vkh_image_create((VkhDevice)&surf->dev->vkDev, dev->pngStagFormat, surf->width, surf->height, + stagImgLinear = vkh_image_create(dev->vkhDev, dev->pngStagFormat, surf->width, surf->height, VK_IMAGE_TILING_LINEAR, VKH_MEMORY_USAGE_GPU_TO_CPU, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); VkImageCopy cpy = {.srcSubresource = imgSubResLayers, @@ -418,7 +399,7 @@ vkvg_status_t vkvg_surface_write_to_memory(VkvgSurface surf, unsigned char* cons VkvgDevice dev = surf->dev; // RGBA to blit to, surf img is bgra - VkhImage stagImg = vkh_image_create((VkhDevice)&surf->dev->vkDev, VK_FORMAT_R8G8B8A8_UNORM, surf->width, + VkhImage stagImg = vkh_image_create(dev->vkhDev, VK_FORMAT_R8G8B8A8_UNORM, surf->width, surf->height, VK_IMAGE_TILING_LINEAR, VKH_MEMORY_USAGE_GPU_TO_CPU, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); diff --git a/src/vkvg_surface_internal.c b/src/vkvg_surface_internal.c index 3a2b7ce..ab37540 100644 --- a/src/vkvg_surface_internal.c +++ b/src/vkvg_surface_internal.c @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #include "vkvg_device_internal.h" #include "vkvg_surface_internal.h" @@ -457,7 +439,7 @@ void _setupPipelines(surface_class* surf) { } void _create_surface_main_image(VkvgSurface surf) { - VkhDevice vkhd = (VkhDevice)&surf->dev->vkDev; + VkhDevice vkhd = surf->dev->vkhDev; surf->img = vkh_image_create(vkhd, surf->surfClass->format, surf->width, surf->height, surf->dev->supportedTiling, VKH_MEMORY_USAGE_GPU_ONLY, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | @@ -473,7 +455,7 @@ void _create_surface_main_image(VkvgSurface surf) { } // create multisample color img if sample count > 1 and the stencil buffer multisampled or not void _create_surface_secondary_images(VkvgSurface surf) { - VkhDevice vkhd = (VkhDevice)&surf->dev->vkDev; + VkhDevice vkhd = surf->dev->vkhDev; if (surf->surfClass->samples > VK_SAMPLE_COUNT_1_BIT) { surf->imgMS = vkh_image_ms_create( vkhd, surf->surfClass->format, surf->surfClass->samples, surf->width, surf->height, VKH_MEMORY_USAGE_GPU_ONLY, @@ -527,7 +509,7 @@ void _create_framebuffer(VkvgSurface surf) { } VK_CHECK_RESULT(vkCreateFramebuffer(surf->dev->vkDev, &frameBufferCreateInfo, NULL, &surf->fb)); #if defined(DEBUG) && defined(VKVG_DBG_UTILS) - vkh_device_set_object_name((VkhDevice)&surf->dev->vkDev, VK_OBJECT_TYPE_FRAMEBUFFER, (uint64_t)surf->fb, "SURF FB"); + vkh_device_set_object_name(surf->dev->vkhDev, VK_OBJECT_TYPE_FRAMEBUFFER, (uint64_t)surf->fb, "SURF FB"); #endif } void _create_surface_images(VkvgSurface surf) { @@ -550,7 +532,7 @@ surface_class* _create_surface_class (VkvgDevice dev, VkFormat format, VkSampleC return NULL; } - VkhDevice vkhd = (VkhDevice)&dev->vkDev; + VkhDevice vkhd = dev->vkhDev; surf->dev = dev; surf->format = format; @@ -650,7 +632,7 @@ VkvgSurface _create_surface(VkvgDevice dev, VkFormat format, VkSampleCountFlags if (dev->threadAware) mtx_init(&surf->mutex, mtx_plain); - VkhDevice vkhd = (VkhDevice)&surf->dev->vkDev; + VkhDevice vkhd = surf->dev->vkhDev; surf->cmdPool = vkh_cmd_pool_create(vkhd, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); vkh_cmd_buffs_create(vkhd, surf->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1, &surf->cmd); @@ -677,7 +659,7 @@ VkvgSurface _create_surface(VkvgDevice dev, VkFormat format, VkSampleCountFlags .pSetLayouts = &dev->dslGrad}; VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &surf->dsGradient)); - vkh_buffer_init((VkhDevice)dev, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, + vkh_buffer_init(dev->vkhDev, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, sizeof(vkvg_gradient_t), &surf->uboGrad, true); VkDescriptorBufferInfo dbi = {surf->uboGrad.buffer, 0, VK_WHOLE_SIZE}; @@ -706,7 +688,7 @@ VkvgSurface _create_surface(VkvgDevice dev, VkFormat format, VkSampleCountFlags /*bool _surface_wait_cmd (VkvgSurface surf) { LOG(VKVG_LOG_INFO, "SURF: _surface__wait_flush_fence\n"); #ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE - if (vkh_timeline_wait ((VkhDevice)surf->dev, surf->timeline, surf->timelineStep) == VK_SUCCESS) + if (vkh_timeline_wait (surf->dev->vkhDev, surf->timeline, surf->timelineStep) == VK_SUCCESS) return true; #else if (WaitForFences (surf->dev->vkDev, 1, &surf->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT) == VK_SUCCESS) { @@ -726,7 +708,7 @@ void _surface_submit_cmd(VkvgSurface surf) { vkh_cmd_submit_timelined(dev->gQueue, &surf->cmd, surf->timeline, surf->timelineStep, surf->timelineStep + 1); surf->timelineStep++; UNLOCK_DEVICE - vkh_timeline_wait((VkhDevice)&dev->vkDev, surf->timeline, surf->timelineStep); + vkh_timeline_wait(dev->vkhDev, surf->timeline, surf->timelineStep); #else LOCK_DEVICE vkh_cmd_submit(surf->dev->gQueue, &surf->cmd, surf->flushFence); diff --git a/src/vkvg_surface_internal.h b/src/vkvg_surface_internal.h index 5b7614e..cd5b395 100644 --- a/src/vkvg_surface_internal.h +++ b/src/vkvg_surface_internal.h @@ -1,24 +1,6 @@ -/* - * Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #ifndef SURFACE_INTERNAL_H #define SURFACE_INTERNAL_H diff --git a/tests/text.c b/tests/text.c index 82f9c02..d151b53 100644 --- a/tests/text.c +++ b/tests/text.c @@ -176,16 +176,17 @@ void test() { void single_font_and_size() { VkvgContext ctx = vkvg_create(surf); vkvg_clear(ctx); + VkvgFont font = vkvg_font_create(surf, "mono", 20); for (uint32_t i = 0; i < test_size; i++) { randomize_color(ctx); float x = rndf() * test_width; float y = rndf() * test_height; - vkvg_select_font_face(ctx, "mono"); - vkvg_set_font_size(ctx, 20); + vkvg_set_font(ctx, font); vkvg_move_to(ctx, x, y); vkvg_show_text(ctx, "This is a test string!"); } vkvg_destroy(ctx); + vkvg_font_destroy(font); } void simple_text() { VkvgContext ctx = vkvg_create(surf); @@ -288,6 +289,7 @@ const char* const fonts[] = {"mono", "droid", "times", "arial", "times:bold"}; void random_font_and_size() { VkvgContext ctx = vkvg_create(surf); vkvg_clear(ctx); + //vkvg_log_level = VKVG_LOG_FONT; for (uint32_t i = 0; i < test_size; i++) { randomize_color(ctx); @@ -295,13 +297,13 @@ void random_font_and_size() { float y = rndf() * test_height; uint32_t c = (uint32_t)(rndf() * 80) + 1; uint32_t f = (uint32_t)(rndf() * 4); - - vkvg_set_font_size(ctx, c); - vkvg_select_font_face(ctx, fonts[f]); + VkvgFont font = vkvg_font_create(surf, fonts[f], c); + vkvg_set_font(ctx,font); vkvg_move_to(ctx, x, y); vkvg_show_text(ctx, "This is a test string!"); } vkvg_destroy(ctx); + } void proto_sinaitic() { VkvgContext ctx = vkvg_create(surf); @@ -318,16 +320,16 @@ void proto_sinaitic() { int main(int argc, char* argv[]) { no_test_size = true; vkh_log_level = VKVG_LOG_INFO; - //PERFORM_TEST(simple_text, argc, argv); + PERFORM_TEST(simple_text, argc, argv); PERFORM_TEST(variable_text, argc, argv); - /*PERFORM_TEST(font_file_path, argc, argv); + PERFORM_TEST(font_file_path, argc, argv); PERFORM_TEST(single_font_and_size, argc, argv); PERFORM_TEST(random_size, argc, argv); PERFORM_TEST(random_font_and_size, argc, argv); PERFORM_TEST(test, argc, argv); PERFORM_TEST(test1, argc, argv); PERFORM_TEST(test2, argc, argv); - PERFORM_TEST(proto_sinaitic, argc, argv);*/ + PERFORM_TEST(proto_sinaitic, argc, argv); return 0; } diff --git a/tests/vkvg-svg/svg-viewer.c b/tests/vkvg-svg/svg-viewer.c index 27a5029..38059c4 100644 --- a/tests/vkvg-svg/svg-viewer.c +++ b/tests/vkvg-svg/svg-viewer.c @@ -359,8 +359,8 @@ int main(int argc, char* argv[]) { vkvg_paint(ctx); vkvg_set_source_surface(ctx, surf, 0, 0); vkvg_paint(ctx); - vkvg_surface_destroy(surf); vkvg_destroy(ctx); + vkvg_surface_destroy(surf); update = false; } } diff --git a/vkh b/vkh -Subproject 5ca4e5debfa35aeaf9fc1688890c238e40d7247 +Subproject c5b7f0e6000fd61a920a69d4983624ae105a644 |