2 * Copyright (c) 2021 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 <dali-toolkit/internal/visuals/texture-manager-impl.h>
22 #include <dali/devel-api/adaptor-framework/environment-variable.h>
23 #include <dali/devel-api/adaptor-framework/image-loading.h>
24 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
25 #include <dali/devel-api/common/hash.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/math/vector4.h>
28 #include <dali/public-api/rendering/geometry.h>
33 #include <dali-toolkit/internal/image-loader/image-atlas-impl.h>
34 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
35 #include <dali-toolkit/internal/visuals/rendering-addon.h>
36 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
40 constexpr auto INITIAL_CACHE_NUMBER = size_t{0u};
41 constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS = size_t{4u};
42 constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
44 constexpr auto NUMBER_OF_LOCAL_LOADER_THREADS_ENV = "DALI_TEXTURE_LOCAL_THREADS";
45 constexpr auto NUMBER_OF_REMOTE_LOADER_THREADS_ENV = "DALI_TEXTURE_REMOTE_THREADS";
47 size_t GetNumberOfThreads(const char* environmentVariable, size_t defaultValue)
49 using Dali::EnvironmentVariable::GetEnvironmentVariable;
50 auto numberString = GetEnvironmentVariable(environmentVariable);
51 auto numberOfThreads = numberString ? std::strtoul(numberString, nullptr, 10) : 0;
52 constexpr auto MAX_NUMBER_OF_THREADS = 100u;
53 DALI_ASSERT_DEBUG(numberOfThreads < MAX_NUMBER_OF_THREADS);
54 return (numberOfThreads > 0 && numberOfThreads < MAX_NUMBER_OF_THREADS) ? numberOfThreads : defaultValue;
57 size_t GetNumberOfLocalLoaderThreads()
59 return GetNumberOfThreads(NUMBER_OF_LOCAL_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS);
62 size_t GetNumberOfRemoteLoaderThreads()
64 return GetNumberOfThreads(NUMBER_OF_REMOTE_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS);
78 Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TEXTURE_MANAGER");
80 #define GET_LOAD_STATE_STRING(loadState) \
81 loadState == TextureManager::LoadState::NOT_STARTED ? "NOT_STARTED" : loadState == TextureManager::LoadState::LOADING ? "LOADING" \
82 : loadState == TextureManager::LoadState::LOAD_FINISHED ? "LOAD_FINISHED" \
83 : loadState == TextureManager::LoadState::WAITING_FOR_MASK ? "WAITING_FOR_MASK" \
84 : loadState == TextureManager::LoadState::MASK_APPLYING ? "MASK_APPLYING" \
85 : loadState == TextureManager::LoadState::MASK_APPLIED ? "MASK_APPLIED" \
86 : loadState == TextureManager::LoadState::UPLOADED ? "UPLOADED" \
87 : loadState == TextureManager::LoadState::CANCELLED ? "CANCELLED" \
88 : loadState == TextureManager::LoadState::LOAD_FAILED ? "LOAD_FAILED" \
93 const uint32_t DEFAULT_ATLAS_SIZE(1024u); ///< This size can fit 8 by 8 images of average size 128 * 128
94 const Vector4 FULL_ATLAS_RECT(0.0f, 0.0f, 1.0f, 1.0f); ///< UV Rectangle that covers the full Texture
95 const int INVALID_INDEX(-1); ///< Invalid index used to represent a non-existant TextureInfo struct
96 const int INVALID_CACHE_INDEX(-1); ///< Invalid Cache index
98 void PreMultiply(Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
100 if(Pixel::HasAlpha(pixelBuffer.GetPixelFormat()))
102 if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
104 pixelBuffer.MultiplyColorByAlpha();
109 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
113 } // Anonymous namespace
115 TextureManager::MaskingData::MaskingData()
117 mAlphaMaskId(INVALID_TEXTURE_ID),
118 mContentScaleFactor(1.0f),
123 TextureManager::TextureManager()
124 : mAsyncLocalLoaders(GetNumberOfLocalLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); }),
125 mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); }),
127 mLifecycleObservers(),
129 mCurrentTextureId(0),
130 mQueueLoadFlag(false)
132 // Initialize the AddOn
133 RenderingAddOn::Get();
136 TextureManager::~TextureManager()
138 for(auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
140 (*iter)->TextureManagerDestroyed();
144 TextureSet TextureManager::LoadAnimatedImageTexture(
145 Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, Dali::SamplingMode::Type samplingMode, bool synchronousLoading, TextureManager::TextureId& textureId, Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver)
147 TextureSet textureSet;
149 if(synchronousLoading)
151 Devel::PixelBuffer pixelBuffer;
152 if(animatedImageLoading)
154 pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
158 DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
162 PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
165 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
166 texture.Upload(pixelData);
167 textureSet = TextureSet::New();
168 textureSet.SetTexture(0u, texture);
174 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
175 textureId = RequestLoadInternal(animatedImageLoading.GetUrl(), INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, TextureManager::NO_ATLAS, false, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex);
176 TextureManager::LoadState loadState = GetTextureStateInternal(textureId);
177 if(loadState == TextureManager::LoadState::UPLOADED)
179 // UploadComplete has already been called - keep the same texture set
180 textureSet = GetTextureSet(textureId);
186 Sampler sampler = Sampler::New();
187 sampler.SetWrapMode(wrapModeU, wrapModeV);
188 textureSet.SetSampler(0u, sampler);
194 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
195 const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, bool synchronousLoading, TextureUploadObserver* textureObserver, bool orientationCorrection, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
197 Devel::PixelBuffer pixelBuffer;
198 if(synchronousLoading)
202 pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
203 if(pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
205 PreMultiply(pixelBuffer, preMultiplyOnLoad);
211 RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u);
217 TextureSet TextureManager::LoadTexture(
218 const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, MaskingDataPointer& maskInfo, bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect, Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus, Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver, AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection, TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
220 TextureSet textureSet;
222 loadingStatus = false;
223 textureRect = FULL_ATLAS_RECT;
225 if(VisualUrl::TEXTURE == url.GetProtocolType())
227 std::string location = url.GetLocation();
228 if(location.size() > 0u)
230 TextureId id = std::stoi(location);
231 for(auto&& elem : mExternalTextures)
233 if(elem.textureId == id)
235 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
236 textureId = elem.textureId;
237 return elem.textureSet;
242 else if(synchronousLoading)
247 Devel::PixelBuffer pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
248 if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
250 Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
253 pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
258 PreMultiply(pixelBuffer, preMultiplyOnLoad);
259 data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
264 DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous loading is failed\n");
268 if(atlasingStatus) // attempt atlasing
270 textureSet = imageAtlasManager->Add(textureRect, data);
272 if(!textureSet) // big image, no atlasing or atlasing failed
274 atlasingStatus = false;
275 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(), data.GetWidth(), data.GetHeight());
276 texture.Upload(data);
277 textureSet = TextureSet::New();
278 textureSet.SetTexture(0u, texture);
282 textureRectSize.SetWidth(data.GetWidth());
283 textureRectSize.SetHeight(data.GetHeight());
289 loadingStatus = true;
292 textureSet = imageAtlasManager->Add(textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver);
294 if(!textureSet) // big image, no atlasing or atlasing failed
296 atlasingStatus = false;
297 if(!maskInfo || !maskInfo->mAlphaMaskUrl.IsValid())
299 textureId = RequestLoad(url, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad);
303 maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl);
304 textureId = RequestLoad(url,
305 maskInfo->mAlphaMaskId,
306 maskInfo->mContentScaleFactor,
310 TextureManager::NO_ATLAS,
311 maskInfo->mCropToMask,
313 orientationCorrection,
318 TextureManager::LoadState loadState = GetTextureStateInternal(textureId);
319 if(loadState == TextureManager::LoadState::UPLOADED)
321 // UploadComplete has already been called - keep the same texture set
322 textureSet = GetTextureSet(textureId);
325 // If we are loading the texture, or waiting for the ready signal handler to complete, inform
326 // caller that they need to wait.
327 loadingStatus = (loadState == TextureManager::LoadState::LOADING ||
328 loadState == TextureManager::LoadState::WAITING_FOR_MASK ||
329 loadState == TextureManager::LoadState::MASK_APPLYING ||
330 loadState == TextureManager::LoadState::MASK_APPLIED ||
331 loadState == TextureManager::LoadState::NOT_STARTED ||
336 textureRectSize = desiredSize;
340 if(!atlasingStatus && textureSet)
342 Sampler sampler = Sampler::New();
343 sampler.SetWrapMode(wrapModeU, wrapModeV);
344 textureSet.SetSampler(0u, sampler);
350 TextureManager::TextureId TextureManager::RequestLoad(
351 const VisualUrl& url,
352 const ImageDimensions desiredSize,
353 FittingMode::Type fittingMode,
354 Dali::SamplingMode::Type samplingMode,
355 const UseAtlas useAtlas,
356 TextureUploadObserver* observer,
357 bool orientationCorrection,
358 TextureManager::ReloadPolicy reloadPolicy,
359 TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
361 return RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u);
364 TextureManager::TextureId TextureManager::RequestLoad(
365 const VisualUrl& url,
366 TextureId maskTextureId,
368 const ImageDimensions desiredSize,
369 FittingMode::Type fittingMode,
370 Dali::SamplingMode::Type samplingMode,
371 const UseAtlas useAtlas,
373 TextureUploadObserver* observer,
374 bool orientationCorrection,
375 TextureManager::ReloadPolicy reloadPolicy,
376 TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
378 return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u);
381 TextureManager::TextureId TextureManager::RequestMaskLoad(const VisualUrl& maskUrl)
383 // Use the normal load procedure to get the alpha mask.
384 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
385 return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, NO_ATLAS, false, StorageType::KEEP_PIXEL_BUFFER, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u);
388 TextureManager::TextureId TextureManager::RequestLoadInternal(
389 const VisualUrl& url,
390 TextureId maskTextureId,
392 const ImageDimensions desiredSize,
393 FittingMode::Type fittingMode,
394 Dali::SamplingMode::Type samplingMode,
397 StorageType storageType,
398 TextureUploadObserver* observer,
399 bool orientationCorrection,
400 TextureManager::ReloadPolicy reloadPolicy,
401 TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
402 Dali::AnimatedImageLoading animatedImageLoading,
405 // First check if the requested Texture is cached.
406 bool isAnimatedImage = (animatedImageLoading) ? true : false;
408 TextureHash textureHash = INITIAL_CACHE_NUMBER;
409 int cacheIndex = INVALID_CACHE_INDEX;
410 if(storageType != StorageType::RETURN_PIXEL_BUFFER && !isAnimatedImage)
412 textureHash = GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId);
414 // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
415 cacheIndex = FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad);
418 TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
419 // Check if the requested Texture exists in the cache.
420 if(cacheIndex != INVALID_CACHE_INDEX)
422 if(TextureManager::ReloadPolicy::CACHED == reloadPolicy)
424 // Mark this texture being used by another client resource. Forced reload would replace the current texture
425 // without the need for incrementing the reference count.
426 ++(mTextureInfoContainer[cacheIndex].referenceCount);
428 textureId = mTextureInfoContainer[cacheIndex].textureId;
430 // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
431 preMultiplyOnLoad = mTextureInfoContainer[cacheIndex].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
433 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex, textureId);
436 if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
438 // We need a new Texture.
439 textureId = GenerateUniqueTextureId();
440 bool preMultiply = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
441 mTextureInfoContainer.push_back(TextureInfo(textureId, maskTextureId, url.GetUrl(), desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, useAtlas, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex));
442 cacheIndex = mTextureInfoContainer.size() - 1u;
444 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex, textureId);
447 // The below code path is common whether we are using the cache or not.
448 // The textureInfoIndex now refers to either a pre-existing cached TextureInfo,
449 // or a new TextureInfo just created.
450 TextureInfo& textureInfo(mTextureInfoContainer[cacheIndex]);
451 textureInfo.maskTextureId = maskTextureId;
452 textureInfo.storageType = storageType;
453 textureInfo.orientationCorrection = orientationCorrection;
455 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n", GET_LOAD_STATE_STRING(textureInfo.loadState));
457 // Force reloading of texture by setting loadState unless already loading or cancelled.
458 if(TextureManager::ReloadPolicy::FORCED == reloadPolicy &&
459 TextureManager::LoadState::LOADING != textureInfo.loadState &&
460 TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
461 TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
462 TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
463 TextureManager::LoadState::CANCELLED != textureInfo.loadState)
465 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex, textureId);
467 textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
470 // Check if we should add the observer.
471 // Only do this if we have not loaded yet and it will not have loaded by the end of this method.
472 switch(textureInfo.loadState)
474 case TextureManager::LoadState::LOAD_FAILED: // Failed notifies observer which then stops observing.
475 case TextureManager::LoadState::NOT_STARTED:
477 LoadOrQueueTexture(textureInfo, observer); // If called inside NotifyObservers, queues until afterwards
480 case TextureManager::LoadState::LOADING:
481 case TextureManager::LoadState::WAITING_FOR_MASK:
482 case TextureManager::LoadState::MASK_APPLYING:
483 case TextureManager::LoadState::MASK_APPLIED:
485 ObserveTexture(textureInfo, observer);
488 case TextureManager::LoadState::UPLOADED:
492 LoadOrQueueTexture(textureInfo, observer);
496 case TextureManager::LoadState::CANCELLED:
498 // A cancelled texture hasn't finished loading yet. Treat as a loading texture
499 // (it's ref count has already been incremented, above)
500 textureInfo.loadState = TextureManager::LoadState::LOADING;
501 ObserveTexture(textureInfo, observer);
504 case TextureManager::LoadState::LOAD_FINISHED:
506 // Loading has already completed.
507 if(observer && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
509 LoadOrQueueTexture(textureInfo, observer);
515 // Return the TextureId for which this Texture can now be referenced by externally.
519 void TextureManager::Remove(const TextureManager::TextureId textureId, TextureUploadObserver* observer)
521 int textureInfoIndex = GetCacheIndexFromId(textureId);
522 if(textureInfoIndex != INVALID_INDEX)
524 TextureInfo& textureInfo(mTextureInfoContainer[textureInfoIndex]);
526 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::Remove(%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n", textureId, textureInfo.url.GetUrl().c_str(), textureInfoIndex, GET_LOAD_STATE_STRING(textureInfo.loadState), textureInfo.referenceCount);
528 // Decrement the reference count and check if this is the last user of this Texture.
529 if(--textureInfo.referenceCount <= 0)
531 // This is the last remove for this Texture.
532 textureInfo.referenceCount = 0;
533 bool removeTextureInfo = false;
535 // If loaded, we can remove the TextureInfo and the Atlas (if atlased).
536 if(textureInfo.loadState == LoadState::UPLOADED)
538 if(textureInfo.atlas)
540 textureInfo.atlas.Remove(textureInfo.atlasRect);
542 removeTextureInfo = true;
544 else if(textureInfo.loadState == LoadState::LOADING)
546 // We mark the textureInfo for removal.
547 // Once the load has completed, this method will be called again.
548 textureInfo.loadState = LoadState::CANCELLED;
552 // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data.
553 removeTextureInfo = true;
556 // If the state allows us to remove the TextureInfo data, we do so.
557 if(removeTextureInfo)
559 // Permanently remove the textureInfo struct.
560 mTextureInfoContainer.erase(mTextureInfoContainer.begin() + textureInfoIndex);
566 // Remove element from the LoadQueue
567 for(auto&& element : mLoadQueue)
569 if(element.mObserver == observer)
571 // Do not erase the item. We will clear it later in ProcessQueuedTextures().
572 element.mObserver = nullptr;
580 VisualUrl TextureManager::GetVisualUrl(TextureId textureId)
582 VisualUrl visualUrl("");
583 int cacheIndex = GetCacheIndexFromId(textureId);
585 if(cacheIndex != INVALID_CACHE_INDEX)
587 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::GetVisualUrl. Using cached texture id=%d, textureId=%d\n", cacheIndex, textureId);
589 TextureInfo& cachedTextureInfo(mTextureInfoContainer[cacheIndex]);
590 visualUrl = cachedTextureInfo.url;
595 TextureManager::LoadState TextureManager::GetTextureState(TextureId textureId)
597 LoadState loadState = TextureManager::LoadState::NOT_STARTED;
599 int cacheIndex = GetCacheIndexFromId(textureId);
600 if(cacheIndex != INVALID_CACHE_INDEX)
602 TextureInfo& cachedTextureInfo(mTextureInfoContainer[cacheIndex]);
603 loadState = cachedTextureInfo.loadState;
607 for(auto&& elem : mExternalTextures)
609 if(elem.textureId == textureId)
611 loadState = LoadState::UPLOADED;
619 TextureManager::LoadState TextureManager::GetTextureStateInternal(TextureId textureId)
621 LoadState loadState = TextureManager::LoadState::NOT_STARTED;
623 int cacheIndex = GetCacheIndexFromId(textureId);
624 if(cacheIndex != INVALID_CACHE_INDEX)
626 TextureInfo& cachedTextureInfo(mTextureInfoContainer[cacheIndex]);
627 loadState = cachedTextureInfo.loadState;
633 TextureSet TextureManager::GetTextureSet(TextureId textureId)
635 TextureSet textureSet; // empty handle
637 int cacheIndex = GetCacheIndexFromId(textureId);
638 if(cacheIndex != INVALID_CACHE_INDEX)
640 TextureInfo& cachedTextureInfo(mTextureInfoContainer[cacheIndex]);
641 textureSet = cachedTextureInfo.textureSet;
645 for(auto&& elem : mExternalTextures)
647 if(elem.textureId == textureId)
649 textureSet = elem.textureSet;
657 std::string TextureManager::AddExternalTexture(TextureSet& textureSet)
659 TextureManager::ExternalTextureInfo info;
660 info.textureId = GenerateUniqueTextureId();
661 info.textureSet = textureSet;
662 mExternalTextures.emplace_back(info);
663 return VisualUrl::CreateTextureUrl(std::to_string(info.textureId));
666 TextureSet TextureManager::RemoveExternalTexture(const std::string& url)
670 // get the location from the Url
671 VisualUrl parseUrl(url);
672 if(VisualUrl::TEXTURE == parseUrl.GetProtocolType())
674 std::string location = parseUrl.GetLocation();
675 if(location.size() > 0u)
677 TextureId id = std::stoi(location);
678 const auto end = mExternalTextures.end();
679 for(auto iter = mExternalTextures.begin(); iter != end; ++iter)
681 if(iter->textureId == id)
683 auto textureSet = iter->textureSet;
684 mExternalTextures.erase(iter);
694 void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
696 // make sure an observer doesn't observe the same object twice
697 // otherwise it will get multiple calls to ObjectDestroyed()
698 DALI_ASSERT_DEBUG(mLifecycleObservers.End() == std::find(mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
699 mLifecycleObservers.PushBack(&observer);
702 void TextureManager::RemoveObserver(TextureManager::LifecycleObserver& observer)
704 // Find the observer...
705 auto endIter = mLifecycleObservers.End();
706 for(auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
708 if((*iter) == &observer)
710 mLifecycleObservers.Erase(iter);
714 DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
717 void TextureManager::LoadOrQueueTexture(TextureInfo& textureInfo, TextureUploadObserver* observer)
719 switch(textureInfo.loadState)
721 case LoadState::NOT_STARTED:
722 case LoadState::LOAD_FAILED:
726 QueueLoadTexture(textureInfo, observer);
730 LoadTexture(textureInfo, observer);
734 case LoadState::UPLOADED:
738 QueueLoadTexture(textureInfo, observer);
742 // The Texture has already loaded. The other observers have already been notified.
743 // We need to send a "late" loaded notification for this observer.
744 observer->UploadComplete(true, textureInfo.textureId, textureInfo.textureSet, textureInfo.useAtlas, textureInfo.atlasRect, textureInfo.preMultiplied);
748 case LoadState::LOADING:
749 case LoadState::CANCELLED:
750 case LoadState::LOAD_FINISHED:
751 case LoadState::WAITING_FOR_MASK:
752 case LoadState::MASK_APPLYING:
753 case LoadState::MASK_APPLIED:
760 void TextureManager::QueueLoadTexture(TextureInfo& textureInfo, TextureUploadObserver* observer)
762 auto textureId = textureInfo.textureId;
763 mLoadQueue.PushBack(LoadQueueElement(textureId, observer));
765 observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
768 void TextureManager::LoadTexture(TextureInfo& textureInfo, TextureUploadObserver* observer)
770 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
772 textureInfo.loadState = LoadState::LOADING;
773 if(!textureInfo.loadSynchronously)
775 auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
776 auto loadingHelperIt = loadersContainer.GetNext();
777 auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
778 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
779 if(textureInfo.animatedImageLoading)
781 loadingHelperIt->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex);
785 loadingHelperIt->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad);
788 ObserveTexture(textureInfo, observer);
791 void TextureManager::ProcessQueuedTextures()
793 for(auto&& element : mLoadQueue)
795 if(!element.mObserver)
800 int cacheIndex = GetCacheIndexFromId(element.mTextureId);
801 if(cacheIndex != INVALID_CACHE_INDEX)
803 TextureInfo& textureInfo(mTextureInfoContainer[cacheIndex]);
804 if(textureInfo.loadState == LoadState::UPLOADED)
806 element.mObserver->UploadComplete(true, textureInfo.textureId, textureInfo.textureSet, textureInfo.useAtlas, textureInfo.atlasRect, textureInfo.preMultiplied);
808 else if(textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
810 element.mObserver->LoadComplete(true, textureInfo.pixelBuffer, textureInfo.url, textureInfo.preMultiplied);
814 LoadTexture(textureInfo, element.mObserver);
821 void TextureManager::ObserveTexture(TextureInfo& textureInfo,
822 TextureUploadObserver* observer)
824 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ObserveTexture(): url:%s observer:%p\n", textureInfo.url.GetUrl().c_str(), observer);
828 textureInfo.observerList.PushBack(observer);
829 observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
833 void TextureManager::AsyncLoadComplete(AsyncLoadingInfoContainerType& loadingContainer, uint32_t id, Devel::PixelBuffer pixelBuffer)
835 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( id:%d )\n", id);
837 if(loadingContainer.size() >= 1u)
839 AsyncLoadingInfo loadingInfo = loadingContainer.front();
841 if(loadingInfo.loadId == id)
843 int cacheIndex = GetCacheIndexFromId(loadingInfo.textureId);
844 if(cacheIndex != INVALID_CACHE_INDEX)
846 TextureInfo& textureInfo(mTextureInfoContainer[cacheIndex]);
848 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, " textureId:%d Url:%s CacheIndex:%d LoadState: %d\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex, textureInfo.loadState);
850 if(textureInfo.loadState != LoadState::CANCELLED)
852 // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
853 PostLoad(textureInfo, pixelBuffer);
857 Remove(textureInfo.textureId, nullptr);
862 loadingContainer.pop_front();
866 void TextureManager::PostLoad(TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer)
868 // Was the load successful?
869 if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
871 // No atlas support for now
872 textureInfo.useAtlas = NO_ATLAS;
873 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
875 if(textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE)
877 // If there is a mask texture ID associated with this texture, then apply the mask
878 // if it's already loaded. If it hasn't, and the mask is still loading,
879 // wait for the mask to finish loading.
880 if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
882 if(textureInfo.loadState == LoadState::MASK_APPLYING)
884 textureInfo.loadState = LoadState::MASK_APPLIED;
885 UploadTexture(pixelBuffer, textureInfo);
886 NotifyObservers(textureInfo, true);
890 LoadState maskLoadState = GetTextureStateInternal(textureInfo.maskTextureId);
891 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
892 if(maskLoadState == LoadState::LOADING)
894 textureInfo.loadState = LoadState::WAITING_FOR_MASK;
896 else if(maskLoadState == LoadState::LOAD_FINISHED)
898 // Send New Task to Thread
899 ApplyMask(textureInfo, textureInfo.maskTextureId);
905 UploadTexture(pixelBuffer, textureInfo);
906 NotifyObservers(textureInfo, true);
911 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
912 textureInfo.loadState = LoadState::LOAD_FINISHED;
914 if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
916 NotifyObservers(textureInfo, true);
920 // Check if there was another texture waiting for this load to complete
921 // (e.g. if this was an image mask, and its load is on a different thread)
922 CheckForWaitingTexture(textureInfo);
928 textureInfo.loadState = LoadState::LOAD_FAILED;
929 CheckForWaitingTexture(textureInfo);
930 NotifyObservers(textureInfo, false);
934 void TextureManager::CheckForWaitingTexture(TextureInfo& maskTextureInfo)
936 // Search the cache, checking if any texture has this texture id as a
938 const unsigned int size = mTextureInfoContainer.size();
940 for(unsigned int cacheIndex = 0; cacheIndex < size; ++cacheIndex)
942 if(mTextureInfoContainer[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
943 mTextureInfoContainer[cacheIndex].loadState == LoadState::WAITING_FOR_MASK)
945 TextureInfo& textureInfo(mTextureInfoContainer[cacheIndex]);
947 if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
949 // Send New Task to Thread
950 ApplyMask(textureInfo, maskTextureInfo.textureId);
954 textureInfo.pixelBuffer.Reset();
955 textureInfo.loadState = LoadState::LOAD_FAILED;
956 NotifyObservers(textureInfo, false);
962 void TextureManager::ApplyMask(TextureInfo& textureInfo, TextureId maskTextureId)
964 int maskCacheIndex = GetCacheIndexFromId(maskTextureId);
965 if(maskCacheIndex != INVALID_CACHE_INDEX)
967 Devel::PixelBuffer maskPixelBuffer = mTextureInfoContainer[maskCacheIndex].pixelBuffer;
968 Devel::PixelBuffer pixelBuffer = textureInfo.pixelBuffer;
969 textureInfo.pixelBuffer.Reset();
971 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
973 textureInfo.loadState = LoadState::MASK_APPLYING;
974 auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
975 auto loadingHelperIt = loadersContainer.GetNext();
976 auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
977 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
978 loadingHelperIt->ApplyMask(textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad);
982 void TextureManager::UploadTexture(Devel::PixelBuffer& pixelBuffer, TextureInfo& textureInfo)
984 if(textureInfo.useAtlas != USE_ATLAS)
986 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, " TextureManager::UploadTexture() New Texture for textureId:%d\n", textureInfo.textureId);
988 // Check if this pixelBuffer is premultiplied
989 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
991 auto& renderingAddOn = RenderingAddOn::Get();
992 if(renderingAddOn.IsValid())
994 renderingAddOn.CreateGeometry(textureInfo.textureId, pixelBuffer);
997 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
999 PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
1000 texture.Upload(pixelData);
1001 if(!textureInfo.textureSet)
1003 textureInfo.textureSet = TextureSet::New();
1005 textureInfo.textureSet.SetTexture(0u, texture);
1008 // Update the load state.
1009 // Note: This is regardless of success as we care about whether a
1010 // load attempt is in progress or not. If unsuccessful, a broken
1011 // image is still loaded.
1012 textureInfo.loadState = LoadState::UPLOADED;
1015 void TextureManager::NotifyObservers(TextureInfo& textureInfo, bool success)
1017 TextureId textureId = textureInfo.textureId;
1019 // If there is an observer: Notify the load is complete, whether successful or not,
1020 // and erase it from the list
1021 TextureInfo* info = &textureInfo;
1023 mQueueLoadFlag = true;
1025 while(info->observerList.Count())
1027 TextureUploadObserver* observer = info->observerList[0];
1029 // During UploadComplete() a Control ResourceReady() signal is emitted.
1030 // During that signal the app may add remove /add Textures (e.g. via
1032 // It is possible for observers to be removed from the observer list,
1033 // and it is also possible for the mTextureInfoContainer to be modified,
1034 // invalidating the reference to the textureInfo struct.
1035 // Texture load requests for the same URL are deferred until the end of this
1037 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "NotifyObservers() url:%s loadState:%s\n", textureInfo.url.GetUrl().c_str(), GET_LOAD_STATE_STRING(textureInfo.loadState));
1039 // It is possible for the observer to be deleted.
1040 // Disconnect and remove the observer first.
1041 observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1043 info->observerList.Erase(info->observerList.begin());
1045 if(info->storageType == StorageType::RETURN_PIXEL_BUFFER)
1047 observer->LoadComplete(success, info->pixelBuffer, info->url, info->preMultiplied);
1051 observer->UploadComplete(success, info->textureId, info->textureSet, info->useAtlas, info->atlasRect, info->preMultiplied);
1054 // Get the textureInfo from the container again as it may have been invalidated.
1055 int textureInfoIndex = GetCacheIndexFromId(textureId);
1056 if(textureInfoIndex == INVALID_CACHE_INDEX)
1058 break; // texture has been removed - can stop.
1060 info = &mTextureInfoContainer[textureInfoIndex];
1063 mQueueLoadFlag = false;
1064 ProcessQueuedTextures();
1066 if(info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
1068 Remove(info->textureId, nullptr);
1072 TextureManager::TextureId TextureManager::GenerateUniqueTextureId()
1074 return mCurrentTextureId++;
1077 int TextureManager::GetCacheIndexFromId(const TextureId textureId)
1079 const unsigned int size = mTextureInfoContainer.size();
1081 for(unsigned int i = 0; i < size; ++i)
1083 if(mTextureInfoContainer[i].textureId == textureId)
1089 return INVALID_CACHE_INDEX;
1092 TextureManager::TextureHash TextureManager::GenerateHash(
1093 const std::string& url,
1094 const ImageDimensions size,
1095 const FittingMode::Type fittingMode,
1096 const Dali::SamplingMode::Type samplingMode,
1097 const UseAtlas useAtlas,
1098 TextureId maskTextureId)
1100 std::string hashTarget(url);
1101 const size_t urlLength = hashTarget.length();
1102 const uint16_t width = size.GetWidth();
1103 const uint16_t height = size.GetWidth();
1105 // If either the width or height has been specified, include the resizing options in the hash
1106 if(width != 0 || height != 0)
1108 // We are appending 5 bytes to the URL to form the hash input.
1109 hashTarget.resize(urlLength + 5u);
1110 char* hashTargetPtr = &(hashTarget[urlLength]);
1112 // Pack the width and height (4 bytes total).
1113 *hashTargetPtr++ = size.GetWidth() & 0xff;
1114 *hashTargetPtr++ = (size.GetWidth() >> 8u) & 0xff;
1115 *hashTargetPtr++ = size.GetHeight() & 0xff;
1116 *hashTargetPtr++ = (size.GetHeight() >> 8u) & 0xff;
1118 // Bit-pack the FittingMode, SamplingMode and atlasing.
1119 // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit
1120 *hashTargetPtr = (fittingMode << 4u) | (samplingMode << 1) | useAtlas;
1124 // We are not including sizing information, but we still need an extra byte for atlasing.
1125 hashTarget.resize(urlLength + 1u);
1127 // Add the atlasing to the hash input.
1130 case UseAtlas::NO_ATLAS:
1132 hashTarget[urlLength] = 'f';
1135 case UseAtlas::USE_ATLAS:
1137 hashTarget[urlLength] = 't';
1143 if(maskTextureId != INVALID_TEXTURE_ID)
1145 auto textureIdIndex = hashTarget.length();
1146 hashTarget.resize(hashTarget.length() + sizeof(TextureId));
1147 unsigned char* hashTargetPtr = reinterpret_cast<unsigned char*>(&(hashTarget[textureIdIndex]));
1149 // Append the texture id to the end of the URL byte by byte:
1150 // (to avoid SIGBUS / alignment issues)
1151 for(size_t byteIter = 0; byteIter < sizeof(TextureId); ++byteIter)
1153 *hashTargetPtr++ = maskTextureId & 0xff;
1154 maskTextureId >>= 8u;
1158 return Dali::CalculateHash(hashTarget);
1161 int TextureManager::FindCachedTexture(
1162 const TextureManager::TextureHash hash,
1163 const std::string& url,
1164 const ImageDimensions size,
1165 const FittingMode::Type fittingMode,
1166 const Dali::SamplingMode::Type samplingMode,
1167 const bool useAtlas,
1168 TextureId maskTextureId,
1169 TextureManager::MultiplyOnLoad preMultiplyOnLoad)
1171 // Default to an invalid ID, in case we do not find a match.
1172 int cacheIndex = INVALID_CACHE_INDEX;
1174 // Iterate through our hashes to find a match.
1175 const unsigned int count = mTextureInfoContainer.size();
1176 for(unsigned int i = 0u; i < count; ++i)
1178 if(mTextureInfoContainer[i].hash == hash)
1180 // We have a match, now we check all the original parameters in case of a hash collision.
1181 TextureInfo& textureInfo(mTextureInfoContainer[i]);
1183 if((url == textureInfo.url.GetUrl()) &&
1184 (useAtlas == textureInfo.useAtlas) &&
1185 (maskTextureId == textureInfo.maskTextureId) &&
1186 (size == textureInfo.desiredSize) &&
1187 ((size.GetWidth() == 0 && size.GetHeight() == 0) ||
1188 (fittingMode == textureInfo.fittingMode &&
1189 samplingMode == textureInfo.samplingMode)))
1191 // 1. If preMultiplyOnLoad is MULTIPLY_ON_LOAD, then textureInfo.preMultiplyOnLoad should be true. The premultiplication result can be different.
1192 // 2. If preMultiplyOnLoad is LOAD_WITHOUT_MULTIPLY, then textureInfo.preMultiplied should be false.
1193 if((preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD && textureInfo.preMultiplyOnLoad) || (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY && !textureInfo.preMultiplied))
1195 // The found Texture is a match.
1206 void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
1208 const unsigned int count = mTextureInfoContainer.size();
1209 for(unsigned int i = 0; i < count; ++i)
1211 TextureInfo& textureInfo(mTextureInfoContainer[i]);
1212 for(TextureInfo::ObserverListType::Iterator j = textureInfo.observerList.Begin();
1213 j != textureInfo.observerList.End();)
1217 j = textureInfo.observerList.Erase(j);
1226 // Remove element from the LoadQueue
1227 for(auto&& element : mLoadQueue)
1229 if(element.mObserver == observer)
1231 element.mObserver = nullptr;
1236 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(TextureManager& textureManager)
1237 : AsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager, AsyncLoadingInfoContainerType())
1241 void TextureManager::AsyncLoadingHelper::LoadAnimatedImage(TextureId textureId,
1242 Dali::AnimatedImageLoading animatedImageLoading,
1243 uint32_t frameIndex)
1245 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
1246 auto id = DevelAsyncImageLoader::LoadAnimatedImage(mLoader, animatedImageLoading, frameIndex);
1247 mLoadingInfoContainer.back().loadId = id;
1250 void TextureManager::AsyncLoadingHelper::Load(TextureId textureId,
1251 const VisualUrl& url,
1252 ImageDimensions desiredSize,
1253 FittingMode::Type fittingMode,
1254 SamplingMode::Type samplingMode,
1255 bool orientationCorrection,
1256 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
1258 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
1259 auto id = DevelAsyncImageLoader::Load(mLoader, url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
1260 mLoadingInfoContainer.back().loadId = id;
1263 void TextureManager::AsyncLoadingHelper::ApplyMask(TextureId textureId,
1264 Devel::PixelBuffer pixelBuffer,
1265 Devel::PixelBuffer maskPixelBuffer,
1268 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
1270 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
1271 auto id = DevelAsyncImageLoader::ApplyMask(mLoader, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad);
1272 mLoadingInfoContainer.back().loadId = id;
1275 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(AsyncLoadingHelper&& rhs)
1276 : AsyncLoadingHelper(rhs.mLoader, rhs.mTextureManager, std::move(rhs.mLoadingInfoContainer))
1280 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(
1281 Toolkit::AsyncImageLoader loader,
1282 TextureManager& textureManager,
1283 AsyncLoadingInfoContainerType&& loadingInfoContainer)
1285 mTextureManager(textureManager),
1286 mLoadingInfoContainer(std::move(loadingInfoContainer))
1288 DevelAsyncImageLoader::PixelBufferLoadedSignal(mLoader).Connect(
1289 this, &AsyncLoadingHelper::AsyncLoadComplete);
1292 void TextureManager::AsyncLoadingHelper::AsyncLoadComplete(uint32_t id,
1293 Devel::PixelBuffer pixelBuffer)
1295 mTextureManager.AsyncLoadComplete(mLoadingInfoContainer, id, pixelBuffer);
1298 Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements)
1300 return RenderingAddOn::Get().IsValid() ? RenderingAddOn::Get().GetGeometry(textureId, frontElements, backElements) : Geometry();
1303 } // namespace Internal
1305 } // namespace Toolkit