[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-async-loading-helper.h
1 #ifndef DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H
2 #define DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H
3
4 /*
5  * Copyright (c) 2023 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/signals/connection-tracker.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/internal/image-loader/loading-task.h>
25 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Internal
32 {
33 /**
34  * @brief Helper class to keep the relation between AsyncImageLoader and corresponding LoadingInfo container
35  */
36 class TextureAsyncLoadingHelper : public ConnectionTracker
37 {
38 public:
39   /**
40    * @brief Create an TextureAsyncLoadingHelper.
41    * @param[in] textureManager Reference to the texture manager
42    */
43   TextureAsyncLoadingHelper(TextureManager& textureManager);
44
45   /**
46    * @brief Load a new frame of animated image
47    * @param[in] textureId             TextureId to reference the texture that will be loaded
48    * @param[in] animatedImageLoading  The AnimatedImageLoading to load animated image
49    * @param[in] frameIndex            The frame index of a frame to be loaded frame
50    * @param[in] desiredSize           The size the image is likely to appear at.
51    *                                  This can be set to 0,0 for automatic
52    * @param[in] fittingMode           The FittingMode to use
53    * @param[in] samplingMode          The SamplingMode to use
54    * @param[in] preMultiplyOnLoad     if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
55    */
56   void LoadAnimatedImage(const TextureManager::TextureId                textureId,
57                          Dali::AnimatedImageLoading                     animatedImageLoading,
58                          const uint32_t                                 frameIndex,
59                          const Dali::ImageDimensions&                   desiredSize,
60                          const Dali::FittingMode::Type                  fittingMode,
61                          const Dali::SamplingMode::Type                 samplingMode,
62                          const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
63
64   /**
65    * @brief Load a new texture.
66    * @param[in] textureId             TextureId to reference the texture that will be loaded
67    * @param[in] url                   The URL of the image to load
68    * @param[in] desiredSize           The size the image is likely to appear at.
69    *                                  This can be set to 0,0 for automatic
70    * @param[in] fittingMode           The FittingMode to use
71    * @param[in] samplingMode          The SamplingMode to use
72    * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
73    *                                  e.g., from portrait to landscape
74    * @param[in] preMultiplyOnLoad     if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
75    * @param[in] loadYuvPlanes         True if the image should be loaded as yuv planes
76    */
77   void Load(const TextureManager::TextureId                textureId,
78             const VisualUrl&                               url,
79             const Dali::ImageDimensions&                   desiredSize,
80             const Dali::FittingMode::Type                  fittingMode,
81             const Dali::SamplingMode::Type                 samplingMode,
82             const bool                                     orientationCorrection,
83             const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
84             const bool                                     loadYuvPlanes);
85
86   /**
87    * @brief Apply mask
88    * @param [in] textureId of the texture
89    * @param [in] pixelBuffer of the to be masked image
90    * @param [in] maskPixelBuffer of the mask image
91    * @param [in] contentScale The factor to scale the content
92    * @param [in] cropToMask Whether to crop the content to the mask size
93    * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
94    */
95   void ApplyMask(const TextureManager::TextureId                textureId,
96                  Devel::PixelBuffer                             pixelBuffer,
97                  Devel::PixelBuffer                             maskPixelBuffer,
98                  const float                                    contentScale,
99                  const bool                                     cropToMask,
100                  const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
101
102 public:
103   TextureAsyncLoadingHelper(const TextureAsyncLoadingHelper&) = delete;
104   TextureAsyncLoadingHelper& operator=(const TextureAsyncLoadingHelper&) = delete;
105
106 private:
107   /**
108    * @brief Callback to be called when texture loading is complete, it passes the pixel buffer list on to texture manager.
109    * @param[in] task LoadingTaskPtr
110    */
111   void AsyncLoadComplete(LoadingTaskPtr task);
112
113 private: // Member Variables:
114   TextureManager& mTextureManager;
115   uint32_t        mLoadTaskId;
116 };
117
118 } // namespace Internal
119
120 } // namespace Toolkit
121
122 } // namespace Dali
123
124 #endif // DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H