Async image loading
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / image-load-thread.h
@@ -43,7 +43,7 @@ struct LoadingTask
   /**
    * Constructor.
    */
-  LoadingTask( BitmapLoader loader, uint32_t packPositionX, uint32_t packPositionY, uint32_t width, uint32_t height  );
+  LoadingTask( uint32_t id, BitmapLoader loader );
 
 private:
 
@@ -55,123 +55,69 @@ private:
 
 public:
 
-  BitmapLoader   loader;    ///< The loader used to load the bitmap from URL
-  Rect<uint32_t> packRect;  ///< The x coordinate of the position to pack the image.
-
+  BitmapLoader loader;    ///< The loader used to load the bitmap from URL
+  uint32_t     id;        ///< The id associated with this task.
 };
 
+
 /**
- * The queue of the tasks waiting to load the bitmap from the URL in the worker thread/
+ * The worker thread for image loading.
  */
-class LoadQueue //: public TaskQueue
+class ImageLoadThread : public Thread
 {
 public:
 
   /**
-   * Constructor
+   * Constructor.
+   *
+   * @param[in] mTrigger The trigger to wake up the main thread.
    */
-  LoadQueue();
+  ImageLoadThread( EventThreadCallback* mTrigger );
 
   /**
    * Destructor.
    */
-  ~LoadQueue();
-
-  /**
-   * Pop the next task out from the queue.
-   *
-   * @return The next task to be processed.
-   */
-  LoadingTask* NextTask();
+  virtual ~ImageLoadThread();
 
   /**
-   * Add a task in to the queue
+   * Add a task in to the loading queue
    *
    * @param[in] task The task added to the queue.
    */
   void AddTask( LoadingTask* task );
 
-private:
-
-  // Undefined
-  LoadQueue( const LoadQueue& queue );
-
-  // Undefined
-  LoadQueue& operator=( const LoadQueue& queue );
-
-private:
-
-  Vector< LoadingTask* > mTasks;
-  ConditionalWait mConditionalWait;
-};
-
-/**
- * The queue of the tasks, with the image loaded, waiting for the main thread to upload the bitmap.
- */
-class CompleteQueue //: public TaskQueue
-{
-public:
-
   /**
-   * Constructor
+   * Pop the next task out from the completed queue.
    *
-   * @param[in] mTrigger The trigger to wake up the main thread.
-   */
-  CompleteQueue( EventThreadCallback* mTrigger );
-
-  /**
-   * Destructor.
+   * @return The next task to be processed.
    */
-  ~CompleteQueue();
+  LoadingTask* NextCompletedTask();
 
   /**
-   * Pop the next task out from the queue.
-   *
-   * @return The next task to be processed.
+   * Remove the loading task from the waiting queue.
    */
-  LoadingTask* NextTask();
+  bool CancelTask( uint32_t loadingTaskId );
 
   /**
-   * Add a task in to the queue
-   *
-   * @param[in] task The task added to the queue.
+   * Remove all the loading tasks in the waiting queue.
    */
-  void AddTask( LoadingTask* task );
-
-private:
-
-  // Undefined
-  CompleteQueue( const CompleteQueue& queue );
-
-  // Undefined
-  CompleteQueue& operator=( const CompleteQueue& queue );
+  void CancelAll();
 
 private:
 
-  Vector< LoadingTask* > mTasks;
-  Dali::Mutex            mMutex;
-  EventThreadCallback*   mTrigger;
-};
-
-/**
- * The worker thread for image loading.
- */
-class ImageLoadThread : public Thread
-{
-public:
-
   /**
-   * Constructor.
+   * Pop the next loading task out from the queue to process.
    *
-   * @param[in] loadQueue The task queue with images for loading.
-   * @param[in] completeQurue The task queue with images loaded.
+   * @return The next task to be processed.
    */
-  ImageLoadThread( LoadQueue& loadQueue, CompleteQueue& completeQueue );
+  LoadingTask* NextTaskToProcess();
 
   /**
-   * Destructor.
+   * Add a task in to the loading queue
+   *
+   * @param[in] task The task added to the queue.
    */
-  virtual ~ImageLoadThread();
+  void AddCompletedTask( LoadingTask* task );
 
 protected:
 
@@ -191,8 +137,12 @@ private:
 
 private:
 
-  LoadQueue& mLoadQueue;          ///<The task queue with images for loading.
-  CompleteQueue& mCompleteQueue;  ///<The task queue with images loaded.
+  Vector< LoadingTask* > mLoadQueue;     ///<The task queue with images for loading.
+  Vector< LoadingTask* > mCompleteQueue; ///<The task queue with images loaded.
+
+  ConditionalWait        mConditionalWait;
+  Dali::Mutex            mMutex;
+  EventThreadCallback*   mTrigger;
 };
 
 } // namespace Internal