Add CURRENT_FRAME_NUMBER and TOTAL_FRAME_NUMBER properties to the AnimatedImageVisual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / rolling-animated-image-cache.h
index 503f65e..595adc0 100644 (file)
@@ -37,7 +37,7 @@ namespace Internal
  * Frames are always ready, so the observer.FrameReady callback is never triggered;
  * the FirstFrame and NextFrame APIs will always return a texture.
  */
  * Frames are always ready, so the observer.FrameReady callback is never triggered;
  * the FirstFrame and NextFrame APIs will always return a texture.
  */
-class RollingAnimatedImageCache : public ImageCache
+class RollingAnimatedImageCache : public ImageCache, public TextureUploadObserver
 {
 public:
   /**
 {
 public:
   /**
@@ -48,21 +48,23 @@ public:
    * @param[in] observer FrameReady observer
    * @param[in] cacheSize The size of the cache
    * @param[in] batchSize The size of a batch to load
    * @param[in] observer FrameReady observer
    * @param[in] cacheSize The size of the cache
    * @param[in] batchSize The size of a batch to load
+   * @param[in] isSynchronousLoading The flag to define whether to load first frame synchronously
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes.
    */
   RollingAnimatedImageCache( TextureManager&                 textureManager,
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes.
    */
   RollingAnimatedImageCache( TextureManager&                 textureManager,
-                        AnimatedImageLoading&           animatedImageLoader,
-                        uint32_t                        frameCount,
-                        ImageCache::FrameReadyObserver& observer,
-                        uint16_t                        cacheSize,
-                        uint16_t                        batchSize );
+                             AnimatedImageLoading&           animatedImageLoader,
+                             uint32_t                        frameCount,
+                             ImageCache::FrameReadyObserver& observer,
+                             uint16_t                        cacheSize,
+                             uint16_t                        batchSize,
+                             bool                            isSynchronousLoading );
 
   /**
    * Destructor
    */
 
   /**
    * Destructor
    */
-  virtual ~RollingAnimatedImageCache();
+  ~RollingAnimatedImageCache() override;
 
   /**
    * Get the Nth frame. If it's not ready, this will trigger the
 
   /**
    * Get the Nth frame. If it's not ready, this will trigger the
@@ -77,9 +79,26 @@ public:
   TextureSet FirstFrame() override;
 
   /**
   TextureSet FirstFrame() override;
 
   /**
+   * Get the next frame. If it's not ready, this will trigger the
+   * sending of FrameReady() when the image becomes ready.
+   */
+  TextureSet NextFrame() override;
+
+  /**
    * Get the interval of Nth frame.
    */
    * Get the interval of Nth frame.
    */
-  uint32_t GetFrameInterval( uint32_t frameIndex ) override;
+  uint32_t GetFrameInterval( uint32_t frameIndex ) const override;
+
+  /**
+   * Get the current rendered frame index.
+   * If there isn't any loaded frame, returns -1.
+   */
+  int32_t GetCurrentFrameIndex() const override;
+
+  /**
+   * Get total frame count of the animated image file.
+   */
+  int32_t GetTotalFrameCount() const override;
 
 private:
   /**
 
 private:
   /**
@@ -88,11 +107,21 @@ private:
   bool IsFrontReady() const;
 
   /**
   bool IsFrontReady() const;
 
   /**
+   * Request to Load a frame
+   */
+  void RequestFrameLoading( uint32_t frameIndex );
+
+  /**
    * Load the next batch of images
    */
   void LoadBatch();
 
   /**
    * Load the next batch of images
    */
   void LoadBatch();
 
   /**
+   * Find the matching image frame, and set it to ready
+   */
+  void SetImageFrameReady( TextureManager::TextureId textureId );
+
+  /**
    * Get the texture set of the front frame.
    * @return the texture set
    */
    * Get the texture set of the front frame.
    * @return the texture set
    */
@@ -103,6 +132,27 @@ private:
    */
   TextureManager::TextureId GetCachedTextureId( int index ) const;
 
    */
   TextureManager::TextureId GetCachedTextureId( int index ) const;
 
+  /**
+   * Check if the front frame has become ready - if so, inform observer
+   * @param[in] wasReady Readiness before call.
+   */
+  void CheckFrontFrame( bool wasReady );
+
+protected:
+  void UploadComplete(
+    bool           loadSuccess,
+    int32_t        textureId,
+    TextureSet     textureSet,
+    bool           useAtlasing,
+    const Vector4& atlasRect,
+    bool           preMultiplied ) override;
+
+  void LoadComplete(
+    bool loadSuccess,
+    Devel::PixelBuffer pixelBuffer,
+    const VisualUrl& url,
+    bool preMultiplied ) override;
+
 private:
   /**
    * Secondary class to hold readiness and index into url
 private:
   /**
    * Secondary class to hold readiness and index into url
@@ -110,14 +160,19 @@ private:
   struct ImageFrame
   {
     unsigned int mFrameNumber = 0u;
   struct ImageFrame
   {
     unsigned int mFrameNumber = 0u;
+    bool mReady = false;
   };
 
   };
 
-  Dali::AnimatedImageLoading& mAnimatedImageLoading;
-  uint32_t                   mFrameCount;
-  int                        mFrameIndex;
-  std::vector<UrlStore>      mImageUrls;
-  uint16_t                   mCacheSize;
-  CircularQueue<ImageFrame>  mQueue;
+  Dali::AnimatedImageLoading  mAnimatedImageLoading;
+  uint32_t                    mFrameCount;
+  int                         mFrameIndex;
+  int                         mCacheSize;
+  std::vector<UrlStore>       mImageUrls;
+  std::vector<int32_t>        mIntervals;
+  std::vector<uint32_t>       mLoadWaitingQueue;
+  CircularQueue<ImageFrame>   mQueue;
+  bool                        mIsSynchronousLoading;
+  bool                        mOnLoading;
 };
 
 } // namespace Internal
 };
 
 } // namespace Internal