Updates for const->constexpr
[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) 2020 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/devel-api/image-loader/async-image-loader-devel.h>
27 #include <dali-toolkit/internal/image-loader/image-load-thread.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class AsyncImageLoader : public BaseObject
39 {
40 public:
41
42   /**
43    * Constructor
44    */
45   AsyncImageLoader();
46
47   /**
48    * @copydoc Toolkit::AsyncImageLoader::New()
49    */
50   static IntrusivePtr<AsyncImageLoader> New();
51
52   /**
53    * @copydoc Toolkit::AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex )
54    */
55   uint32_t LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading,
56                               uint32_t frameIndex );
57
58   /**
59    * @copydoc Toolkit::AsyncImageLoader::Load( const std::string&, ImageDimensions, FittingMode::Type, SamplingMode::Type, bool , DevelAsyncImageLoader::PreMultiplyOnLoad )
60    */
61   uint32_t Load( const VisualUrl& url,
62                  ImageDimensions dimensions,
63                  FittingMode::Type fittingMode,
64                  SamplingMode::Type samplingMode,
65                  bool orientationCorrection,
66                  DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
67
68   /**
69    * @brief Starts an mask applying task.
70    * @param[in] pixelBuffer of the to be masked image
71    * @param[in] maskPixelBuffer of the mask image
72    * @param[in] contentScale The factor to scale the content
73    * @param[in] cropToMask Whether to crop the content to the mask size
74    * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
75    * @return The loading task id
76    */
77   uint32_t ApplyMask( Devel::PixelBuffer pixelBuffer,
78                       Devel::PixelBuffer maskPixelBuffer,
79                       float contentScale,
80                       bool cropToMask,
81                       DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
82
83   /**
84    * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
85    */
86   Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
87
88   /**
89    * @copydoc Toolkit::AsyncImageLoader::PixelBufferLoadedSignal
90    */
91   Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& PixelBufferLoadedSignal();
92
93   /**
94    * @copydoc Toolkit::AsyncImageLoader::Cancel
95    */
96   bool Cancel( uint32_t loadingTaskId );
97
98   /**
99    * @copydoc Toolkit::AsyncImageLoader::CancelAll
100    */
101   void CancelAll();
102
103   /**
104    * Process the completed loading task from the worker thread.
105    */
106   void ProcessLoadedImage();
107
108 protected:
109
110   /**
111    * Destructor
112    */
113   ~AsyncImageLoader();
114
115 private:
116   Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
117   Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
118
119   ImageLoadThread mLoadThread;
120   uint32_t        mLoadTaskId;
121   bool            mIsLoadThreadStarted;
122 };
123
124 } // namespace Internal
125
126 inline const Internal::AsyncImageLoader& GetImplementation( const Toolkit::AsyncImageLoader& handle )
127 {
128   DALI_ASSERT_ALWAYS( handle && "AsyncImageLoader handle is empty" );
129
130   const BaseObject& object = handle.GetBaseObject();
131
132   return static_cast<const Internal::AsyncImageLoader&>( object );
133 }
134
135 inline Internal::AsyncImageLoader& GetImplementation( Toolkit::AsyncImageLoader& handle )
136 {
137   DALI_ASSERT_ALWAYS( handle && "AsyncImageLoader handle is empty" );
138
139   BaseObject& object = handle.GetBaseObject();
140
141   return static_cast<Internal::AsyncImageLoader&>( object );
142 }
143
144 } // namespace Toolkit
145
146 } // namespace Dali
147
148 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H