Skip to content

Conversation

hermet
Copy link
Member

@hermet hermet commented Jun 16, 2025

Redefined Tvg_XXX and related types as pointers
e.g., typedef struct _Tvg_Canvas* Tvg_Canvas)
to improve encapsulation and clarity in API usage.

issue: #3116

@hermet hermet self-assigned this Jun 16, 2025
@hermet hermet added the APIs Update / Revise APIs label Jun 16, 2025
@hermet hermet requested a review from Copilot June 16, 2025 12:26
@github-actions github-actions bot added example Sample Code binding CAPI / Wasm and removed APIs Update / Revise APIs labels Jun 16, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the C API to use opaque pointer types for all Tvg_* objects, improving encapsulation and clarity.

  • Changed all typedef struct _Tvg_X declarations to pointer types (typedef struct _Tvg_X* Tvg_X)
  • Updated function signatures in headers and implementations to accept handles (Tvg_X) instead of pointers-to-pointers
  • Adjusted example code to declare handles directly and removed unnecessary indirection

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/bindings/capi/tvgCapi.cpp Updated all C API functions to use opaque pointer types
src/bindings/capi/thorvg_capi.h Changed typedefs and function declarations for handles
examples/Capi.cpp Refactored example code to use new opaque handle usage
Comments suppressed due to low confidence (3)

examples/Capi.cpp:99

  • The variables color_stops2_get and cnt are not declared in this scope. You likely meant to pass color_stops2 and the count 3 (or a named count variable).
tvg_gradient_set_color_stops(grad_stroke, color_stops2_get, cnt);

examples/Capi.cpp:145

  • Typo in comment: "Prapare" should be "Prepare".
        //Prapare a dash for the stroke

src/bindings/capi/thorvg_capi.h:444

  • The doc comment above this signature still refers to canvas as a pointer. Update parameter descriptions (@param canvas) and return-value notes to reflect that canvas is now an opaque handle, not a pointer-to-pointer.
TVG_API Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Tvg_Colorspace cs);

@hermet
Copy link
Member Author

hermet commented Jun 16, 2025

API breaks, but abstracts & simplifies the interface. Let's carefully confirm.

Redefined Tvg_XXX and related types as pointers
e.g., typedef struct _Tvg_Canvas* Tvg_Canvas)
to improve encapsulation and clarity in API usage.

issue: #3116
@hermet
Copy link
Member Author

hermet commented Sep 3, 2025

cc: @theashraf @BenjaminHalko

@hermet hermet merged commit 0ec1d9d into main Sep 3, 2025
15 checks passed
@hermet hermet deleted the hermet/capi branch September 3, 2025 05:43
@vtorri
Copy link
Collaborator

vtorri commented Sep 3, 2025

what about adding a _p to the struct names to say that it is a pointer ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding CAPI / Wasm example Sample Code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants