2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "texture-async-loading-helper.h"
22 #include <dali/integration-api/debug.h>
25 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
26 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
35 extern Debug::Filter* gTextureManagerLogFilter; ///< Define at texture-manager-impl.cpp
38 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureManager& textureManager)
39 : mTextureManager(textureManager),
44 void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId& textureId,
45 Dali::AnimatedImageLoading animatedImageLoading,
46 const std::uint32_t& frameIndex,
47 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
49 LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
50 loadingTask->SetTextureId(textureId);
51 Dali::AsyncTaskManager::Get().AddTask(loadingTask);
54 void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId& textureId,
56 const Dali::ImageDimensions& desiredSize,
57 const Dali::FittingMode::Type& fittingMode,
58 const Dali::SamplingMode::Type& samplingMode,
59 const bool& orientationCorrection,
60 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad,
61 const bool& loadYuvPlanes)
63 LoadingTaskPtr loadingTask;
64 if(DALI_UNLIKELY(url.IsBufferResource()))
66 loadingTask = new LoadingTask(++mLoadTaskId, mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
70 loadingTask = new LoadingTask(++mLoadTaskId, url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadYuvPlanes, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
73 loadingTask->SetTextureId(textureId);
74 Dali::AsyncTaskManager::Get().AddTask(loadingTask);
77 void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId& textureId,
78 Devel::PixelBuffer pixelBuffer,
79 Devel::PixelBuffer maskPixelBuffer,
80 const float& contentScale,
81 const bool& cropToMask,
82 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
85 LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
86 loadingTask->SetTextureId(textureId);
87 Dali::AsyncTaskManager::Get().AddTask(loadingTask);
90 void TextureAsyncLoadingHelper::AsyncLoadComplete(LoadingTaskPtr task)
92 // Call TextureManager::AsyncLoadComplete
93 if(task->textureId != TextureManager::INVALID_TEXTURE_ID)
95 mTextureManager.AsyncLoadComplete(task->textureId, task->pixelBuffers);
99 } // namespace Internal
101 } // namespace Toolkit