api: revise the gl target() api.

API modification:
- Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h)
 -> Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs)
- Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h)
 -> Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs)

issue: https://github.com/thorvg/thorvg/issues/1372
This commit is contained in:
Hermet Park 2024-11-20 13:13:18 +09:00 committed by Hermet Park
parent 0b4f2a49fe
commit 96e8d3d7a2
6 changed files with 11 additions and 9 deletions

View file

@ -344,7 +344,7 @@ struct GlWindow : Window
void resize() override void resize() override
{ {
//Set the canvas target and draw on it. //Set the canvas target and draw on it.
verify(static_cast<tvg::GlCanvas*>(canvas)->target(0, width, height)); verify(static_cast<tvg::GlCanvas*>(canvas)->target(0, width, height, tvg::ColorSpace::ABGR8888S));
} }
void refresh() override void refresh() override

View file

@ -218,7 +218,7 @@ void runGl()
auto canvas = unique_ptr<tvg::GlCanvas>(tvg::GlCanvas::gen()); auto canvas = unique_ptr<tvg::GlCanvas>(tvg::GlCanvas::gen());
// Pass the framebuffer id to the GlCanvas // Pass the framebuffer id to the GlCanvas
tvgexam::verify(canvas->target(glFbo.fbo, SIZE, SIZE)); tvgexam::verify(canvas->target(glFbo.fbo, SIZE, SIZE, tvg::ColorSpace::ABGR8888S));
content(canvas.get()); content(canvas.get());
if (tvgexam::verify(canvas->draw())) { if (tvgexam::verify(canvas->draw())) {

View file

@ -1732,6 +1732,7 @@ public:
* @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface. * @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface.
* @param[in] w The width (in pixels) of the raster image. * @param[in] w The width (in pixels) of the raster image.
* @param[in] h The height (in pixels) of the raster image. * @param[in] h The height (in pixels) of the raster image.
* @param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c ColorSpace::ABGR8888S as @c GL_RGBA8.
* *
* @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced.
* @retval Result::NonSupport In case the gl engine is not supported. * @retval Result::NonSupport In case the gl engine is not supported.
@ -1739,10 +1740,9 @@ public:
* @see Canvas::viewport() * @see Canvas::viewport()
* @see Canvas::sync() * @see Canvas::sync()
* *
* @note Currently, this only allows the GL_RGBA8 color space format.
* @note Experimental API * @note Experimental API
*/ */
Result target(int32_t id, uint32_t w, uint32_t h) noexcept; Result target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept;
/** /**
* @brief Creates a new GlCanvas object. * @brief Creates a new GlCanvas object.

View file

@ -522,15 +522,15 @@ TVG_API Tvg_Canvas* tvg_glcanvas_create(void);
* \param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface. * \param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface.
* \param[in] w The width (in pixels) of the raster image. * \param[in] w The width (in pixels) of the raster image.
* \param[in] h The height (in pixels) of the raster image. * \param[in] h The height (in pixels) of the raster image.
* \param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c TVG_COLORSPACE_ABGR8888S as @c GL_RGBA8.
* *
* \return Tvg_Result enumeration. * \return Tvg_Result enumeration.
* \retval TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced. * \retval TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced.
* \retval TVG_RESULT_NOT_SUPPORTED In case the gl engine is not supported. * \retval TVG_RESULT_NOT_SUPPORTED In case the gl engine is not supported.
* *
* \note Currently, this only allows the GL_RGBA8 color space format.
* \note Experimental API * \note Experimental API
*/ */
TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h); TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs);
/** \} */ // end defgroup ThorVGCapi_GlCanvas /** \} */ // end defgroup ThorVGCapi_GlCanvas

View file

@ -102,10 +102,10 @@ TVG_API Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer,
} }
TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h) TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs)
{ {
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT; if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<GlCanvas*>(canvas)->target(id, w, h); return (Tvg_Result) reinterpret_cast<GlCanvas*>(canvas)->target(id, w, h, static_cast<ColorSpace>(cs));
} }

View file

@ -59,9 +59,11 @@ GlCanvas::~GlCanvas()
} }
Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h) noexcept Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept
{ {
#ifdef THORVG_GL_RASTER_SUPPORT #ifdef THORVG_GL_RASTER_SUPPORT
if (cs != ColorSpace::ABGR8888S) return Result::NonSupport;
if (Canvas::pImpl->status != Status::Damaged && Canvas::pImpl->status != Status::Synced) { if (Canvas::pImpl->status != Status::Damaged && Canvas::pImpl->status != Status::Synced) {
return Result::InsufficientCondition; return Result::InsufficientCondition;
} }