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 : TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager, AsyncLoadingInfoContainerType())
43 void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId& textureId,
44 Dali::AnimatedImageLoading animatedImageLoading,
45 const std::uint32_t& frameIndex,
46 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
48 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
49 auto id = GetImplementation(mLoader).LoadAnimatedImage(animatedImageLoading, frameIndex, preMultiplyOnLoad);
50 mLoadingInfoContainer.back().loadId = id;
53 void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId& textureId,
55 const Dali::ImageDimensions& desiredSize,
56 const Dali::FittingMode::Type& fittingMode,
57 const Dali::SamplingMode::Type& samplingMode,
58 const bool& orientationCorrection,
59 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
61 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
62 if(DALI_UNLIKELY(url.IsBufferResource()))
64 auto id = GetImplementation(mLoader).LoadEncodedImageBuffer(mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
65 mLoadingInfoContainer.back().loadId = id;
69 auto id = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
70 mLoadingInfoContainer.back().loadId = id;
74 void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId& textureId,
75 Devel::PixelBuffer pixelBuffer,
76 Devel::PixelBuffer maskPixelBuffer,
77 const float& contentScale,
78 const bool& cropToMask,
79 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
81 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
82 auto id = GetImplementation(mLoader).ApplyMask(pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad);
83 mLoadingInfoContainer.back().loadId = id;
86 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs)
87 : TextureAsyncLoadingHelper(rhs.mLoader, rhs.mTextureManager, std::move(rhs.mLoadingInfoContainer))
91 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(
92 Toolkit::AsyncImageLoader loader,
93 TextureManager& textureManager,
94 AsyncLoadingInfoContainerType&& loadingInfoContainer)
96 mTextureManager(textureManager),
97 mLoadingInfoContainer(std::move(loadingInfoContainer))
99 DevelAsyncImageLoader::PixelBufferLoadedSignal(mLoader).Connect(
100 this, &TextureAsyncLoadingHelper::AsyncLoadComplete);
103 void TextureAsyncLoadingHelper::AsyncLoadComplete(uint32_t id,
104 Devel::PixelBuffer pixelBuffer)
106 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureAsyncLoadingHelper::AsyncLoadComplete( loadId :%d )\n", id);
107 if(mLoadingInfoContainer.size() >= 1u)
109 AsyncLoadingInfo loadingInfo = mLoadingInfoContainer.front();
111 // We can assume that First Loading task comes First.
112 if(loadingInfo.loadId == id)
114 // Call TextureManager::AsyncLoadComplete
115 mTextureManager.AsyncLoadComplete(loadingInfo.textureId, pixelBuffer);
118 mLoadingInfoContainer.pop_front();
122 } // namespace Internal
124 } // namespace Toolkit