renderer/accessor: added the id generator.

This function computes a unique identifier value based on the provided string.
You can use this to assign a unique ID to the Paint object.

Experimental APIs:
- uint32_t Accessorr::id(const char* name)
- uint32_t tvg_accessor_id(const char* name)
This commit is contained in:
Hermet Park 2024-07-25 14:29:19 +09:00 committed by Hermet Park
parent 45352c9a1f
commit ed9eee897a
5 changed files with 65 additions and 0 deletions

View file

@ -2137,6 +2137,22 @@ public:
*/
Result set(const Picture* picture, std::function<bool(const Paint* paint, void* data)> func, void* data) noexcept;
/**
* @brief Generate a unique ID (hash key) from a given name.
*
* This function computes a unique identifier value based on the provided string.
* You can use this to assign a unique ID to the Paint object.
*
* @param[in] name The input string to generate the unique identifier from.
*
* @return The generated unique identifier value.
*
* @see Paint::id
*
* @note Experimental API
*/
static uint32_t id(const char* name) noexcept;
/**
* @brief Creates a new Accessor object.
*

View file

@ -2575,6 +2575,36 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation);
/** \} */ // end defgroup ThorVGCapi_Animation
/**
* \defgroup ThorVGCapi_Accesssor Accessor
* \brief A module for manipulation of the scene tree
*
* This module helps to control the scene tree.
* \{
*/
/************************************************************************/
/* Accessor API */
/************************************************************************/
/*!
* \brief Generate a unique ID (hash key) from a given name.
*
* This function computes a unique identifier value based on the provided string.
* You can use this to assign a unique ID to the Paint object.
*
* \param[in] name The input string to generate the unique identifier from.
*
* \return The generated unique identifier value.
*
* \note Experimental API
*/
TVG_API uint32_t tvg_accessor_generate_id(const char* name);
/** \} */ // end defgroup ThorVGCapi_Accessor
/**
* \defgroup ThorVGCapi_LottieAnimation LottieAnimation
* \brief A module for manipulation of lottie extension features.

View file

@ -894,6 +894,16 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation)
}
/************************************************************************/
/* Accessor API */
/************************************************************************/
TVG_API uint32_t tvg_accessor_generate_id(const char* name)
{
return Accessor::id(name);
}
/************************************************************************/
/* Lottie Animation API */
/************************************************************************/

View file

@ -478,6 +478,8 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded)
unsigned long djb2Encode(const char* str)
{
if (!str) return 0;
unsigned long hash = 5381;
int c;

View file

@ -21,6 +21,7 @@
*/
#include "tvgIteratorAccessor.h"
#include "tvgCompressor.h"
/************************************************************************/
/* Internal Class Implementation */
@ -81,6 +82,12 @@ Result Accessor::set(const Picture* picture, function<bool(const Paint* paint, v
}
uint32_t Accessor::id(const char* name) noexcept
{
return djb2Encode(name);
}
Accessor::~Accessor()
{