Change filter mode in TextLabel to improve quality while scaling
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / 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) 2016 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/public-api/images/image-operations.h>
24 #include <dali/devel-api/threading/conditional-wait.h>
25 #include <dali/devel-api/threading/mutex.h>
26 #include <dali/devel-api/threading/thread.h>
27 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
28 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 /**
41  * The task of loading and packing an image into the atlas.
42  */
43 struct LoadingTask
44 {
45   /**
46    * Constructor.
47    * @param [in] id of the task
48    * @param [in] url The URL of the image file to load.
49    * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
50    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
51    * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
52    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
53    */
54   LoadingTask( uint32_t id, const VisualUrl& url, ImageDimensions dimensions,
55                FittingMode::Type fittingMode, SamplingMode::Type samplingMode,
56                bool orientationCorrection );
57
58   /**
59    * Load the image
60    */
61   void Load();
62
63 private:
64
65   // Undefined
66   LoadingTask( const LoadingTask& queue );
67
68   // Undefined
69   LoadingTask& operator=( const LoadingTask& queue );
70
71 public:
72
73   Devel::PixelBuffer pixelBuffer;   ///< pixelBuffer handle after successful load
74   VisualUrl          url;           ///< url of the image to load
75   uint32_t           id;            ///< The unique id associated with this task.
76   ImageDimensions    dimensions;    ///< dimensions to load
77   FittingMode::Type  fittingMode;   ///< fitting options
78   SamplingMode::Type samplingMode;  ///< sampling options
79   bool               orientationCorrection:1; ///< if orientation correction is needed
80
81 };
82
83
84 /**
85  * The worker thread for image loading.
86  */
87 class ImageLoadThread : public Thread
88 {
89 public:
90
91   /**
92    * Constructor.
93    *
94    * @param[in] mTrigger The trigger to wake up the main thread.
95    */
96   ImageLoadThread( EventThreadCallback* mTrigger );
97
98   /**
99    * Destructor.
100    */
101   virtual ~ImageLoadThread();
102
103   /**
104    * Add a task in to the loading queue
105    *
106    * @param[in] task The task added to the queue.
107    *
108    * @note This class takes ownership of the task object
109    */
110   void AddTask( LoadingTask* task );
111
112   /**
113    * Pop the next task out from the completed queue.
114    *
115    * @return The next task to be processed.
116    */
117   LoadingTask* NextCompletedTask();
118
119   /**
120    * Remove the loading task from the waiting queue.
121    */
122   bool CancelTask( uint32_t loadingTaskId );
123
124   /**
125    * Remove all the loading tasks in the waiting queue.
126    */
127   void CancelAll();
128
129 private:
130
131   /**
132    * Pop the next loading task out from the queue to process.
133    *
134    * @return The next task to be processed.
135    */
136   LoadingTask* NextTaskToProcess();
137
138   /**
139    * Add a task in to the loading queue
140    *
141    * @param[in] task The task added to the queue.
142    */
143   void AddCompletedTask( LoadingTask* task );
144
145 protected:
146
147   /**
148    * The entry function of the worker thread.
149    * It fetches loading task from the loadQueue, loads the image and adds to the completeQueue.
150    */
151   virtual void Run();
152
153 private:
154
155   // Undefined
156   ImageLoadThread( const ImageLoadThread& thread );
157
158   // Undefined
159   ImageLoadThread& operator=( const ImageLoadThread& thread );
160
161 private:
162
163   Vector< LoadingTask* > mLoadQueue;     ///<The task queue with images for loading.
164   Vector< LoadingTask* > mCompleteQueue; ///<The task queue with images loaded.
165
166   ConditionalWait        mConditionalWait;
167   Dali::Mutex            mMutex;
168   EventThreadCallback*   mTrigger;
169 };
170
171 } // namespace Internal
172
173 } // namespace Toolkit
174
175 } // namespace Dali
176
177 #endif /* __DALI_TOOLKIT_IMAGE_LOAD_THREAD_H__ */