Merge "Fix the texture bleeding with wrapping in atlas" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-atlas / image-load-thread.h
1 #ifndef __DALI_TOOLKIT_IMAGE_LOAD_THREAD_H__
2 #define __DALI_TOOLKIT_IMAGE_LOAD_THREAD_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/dali-vector.h>
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/devel-api/threading/conditional-wait.h>
24 #include <dali/devel-api/threading/mutex.h>
25 #include <dali/devel-api/threading/thread.h>
26 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
27 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The task of loading and packing an image into the atlas.
40  */
41 struct LoadingTask
42 {
43   /**
44    * Constructor.
45    */
46   LoadingTask( BitmapLoader loader, uint32_t packPositionX, uint32_t packPositionY, uint32_t width, uint32_t height  );
47
48 private:
49
50   // Undefined
51   LoadingTask( const LoadingTask& queue );
52
53   // Undefined
54   LoadingTask& operator=( const LoadingTask& queue );
55
56 public:
57
58   BitmapLoader   loader;    ///< The loader used to load the bitmap from URL
59   Rect<uint32_t> packRect;  ///< The x coordinate of the position to pack the image.
60
61 };
62
63 /**
64  * The queue of the tasks waiting to load the bitmap from the URL in the worker thread/
65  */
66 class LoadQueue //: public TaskQueue
67 {
68 public:
69
70   /**
71    * Constructor
72    */
73   LoadQueue();
74
75   /**
76    * Destructor.
77    */
78   ~LoadQueue();
79
80   /**
81    * Pop the next task out from the queue.
82    *
83    * @return The next task to be processed.
84    */
85   LoadingTask* NextTask();
86
87   /**
88    * Add a task in to the queue
89    *
90    * @param[in] task The task added to the queue.
91    */
92   void AddTask( LoadingTask* task );
93
94 private:
95
96   // Undefined
97   LoadQueue( const LoadQueue& queue );
98
99   // Undefined
100   LoadQueue& operator=( const LoadQueue& queue );
101
102 private:
103
104   Vector< LoadingTask* > mTasks;
105   ConditionalWait mConditionalWait;
106 };
107
108 /**
109  * The queue of the tasks, with the image loaded, waiting for the main thread to upload the bitmap.
110  */
111 class CompleteQueue //: public TaskQueue
112 {
113 public:
114
115   /**
116    * Constructor
117    *
118    * @param[in] mTrigger The trigger to wake up the main thread.
119    */
120   CompleteQueue( EventThreadCallback* mTrigger );
121
122   /**
123    * Destructor.
124    */
125   ~CompleteQueue();
126
127   /**
128    * Pop the next task out from the queue.
129    *
130    * @return The next task to be processed.
131    */
132   LoadingTask* NextTask();
133
134   /**
135    * Add a task in to the queue
136    *
137    * @param[in] task The task added to the queue.
138    */
139   void AddTask( LoadingTask* task );
140
141 private:
142
143   // Undefined
144   CompleteQueue( const CompleteQueue& queue );
145
146   // Undefined
147   CompleteQueue& operator=( const CompleteQueue& queue );
148
149 private:
150
151   Vector< LoadingTask* > mTasks;
152   Dali::Mutex            mMutex;
153   EventThreadCallback*   mTrigger;
154 };
155
156 /**
157  * The worker thread for image loading.
158  */
159 class ImageLoadThread : public Thread
160 {
161 public:
162
163   /**
164    * Constructor.
165    *
166    * @param[in] loadQueue The task queue with images for loading.
167    * @param[in] completeQurue The task queue with images loaded.
168    */
169   ImageLoadThread( LoadQueue& loadQueue, CompleteQueue& completeQueue );
170
171   /**
172    * Destructor.
173    */
174   virtual ~ImageLoadThread();
175
176 protected:
177
178   /**
179    * The entry function of the worker thread.
180    * It fetches loading task from the loadQueue, loads the image and adds to the completeQueue.
181    */
182   virtual void Run();
183
184 private:
185
186   // Undefined
187   ImageLoadThread( const ImageLoadThread& thread );
188
189   // Undefined
190   ImageLoadThread& operator=( const ImageLoadThread& thread );
191
192 private:
193
194   LoadQueue& mLoadQueue;          ///<The task queue with images for loading.
195   CompleteQueue& mCompleteQueue;  ///<The task queue with images loaded.
196 };
197
198 } // namespace Internal
199
200 } // namespace Toolkit
201
202 } // namespace Dali
203
204 #endif /* __DALI_TOOLKIT_IMAGE_LOAD_THREAD_H__ */