Async image loading
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / async-image-loader-impl.h
1 #ifndef DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H__
2 #define DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_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/images/pixel-data.h>
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/image-loader/async-image-loader.h>
26 #include <dali-toolkit/internal/image-loader/image-load-thread.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 class AsyncImageLoader : public BaseObject
38 {
39 public:
40
41   /**
42    * Constructor
43    */
44   AsyncImageLoader();
45
46   /**
47    * @copydoc Toolkit::AsyncImageLoader::New()
48    */
49   static IntrusivePtr<AsyncImageLoader> New();
50
51   /**
52    * @copydoc Toolkit::AsyncImageLoader::Load( const std::string&, ImageDimensions,FittingMode::Type, SamplingMode::Type, bool )
53    */
54   uint32_t Load( const std::string& url,
55                  ImageDimensions size,
56                  FittingMode::Type fittingMode,
57                  SamplingMode::Type samplingMode,
58                  bool orientationCorrection );
59
60   /**
61    * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
62    */
63   Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
64
65   /**
66    * @copydoc Toolkit::AsyncImageLoader::Cancel
67    */
68   bool Cancel( uint32_t loadingTaskId );
69
70   /**
71    * @copydoc Toolkit::AsyncImageLoader::CancelAll
72    */
73   void CancelAll();
74
75   /**
76    * Process the completed loading task from the worker thread.
77    */
78   void ProcessLoadedImage();
79
80 protected:
81
82   /**
83    * Destructor
84    */
85   ~AsyncImageLoader();
86
87 private:
88
89   Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
90
91   ImageLoadThread mLoadThread;
92   uint32_t        mLoadTaskId;
93   bool            mIsLoadThreadStarted;
94
95
96 };
97
98 } // namespace Internal
99
100 inline const Internal::AsyncImageLoader& GetImplementation( const Toolkit::AsyncImageLoader& loader )
101 {
102   DALI_ASSERT_ALWAYS( loader && "AsyncImageLoader handle is empty" );
103
104   const BaseObject& object = loader.GetBaseObject();
105
106   return static_cast<const Internal::AsyncImageLoader&>( object );
107 }
108
109 inline Internal::AsyncImageLoader& GetImplementation( Toolkit::AsyncImageLoader& loader )
110 {
111   DALI_ASSERT_ALWAYS( loader && "AsyncImageLoader handle is empty" );
112
113   BaseObject& object = loader.GetBaseObject();
114
115   return static_cast<Internal::AsyncImageLoader&>( object );
116 }
117
118 } // namespace Toolkit
119
120 } // namespace Dali
121
122 #endif /* DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H__ */