summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2024-12-04 12:29:07 +0100
committerj-p <jp_bruyere@hotmail.com>2025-03-24 19:12:00 +0100
commit55fbcfd54f65f89e5a24c631a8194ae33592edb5 (patch)
tree2d85f271de0010a4b96482f7949457c36679b601
parent90751ff88f90f22539f5f76cbbd577493961b0d5 (diff)
gunit tests wip + api calls strenghtenings
-rw-r--r--.clang-format2
-rw-r--r--README.md6
-rw-r--r--gunit_tests/context.cpp147
-rw-r--r--include/vkvg.h66
-rw-r--r--src/vkvg_context.c28
-rw-r--r--src/vkvg_context_internal.h2
-rw-r--r--src/vkvg_internal.h6
-rw-r--r--src/vkvg_surface.c24
8 files changed, 217 insertions, 64 deletions
diff --git a/.clang-format b/.clang-format
index cf8cd36..5530d2a 100644
--- a/.clang-format
+++ b/.clang-format
@@ -159,7 +159,7 @@ PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
-PointerAlignment: Right
+PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
diff --git a/README.md b/README.md
index db5ff8c..e15f57a 100644
--- a/README.md
+++ b/README.md
@@ -11,12 +11,6 @@
<a href="https://github.com/jpbruyere/vkvg/actions/workflows/cmake.yml">
<img src="https://github.com/jpbruyere/vkvg/actions/workflows/cmake.yml/badge.svg">
</a>
- <a href="https://travis-ci.org/jpbruyere/vkvg">
- <img src="https://img.shields.io/travis/jpbruyere/vkvg.svg?label=Linux&logo=travis&logoColor=white&message=build">
- </a>
- <a href="https://ci.appveyor.com/project/jpbruyere/vkvg">
- <img src="https://img.shields.io/appveyor/ci/jpbruyere/vkvg?label=Win64&logo=appveyor&logoColor=lightgrey">
- </a>
<img src="https://img.shields.io/github/license/jpbruyere/vkvg.svg?style=flat-square">
<a href="https://www.paypal.me/GrandTetraSoftware">
<img src="https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square">
diff --git a/gunit_tests/context.cpp b/gunit_tests/context.cpp
index e44a3d7..82fb78c 100644
--- a/gunit_tests/context.cpp
+++ b/gunit_tests/context.cpp
@@ -70,3 +70,150 @@ TEST_F(ContextTest, CtxReference) {
EXPECT_EQ(1, vkvg_surface_get_reference_count(surf));
EXPECT_EQ(2, vkvg_device_get_reference_count(dev));
}
+TEST_F(ContextTest, CtxDrawBasicNullContext) {
+ //test method with context in error
+ VkvgContext ctx = vkvg_create(NULL);
+ EXPECT_NO_FATAL_FAILURE(vkvg_new_path(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_close_path(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_new_sub_path(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_path_extents(ctx, NULL, NULL, NULL, NULL));
+ EXPECT_NO_FATAL_FAILURE(vkvg_get_current_point(ctx, NULL, NULL));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_line_to(ctx,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rel_line_to(ctx,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_move_to(ctx,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rel_move_to(ctx,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_arc(ctx,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_arc_negative(ctx,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_curve_to(ctx,0,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rel_curve_to(ctx,0,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_quadratic_to(ctx,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rel_quadratic_to(ctx,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rectangle(ctx,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rounded_rectangle(ctx,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rounded_rectangle2(ctx,0,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_ellipse(ctx,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_elliptic_arc_to(ctx,0,0,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rel_elliptic_arc_to(ctx,0,0,0,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_stroke(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_stroke_preserve(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_fill(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_fill_preserve(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_paint(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_clear(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_reset_clip(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_clip(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_clip_preserve(ctx));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_opacity(ctx,0));
+
+ EXPECT_EQ(0, vkvg_get_opacity(ctx));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_source_color(ctx,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_source_rgb(ctx,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_source_rgba(ctx,0,0,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_source_surface(ctx,NULL,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_source(ctx,NULL));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_line_width(ctx,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_miter_limit(ctx,0));
+
+ EXPECT_EQ(0, vkvg_get_miter_limit(ctx));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_line_cap(ctx, VKVG_LINE_CAP_ROUND));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_line_join(ctx, VKVG_LINE_JOIN_MITER));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_operator(ctx, VKVG_OPERATOR_OVER));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_dash(ctx, NULL, 0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_get_dash(ctx, NULL, NULL,NULL));
+
+ EXPECT_EQ(0, vkvg_get_line_width(ctx));
+
+ EXPECT_EQ(VKVG_LINE_CAP_BUTT, vkvg_get_line_cap(ctx));
+ EXPECT_EQ(VKVG_LINE_JOIN_MITER, vkvg_get_line_join(ctx));
+ EXPECT_EQ(VKVG_OPERATOR_OVER, vkvg_get_operator(ctx));
+ EXPECT_EQ(VKVG_FILL_RULE_NON_ZERO, vkvg_get_fill_rule(ctx));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_get_source(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_get_target(ctx));
+
+ EXPECT_EQ(false, vkvg_has_current_point(ctx));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_save(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_restore(ctx));
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_translate(ctx,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_scale(ctx,0,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_rotate(ctx,0));
+ EXPECT_NO_FATAL_FAILURE(vkvg_transform(ctx,NULL));
+ EXPECT_NO_FATAL_FAILURE(vkvg_set_matrix(ctx,NULL));
+ EXPECT_NO_FATAL_FAILURE(vkvg_get_matrix(ctx,NULL));
+ EXPECT_NO_FATAL_FAILURE(vkvg_identity_matrix(ctx));
+
+ 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));
+ EXPECT_NO_FATAL_FAILURE(vkvg_font_extents(ctx,NULL));
+
+ vkvg_text_run_create(ctx,NULL);
+ vkvg_text_run_create_with_length(ctx,NULL,10);
+
+ //vkvg_text_run_destroy(NULL);
+ vkvg_show_text_run(ctx,NULL);
+}
+#define EXPECT_CP(x,y) { \
+ vkvg_get_current_point(ctx, &a, &b);\
+ EXPECT_FLOAT_EQ(x, a);\
+ EXPECT_FLOAT_EQ(y, b);\
+}
+#define EXPECT_NO_CP() {\
+ EXPECT_EQ(false, vkvg_has_current_point(ctx));\
+ EXPECT_CP(0,0);\
+}
+
+TEST_F(ContextTest, CtxBasicPathCommands) {
+ float a = 0.0,b = 0.0,c = 0.0,d = 0.0;
+ VkvgContext ctx = vkvg_create(surf);
+ EXPECT_NO_CP();
+
+ EXPECT_NO_FATAL_FAILURE(vkvg_new_path(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_close_path(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_new_sub_path(ctx));
+ EXPECT_NO_FATAL_FAILURE(vkvg_path_extents(ctx, &a, &b, &c, &d));
+ EXPECT_FLOAT_EQ(0, a && b && c && d);
+
+ EXPECT_NO_CP();
+
+ vkvg_line_to(ctx, 50, 10);
+ EXPECT_CP(50,10);
+
+ vkvg_move_to(ctx, 10, 50);
+ EXPECT_EQ(true, vkvg_has_current_point(ctx));
+ EXPECT_CP(10,50);
+
+ vkvg_line_to(ctx, 50, 10);
+ EXPECT_CP(50,10);
+
+ vkvg_rel_line_to(ctx, 10, 10);
+ EXPECT_CP(60,20);
+
+ vkvg_close_path(ctx);
+
+ EXPECT_NO_CP();
+
+ vkvg_line_to(ctx, 50, 10);
+ vkvg_rel_line_to(ctx, 10, 10);
+ vkvg_new_sub_path(ctx);
+
+ EXPECT_NO_CP();
+
+ vkvg_line_to(ctx, 50, 10);
+ vkvg_rel_line_to(ctx, 10, 10);
+ vkvg_new_path(ctx);
+
+ EXPECT_NO_CP();
+
+ vkvg_destroy(ctx);
+}
diff --git a/include/vkvg.h b/include/vkvg.h
index 1de905c..86a1a24 100644
--- a/include/vkvg.h
+++ b/include/vkvg.h
@@ -650,7 +650,7 @@ vkvg_public vkvg_status_t vkvg_device_status(VkvgDevice dev);
* @brief Increment the reference count on this device.
*
* Increment by one the reference count on the device.
- * @param The vkvg device pointer to increment the reference count for.
+ * @param dev The vkvg device pointer to increment the reference count for.
* @return
*/
vkvg_public VkvgDevice vkvg_device_reference(VkvgDevice dev);
@@ -761,24 +761,24 @@ vkvg_public VkvgSurface vkvg_surface_create_from_bitmap(VkvgDevice dev, unsigned
vkvg_public vkvg_status_t vkvg_surface_status(VkvgSurface surf);
/**
* @brief Increment reference count on the surface by one.
- * @param The vkvg surface to increment the reference count for.
+ * @param surf The vkvg surface to increment the reference count for.
* @return ?
*/
vkvg_public VkvgSurface vkvg_surface_reference(VkvgSurface surf);
/**
* @brief Get the current reference count on this surface.
- * @param The vkvg surface to get the reference count for.
+ * @param surf The vkvg surface to get the reference count for.
* @return The reference count on the surface.
*/
vkvg_public uint32_t vkvg_surface_get_reference_count(VkvgSurface surf);
/**
* @brief Decrement the reference count on the surface by one. Destroy it if count reach 0.
- * @param The vkvg surface to destroy.
+ * @param surf The vkvg surface to destroy.
*/
vkvg_public void vkvg_surface_destroy(VkvgSurface surf);
/**
* @brief Query the current status of the surface.
- * @param The vkvg surface to query the status for.
+ * @param surf The vkvg surface to query the status for.
* @return The current surface status.
*/
vkvg_public vkvg_status_t vkvg_surface_status(VkvgSurface surf);
@@ -790,44 +790,44 @@ vkvg_public vkvg_status_t vkvg_surface_status(VkvgSurface surf);
*
* @remark Internaly, the vulkan method used to clear the surface is the slowest, prefer using the @ref vkvg_clear
* function of the context that will try to use the render pass load operations when possible.
- * @param The surface to clear.
+ * @param surf The surface to clear.
*/
vkvg_public void vkvg_surface_clear(VkvgSurface surf);
/**
* @brief Get the final single sampled vulkan image of this surface.
- * @param The vkvg surface to get the vulkan texture of.
+ * @param surf The vkvg surface to get the vulkan texture of.
* @return The VkImage object containing the result of the drawing operations on the surface.
*/
vkvg_public VkImage vkvg_surface_get_vk_image(VkvgSurface surf);
/**
* @brief Get the vulkan format of the vulkan texture used as backend for this surface.
- * @param The surface to get the format for.
+ * @param surf The surface to get the format for.
* @return The VkFormat.
*/
vkvg_public VkFormat vkvg_surface_get_vk_format(VkvgSurface surf);
/**
* @brief Get the actual surface width.
- * @param The vkvg surface to get the width for.
+ * @param surf The vkvg surface to get the width for.
* @return The width in pixel of the surface.
*/
vkvg_public uint32_t vkvg_surface_get_width(VkvgSurface surf);
/**
* @brief Get the actual surface height.
- * @param The vkvg surface to get the height for.
+ * @param surf The vkvg surface to get the height for.
* @return The height in pixel of the surface.
*/
vkvg_public uint32_t vkvg_surface_get_height(VkvgSurface surf);
/**
* @brief Write surface content to a png file on disk.
- * @param The surface to save on disk.
- * @param The png file path.
+ * @param surf The surface to save on disk.
+ * @param path The png file path.
* @return SUCCESS or not.
*/
vkvg_public vkvg_status_t vkvg_surface_write_to_png(VkvgSurface surf, const char *path);
/**
* @brief Save surface to memory
- * @param The surface to save
- * @param A valid pointer on cpu memory large enough to contain surface pixels (stride * height)
+ * @param surf The surface to save
+ * @param bitmap A valid pointer on cpu memory large enough to contain surface pixels (stride * height)
* @return SUCCESS or not.
*/
vkvg_public vkvg_status_t vkvg_surface_write_to_memory(VkvgSurface surf, unsigned char *const bitmap);
@@ -986,7 +986,7 @@ vkvg_public void vkvg_new_sub_path(VkvgContext ctx);
* @param x2 right of the resulting extents
* @param y2 bottom of the resulting extents
*/
-vkvg_public void vkvg_path_extents(VkvgContext ctx, float *x1, float *y1, float *x2, float *y2);
+vkvg_public void vkvg_path_extents(VkvgContext ctx, float* const x1, float *const y1, float *const x2, float *const y2);
/**
* @brief Get the current point.
*
@@ -1375,6 +1375,24 @@ vkvg_public void vkvg_set_source_rgba(VkvgContext ctx, float r, float g, float b
*/
vkvg_public void vkvg_set_source_rgb(VkvgContext ctx, float r, float g, float b);
/**
+ * @brief use supplied surface as current pattern.
+ *
+ * set #VkvgSurface as the current context source.
+ * @param ctx a valid vkvg @ref context
+ * @param surf the vkvg surface to use as source.
+ * @param x an x offset to apply for drawing operations using this surface.
+ * @param y an y offset to apply for drawing operations using this surface.
+ */
+vkvg_public void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y);
+/**
+ * @brief set supplied pattern as current source.
+ *
+ * set #VkvgPattern as the new source for the targeted context.
+ * @param ctx a valid vkvg @ref context
+ * @param pat the new pattern to use as source for further drawing operations.
+ */
+vkvg_public void vkvg_set_source(VkvgContext ctx, VkvgPattern pat);
+/**
* @brief set line width for the next draw command.
*
* Set the current line width for the targeted context. All further calls to #vkvg_stroke on this context
@@ -1427,24 +1445,6 @@ vkvg_public void vkvg_set_line_cap(VkvgContext ctx, vkvg_line_cap_t cap);
*/
vkvg_public void vkvg_set_line_join(VkvgContext ctx, vkvg_line_join_t join);
/**
- * @brief use supplied surface as current pattern.
- *
- * set #VkvgSurface as the current context source.
- * @param ctx a valid vkvg @ref context
- * @param surf the vkvg surface to use as source.
- * @param x an x offset to apply for drawing operations using this surface.
- * @param y an y offset to apply for drawing operations using this surface.
- */
-vkvg_public void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y);
-/**
- * @brief set supplied pattern as current source.
- *
- * set #VkvgPattern as the new source for the targeted context.
- * @param ctx a valid vkvg @ref context
- * @param pat the new pattern to use as source for further drawing operations.
- */
-vkvg_public void vkvg_set_source(VkvgContext ctx, VkvgPattern pat);
-/**
* @brief
*
* @param ctx a valid vkvg @ref context
diff --git a/src/vkvg_context.c b/src/vkvg_context.c
index de3151d..a548103 100644
--- a/src/vkvg_context.c
+++ b/src/vkvg_context.c
@@ -120,6 +120,7 @@ VkvgContext vkvg_create(VkvgSurface surf) {
free(ctx->vertexCache);
if (ctx->indexCache)
free(ctx->indexCache);
+ free(ctx);
LOG(VKVG_LOG_ERR, "CREATE context failed, no memory\n");
return (VkvgContext)&_vkvg_status_no_memory;
}
@@ -336,10 +337,10 @@ void vkvg_new_path(VkvgContext ctx) {
if (vkvg_status(ctx))
return;
+ RECORD(ctx, VKVG_CMD_NEW_PATH);
LOG(VKVG_LOG_INFO_CMD, "\tCMD: new_path:\n");
_clear_path(ctx);
- RECORD(ctx, VKVG_CMD_NEW_PATH);
}
void vkvg_close_path(VkvgContext ctx) {
if (vkvg_status(ctx))
@@ -520,7 +521,11 @@ bool vkvg_has_current_point(VkvgContext ctx) {
return !_current_path_is_empty(ctx);
}
void vkvg_get_current_point(VkvgContext ctx, float *x, float *y) {
- if (ctx->status || _current_path_is_empty(ctx)) {
+ if (vkvg_status(ctx))
+ return;
+ assert(x);
+ assert(y);
+ if (_current_path_is_empty(ctx)) {
*x = *y = 0;
return;
}
@@ -671,7 +676,7 @@ void vkvg_rounded_rectangle2(VkvgContext ctx, float x, float y, float w, float h
vkvg_close_path(ctx);
}
-void vkvg_path_extents(VkvgContext ctx, float *x1, float *y1, float *x2, float *y2) {
+void vkvg_path_extents(VkvgContext ctx, float* const x1, float *const y1, float *const x2, float *const y2) {
if (vkvg_status(ctx))
return;
@@ -1013,7 +1018,7 @@ void vkvg_set_source_rgba(VkvgContext ctx, float r, float g, float b, float a) {
_update_cur_pattern(ctx, NULL);
}
void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y) {
- if (ctx->status || surf->status)
+ if (vkvg_status(ctx) || vkvg_surface_status(surf))
return;
RECORD(ctx, VKVG_CMD_SET_SOURCE_SURFACE, x, y, surf);
ctx->pushConsts.source.x = x;
@@ -1022,7 +1027,7 @@ void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y
ctx->pushCstDirty = true;
}
void vkvg_set_source(VkvgContext ctx, VkvgPattern pat) {
- if (ctx->status || pat->status)
+ if (vkvg_status(ctx) || vkvg_pattern_status(pat))
return;
RECORD(ctx, VKVG_CMD_SET_SOURCE, pat);
_update_cur_pattern(ctx, pat);
@@ -1085,6 +1090,11 @@ float vkvg_get_line_width(VkvgContext ctx) {
return 0;
return ctx->lineWidth;
}
+float vkvg_get_miter_limit(VkvgContext ctx) {
+ if (vkvg_status(ctx))
+ return 0;
+ return ctx->miterLimit;
+}
void vkvg_set_dash(VkvgContext ctx, const float *dashes, uint32_t num_dashes, float offset) {
if (vkvg_status(ctx))
return;
@@ -1120,7 +1130,7 @@ vkvg_line_join_t vkvg_get_line_join(VkvgContext ctx) {
}
vkvg_operator_t vkvg_get_operator(VkvgContext ctx) {
if (vkvg_status(ctx))
- return (vkvg_operator_t)0;
+ return VKVG_OPERATOR_OVER;
return ctx->curOperator;
}
VkvgPattern vkvg_get_source(VkvgContext ctx) {
@@ -1555,7 +1565,11 @@ void vkvg_set_matrix(VkvgContext ctx, const vkvg_matrix_t *matrix) {
ctx->pushConsts.mat = (*matrix);
_set_mat_inv_and_vkCmdPush(ctx);
}
-void vkvg_get_matrix(VkvgContext ctx, vkvg_matrix_t *const matrix) { *matrix = ctx->pushConsts.mat; }
+void vkvg_get_matrix(VkvgContext ctx, vkvg_matrix_t *const matrix) {
+ if (vkvg_status(ctx) || !matrix)
+ return;
+ *matrix = ctx->pushConsts.mat;
+}
void vkvg_elliptic_arc_to(VkvgContext ctx, float x2, float y2, bool largeArc, bool sweepFlag, float rx, float ry,
float phi) {
diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h
index 4c598b7..79af73c 100644
--- a/src/vkvg_context_internal.h
+++ b/src/vkvg_context_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+ * 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
diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h
index bceecdb..4bd88fb 100644
--- a/src/vkvg_internal.h
+++ b/src/vkvg_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+ * 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
@@ -19,8 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef VKVG_INTERNAL_H
-#define VKVG_INTERNAL_H
+#pragma once
// disable warning on iostream functions on windows
#define _CRT_SECURE_NO_WARNINGS
@@ -109,4 +108,3 @@ static vkvg_status_t _vkvg_status_invalid_dev_ci = VKVG_STATUS_INVALID_DEVICE_C
static vkvg_status_t _vkvg_status_device_error = VKVG_STATUS_DEVICE_ERROR;
static vkvg_status_t _vkvg_status_invalid_surface = VKVG_STATUS_INVALID_SURFACE;
-#endif
diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c
index c52e722..b0beb0e 100644
--- a/src/vkvg_surface.c
+++ b/src/vkvg_surface.c
@@ -197,7 +197,7 @@ void vkvg_surface_destroy(VkvgSurface surf) {
LOG(VKVG_LOG_ERR, "DESTROY surface failed, invalid surface\n");
return;
}
- if (!surf->dev || surf->dev->status) {
+ if (vkvg_device_status(surf->dev)) {
LOG(VKVG_LOG_ERR, "DESTROY surface failed, device error\n");
return;
}
@@ -251,40 +251,40 @@ uint32_t vkvg_surface_get_reference_count(VkvgSurface surf) {
}
VkImage vkvg_surface_get_vk_image(VkvgSurface surf) {
- if (surf->status)
+ if (vkvg_surface_status(surf))
return NULL;
if (surf->dev->deferredResolve)
_explicit_ms_resolve(surf);
return vkh_image_get_vkimage(surf->img);
}
void vkvg_surface_resolve(VkvgSurface surf) {
- if (surf->status || !surf->dev->deferredResolve)
+ if (vkvg_surface_status(surf) || !surf->dev->deferredResolve)
return;
_explicit_ms_resolve(surf);
}
VkFormat vkvg_surface_get_vk_format(VkvgSurface surf) {
- if (surf->status)
+ if (vkvg_surface_status(surf))
return VK_FORMAT_UNDEFINED;
return surf->format;
}
uint32_t vkvg_surface_get_width(VkvgSurface surf) {
- if (surf->status)
+ if (vkvg_surface_status(surf))
return 0;
return surf->width;
}
uint32_t vkvg_surface_get_height(VkvgSurface surf) {
- if (surf->status)
+ if (vkvg_surface_status(surf))
return 0;
return surf->height;
}
vkvg_status_t vkvg_surface_write_to_png(VkvgSurface surf, const char *path) {
- if (surf->status) {
- LOG(VKVG_LOG_ERR, "vkvg_surface_write_to_png failed, invalid status: %d\n", surf->status);
+ if (vkvg_surface_status(surf)) {
+ LOG(VKVG_LOG_ERR, "vkvg_surface_write_to_png failed, invalid status: %d\n", vkvg_surface_status(surf));
return VKVG_STATUS_INVALID_STATUS;
}
- if (surf->dev->status) {
- LOG(VKVG_LOG_ERR, "vkvg_surface_write_to_png failed, invalid device status: %d\n", surf->dev->status);
+ if (vkvg_device_status(surf->dev)) {
+ LOG(VKVG_LOG_ERR, "vkvg_surface_write_to_png failed, invalid device status: %d\n", vkvg_device_status(surf->dev));
return VKVG_STATUS_INVALID_STATUS;
}
if (surf->dev->pngStagFormat == VK_FORMAT_UNDEFINED) {
@@ -376,8 +376,8 @@ vkvg_status_t vkvg_surface_write_to_png(VkvgSurface surf, const char *path) {
}
vkvg_status_t vkvg_surface_write_to_memory(VkvgSurface surf, unsigned char *const bitmap) {
- if (surf->status) {
- LOG(VKVG_LOG_ERR, "vkvg_surface_write_to_memory failed, invalid status: %d\n", surf->status);
+ if (vkvg_surface_status(surf)) {
+ LOG(VKVG_LOG_ERR, "vkvg_surface_write_to_memory failed, invalid status: %d\n", vkvg_surface_status(surf));
return VKVG_STATUS_INVALID_STATUS;
}
if (!bitmap) {