[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-async-loading-helper.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL HEADERS
25 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
26 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34 #ifdef DEBUG_ENABLED
35 extern Debug::Filter* gTextureManagerLogFilter; ///< Define at texture-manager-impl.cpp
36 #endif
37
38 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureManager& textureManager)
39 : mTextureManager(textureManager),
40   mLoadTaskId(0u)
41 {
42 }
43
44 void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId                textureId,
45                                                   Dali::AnimatedImageLoading                     animatedImageLoading,
46                                                   const uint32_t                                 frameIndex,
47                                                   const Dali::ImageDimensions&                   desiredSize,
48                                                   const Dali::FittingMode::Type                  fittingMode,
49                                                   const Dali::SamplingMode::Type                 samplingMode,
50                                                   const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
51 {
52   LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, desiredSize, fittingMode, samplingMode, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
53   loadingTask->SetTextureId(textureId);
54   Dali::AsyncTaskManager::Get().AddTask(loadingTask);
55 }
56
57 void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId                textureId,
58                                      const VisualUrl&                               url,
59                                      const Dali::ImageDimensions&                   desiredSize,
60                                      const Dali::FittingMode::Type                  fittingMode,
61                                      const Dali::SamplingMode::Type                 samplingMode,
62                                      const bool                                     orientationCorrection,
63                                      const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
64                                      const bool                                     loadYuvPlanes)
65 {
66   LoadingTaskPtr loadingTask;
67   if(DALI_UNLIKELY(url.IsBufferResource()))
68   {
69     loadingTask = new LoadingTask(++mLoadTaskId, mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
70   }
71   else
72   {
73     loadingTask = new LoadingTask(++mLoadTaskId, url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadYuvPlanes, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
74   }
75
76   loadingTask->SetTextureId(textureId);
77   Dali::AsyncTaskManager::Get().AddTask(loadingTask);
78 }
79
80 void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId                textureId,
81                                           Devel::PixelBuffer                             pixelBuffer,
82                                           Devel::PixelBuffer                             maskPixelBuffer,
83                                           const float                                    contentScale,
84                                           const bool                                     cropToMask,
85                                           const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
86 {
87   LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
88   loadingTask->SetTextureId(textureId);
89   Dali::AsyncTaskManager::Get().AddTask(loadingTask);
90 }
91
92 void TextureAsyncLoadingHelper::AsyncLoadComplete(LoadingTaskPtr task)
93 {
94   // Call TextureManager::AsyncLoadComplete
95   if(task->textureId != TextureManager::INVALID_TEXTURE_ID)
96   {
97     mTextureManager.AsyncLoadComplete(task->textureId, task->pixelBuffers);
98   }
99 }
100
101 } // namespace Internal
102
103 } // namespace Toolkit
104
105 } // namespace Dali