/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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/vector-animation-renderer.h>
#include <dali/public-api/object/base-object.h>
#include <toolkit-application.h>
+#include <toolkit-vector-animation-renderer.h>
+#include <toolkit-event-thread-callback.h>
+#include <memory>
+#include <thread>
+#include <chrono>
namespace Dali
{
namespace Adaptor
{
+namespace
+{
+Dali::Internal::Adaptor::VectorAnimationRenderer* gVectorAnimationRenderer = nullptr;
+}
+
class VectorAnimationRenderer: public Dali::BaseObject
{
public:
- VectorAnimationRenderer( const std::string& url )
- : mUrl( url ),
+ VectorAnimationRenderer()
+ : mUrl(),
mRenderer(),
mWidth( 0 ),
mHeight( 0 ),
+ mTotalFrameNumber(VECTOR_ANIMATION_TOTAL_FRAME_NUMBER),
mPreviousFrame( 0 ),
- mFrameRate( 60.0f )
+ mDelayTime(0),
+ mDroppedFrames(0),
+ mFrameRate( 60.0f ),
+ mNeedDroppedFrames(false),
+ mEventThreadCallback( new EventThreadCallback( MakeCallback( this, &VectorAnimationRenderer::OnTriggered ) ) )
{
mCount++;
mCount--;
}
+ bool Load(const std::string& url)
+ {
+ mUrl = url;
+ if(mUrl == "invalid.json" || mUrl == "invalid.riv")
+ {
+ return false;
+ }
+ else if(mUrl == "framedrop.json")
+ {
+ // Change total frame number for test
+ mTotalFrameNumber = 200;
+ }
+ return true;
+ }
+
void SetRenderer( Dali::Renderer renderer )
{
mRenderer = renderer;
bool Render( uint32_t frameNumber )
{
+ if(mDelayTime != 0)
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int32_t>(mDelayTime)));
+ mDelayTime = 0;
+ mNeedDroppedFrames = true;
+ }
+ else if(mNeedDroppedFrames)
+ {
+ mDroppedFrames = (frameNumber > mPreviousFrame) ? frameNumber - mPreviousFrame - 1: frameNumber + (mTotalFrameNumber - mPreviousFrame) - 1;
+ mNeedTrigger = true;
+ mNeedDroppedFrames = false;
+ }
+
+ if( mNeedTrigger )
+ {
+ mEventThreadCallback->Trigger();
+ mNeedTrigger = false;
+ }
+
if( frameNumber == 1 && mPreviousFrame != frameNumber )
{
mPreviousFrame = frameNumber;
uint32_t GetTotalFrameNumber() const
{
- return 5;
+ return mTotalFrameNumber;
}
float GetFrameRate() const
height = 100;
}
- void GetLayerInfo( Property::Map& map ) const
+ bool GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
{
+ if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_1 ) == 0 )
+ {
+ startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_1;
+ endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_1;
+ }
+ else if( marker.compare( VECTOR_ANIMATION_MARKER_NAME_2 ) == 0 )
+ {
+ startFrame = VECTOR_ANIMATION_MARKER_START_FRAME_2;
+ endFrame = VECTOR_ANIMATION_MARKER_END_FRAME_2;
+ }
+ else
+ {
+ return false;
+ }
+ return true;
}
Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
return mUploadCompletedSignal;
}
+ void OnTriggered()
+ {
+ }
+
public:
static uint32_t mCount;
+ static bool mNeedTrigger;
std::string mUrl;
Dali::Renderer mRenderer;
uint32_t mWidth;
uint32_t mHeight;
+ uint32_t mTotalFrameNumber;
uint32_t mPreviousFrame;
+ uint32_t mDelayTime;
+ uint32_t mDroppedFrames;
float mFrameRate;
+ bool mNeedDroppedFrames;
Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
+ std::unique_ptr< EventThreadCallback > mEventThreadCallback;
};
uint32_t VectorAnimationRenderer::mCount = 0;
+bool VectorAnimationRenderer::mNeedTrigger = true;
inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
{
/********************************* PUBLIC CLASS *******************************/
/********************************************************************************/
-VectorAnimationRenderer VectorAnimationRenderer::New( const std::string& url )
+VectorAnimationRenderer VectorAnimationRenderer::New()
{
- Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer( url );
+ Internal::Adaptor::VectorAnimationRenderer* animationRenderer = new Internal::Adaptor::VectorAnimationRenderer();
+
+ Internal::Adaptor::gVectorAnimationRenderer = animationRenderer;
return VectorAnimationRenderer( animationRenderer );
}
return *this;
}
+void VectorAnimationRenderer::Finalize()
+{
+}
+
+bool VectorAnimationRenderer::Load(const std::string& url)
+{
+ return Internal::Adaptor::GetImplementation( *this ).Load(url);
+}
+
void VectorAnimationRenderer::SetRenderer( Renderer renderer )
{
Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
{
- Internal::Adaptor::GetImplementation( *this ).GetLayerInfo( map );
+}
+
+bool VectorAnimationRenderer::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
+{
+ return Internal::Adaptor::GetImplementation( *this ).GetMarkerInfo( marker, startFrame, endFrame );
}
VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
return Internal::Adaptor::GetImplementation( *this ).UploadCompletedSignal();
}
-} // namespace Dali;
+} // namespace Dali
+
+namespace Test
+{
+namespace VectorAnimationRenderer
+{
+
+void RequestTrigger()
+{
+ Dali::Internal::Adaptor::VectorAnimationRenderer::mNeedTrigger = true;
+}
+
+void DelayRendering(uint32_t delay)
+{
+ Dali::Internal::Adaptor::gVectorAnimationRenderer->mDelayTime = delay;
+}
+
+uint32_t GetDroppedFrames()
+{
+ return Dali::Internal::Adaptor::gVectorAnimationRenderer->mDroppedFrames;
+}
+
+} // VectorAnimationRenderer
+} // Test