From d8d717ec3ff6db92165894d85b8593526ba0d37c Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 14 May 2024 15:33:26 +0900 Subject: [PATCH] capi: support canvas viewport api New Experimental API: - Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h); --- src/bindings/capi/thorvg_capi.h | 26 +++++++++++++++++++++++++- src/bindings/capi/tvgCapi.cpp | 7 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 4dc27f70..a8451920 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -453,7 +453,7 @@ TVG_API Tvg_Canvas* tvg_swcanvas_create(); * \retval TVG_RESULT_INVALID_ARGUMENTS An invalid canvas or buffer pointer passed or one of the @p stride, @p w or @p h being zero. * \retval TVG_RESULT_NOT_SUPPORTED The software engine is not supported. * -* \warning Do not access @p buffer during tvg_canvas_draw() - tvg_canvas_sync(). It should not be accessed while TVG is writing on it. +* \warning Do not access @p buffer during tvg_canvas_draw() - tvg_canvas_sync(). It should not be accessed while the engine is writing on it. * * \see Tvg_Colorspace */ @@ -743,6 +743,30 @@ TVG_API Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas); TVG_API Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas); +/*! +* \brief Sets the drawing region in the canvas. +* +* This function defines the rectangular area of the canvas that will be used for drawing operations. +* The specified viewport is used to clip the rendering output to the boundaries of the rectangle. +* +* \param[in] canvas The Tvg_Canvas object containing elements which were drawn. +* \param[in] x The x-coordinate of the upper-left corner of the rectangle. +* \param[in] y The y-coordinate of the upper-left corner of the rectangle. +* \param[in] w The width of the rectangle. +* \param[in] h The height of the rectangle. +* +* \return Tvg_Result enumeration. +* \retval TVG_RESULT_SUCCESS Succeed. +* \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error. +* +* \warning It's not allowed to change the viewport during tvg_canvas_update() - tvg_canvas_sync() or tvg_canvas_push() - tvg_canvas_sync(). +* +* \note The specified viewport region will be intersected with the target region. +* \note Experimental API +* \see tvg_swcanvas_set_target() +*/ +TVG_API Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h); + /** \} */ // end defgroup ThorVGCapi_Canvas diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 8aca4294..1c1acc2e 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -111,6 +111,13 @@ TVG_API Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas) } +TVG_API Tvg_Result tvg_canvas_est_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h) +{ + if (!canvas) return TVG_RESULT_INVALID_ARGUMENT; + return (Tvg_Result) reinterpret_cast(canvas)->viewport(x, y, w, h); +} + + TVG_API Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint) { if (!canvas || !paint) return TVG_RESULT_INVALID_ARGUMENT;