(AnimatedVectorImageVisual) Use the content default size 31/202631/3
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 1 Apr 2019 08:30:09 +0000 (17:30 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 10 Apr 2019 01:24:55 +0000 (01:24 +0000)
- Use the content default size when a user doesn't set a control size.
- To do this, the vector renderer object creation is moved to VectorRasterizeThread constructor.

Change-Id: Icfeeea9ecbd906e0627c81ed813216b863202c07

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp
automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.h

index 869bbc2..fbc24bf 100755 (executable)
@@ -43,17 +43,26 @@ public:
   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 );
+    }
   }
 
   void SetSize( uint32_t width, uint32_t height )
   {
     mWidth = width;
     mHeight = height;
-  }
 
-  bool StartRender()
-  {
-    return true;
+    if( mRenderer )
+    {
+      Dali::TextureSet textureSet = mRenderer.GetTextures();
+      Dali::Texture texture = Dali::Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight );
+      textureSet.SetTexture( 0, texture );
+    }
   }
 
   void StopRender()
@@ -74,13 +83,18 @@ public:
     return 60.0f;
   }
 
+  void GetDefaultSize( uint32_t& width, uint32_t& height ) const
+  {
+    width = 100;
+    height = 100;
+  }
+
 public:
 
   std::string mUrl;
   Dali::Renderer mRenderer;
   uint32_t mWidth;
   uint32_t mHeight;
-
 };
 
 inline VectorAnimationRenderer& GetImplementation( Dali::VectorAnimationRenderer& renderer )
@@ -147,11 +161,6 @@ void VectorAnimationRenderer::SetSize( uint32_t width, uint32_t height )
   Internal::Adaptor::GetImplementation( *this ).SetSize( width, height );
 }
 
-bool VectorAnimationRenderer::StartRender()
-{
-  return Internal::Adaptor::GetImplementation( *this ).StartRender();
-}
-
 void VectorAnimationRenderer::StopRender()
 {
   Internal::Adaptor::GetImplementation( *this ).StopRender();
@@ -172,5 +181,10 @@ float VectorAnimationRenderer::GetFrameRate() const
   return Internal::Adaptor::GetImplementation( *this ).GetFrameRate();
 }
 
+void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height ) const
+{
+  Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
+}
+
 } // namespace Dali;
 
index 01716ed..f47a656 100644 (file)
@@ -458,7 +458,6 @@ int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
   Vector2 controlSize( 20.f, 30.f );
   Vector2 naturalSize;
 
-  actor.SetSize( controlSize );
   Stage::GetCurrent().Add( actor );
 
   application.SendNotification();
@@ -468,6 +467,17 @@ int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
 
   visual.GetNaturalSize( naturalSize );
 
+  DALI_TEST_EQUALS( naturalSize, Vector2( 100.0f, 100.0f ), TEST_LOCATION );    // 100x100 is the content default size.
+
+  actor.SetSize( controlSize );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+  visual.GetNaturalSize( naturalSize );
+
   DALI_TEST_EQUALS( naturalSize, controlSize, TEST_LOCATION );
 
   END_TEST;
index 35fd8aa..e693fd1 100644 (file)
@@ -100,7 +100,25 @@ AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
 
 void AnimatedVectorImageVisual::GetNaturalSize( Vector2& naturalSize )
 {
-  naturalSize = mVisualSize;
+  if( mImpl->mRenderer ) // Check if we have a rendered image
+  {
+    auto textureSet = mImpl->mRenderer.GetTextures();
+    if( textureSet )
+    {
+      if( textureSet.GetTextureCount() > 0 )
+      {
+        auto texture = textureSet.GetTexture( 0 );
+        naturalSize.x = texture.GetWidth();
+        naturalSize.y = texture.GetHeight();
+        return;
+      }
+    }
+  }
+
+  uint32_t width, height;
+  mVectorRasterizeThread.GetDefaultSize( width, height );
+  naturalSize.x = width;
+  naturalSize.y = height;
 }
 
 void AnimatedVectorImageVisual::DoCreatePropertyMap( Property::Map& map ) const
index 25d0743..42ffe5a 100644 (file)
@@ -80,7 +80,7 @@ VectorRasterizeThread::VectorRasterizeThread( const std::string& url )
   mCurrentFrameUpdated( false ),
   mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
 {
-  mVectorRenderer = VectorAnimationRenderer::New( mUrl );
+  Initialize();
 }
 
 VectorRasterizeThread::~VectorRasterizeThread()
@@ -105,9 +105,6 @@ void VectorRasterizeThread::Run()
   SetThreadName( "VectorImageThread" );
   mLogFactory.InstallLogFunction();
 
-  //TODO: check the return value
-  StartRender();
-
   while( !mDestroyThread )
   {
     Rasterize();
@@ -234,26 +231,23 @@ void VectorRasterizeThread::SetPlayRange( Vector2 range )
 
       mPlayRange = orderedRange;
 
-      if( mTotalFrame != 0 )
-      {
-        mStartFrame = static_cast< uint32_t >( mPlayRange.x * mTotalFrame + 0.5f );
-        mEndFrame = static_cast< uint32_t >( mPlayRange.y * mTotalFrame + 0.5f );
+      mStartFrame = static_cast< uint32_t >( mPlayRange.x * mTotalFrame + 0.5f );
+      mEndFrame = static_cast< uint32_t >( mPlayRange.y * mTotalFrame + 0.5f );
 
-        // If the current frame is out of the range, change the current frame also.
-        if( mStartFrame > mCurrentFrame )
-        {
-          mCurrentFrame = mStartFrame;
+      // If the current frame is out of the range, change the current frame also.
+      if( mStartFrame > mCurrentFrame )
+      {
+        mCurrentFrame = mStartFrame;
 
-          mCurrentFrameUpdated = true;
-          mResourceReady = false;
-        }
-        else if( mEndFrame < mCurrentFrame )
-        {
-          mCurrentFrame = mEndFrame;
+        mCurrentFrameUpdated = true;
+        mResourceReady = false;
+      }
+      else if( mEndFrame < mCurrentFrame )
+      {
+        mCurrentFrame = mEndFrame;
 
-          mCurrentFrameUpdated = true;
-          mResourceReady = false;
-        }
+        mCurrentFrameUpdated = true;
+        mResourceReady = false;
       }
     }
   }
@@ -272,11 +266,8 @@ void VectorRasterizeThread::SetCurrentProgress( float progress )
   {
     mProgress = progress;
 
-    if( mTotalFrame != 0 )
-    {
-      mCurrentFrame = static_cast< uint32_t >( mTotalFrame * progress + 0.5f );
-      mCurrentFrameUpdated = true;
-    }
+    mCurrentFrame = static_cast< uint32_t >( mTotalFrame * progress + 0.5f );
+    mCurrentFrameUpdated = true;
 
     mResourceReady = false;
 
@@ -289,6 +280,11 @@ float VectorRasterizeThread::GetCurrentProgress() const
   return ( static_cast< float >( mCurrentFrame ) / static_cast< float >( mTotalFrame ) );
 }
 
+void VectorRasterizeThread::GetDefaultSize( uint32_t& width, uint32_t& height ) const
+{
+  mVectorRenderer.GetDefaultSize( width, height );
+}
+
 DevelImageVisual::PlayState VectorRasterizeThread::GetPlayState() const
 {
   return mPlayState;
@@ -299,10 +295,9 @@ bool VectorRasterizeThread::IsResourceReady() const
   return mResourceReady;
 }
 
-bool VectorRasterizeThread::StartRender()
+void VectorRasterizeThread::Initialize()
 {
-  //TODO: check the return value
-  mVectorRenderer.StartRender();
+  mVectorRenderer = VectorAnimationRenderer::New( mUrl );
 
   mTotalFrame = mVectorRenderer.GetTotalFrameNumber();
 
@@ -314,9 +309,7 @@ bool VectorRasterizeThread::StartRender()
   mFrameRate = mVectorRenderer.GetFrameRate();
   mFrameDurationNanoSeconds = NANOSECONDS_PER_SECOND / mFrameRate;
 
-  DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartRender: Renderer is started [%d, %f fps]\n", mTotalFrame, mFrameRate );
-
-  return true;
+  DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Initialize: file = %s [%d frames, %f fps]\n", mUrl.c_str(), mTotalFrame, mFrameRate );
 }
 
 void VectorRasterizeThread::Rasterize()
index cb5220d..c40e6e9 100644 (file)
@@ -154,6 +154,12 @@ public:
    */
   float GetCurrentProgress() const;
 
+  /**
+   * @brief Gets the default size of the file,.
+   * @return The default size of the file
+   */
+  void GetDefaultSize( uint32_t& width, uint32_t& height ) const;
+
 protected:
 
   /**
@@ -165,9 +171,9 @@ protected:
 private:
 
   /**
-   * @brief Start rendering
+   * @brief Initialize the vector renderer.
    */
-  bool StartRender();
+  void Initialize();
 
   /**
    * @brief Rasterize the current frame.