Changed 'virtual' function override declarations to 'override' in automated-tests.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-vector-animation-renderer.cpp
index 869bbc2..b0075d2 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -18,6 +18,9 @@
 #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>
 
 namespace Dali
 {
@@ -36,53 +39,131 @@ public:
   : mUrl( url ),
     mRenderer(),
     mWidth( 0 ),
-    mHeight( 0 )
+    mHeight( 0 ),
+    mPreviousFrame( 0 ),
+    mFrameRate( 60.0f ),
+    mEventThreadCallback( new EventThreadCallback( MakeCallback( this, &VectorAnimationRenderer::OnTriggered ) ) )
   {
+    mCount++;
+
+    if( mCount == 2 )
+    {
+      mFrameRate = 0.1f;
+    }
+  }
+
+  ~VectorAnimationRenderer()
+  {
+    mCount--;
   }
 
   void SetRenderer( Dali::Renderer renderer )
   {
     mRenderer = renderer;
+
+    if( mWidth != 0 && mHeight != 0 )
+    {
+      Dali::TextureSet textureSet = mRenderer.GetTextures();
+      Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
+      textureSet.SetTexture( 0, texture );
+      mUploadCompletedSignal.Emit();
+    }
   }
 
   void SetSize( uint32_t width, uint32_t height )
   {
     mWidth = width;
     mHeight = height;
+
+    if( mRenderer )
+    {
+      Dali::TextureSet textureSet = mRenderer.GetTextures();
+      Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
+      textureSet.SetTexture( 0, texture );
+      mUploadCompletedSignal.Emit();
+    }
   }
 
-  bool StartRender()
+  bool Render( uint32_t frameNumber )
   {
+    if( mNeedTrigger )
+    {
+      mEventThreadCallback->Trigger();
+      mNeedTrigger = false;
+    }
+
+    if( frameNumber == 1 && mPreviousFrame != frameNumber )
+    {
+      mPreviousFrame = frameNumber;
+      // For test corverage
+      return false;
+    }
+    mPreviousFrame = frameNumber;
     return true;
   }
 
-  void StopRender()
+  uint32_t GetTotalFrameNumber() const
   {
+    return VECTOR_ANIMATION_TOTAL_FRAME_NUMBER;
   }
 
-  void Render( uint32_t frameNumber )
+  float GetFrameRate() const
   {
+    return mFrameRate;
   }
 
-  uint32_t GetTotalFrameNumber() const
+  void GetDefaultSize( uint32_t& width, uint32_t& height ) const
   {
-    return 5;
+    width = 100;
+    height = 100;
   }
 
-  float GetFrameRate() 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()
   {
-    return 60.0f;
   }
 
 public:
 
+  static uint32_t mCount;
+  static bool mNeedTrigger;
+
   std::string mUrl;
   Dali::Renderer mRenderer;
   uint32_t mWidth;
   uint32_t mHeight;
-
+  uint32_t mPreviousFrame;
+  float mFrameRate;
+  Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
+  std::unique_ptr< EventThreadCallback > mEventThreadCallback;
 };
 
+uint32_t VectorAnimationRenderer::mCount = 0;
+bool VectorAnimationRenderer::mNeedTrigger = true;
+
 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
 {
   DALI_ASSERT_ALWAYS( renderer && "VectorAnimationRenderer handle is empty." );
@@ -137,6 +218,10 @@ VectorAnimationRenderer& VectorAnimationRenderer::operator=( const VectorAnimati
   return *this;
 }
 
+void VectorAnimationRenderer::Finalize()
+{
+}
+
 void VectorAnimationRenderer::SetRenderer( Renderer renderer )
 {
   Internal::Adaptor::GetImplementation( *this ).SetRenderer( renderer );
@@ -147,30 +232,52 @@ void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
   Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
 }
 
-bool VectorAnimationRenderer::StartRender()
+bool VectorAnimationRenderer::Render( uint32_t frameNumber )
 {
-  return Internal::Adaptor::GetImplementation( *this ).StartRender();
+  return Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
 }
 
-void VectorAnimationRenderer::StopRender()
+uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
 {
-  Internal::Adaptor::GetImplementation( *this ).StopRender();
+  return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
 }
 
-void VectorAnimationRenderer::Render( uint32_t frameNumber )
+float VectorAnimationRenderer::GetFrameRate() const
 {
-  Internal::Adaptor::GetImplementation( *this ).Render( frameNumber );
+  return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
 }
 
-uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
+void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
 {
-  return Internal::Adaptor::GetImplementation( *this ).GetTotalFrameNumber();
+  Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
 }
 
-float VectorAnimationRenderer::GetFrameRate() const
+void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
 {
-  return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
 }
 
-} // namespace Dali;
+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 Test
+{
+namespace VectorAnimationRenderer
+{
+
+void RequestTrigger()
+{
+  Dali::Internal::Adaptor::VectorAnimationRenderer::mNeedTrigger = true;
+}
+
+} // VectorAnimationRenderer
+} // Test