SET( root_dir ${ROOT_SRC_DIR}/dali-extension/vector-animation-renderer )
SET( SOURCES ${SOURCES}
- ${root_dir}/tizen-vector-animation-manager.cpp
- ${root_dir}/tizen-vector-animation-renderer-x.cpp
+ ${root_dir}/vector-animation-renderer.cpp
+ ${root_dir}/vector-animation-renderer-x.cpp
+ ${root_dir}/vector-animation-plugin-manager.cpp
)
vector_animation_renderer_plugin_src_files = \
- $(extension_src_dir)/vector-animation-renderer/tizen-vector-animation-renderer.cpp \
- $(extension_src_dir)/vector-animation-renderer/tizen-vector-animation-manager.cpp
-
+ $(extension_src_dir)/vector-animation-renderer/vector-animation-renderer.cpp \
+ $(extension_src_dir)/vector-animation-renderer/vector-animation-renderer-tizen.cpp \
+ $(extension_src_dir)/vector-animation-renderer/vector-animation-plugin-manager.cpp
+++ /dev/null
-#ifndef DALI_TIZEN_VECTOR_ANIMATION_RENDERER_X_H
-#define DALI_TIZEN_VECTOR_ANIMATION_RENDERER_X_H
-
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
-#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
-#include <dali/devel-api/adaptor-framework/vector-animation-renderer-plugin.h>
-#include <dali/devel-api/threading/mutex.h>
-#include <dali/public-api/adaptor-framework/native-image-source.h>
-#include <dali/public-api/common/vector-wrapper.h>
-#include <rlottie.h>
-#include <memory>
-
-// INTERNAL INCLUDES
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-event-handler.h>
-
-namespace Dali
-{
-namespace Plugin
-{
-/**
- * @brief Implementation of the Tizen vector animation renderer class which has Tizen platform dependency.
- */
-class TizenVectorAnimationRenderer : public Dali::VectorAnimationRendererPlugin, public TizenVectorAnimationEventHandler
-{
-public:
- /**
- * @brief Constructor.
- */
- TizenVectorAnimationRenderer();
-
- /**
- * @brief Destructor.
- */
- virtual ~TizenVectorAnimationRenderer();
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::Finalize()
- */
- void Finalize() override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::Load()
- */
- 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;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::SetSize()
- */
- void SetSize(uint32_t width, uint32_t height) override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::Render()
- */
- bool Render(uint32_t frameNumber) override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::RenderStopped()
- */
- void RenderStopped() override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::GetTotalFrameNumber()
- */
- uint32_t GetTotalFrameNumber() const override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::GetFrameRate()
- */
- float GetFrameRate() const override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::GetDefaultSize()
- */
- void GetDefaultSize(uint32_t& width, uint32_t& height) const override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::GetLayerInfo()
- */
- void GetLayerInfo(Property::Map& map) const override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::GetMarkerInfo()
- */
- bool GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::GetMarkerInfo()
- */
- void GetMarkerInfo(Property::Map& map) const override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::InvalidateBuffer()
- */
- void InvalidateBuffer() override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::AddPropertyValueCallback()
- */
- void AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id) override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::UploadCompletedSignal()
- */
- UploadCompletedSignalType& UploadCompletedSignal() override;
-
-protected: // Implementation of TizenVectorAnimationEventHandler
- /**
- * @copydoc Dali::Plugin::TizenVectorAnimationEventHandler::NotifyEvent()
- */
- void NotifyEvent() override;
-
-private:
- /**
- * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
- */
- void SetShader();
-
- /**
- * @brief Reset buffer list.
- */
- void ResetBuffers();
-
- /**
- * @brief Event callback to process events.
- */
- void OnLottieRendered();
-
-private:
- std::string mUrl; ///< The content file path
- std::vector<std::unique_ptr<CallbackBase>> mPropertyCallbacks; ///< Property callback list
-
- mutable Dali::Mutex mMutex; ///< Mutex
- Dali::Renderer mRenderer; ///< Renderer
- Dali::Texture mTexture; ///< Texture
- rlottie::Surface mLottieSurface; ///
- std::unique_ptr<rlottie::Animation> mVectorRenderer; ///< The vector animation renderer
- UploadCompletedSignalType mUploadCompletedSignal; ///< Upload completed signal
- uint32_t mTotalFrameNumber; ///< The total frame number
- uint32_t mWidth; ///< The width of the surface
- uint32_t mHeight; ///< The height of the surface
- uint32_t mDefaultWidth; ///< The width of the surface
- uint32_t mDefaultHeight; ///< The height of the surface
- float mFrameRate; ///< The frame rate of the content
- bool mLoadFailed; ///< Whether the file is loaded
- bool mResourceReady; ///< Whether the resource is ready
- bool mShaderChanged; ///< Whether the shader is changed to support native image
- bool mResourceReadyTriggered; ///< Whether the resource ready is triggered
- Dali::Devel::PixelBuffer mPixelBuffer; ///
- std::unique_ptr<EventThreadCallback> mRenderCallback; ///
-};
-
-} // namespace Plugin
-
-} // namespace Dali
-
-#endif // DALI_TIZEN_VECTOR_ANIMATION_RENDERER_X_H
+++ /dev/null
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-renderer.h>
-
-// 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>
-#include <cstring> // for strlen()
-
-// INTERNAL INCLUDES
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-manager.h>
-
-// The plugin factories
-extern "C" DALI_EXPORT_API Dali::VectorAnimationRendererPlugin* CreateVectorAnimationRendererPlugin(void)
-{
- return new Dali::Plugin::TizenVectorAnimationRenderer;
-}
-
-namespace Dali
-{
-namespace Plugin
-{
-namespace
-{
-const char* const PIXEL_AREA_UNIFORM_NAME("pixelArea");
-const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-
-#if defined(DEBUG_ENABLED)
-Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
-#endif
-} // unnamed namespace
-
-TizenVectorAnimationRenderer::TizenVectorAnimationRenderer()
-: mUrl(),
- mBuffers(),
- mMutex(),
- mRenderer(),
- mTexture(),
- mRenderedTexture(),
- mPreviousTexture(),
- mTargetSurface(),
- mVectorRenderer(),
- mUploadCompletedSignal(),
- mTbmQueue(NULL),
- mTotalFrameNumber(0),
- mWidth(0),
- mHeight(0),
- mDefaultWidth(0),
- mDefaultHeight(0),
- mFrameRate(60.0f),
- mLoadFailed(false),
- mResourceReady(false),
- mShaderChanged(false),
- mResourceReadyTriggered(false)
-{
- TizenVectorAnimationManager::Get().AddEventHandler(*this);
-}
-
-TizenVectorAnimationRenderer::~TizenVectorAnimationRenderer()
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- ResetBuffers();
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "this = %p\n", this);
-}
-
-void TizenVectorAnimationRenderer::Finalize()
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- TizenVectorAnimationManager::Get().RemoveEventHandler(*this);
-
- mRenderer.Reset();
- mTexture.Reset();
- mRenderedTexture.Reset();
- mPreviousTexture.Reset();
- mVectorRenderer.reset();
-
- mTargetSurface = nullptr;
- mTbmQueue = NULL;
-
- mPropertyCallbacks.clear();
-
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "[%p]\n", this);
-}
-
-bool TizenVectorAnimationRenderer::Load(const std::string& url)
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- mUrl = url;
-
- mVectorRenderer = rlottie::Animation::loadFromFile(mUrl);
- if(!mVectorRenderer)
- {
- DALI_LOG_ERROR("Failed to load a Lottie file [%s] [%p]\n", mUrl.c_str(), 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, "file [%s] [%p]\n", url.c_str(), this);
-
- 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(std::move(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;
- mShaderChanged = false;
-
- if(mTargetSurface)
- {
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mResourceReady && mRenderedTexture)
- {
- TextureSet textureSet = renderer.GetTextures();
-
- textureSet.SetTexture(0, mRenderedTexture);
-
- mUploadCompletedSignal.Emit();
- }
-
- SetShader();
- }
-}
-
-void TizenVectorAnimationRenderer::SetSize(uint32_t width, uint32_t height)
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mWidth == width && mHeight == height)
- {
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Same size (%d, %d) [%p]\n", mWidth, mHeight, this);
- return;
- }
-
- if(mLoadFailed)
- {
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Load is failed. Do not make texture [%p]\n", this);
- return;
- }
-
- mTargetSurface = NativeImageSourceQueue::New(width, height, NativeImageSourceQueue::ColorFormat::RGBA8888);
-
- mTexture = Texture::New(*mTargetSurface);
-
- if(mRenderer)
- {
- SetShader();
- }
-
- mTbmQueue = AnyCast<tbm_surface_queue_h>(mTargetSurface->GetNativeImageSourceQueue());
-
- mWidth = width;
- mHeight = height;
-
- mResourceReady = false;
-
- // Reset the previous texture to destroy it in the main thread
- mPreviousTexture.Reset();
-
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "width = %d, height = %d [%p]\n", mWidth, mHeight, this);
-}
-
-bool TizenVectorAnimationRenderer::Render(uint32_t frameNumber)
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(!mTbmQueue || !mVectorRenderer || !mTargetSurface)
- {
- return false;
- }
-
- int canDequeue = tbm_surface_queue_can_dequeue(mTbmQueue, 0);
- if(!canDequeue)
- {
- // Ignore the previous image which is inserted to the queue.
- mTargetSurface->IgnoreSourceImage();
-
- // Check again
- canDequeue = tbm_surface_queue_can_dequeue(mTbmQueue, 0);
- if(!canDequeue)
- {
- return false;
- }
- }
-
- tbm_surface_h tbmSurface;
-
- if(tbm_surface_queue_dequeue(mTbmQueue, &tbmSurface) != TBM_SURFACE_QUEUE_ERROR_NONE)
- {
- DALI_LOG_ERROR("Failed to dequeue a tbm_surface [%p]\n", this);
- return false;
- }
-
- tbm_surface_info_s info;
- int ret = tbm_surface_map(tbmSurface, TBM_OPTION_WRITE, &info);
- if(ret != TBM_SURFACE_ERROR_NONE)
- {
- DALI_LOG_ERROR("TizenVectorAnimationRenderer::Render: tbm_surface_map is failed! [%d] [%p]\n", ret, this);
- tbm_surface_queue_cancel_dequeue(mTbmQueue, tbmSurface);
- return false;
- }
-
- unsigned char* buffer = info.planes[0].ptr;
- if(info.width != mWidth || info.height != mHeight || !buffer)
- {
- DALI_LOG_ERROR("TizenVectorAnimationRenderer::Render: Invalid tbm surface! [%d, %d, %p] [%p]\n", info.width, info.height, buffer, this);
- tbm_surface_unmap(tbmSurface);
- tbm_surface_queue_cancel_dequeue(mTbmQueue, tbmSurface);
- return false;
- }
-
- rlottie::Surface surface;
- bool existing = false;
-
- if(!mResourceReady)
- {
- // Need to reset buffer list
- ResetBuffers();
- }
- else
- {
- for(auto&& iter : mBuffers)
- {
- if(iter.first == tbmSurface)
- {
- // Find the buffer in the existing list
- existing = true;
- surface = iter.second;
- break;
- }
- }
- }
-
- if(!existing)
- {
- tbm_surface_internal_ref(tbmSurface);
-
- // Create Surface object
- surface = rlottie::Surface(reinterpret_cast<uint32_t*>(buffer), mWidth, mHeight, static_cast<size_t>(info.planes[0].stride));
-
- // Push the buffer
- mBuffers.push_back(SurfacePair(tbmSurface, surface));
- }
-
- // Render the frame
- mVectorRenderer->renderSync(frameNumber, surface);
-
- tbm_surface_unmap(tbmSurface);
-
- tbm_surface_queue_enqueue(mTbmQueue, tbmSurface);
-
- if(!mResourceReady)
- {
- mPreviousTexture = mRenderedTexture; // It is used to destroy the object in the main thread.
- mRenderedTexture = mTexture;
- mResourceReady = true;
- mResourceReadyTriggered = true;
-
- TizenVectorAnimationManager::Get().TriggerEvent(*this);
-
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Resource ready [current = %d] [%p]\n", frameNumber, this);
- }
-
- return true;
-}
-
-void TizenVectorAnimationRenderer::RenderStopped()
-{
- if(mTargetSurface)
- {
- // Animation is stopped. Free empty buffers
- mTargetSurface->FreeReleasedBuffers();
-
- {
- Dali::Mutex::ScopedLock lock(mMutex);
- ResetBuffers();
- }
- }
-}
-
-uint32_t TizenVectorAnimationRenderer::GetTotalFrameNumber() const
-{
- return mTotalFrameNumber;
-}
-
-float TizenVectorAnimationRenderer::GetFrameRate() const
-{
- return mFrameRate;
-}
-
-void TizenVectorAnimationRenderer::GetDefaultSize(uint32_t& width, uint32_t& height) const
-{
- width = mDefaultWidth;
- height = mDefaultHeight;
-}
-
-void TizenVectorAnimationRenderer::GetLayerInfo(Property::Map& map) const
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mVectorRenderer)
- {
- auto layerInfo = mVectorRenderer->layers();
-
- for(auto&& iter : layerInfo)
- {
- Property::Array frames;
- frames.PushBack(std::get<1>(iter));
- frames.PushBack(std::get<2>(iter));
- map.Add(std::get<0>(iter), frames);
- }
- }
-}
-
-bool TizenVectorAnimationRenderer::GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mVectorRenderer)
- {
- auto markerList = mVectorRenderer->markers();
- for(auto&& iter : markerList)
- {
- if(std::get<0>(iter).compare(marker) == 0)
- {
- startFrame = static_cast<uint32_t>(std::get<1>(iter));
- endFrame = static_cast<uint32_t>(std::get<2>(iter));
- return true;
- }
- }
- }
- return false;
-}
-
-void TizenVectorAnimationRenderer::GetMarkerInfo(Property::Map& map) const
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mVectorRenderer)
- {
- auto markerList = mVectorRenderer->markers();
- for(auto&& iter : markerList)
- {
- Property::Array frames;
- frames.PushBack(std::get<1>(iter));
- frames.PushBack(std::get<2>(iter));
- map.Add(std::get<0>(iter), frames);
- }
- }
-}
-
-void TizenVectorAnimationRenderer::InvalidateBuffer()
-{
- Dali::Mutex::ScopedLock lock(mMutex);
- mResourceReady = false;
-}
-
-void TizenVectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id)
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- mPropertyCallbacks.push_back(std::unique_ptr<CallbackBase>(callback));
-
- switch(property)
- {
- case VectorProperty::FILL_COLOR:
- {
- mVectorRenderer->setValue<rlottie::Property::FillColor>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- Vector3 color;
- if(value.Get(color))
- {
- return rlottie::Color(color.r, color.g, color.b);
- }
- return rlottie::Color(1.0f, 1.0f, 1.0f);
- });
- break;
- }
- case VectorProperty::FILL_OPACITY:
- {
- mVectorRenderer->setValue<rlottie::Property::FillOpacity>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- float opacity;
- if(value.Get(opacity))
- {
- return opacity * 100;
- }
- return 100.0f;
- });
- break;
- }
- case VectorProperty::STROKE_COLOR:
- {
- mVectorRenderer->setValue<rlottie::Property::StrokeColor>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- Vector3 color;
- if(value.Get(color))
- {
- return rlottie::Color(color.r, color.g, color.b);
- }
- return rlottie::Color(1.0f, 1.0f, 1.0f);
- });
- break;
- }
- case VectorProperty::STROKE_OPACITY:
- {
- mVectorRenderer->setValue<rlottie::Property::StrokeOpacity>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- float opacity;
- if(value.Get(opacity))
- {
- return opacity * 100;
- }
- return 100.0f;
- });
- break;
- }
- case VectorProperty::STROKE_WIDTH:
- {
- mVectorRenderer->setValue<rlottie::Property::StrokeWidth>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- float width;
- if(value.Get(width))
- {
- return width;
- }
- return 1.0f;
- });
- break;
- }
- case VectorProperty::TRANSFORM_ANCHOR:
- {
- mVectorRenderer->setValue<rlottie::Property::TrAnchor>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- Vector2 point;
- if(value.Get(point))
- {
- return rlottie::Point(point.x, point.y);
- }
- return rlottie::Point(0.0f, 0.0f);
- });
- break;
- }
- case VectorProperty::TRANSFORM_POSITION:
- {
- mVectorRenderer->setValue<rlottie::Property::TrPosition>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- Vector2 position;
- if(value.Get(position))
- {
- return rlottie::Point(position.x, position.y);
- }
- return rlottie::Point(0.0f, 0.0f);
- });
- break;
- }
- case VectorProperty::TRANSFORM_SCALE:
- {
- mVectorRenderer->setValue<rlottie::Property::TrScale>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- Vector2 scale;
- if(value.Get(scale))
- {
- return rlottie::Size(scale.x, scale.y);
- }
- return rlottie::Size(100.0f, 100.0f);
- });
- break;
- }
- case VectorProperty::TRANSFORM_ROTATION:
- {
- mVectorRenderer->setValue<rlottie::Property::TrRotation>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- float rotation;
- if(value.Get(rotation))
- {
- return rotation;
- }
- return 0.0f;
- });
- break;
- }
- case VectorProperty::TRANSFORM_OPACITY:
- {
- mVectorRenderer->setValue<rlottie::Property::TrOpacity>(keyPath,
- [property, callback, id](const rlottie::FrameInfo& info) {
- Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
- float opacity;
- if(value.Get(opacity))
- {
- return opacity * 100;
- }
- return 100.0f;
- });
- break;
- }
- }
-}
-
-VectorAnimationRendererPlugin::UploadCompletedSignalType& TizenVectorAnimationRenderer::UploadCompletedSignal()
-{
- return mUploadCompletedSignal;
-}
-
-void TizenVectorAnimationRenderer::NotifyEvent()
-{
- bool emitSignal = false;
- {
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mResourceReadyTriggered)
- {
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Set Texture [%p]\n", this);
-
- // Set texture
- if(mRenderer && mRenderedTexture)
- {
- TextureSet textureSet = mRenderer.GetTextures();
- textureSet.SetTexture(0, mRenderedTexture);
- }
-
- mResourceReadyTriggered = false;
- emitSignal = true;
- }
-
- mPreviousTexture.Reset();
- }
- if(emitSignal)
- {
- mUploadCompletedSignal.Emit();
- }
-}
-
-void TizenVectorAnimationRenderer::SetShader()
-{
- if(mShaderChanged)
- {
- return;
- }
-
- Shader shader = mRenderer.GetShader();
-
- std::string fragmentShader;
- std::string vertexShader;
-
- // Get the current fragment shader source
- Property::Value program = shader.GetProperty(Shader::Property::PROGRAM);
- Property::Map* map = program.GetMap();
- if(map)
- {
- Property::Value* fragment = map->Find("fragment");
- if(fragment)
- {
- fragmentShader = fragment->Get<std::string>();
- }
-
- Property::Value* vertex = map->Find("vertex");
- if(vertex)
- {
- vertexShader = vertex->Get<std::string>();
- }
- }
-
- // Get custom fragment shader prefix
- mTargetSurface->ApplyNativeFragmentShader(fragmentShader);
-
- // Set the modified shader again
- Shader newShader = Shader::New(vertexShader, fragmentShader);
- newShader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
-
- mRenderer.SetShader(newShader);
-
- mShaderChanged = true;
-}
-
-void TizenVectorAnimationRenderer::ResetBuffers()
-{
- for(auto&& iter : mBuffers)
- {
- tbm_surface_internal_unref(iter.first);
- }
- mBuffers.clear();
-}
-
-} // namespace Plugin
-
-} // namespace Dali
-#ifndef DALI_TIZEN_VECTOR_ANIMATION_EVENT_HANDLER_H
-#define DALI_TIZEN_VECTOR_ANIMATION_EVENT_HANDLER_H
+#ifndef DALI_VECTOR_ANIMATION_EVENT_HANDLER_H
+#define DALI_VECTOR_ANIMATION_EVENT_HANDLER_H
/*
- * Copyright (c) 2019 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.
/**
* @brief Tizen vector animation event handler
*/
-class TizenVectorAnimationEventHandler
+class VectorAnimationEventHandler
{
public:
/**
* constructor
*/
- TizenVectorAnimationEventHandler()
+ VectorAnimationEventHandler()
{
}
/**
* virtual destructor
*/
- virtual ~TizenVectorAnimationEventHandler()
+ virtual ~VectorAnimationEventHandler()
{
}
// Undefined copy constructor.
- TizenVectorAnimationEventHandler( const TizenVectorAnimationEventHandler& ) = delete;
+ VectorAnimationEventHandler( const VectorAnimationEventHandler& ) = delete;
// Undefined assignment operator.
- TizenVectorAnimationEventHandler& operator=( const TizenVectorAnimationEventHandler& ) = delete;
+ VectorAnimationEventHandler& operator=( const VectorAnimationEventHandler& ) = delete;
};
} // namespace Plugin
/*
- * 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.
*/
// CLASS HEADER
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-manager.h>
+#include <dali-extension/vector-animation-renderer/vector-animation-plugin-manager.h>
// EXTERNAL INCLUDES
#include <dali/integration-api/adaptor-framework/adaptor.h>
#endif
} // unnamed namespace
-TizenVectorAnimationManager& TizenVectorAnimationManager::Get()
+VectorAnimationPluginManager& VectorAnimationPluginManager::Get()
{
- static TizenVectorAnimationManager animationManager;
+ static VectorAnimationPluginManager animationManager;
return animationManager;
}
-TizenVectorAnimationManager::TizenVectorAnimationManager()
+VectorAnimationPluginManager::VectorAnimationPluginManager()
: mEventHandlers(),
mTriggeredHandlers(),
mMutex(),
{
}
-TizenVectorAnimationManager::~TizenVectorAnimationManager()
+VectorAnimationPluginManager::~VectorAnimationPluginManager()
{
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "this = %p\n", this);
}
-void TizenVectorAnimationManager::AddEventHandler(TizenVectorAnimationEventHandler& handler)
+void VectorAnimationPluginManager::AddEventHandler(VectorAnimationEventHandler& handler)
{
if(mEventHandlers.end() == std::find(mEventHandlers.begin(), mEventHandlers.end(), &handler))
{
if(!mEventTrigger)
{
- mEventTrigger = std::unique_ptr<EventThreadCallback>(new EventThreadCallback(MakeCallback(this, &TizenVectorAnimationManager::OnEventTriggered)));
+ mEventTrigger = std::unique_ptr<EventThreadCallback>(new EventThreadCallback(MakeCallback(this, &VectorAnimationPluginManager::OnEventTriggered)));
}
}
}
}
-void TizenVectorAnimationManager::RemoveEventHandler(TizenVectorAnimationEventHandler& handler)
+void VectorAnimationPluginManager::RemoveEventHandler(VectorAnimationEventHandler& handler)
{
auto iter = std::find(mEventHandlers.begin(), mEventHandlers.end(), &handler);
if(iter != mEventHandlers.end())
}
}
-void TizenVectorAnimationManager::TriggerEvent(TizenVectorAnimationEventHandler& handler)
+void VectorAnimationPluginManager::TriggerEvent(VectorAnimationEventHandler& handler)
{
Dali::Mutex::ScopedLock lock(mMutex);
}
}
-void TizenVectorAnimationManager::Process(bool postProcessor)
+void VectorAnimationPluginManager::Process(bool postProcessor)
{
OnEventTriggered();
}
// This function is called in the main thread.
-void TizenVectorAnimationManager::OnEventTriggered()
+void VectorAnimationPluginManager::OnEventTriggered()
{
- std::vector<TizenVectorAnimationEventHandler*> handlers;
+ std::vector<VectorAnimationEventHandler*> handlers;
{
Dali::Mutex::ScopedLock lock(mMutex);
-#ifndef DALI_TIZEN_VECTOR_ANIMATION_MANAGER_H
-#define DALI_TIZEN_VECTOR_ANIMATION_MANAGER_H
+#ifndef DALI_VECTOR_ANIMATION_PLUGIN_MANAGER_H
+#define DALI_VECTOR_ANIMATION_PLUGIN_MANAGER_H
/*
- * Copyright (c) 2019 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 <memory>
// INTERNAL INCLUDES
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-event-handler.h>
+#include <dali-extension/vector-animation-renderer/vector-animation-event-handler.h>
namespace Dali
{
/**
* @brief Tizen vector animation manager
*/
-class TizenVectorAnimationManager : public Integration::Processor
+class VectorAnimationPluginManager : public Integration::Processor
{
public:
/**
- * @brief Create or retrieve TizenVectorAnimationManager singleton.
+ * @brief Create or retrieve VectorAnimationPluginManager singleton.
*
- * @return A reference to the TizenVectorAnimationManager.
+ * @return A reference to the VectorAnimationPluginManager.
*/
- static TizenVectorAnimationManager& Get();
+ static VectorAnimationPluginManager& Get();
/**
* @brief Add the event handler.
*
* @param handler The event handler to add.
*/
- void AddEventHandler( TizenVectorAnimationEventHandler& handler );
+ void AddEventHandler( VectorAnimationEventHandler& handler );
/**
* @brief Remove the event handler.
*
* @param handler The event handler to remove.
*/
- void RemoveEventHandler( TizenVectorAnimationEventHandler& handler );
+ void RemoveEventHandler( VectorAnimationEventHandler& handler );
/**
* @brief Trigger the event.
*/
- void TriggerEvent( TizenVectorAnimationEventHandler& handler );
+ void TriggerEvent( VectorAnimationEventHandler& handler );
protected: // Implementation of Processor
/**
* @brief Constructor.
*/
- TizenVectorAnimationManager();
+ VectorAnimationPluginManager();
/**
* @brief Destructor.
*/
- virtual ~TizenVectorAnimationManager();
+ virtual ~VectorAnimationPluginManager();
// Undefined
- TizenVectorAnimationManager( const TizenVectorAnimationManager& ) = delete;
+ VectorAnimationPluginManager( const VectorAnimationPluginManager& ) = delete;
// Undefined
- TizenVectorAnimationManager& operator=( const TizenVectorAnimationManager& ) = delete;
+ VectorAnimationPluginManager& operator=( const VectorAnimationPluginManager& ) = delete;
private:
- std::vector< TizenVectorAnimationEventHandler* > mEventHandlers;
- std::vector< TizenVectorAnimationEventHandler* > mTriggeredHandlers;
+ std::vector< VectorAnimationEventHandler* > mEventHandlers;
+ std::vector< VectorAnimationEventHandler* > mTriggeredHandlers;
Dali::Mutex mMutex;
std::unique_ptr< EventThreadCallback > mEventTrigger;
};
--- /dev/null
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-extension/vector-animation-renderer/vector-animation-renderer-tizen.h>
+
+// 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>
+#include <cstring> // for strlen()
+
+// INTERNAL INCLUDES
+#include <dali-extension/vector-animation-renderer/vector-animation-plugin-manager.h>
+
+// The plugin factories
+extern "C" DALI_EXPORT_API Dali::VectorAnimationRendererPlugin* CreateVectorAnimationRendererPlugin(void)
+{
+ return new Dali::Plugin::VectorAnimationRendererTizen;
+}
+
+namespace Dali
+{
+namespace Plugin
+{
+namespace
+{
+const char* const PIXEL_AREA_UNIFORM_NAME("pixelArea");
+const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
+
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
+#endif
+} // unnamed namespace
+
+VectorAnimationRendererTizen::VectorAnimationRendererTizen()
+: mBuffers(),
+ mRenderedTexture(),
+ mPreviousTexture(),
+ mTargetSurface(),
+ mTbmQueue(NULL)
+{
+}
+
+VectorAnimationRendererTizen::~VectorAnimationRendererTizen()
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ ResetBuffers();
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "this = %p\n", this);
+}
+
+bool VectorAnimationRendererTizen::Render(uint32_t frameNumber)
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ if(!mTbmQueue || !mVectorRenderer || !mTargetSurface)
+ {
+ return false;
+ }
+
+ int canDequeue = tbm_surface_queue_can_dequeue(mTbmQueue, 0);
+ if(!canDequeue)
+ {
+ // Ignore the previous image which is inserted to the queue.
+ mTargetSurface->IgnoreSourceImage();
+
+ // Check again
+ canDequeue = tbm_surface_queue_can_dequeue(mTbmQueue, 0);
+ if(!canDequeue)
+ {
+ return false;
+ }
+ }
+
+ tbm_surface_h tbmSurface;
+
+ if(tbm_surface_queue_dequeue(mTbmQueue, &tbmSurface) != TBM_SURFACE_QUEUE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("Failed to dequeue a tbm_surface [%p]\n", this);
+ return false;
+ }
+
+ tbm_surface_info_s info;
+ int ret = tbm_surface_map(tbmSurface, TBM_OPTION_WRITE, &info);
+ if(ret != TBM_SURFACE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("VectorAnimationRendererTizen::Render: tbm_surface_map is failed! [%d] [%p]\n", ret, this);
+ tbm_surface_queue_cancel_dequeue(mTbmQueue, tbmSurface);
+ return false;
+ }
+
+ unsigned char* buffer = info.planes[0].ptr;
+ if(info.width != mWidth || info.height != mHeight || !buffer)
+ {
+ DALI_LOG_ERROR("VectorAnimationRendererTizen::Render: Invalid tbm surface! [%d, %d, %p] [%p]\n", info.width, info.height, buffer, this);
+ tbm_surface_unmap(tbmSurface);
+ tbm_surface_queue_cancel_dequeue(mTbmQueue, tbmSurface);
+ return false;
+ }
+
+ rlottie::Surface surface;
+ bool existing = false;
+
+ if(!mResourceReady)
+ {
+ // Need to reset buffer list
+ ResetBuffers();
+ }
+ else
+ {
+ for(auto&& iter : mBuffers)
+ {
+ if(iter.first == tbmSurface)
+ {
+ // Find the buffer in the existing list
+ existing = true;
+ surface = iter.second;
+ break;
+ }
+ }
+ }
+
+ if(!existing)
+ {
+ tbm_surface_internal_ref(tbmSurface);
+
+ // Create Surface object
+ surface = rlottie::Surface(reinterpret_cast<uint32_t*>(buffer), mWidth, mHeight, static_cast<size_t>(info.planes[0].stride));
+
+ // Push the buffer
+ mBuffers.push_back(SurfacePair(tbmSurface, surface));
+ }
+
+ // Render the frame
+ mVectorRenderer->renderSync(frameNumber, surface);
+
+ tbm_surface_unmap(tbmSurface);
+
+ tbm_surface_queue_enqueue(mTbmQueue, tbmSurface);
+
+ if(!mResourceReady)
+ {
+ mPreviousTexture = mRenderedTexture; // It is used to destroy the object in the main thread.
+ mRenderedTexture = mTexture;
+ mResourceReady = true;
+ mResourceReadyTriggered = true;
+
+ VectorAnimationPluginManager::Get().TriggerEvent(*this);
+
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Resource ready [current = %d] [%p]\n", frameNumber, this);
+ }
+
+ return true;
+}
+
+void VectorAnimationRendererTizen::RenderStopped()
+{
+ if(mTargetSurface)
+ {
+ // Animation is stopped. Free empty buffers
+ mTargetSurface->FreeReleasedBuffers();
+
+ {
+ Dali::Mutex::ScopedLock lock(mMutex);
+ ResetBuffers();
+ }
+ }
+}
+
+void VectorAnimationRendererTizen::SetShader()
+{
+ if(mShaderChanged)
+ {
+ return;
+ }
+
+ Shader shader = mRenderer.GetShader();
+
+ std::string fragmentShader;
+ std::string vertexShader;
+
+ // Get the current fragment shader source
+ Property::Value program = shader.GetProperty(Shader::Property::PROGRAM);
+ Property::Map* map = program.GetMap();
+ if(map)
+ {
+ Property::Value* fragment = map->Find("fragment");
+ if(fragment)
+ {
+ fragmentShader = fragment->Get<std::string>();
+ }
+
+ Property::Value* vertex = map->Find("vertex");
+ if(vertex)
+ {
+ vertexShader = vertex->Get<std::string>();
+ }
+ }
+
+ // Get custom fragment shader prefix
+ mTargetSurface->ApplyNativeFragmentShader(fragmentShader);
+
+ // Set the modified shader again
+ Shader newShader = Shader::New(vertexShader, fragmentShader);
+ newShader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
+
+ mRenderer.SetShader(newShader);
+
+ mShaderChanged = true;
+}
+
+void VectorAnimationRendererTizen::ResetBuffers()
+{
+ for(auto&& iter : mBuffers)
+ {
+ tbm_surface_internal_unref(iter.first);
+ }
+ mBuffers.clear();
+}
+
+void VectorAnimationRendererTizen::OnFinalize()
+{
+ mRenderedTexture.Reset();
+ mPreviousTexture.Reset();
+
+ mTargetSurface = nullptr;
+ mTbmQueue = NULL;
+}
+
+void VectorAnimationRendererTizen::OnSetSize()
+{
+ mTbmQueue = AnyCast<tbm_surface_queue_h>(mTargetSurface->GetNativeImageSourceQueue());
+
+ // Reset the previous texture to destroy it in the main thread
+ mPreviousTexture.Reset();
+}
+
+void VectorAnimationRendererTizen::PrepareTarget()
+{
+ mTargetSurface = NativeImageSourceQueue::New(mWidth, mHeight, NativeImageSourceQueue::ColorFormat::RGBA8888);
+
+ mTexture = Texture::New(*mTargetSurface);
+}
+
+bool VectorAnimationRendererTizen::IsTargetPrepared()
+{
+ return !!mTargetSurface;
+}
+
+bool VectorAnimationRendererTizen::IsRenderReady()
+{
+ return (mResourceReady && mRenderedTexture);
+}
+
+Dali::Texture VectorAnimationRendererTizen::GetTargetTexture()
+{
+ return mRenderedTexture;
+}
+
+} // namespace Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_VECTOR_ANIMATION_RENDERER_TIZEN_H
+#define DALI_VECTOR_ANIMATION_RENDERER_TIZEN_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
+#include <tbm_surface.h>
+#include <tbm_surface_queue.h>
+
+// INTERNAL INCLUDES
+#include <dali-extension/vector-animation-renderer/vector-animation-renderer.h>
+
+namespace Dali
+{
+namespace Plugin
+{
+/**
+ * @brief Implementation of the Tizen vector animation renderer class which has Tizen platform dependency.
+ */
+class VectorAnimationRendererTizen : public VectorAnimationRenderer
+{
+public:
+ /**
+ * @brief Constructor.
+ */
+ VectorAnimationRendererTizen();
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~VectorAnimationRendererTizen();
+
+ /**
+ * @copydoc Dali::VectorAnimationRendererPlugin::Render()
+ */
+ bool Render(uint32_t frameNumber) override;
+
+ /**
+ * @copydoc Dali::VectorAnimationRendererPlugin::RenderStopped()
+ */
+ void RenderStopped() override;
+
+private:
+ /**
+ * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
+ */
+ void SetShader() override;
+
+ /**
+ * @brief Reset buffer list.
+ */
+ void ResetBuffers() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::Finalize()
+ */
+ void OnFinalize() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::OnSetSize()
+ */
+ void OnSetSize() override;
+
+ /**
+ * @brief Event callback to process events.
+ */
+ void OnLottieRendered() override
+ {}
+
+ /**
+ * @copydoc VectorAnimationRenderer::PrepareTarget()
+ */
+ void PrepareTarget() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::IsTargetPrepared()
+ */
+ bool IsTargetPrepared() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::IsRenderReady()
+ */
+ bool IsRenderReady() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::GetTargetTexture()
+ */
+ Dali::Texture GetTargetTexture() override;
+
+private:
+ using SurfacePair = std::pair<tbm_surface_h, rlottie::Surface>;
+
+ std::vector<SurfacePair> mBuffers; ///< EGL Image vector
+
+ Dali::Texture mRenderedTexture; ///< Rendered Texture
+ Dali::Texture mPreviousTexture; ///< Previous rendered texture
+ NativeImageSourceQueuePtr mTargetSurface; ///< The target surface
+ tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
+};
+
+} // namespace Plugin
+
+} // namespace Dali
+
+#endif // DALI_TIZEN_VECTOR_ANIMATION_RENDERER_PLUGIN_H
--- /dev/null
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-extension/vector-animation-renderer/vector-animation-renderer-x.h>
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/common/hash.h>
+#include <dali/devel-api/rendering/texture-devel.h>
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/object/property-array.h>
+
+#include <cstring> // for strlen()
+
+// INTERNAL INCLUDES
+#include <dali-extension/vector-animation-renderer/vector-animation-plugin-manager.h>
+
+// The plugin factories
+extern "C" DALI_EXPORT_API Dali::VectorAnimationRendererPlugin* CreateVectorAnimationRendererPlugin(void)
+{
+ return new Dali::Plugin::VectorAnimationRendererX;
+}
+
+namespace Dali
+{
+namespace Plugin
+{
+namespace
+{
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
+#endif
+} // unnamed namespace
+
+VectorAnimationRendererX::VectorAnimationRendererX()
+: mLottieSurface(),
+ mRenderCallback(std::unique_ptr<EventThreadCallback>(new EventThreadCallback(MakeCallback(this, &VectorAnimationRendererX::OnLottieRendered))))
+{
+}
+
+VectorAnimationRendererX::~VectorAnimationRendererX()
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ ResetBuffers();
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "this = %p\n", this);
+}
+
+bool VectorAnimationRendererX::Render(uint32_t frameNumber)
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ if(!mVectorRenderer || !mPixelBuffer)
+ {
+ return false;
+ }
+
+ mVectorRenderer->renderSync(frameNumber, mLottieSurface);
+ mRenderCallback->Trigger();
+
+ if(!mResourceReady)
+ {
+ mResourceReady = true;
+ mResourceReadyTriggered = true;
+
+ VectorAnimationPluginManager::Get().TriggerEvent(*this);
+ }
+
+ return true;
+}
+
+void VectorAnimationRendererX::RenderStopped()
+{
+}
+
+
+void VectorAnimationRendererX::SetShader()
+{
+ if(mShaderChanged || !mTexture)
+ {
+ return;
+ }
+
+ // Not implemented
+
+ mShaderChanged = true;
+}
+
+void VectorAnimationRendererX::ResetBuffers()
+{
+ if(mPixelBuffer)
+ {
+ uint32_t bufferSize = mPixelBuffer.GetWidth() * mPixelBuffer.GetHeight() * Dali::Pixel::GetBytesPerPixel(mPixelBuffer.GetPixelFormat());
+ memset(mPixelBuffer.GetBuffer(), 0, bufferSize);
+ }
+}
+
+void VectorAnimationRendererX::OnFinalize()
+{
+}
+
+void VectorAnimationRendererX::OnLottieRendered()
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ if(mPixelBuffer && mTexture)
+ {
+ PixelData pixelData = mPixelBuffer.CreatePixelData();
+ mTexture.Upload(pixelData);
+ }
+}
+
+void VectorAnimationRendererX::PrepareTarget()
+{
+ mTexture = Texture::New(Dali::TextureType::TEXTURE_2D, Dali::Pixel::BGRA8888, mWidth, mHeight);
+
+ mPixelBuffer = Dali::Devel::PixelBuffer::New(mWidth, mHeight, Dali::Pixel::BGRA8888);
+ mLottieSurface = rlottie::Surface(reinterpret_cast<uint32_t*>(mPixelBuffer.GetBuffer()), mWidth, mHeight, static_cast<size_t>(mPixelBuffer.GetStride() * 4));
+}
+
+bool VectorAnimationRendererX::IsTargetPrepared()
+{
+ return !!mPixelBuffer;
+}
+
+bool VectorAnimationRendererX::IsRenderReady()
+{
+ return mResourceReady && mTexture;
+}
+
+Dali::Texture VectorAnimationRendererX::GetTargetTexture()
+{
+ return mTexture;
+}
+
+} // namespace Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_VECTOR_ANIMATION_RENDERER_X_H
+#define DALI_VECTOR_ANIMATION_RENDERER_X_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
+
+// INTERNAL INCLUDES
+#include <dali-extension/vector-animation-renderer/vector-animation-renderer.h>
+
+namespace Dali
+{
+namespace Plugin
+{
+/**
+ * @brief Implementation of the Tizen vector animation renderer class which has Tizen platform dependency.
+ */
+class VectorAnimationRendererX : public VectorAnimationRenderer
+{
+public:
+ /**
+ * @brief Constructor.
+ */
+ VectorAnimationRendererX();
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~VectorAnimationRendererX();
+
+ /**
+ * @copydoc Dali::VectorAnimationRendererPlugin::Render()
+ */
+ bool Render(uint32_t frameNumber) override;
+
+ /**
+ * @copydoc Dali::VectorAnimationRendererPlugin::RenderStopped()
+ */
+ void RenderStopped() override;
+
+private:
+ /**
+ * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
+ */
+ void SetShader() override;
+
+ /**
+ * @brief Reset buffer list.
+ */
+ void ResetBuffers() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::Finalize()
+ */
+ void OnFinalize() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::OnSetSize()
+ */
+ void OnSetSize() override
+ {}
+
+ /**
+ * @brief Event callback to process events.
+ */
+ void OnLottieRendered() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::PrepareTarget()
+ */
+ void PrepareTarget() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::IsTargetPrepared()
+ */
+ bool IsTargetPrepared() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::IsRenderReady()
+ */
+ bool IsRenderReady() override;
+
+ /**
+ * @copydoc VectorAnimationRenderer::GetTargetTexture()
+ */
+ Dali::Texture GetTargetTexture() override;
+
+private:
+ rlottie::Surface mLottieSurface; ///
+ Dali::Devel::PixelBuffer mPixelBuffer; ///
+ std::unique_ptr<EventThreadCallback> mRenderCallback; ///
+};
+
+} // namespace Plugin
+
+} // namespace Dali
+
+#endif // DALI_TIZEN_VECTOR_ANIMATION_RENDERER_X_H
*/
// CLASS HEADER
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-renderer-x.h>
+#include <dali-extension/vector-animation-renderer/vector-animation-renderer.h>
// EXTERNAL INCLUDES
#include <dali/devel-api/common/hash.h>
-#include <dali/devel-api/rendering/texture-devel.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/object/property-array.h>
#include <cstring> // for strlen()
// INTERNAL INCLUDES
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-manager.h>
-
-// The plugin factories
-extern "C" DALI_EXPORT_API Dali::VectorAnimationRendererPlugin* CreateVectorAnimationRendererPlugin(void)
-{
- return new Dali::Plugin::TizenVectorAnimationRenderer;
-}
+#include <dali-extension/vector-animation-renderer/vector-animation-plugin-manager.h>
namespace Dali
{
#endif
} // unnamed namespace
-TizenVectorAnimationRenderer::TizenVectorAnimationRenderer()
+VectorAnimationRenderer::VectorAnimationRenderer()
: mUrl(),
mMutex(),
mRenderer(),
mTexture(),
- mLottieSurface(),
mVectorRenderer(),
mUploadCompletedSignal(),
mTotalFrameNumber(0),
mLoadFailed(false),
mResourceReady(false),
mShaderChanged(false),
- mResourceReadyTriggered(false),
- mRenderCallback(std::unique_ptr<EventThreadCallback>(new EventThreadCallback(MakeCallback(this, &TizenVectorAnimationRenderer::OnLottieRendered))))
+ mResourceReadyTriggered(false)
{
- TizenVectorAnimationManager::Get().AddEventHandler(*this);
+ VectorAnimationPluginManager::Get().AddEventHandler(*this);
}
-TizenVectorAnimationRenderer::~TizenVectorAnimationRenderer()
+VectorAnimationRenderer::~VectorAnimationRenderer()
{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- ResetBuffers();
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "this = %p\n", this);
}
-void TizenVectorAnimationRenderer::Finalize()
+void VectorAnimationRenderer::Finalize()
{
Dali::Mutex::ScopedLock lock(mMutex);
- TizenVectorAnimationManager::Get().RemoveEventHandler(*this);
+ VectorAnimationPluginManager::Get().RemoveEventHandler(*this);
mRenderer.Reset();
mTexture.Reset();
mVectorRenderer.reset();
mPropertyCallbacks.clear();
+ OnFinalize();
+
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "[%p]\n", this);
}
-bool TizenVectorAnimationRenderer::Load(const std::string& url)
+bool VectorAnimationRenderer::Load(const std::string& url)
{
Dali::Mutex::ScopedLock lock(mMutex);
return true;
}
-bool TizenVectorAnimationRenderer::Load(const Dali::Vector<uint8_t>& data)
+bool VectorAnimationRenderer::Load(const Dali::Vector<uint8_t>& data)
{
Dali::Mutex::ScopedLock lock(mMutex);
return true;
}
-void TizenVectorAnimationRenderer::OnLottieRendered()
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(mPixelBuffer && mTexture)
- {
- PixelData pixelData = mPixelBuffer.CreatePixelData();
- mTexture.Upload(pixelData);
- }
-}
-
-void TizenVectorAnimationRenderer::SetRenderer(Renderer renderer)
+void VectorAnimationRenderer::SetRenderer(Renderer renderer)
{
mRenderer = renderer;
mShaderChanged = false;
- if(mPixelBuffer)
+ if(IsTargetPrepared())
{
Dali::Mutex::ScopedLock lock(mMutex);
- if(mResourceReady && mTexture)
+ if(IsRenderReady())
{
TextureSet textureSet = renderer.GetTextures();
- textureSet.SetTexture(0, mTexture);
+ textureSet.SetTexture(0, GetTargetTexture());
mUploadCompletedSignal.Emit();
}
}
}
-void TizenVectorAnimationRenderer::SetSize(uint32_t width, uint32_t height)
+void VectorAnimationRenderer::SetSize(uint32_t width, uint32_t height)
{
Dali::Mutex::ScopedLock lock(mMutex);
return;
}
- mTexture = Texture::New(Dali::TextureType::TEXTURE_2D, Dali::Pixel::BGRA8888, width, height);
+ mWidth = width;
+ mHeight = height;
- mPixelBuffer = Dali::Devel::PixelBuffer::New(width, height, Dali::Pixel::BGRA8888);
- mLottieSurface = rlottie::Surface(reinterpret_cast<uint32_t*>(mPixelBuffer.GetBuffer()), width, height, static_cast<size_t>(mPixelBuffer.GetStride() * 4));
+ PrepareTarget();
if(mRenderer)
{
SetShader();
}
- mWidth = width;
- mHeight = height;
-
mResourceReady = false;
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "width = %d, height = %d [%p]\n", mWidth, mHeight, this);
-}
-
-bool TizenVectorAnimationRenderer::Render(uint32_t frameNumber)
-{
- Dali::Mutex::ScopedLock lock(mMutex);
-
- if(!mVectorRenderer || !mPixelBuffer)
- {
- return false;
- }
-
- mVectorRenderer->renderSync(frameNumber, mLottieSurface);
- mRenderCallback->Trigger();
-
- if(!mResourceReady)
- {
- mResourceReady = true;
- mResourceReadyTriggered = true;
-
- TizenVectorAnimationManager::Get().TriggerEvent(*this);
- }
+ OnSetSize();
- return true;
-}
-
-void TizenVectorAnimationRenderer::RenderStopped()
-{
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "width = %d, height = %d [%p]\n", mWidth, mHeight, this);
}
-uint32_t TizenVectorAnimationRenderer::GetTotalFrameNumber() const
+uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
{
return mTotalFrameNumber;
}
-float TizenVectorAnimationRenderer::GetFrameRate() const
+float VectorAnimationRenderer::GetFrameRate() const
{
return mFrameRate;
}
-void TizenVectorAnimationRenderer::GetDefaultSize(uint32_t& width, uint32_t& height) const
+void VectorAnimationRenderer::GetDefaultSize(uint32_t& width, uint32_t& height) const
{
width = mDefaultWidth;
height = mDefaultHeight;
}
-void TizenVectorAnimationRenderer::GetLayerInfo(Property::Map& map) const
+void VectorAnimationRenderer::GetLayerInfo(Property::Map& map) const
{
Dali::Mutex::ScopedLock lock(mMutex);
}
}
-bool TizenVectorAnimationRenderer::GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const
+bool VectorAnimationRenderer::GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const
{
Dali::Mutex::ScopedLock lock(mMutex);
return false;
}
-void TizenVectorAnimationRenderer::GetMarkerInfo(Property::Map& map) const
+void VectorAnimationRenderer::GetMarkerInfo(Property::Map& map) const
{
Dali::Mutex::ScopedLock lock(mMutex);
}
}
-void TizenVectorAnimationRenderer::InvalidateBuffer()
+void VectorAnimationRenderer::InvalidateBuffer()
{
Dali::Mutex::ScopedLock lock(mMutex);
mResourceReady = false;
}
-void TizenVectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id)
+void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id)
{
Dali::Mutex::ScopedLock lock(mMutex);
}
}
-VectorAnimationRendererPlugin::UploadCompletedSignalType& TizenVectorAnimationRenderer::UploadCompletedSignal()
+VectorAnimationRendererPlugin::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
{
return mUploadCompletedSignal;
}
-void TizenVectorAnimationRenderer::NotifyEvent()
+void VectorAnimationRenderer::NotifyEvent()
{
bool emitSignal = false;
{
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Set Texture [%p]\n", this);
// Set texture
- if(mRenderer && mTexture)
+ if(mRenderer && GetTargetTexture())
{
TextureSet textureSet = mRenderer.GetTextures();
- textureSet.SetTexture(0, mTexture);
+ textureSet.SetTexture(0, GetTargetTexture());
}
mResourceReadyTriggered = false;
}
}
-void TizenVectorAnimationRenderer::SetShader()
-{
- if(mShaderChanged || !mTexture)
- {
- return;
- }
-
- // Not implemented
-
- mShaderChanged = true;
-}
-
-void TizenVectorAnimationRenderer::ResetBuffers()
-{
- if(mPixelBuffer)
- {
- uint32_t bufferSize = mPixelBuffer.GetWidth() * mPixelBuffer.GetHeight() * Dali::Pixel::GetBytesPerPixel(mPixelBuffer.GetPixelFormat());
- memset(mPixelBuffer.GetBuffer(), 0, bufferSize);
- }
-}
-
} // namespace Plugin
} // namespace Dali
-#ifndef DALI_TIZEN_VECTOR_ANIMATION_RENDERER_PLUGIN_H
-#define DALI_TIZEN_VECTOR_ANIMATION_RENDERER_PLUGIN_H
+#ifndef DALI_EXTENSION_VECTOR_ANIMATION_RENDERER_H
+#define DALI_EXTENSION_VECTOR_ANIMATION_RENDERER_H
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd.
*/
// EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
#include <dali/devel-api/adaptor-framework/vector-animation-renderer-plugin.h>
#include <dali/devel-api/threading/mutex.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <rlottie.h>
-#include <tbm_surface.h>
-#include <tbm_surface_queue.h>
#include <memory>
// INTERNAL INCLUDES
-#include <dali-extension/vector-animation-renderer/tizen-vector-animation-event-handler.h>
+#include <dali-extension/vector-animation-renderer/vector-animation-event-handler.h>
namespace Dali
{
/**
* @brief Implementation of the Tizen vector animation renderer class which has Tizen platform dependency.
*/
-class TizenVectorAnimationRenderer : public Dali::VectorAnimationRendererPlugin, public TizenVectorAnimationEventHandler
+class VectorAnimationRenderer : public Dali::VectorAnimationRendererPlugin, public VectorAnimationEventHandler
{
public:
/**
* @brief Constructor.
*/
- TizenVectorAnimationRenderer();
+ VectorAnimationRenderer();
/**
* @brief Destructor.
*/
- virtual ~TizenVectorAnimationRenderer();
+ virtual ~VectorAnimationRenderer();
/**
* @copydoc Dali::VectorAnimationRendererPlugin::Finalize()
void SetSize(uint32_t width, uint32_t height) override;
/**
- * @copydoc Dali::VectorAnimationRendererPlugin::Render()
- */
- bool Render(uint32_t frameNumber) override;
-
- /**
- * @copydoc Dali::VectorAnimationRendererPlugin::RenderStopped()
- */
- void RenderStopped() override;
-
- /**
* @copydoc Dali::VectorAnimationRendererPlugin::GetTotalFrameNumber()
*/
uint32_t GetTotalFrameNumber() const override;
*/
UploadCompletedSignalType& UploadCompletedSignal() override;
-protected: // Implementation of TizenVectorAnimationEventHandler
+protected: // Implementation of VectorAnimationEventHandler
/**
- * @copydoc Dali::Plugin::TizenVectorAnimationEventHandler::NotifyEvent()
+ * @copydoc Dali::Plugin::VectorAnimationEventHandler::NotifyEvent()
*/
void NotifyEvent() override;
-private:
+protected:
/**
* @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
*/
- void SetShader();
+ virtual void SetShader() = 0;
/**
* @brief Reset buffer list.
*/
- void ResetBuffers();
+ virtual void ResetBuffers() = 0;
+
+ /**
+ * @brief Reset properties
+ */
+ virtual void OnFinalize() = 0;
+
+ /**
+ * @brief Apply the changes of Size
+ */
+ virtual void OnSetSize() = 0;
+
+ /**
+ * @brief Event callback to process events.
+ */
+ virtual void OnLottieRendered() = 0;
-private:
- using SurfacePair = std::pair<tbm_surface_h, rlottie::Surface>;
+ /**
+ * @brief Prepare target
+ */
+ virtual void PrepareTarget() = 0;
+
+ /**
+ * @brief Retrieve whether the target is prepared or not.
+ */
+ virtual bool IsTargetPrepared() = 0;
+
+ /**
+ * @brief Retrieve whether the rendering is ready or not.
+ */
+ virtual bool IsRenderReady() = 0;
+
+ /**
+ * @brief Retrieve target texture.
+ */
+ virtual Dali::Texture GetTargetTexture() = 0;
+protected:
std::string mUrl; ///< The content file path
- std::vector<SurfacePair> mBuffers; ///< EGL Image vector
std::vector<std::unique_ptr<CallbackBase>> mPropertyCallbacks; ///< Property callback list
mutable Dali::Mutex mMutex; ///< Mutex
Dali::Renderer mRenderer; ///< Renderer
Dali::Texture mTexture; ///< Texture
- Dali::Texture mRenderedTexture; ///< Rendered Texture
- Dali::Texture mPreviousTexture; ///< Previous rendered texture
- NativeImageSourceQueuePtr mTargetSurface; ///< The target surface
std::unique_ptr<rlottie::Animation> mVectorRenderer; ///< The vector animation renderer
UploadCompletedSignalType mUploadCompletedSignal; ///< Upload completed signal
- tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
uint32_t mTotalFrameNumber; ///< The total frame number
uint32_t mWidth; ///< The width of the surface
uint32_t mHeight; ///< The height of the surface
} // namespace Dali
-#endif // DALI_TIZEN_VECTOR_ANIMATION_RENDERER_PLUGIN_H
+#endif // DALI_EXTENSION_VECTOR_ANIMATION_RENDERER_H