void RiveAnimationRenderer::LoadRiveFile(const std::string& filename)
{
- std::streampos length = 0;
Dali::Vector<uint8_t> bytes;
if(!Dali::FileLoader::ReadFile(filename, bytes))
return;
}
+ LoadRiveData(bytes);
+}
+
+void RiveAnimationRenderer::LoadRiveData(const Dali::Vector<uint8_t>& bytes)
+{
if(bytes.Size() == 0)
{
- DALI_LOG_ERROR("Failed to load: empty file %s", filename.c_str());
+ DALI_LOG_ERROR("Failed to load: empty file");
return;
}
ClearRiveAnimations();
- if(!mRiveTizenAdapter->loadRiveResource(&bytes[0], bytes.Size()))
+ if(!mRiveTizenAdapter->loadRiveResource(const_cast<uint8_t*>(&bytes[0]), bytes.Size()))
{
- DALI_LOG_ERROR("Failed to load resource file %s", filename.c_str());
+ DALI_LOG_ERROR("Failed to load resource file");
return;
}
return true;
}
+bool RiveAnimationRenderer::Load(const Dali::Vector<uint8_t>& data)
+{
+ LoadRiveData(data);
+ RiveAnimationRendererManager::Get().AddEventHandler(*this);
+
+ DALI_LOG_INFO(gRiveAnimationLogFilter, Debug::Verbose, "RiveAnimationRenderer::Initialize: data [data size : %zu byte] [%p]\n", data.Size(), this);
+
+ return true;
+}
+
void RiveAnimationRenderer::Finalize()
{
Dali::Mutex::ScopedLock lock(mMutex);
#define DALI_EXTENSION_INTERNAL_RIVE_ANIMATION_RENDERER_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
#include <dali/devel-api/threading/mutex.h>
#include <dali/integration-api/debug.h> ///< note : Debug::DebugPriority::DEBUG can be removed due to <rive/rive_types.hpp>.
+#include <dali/public-api/common/dali-vector.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/rendering/renderer.h>
#include <tbm_surface.h>
bool Load(const std::string& url);
/**
+ * @brief Loads the animation file from data.
+ *
+ * @param[in] data The url of the vector animation file
+ * @return True if loading success, false otherwise.
+ */
+ bool Load(const Dali::Vector<uint8_t>& data);
+
+ /**
* @brief Finalizes the renderer. It will be called in the main thread.
*/
void Finalize();
void LoadRiveFile(const std::string& filename);
/**
+ * @brief Load rive resource data for artboard.
+ */
+ void LoadRiveData(const Dali::Vector<uint8_t>& data);
+
+ /**
* @brief Clear Loaded Animations.
*/
void ClearRiveAnimations();
// EXTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
+#include <dali/devel-api/common/hash.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/object/property-array.h>
#include <tbm_surface_internal.h>
return true;
}
+bool TizenVectorAnimationRenderer::Load(const Dali::Vector<uint8_t>& data)
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ std::string jsonData(data.Begin(), data.End()); ///< Convert from raw buffer to string.
+ auto hashValue = Dali::CalculateHash(data); ///< Will be used for rlottie internal cache system.
+
+ mVectorRenderer = rlottie::Animation::loadFromData(jsonData, std::to_string(hashValue));
+ if(!mVectorRenderer)
+ {
+ DALI_LOG_ERROR("Failed to load a Lottie data [data size : %zu byte] [%p]\n", data.Size(), this);
+ mLoadFailed = true;
+ return false;
+ }
+
+ mTotalFrameNumber = static_cast<uint32_t>(mVectorRenderer->totalFrame());
+ mFrameRate = static_cast<float>(mVectorRenderer->frameRate());
+
+ size_t w, h;
+ mVectorRenderer->size(w, h);
+ mDefaultWidth = static_cast<uint32_t>(w);
+ mDefaultHeight = static_cast<uint32_t>(h);
+
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "data [data size : %zu byte] [%p]\n", data.Size(), this);
+
+ return true;
+}
+
void TizenVectorAnimationRenderer::SetRenderer(Renderer renderer)
{
mRenderer = renderer;
#define DALI_TIZEN_VECTOR_ANIMATION_RENDERER_PLUGIN_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
bool Load(const std::string& url) override;
/**
+ * @copydoc Dali::VectorAnimationRendererPlugin::Load()
+ */
+ bool Load(const Dali::Vector<uint8_t>& data) override;
+
+ /**
* @copydoc Dali::VectorAnimationRendererPlugin::SetRenderer()
*/
void SetRenderer(Renderer renderer) override;