Adding Async remote loading to ImageVisual
[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/public-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 VisualUrl& url,
55                  ImageDimensions dimensions,
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   Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
89
90   ImageLoadThread mLoadThread;
91   uint32_t        mLoadTaskId;
92   bool            mIsLoadThreadStarted;
93 };
94
95 } // namespace Internal
96
97 inline const Internal::AsyncImageLoader& GetImplementation( const Toolkit::AsyncImageLoader& handle )
98 {
99   DALI_ASSERT_ALWAYS( handle && "AsyncImageLoader handle is empty" );
100
101   const BaseObject& object = handle.GetBaseObject();
102
103   return static_cast<const Internal::AsyncImageLoader&>( object );
104 }
105
106 inline Internal::AsyncImageLoader& GetImplementation( Toolkit::AsyncImageLoader& handle )
107 {
108   DALI_ASSERT_ALWAYS( handle && "AsyncImageLoader handle is empty" );
109
110   BaseObject& object = handle.GetBaseObject();
111
112   return static_cast<Internal::AsyncImageLoader&>( object );
113 }
114
115 } // namespace Toolkit
116
117 } // namespace Dali
118
119 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H