2 * Copyright (c) 2020 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>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/devel-api/adaptor-framework/environment-variable.h>
26 #include <dali/devel-api/adaptor-framework/image-loading.h>
27 #include <dali/devel-api/common/hash.h>
28 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/public-api/rendering/geometry.h>
33 #include <dali-toolkit/internal/image-loader/image-atlas-impl.h>
34 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
35 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
36 #include <dali-toolkit/internal/visuals/rendering-addon.h>
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);
82 Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_TEXTURE_MANAGER" );
84 #define GET_LOAD_STATE_STRING( loadState ) \
85 loadState == TextureManager::NOT_STARTED ? "NOT_STARTED" : \
86 loadState == TextureManager::LOADING ? "LOADING" : \
87 loadState == TextureManager::LOAD_FINISHED ? "LOAD_FINISHED" : \
88 loadState == TextureManager::WAITING_FOR_MASK ? "WAITING_FOR_MASK" : \
89 loadState == TextureManager::MASK_APPLYING ? "MASK_APPLYING" : \
90 loadState == TextureManager::MASK_APPLIED ? "MASK_APPLIED" : \
91 loadState == TextureManager::UPLOADED ? "UPLOADED" : \
92 loadState == TextureManager::CANCELLED ? "CANCELLED" : \
93 loadState == TextureManager::LOAD_FAILED ? "LOAD_FAILED" : "Unknown"
97 const uint32_t DEFAULT_ATLAS_SIZE( 1024u ); ///< This size can fit 8 by 8 images of average size 128 * 128
98 const Vector4 FULL_ATLAS_RECT( 0.0f, 0.0f, 1.0f, 1.0f ); ///< UV Rectangle that covers the full Texture
99 const int INVALID_INDEX( -1 ); ///< Invalid index used to represent a non-existant TextureInfo struct
100 const int INVALID_CACHE_INDEX( -1 ); ///< Invalid Cache index
103 void PreMultiply( Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
105 if( Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) )
107 if( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD )
109 pixelBuffer.MultiplyColorByAlpha();
114 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
118 } // Anonymous namespace
120 TextureManager::MaskingData::MaskingData()
122 mAlphaMaskId( INVALID_TEXTURE_ID ),
123 mContentScaleFactor( 1.0f ),
128 TextureManager::TextureManager()
129 : mAsyncLocalLoaders( GetNumberOfLocalLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
130 mAsyncRemoteLoaders( GetNumberOfRemoteLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
132 mLifecycleObservers(),
135 mCurrentTextureId( 0 ),
136 mQueueLoadFlag(false)
138 // Initialize the AddOn
139 RenderingAddOn::Get();
142 TextureManager::~TextureManager()
144 for( auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
146 (*iter)->TextureManagerDestroyed();
150 TextureSet TextureManager::LoadAnimatedImageTexture(
151 Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, Dali::SamplingMode::Type samplingMode,
152 bool synchronousLoading, TextureManager::TextureId& textureId, Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver )
154 TextureSet textureSet;
156 if( synchronousLoading )
158 Devel::PixelBuffer pixelBuffer;
159 if( animatedImageLoading )
161 pixelBuffer = animatedImageLoading.LoadFrame( frameIndex );
166 pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
170 pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
172 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(),
173 pixelData.GetWidth(), pixelData.GetHeight() );
174 texture.Upload( pixelData );
175 textureSet = TextureSet::New();
176 textureSet.SetTexture( 0u, texture );
180 PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
183 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(),
184 pixelData.GetWidth(), pixelData.GetHeight() );
185 texture.Upload( pixelData );
186 textureSet = TextureSet::New();
187 textureSet.SetTexture( 0u, texture );
193 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
194 textureId = RequestLoadInternal( animatedImageLoading.GetUrl(), INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL,
195 SamplingMode::BOX_THEN_LINEAR, TextureManager::NO_ATLAS, false, UPLOAD_TO_TEXTURE, textureObserver,
196 true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex );
197 TextureManager::LoadState loadState = GetTextureStateInternal( textureId );
198 if( loadState == TextureManager::UPLOADED )
200 // UploadComplete has already been called - keep the same texture set
201 textureSet = GetTextureSet( textureId );
207 Sampler sampler = Sampler::New();
208 sampler.SetWrapMode( wrapModeU, wrapModeV );
209 textureSet.SetSampler( 0u, sampler );
215 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
216 const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, bool synchronousLoading, TextureUploadObserver* textureObserver, bool orientationCorrection, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
218 Devel::PixelBuffer pixelBuffer;
219 if( synchronousLoading )
223 pixelBuffer = LoadImageFromFile( url.GetUrl(), desiredSize, fittingMode, samplingMode,
224 orientationCorrection );
225 if( pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD )
227 PreMultiply( pixelBuffer, preMultiplyOnLoad );
233 RequestLoadInternal( url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS,
234 false, RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED,
235 preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u );
241 TextureSet TextureManager::LoadTexture(
242 const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
243 Dali::SamplingMode::Type samplingMode, MaskingDataPointer& maskInfo,
244 bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect,
245 Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus,
246 Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver,
247 AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection,
248 TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
250 TextureSet textureSet;
252 loadingStatus = false;
253 textureRect = FULL_ATLAS_RECT;
255 if( VisualUrl::TEXTURE == url.GetProtocolType())
257 std::string location = url.GetLocation();
258 if( location.size() > 0u )
260 TextureId id = std::stoi( location );
261 for( auto&& elem : mExternalTextures )
263 if( elem.textureId == id )
265 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
266 textureId = elem.textureId;
267 return elem.textureSet;
272 else if( synchronousLoading )
277 Devel::PixelBuffer pixelBuffer = LoadImageFromFile( url.GetUrl(), desiredSize, fittingMode, samplingMode,
278 orientationCorrection );
279 if( maskInfo && maskInfo->mAlphaMaskUrl.IsValid() )
281 Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile( maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(),
282 FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true );
283 if( maskPixelBuffer )
285 pixelBuffer.ApplyMask( maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask );
290 PreMultiply( pixelBuffer, preMultiplyOnLoad );
291 data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
297 Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
300 PreMultiply( pixelBuffer, preMultiplyOnLoad );
301 data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
303 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
304 data.GetWidth(), data.GetHeight() );
305 texture.Upload( data );
306 textureSet = TextureSet::New();
307 textureSet.SetTexture( 0u, texture );
311 if( atlasingStatus ) // attempt atlasing
313 textureSet = imageAtlasManager->Add( textureRect, data );
315 if( !textureSet ) // big image, no atlasing or atlasing failed
317 atlasingStatus = false;
318 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
319 data.GetWidth(), data.GetHeight() );
320 texture.Upload( data );
321 textureSet = TextureSet::New();
322 textureSet.SetTexture( 0u, texture );
326 textureRectSize.SetWidth(data.GetWidth());
327 textureRectSize.SetHeight(data.GetHeight());
333 loadingStatus = true;
336 textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver);
338 if( !textureSet ) // big image, no atlasing or atlasing failed
340 atlasingStatus = false;
341 if( !maskInfo || !maskInfo->mAlphaMaskUrl.IsValid() )
343 textureId = RequestLoad( url, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS,
344 textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad );
348 maskInfo->mAlphaMaskId = RequestMaskLoad( maskInfo->mAlphaMaskUrl );
349 textureId = RequestLoad( url,
350 maskInfo->mAlphaMaskId,
351 maskInfo->mContentScaleFactor,
353 fittingMode, samplingMode,
354 TextureManager::NO_ATLAS,
355 maskInfo->mCropToMask,
357 orientationCorrection,
358 reloadPolicy, preMultiplyOnLoad );
361 TextureManager::LoadState loadState = GetTextureStateInternal( textureId );
362 if( loadState == TextureManager::UPLOADED )
364 // UploadComplete has already been called - keep the same texture set
365 textureSet = GetTextureSet( textureId );
368 // If we are loading the texture, or waiting for the ready signal handler to complete, inform
369 // caller that they need to wait.
370 loadingStatus = ( loadState == TextureManager::LOADING ||
371 loadState == TextureManager::WAITING_FOR_MASK ||
372 loadState == TextureManager::MASK_APPLYING ||
373 loadState == TextureManager::MASK_APPLIED ||
374 loadState == TextureManager::NOT_STARTED ||
380 textureRectSize = desiredSize;
384 if( ! atlasingStatus && textureSet )
386 Sampler sampler = Sampler::New();
387 sampler.SetWrapMode( wrapModeU, wrapModeV );
388 textureSet.SetSampler( 0u, sampler );
394 TextureManager::TextureId TextureManager::RequestLoad(
395 const VisualUrl& url,
396 const ImageDimensions desiredSize,
397 FittingMode::Type fittingMode,
398 Dali::SamplingMode::Type samplingMode,
399 const UseAtlas useAtlas,
400 TextureUploadObserver* observer,
401 bool orientationCorrection,
402 TextureManager::ReloadPolicy reloadPolicy,
403 TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
405 return RequestLoadInternal( url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas,
406 false, UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy,
407 preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u );
410 TextureManager::TextureId TextureManager::RequestLoad(
411 const VisualUrl& url,
412 TextureId maskTextureId,
414 const ImageDimensions desiredSize,
415 FittingMode::Type fittingMode,
416 Dali::SamplingMode::Type samplingMode,
417 const UseAtlas useAtlas,
419 TextureUploadObserver* observer,
420 bool orientationCorrection,
421 TextureManager::ReloadPolicy reloadPolicy,
422 TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
424 return RequestLoadInternal( url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas,
425 cropToMask, UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy,
426 preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u );
429 TextureManager::TextureId TextureManager::RequestMaskLoad( const VisualUrl& maskUrl )
431 // Use the normal load procedure to get the alpha mask.
432 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
433 return RequestLoadInternal( maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL,
434 SamplingMode::NO_FILTER, NO_ATLAS, false, KEEP_PIXEL_BUFFER, NULL, true,
435 TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u );
438 TextureManager::TextureId TextureManager::RequestLoadInternal(
439 const VisualUrl& url,
440 TextureId maskTextureId,
442 const ImageDimensions desiredSize,
443 FittingMode::Type fittingMode,
444 Dali::SamplingMode::Type samplingMode,
447 StorageType storageType,
448 TextureUploadObserver* observer,
449 bool orientationCorrection,
450 TextureManager::ReloadPolicy reloadPolicy,
451 TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
452 Dali::AnimatedImageLoading animatedImageLoading,
453 uint32_t frameIndex )
455 // First check if the requested Texture is cached.
456 bool isAnimatedImage = ( animatedImageLoading ) ? true : false;
457 const TextureHash textureHash = GenerateHash( url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
458 maskTextureId, storageType, isAnimatedImage, frameIndex );
460 TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
461 // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
462 int cacheIndex = FindCachedTexture( textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
463 maskTextureId, preMultiplyOnLoad, storageType, isAnimatedImage, frameIndex );
465 // Check if the requested Texture exists in the cache.
466 if( cacheIndex != INVALID_CACHE_INDEX )
468 if ( TextureManager::ReloadPolicy::CACHED == reloadPolicy )
470 // Mark this texture being used by another client resource. Forced reload would replace the current texture
471 // without the need for incrementing the reference count.
472 ++( mTextureInfoContainer[ cacheIndex ].referenceCount );
474 textureId = mTextureInfoContainer[ cacheIndex ].textureId;
476 // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
477 preMultiplyOnLoad = mTextureInfoContainer[ cacheIndex ].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
479 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d\n",
480 url.GetUrl().c_str(), observer, cacheIndex, textureId );
483 if( textureId == INVALID_TEXTURE_ID ) // There was no caching, or caching not required
485 // We need a new Texture.
486 textureId = GenerateUniqueTextureId();
487 bool preMultiply = ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD );
488 mTextureInfoContainer.push_back( TextureInfo( textureId, maskTextureId, url.GetUrl(),
489 desiredSize, contentScale, fittingMode, samplingMode,
490 false, cropToMask, useAtlas, textureHash, orientationCorrection,
491 preMultiply, animatedImageLoading, frameIndex ) );
492 cacheIndex = mTextureInfoContainer.size() - 1u;
494 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d\n",
495 url.GetUrl().c_str(), observer, cacheIndex, textureId );
498 // The below code path is common whether we are using the cache or not.
499 // The textureInfoIndex now refers to either a pre-existing cached TextureInfo,
500 // or a new TextureInfo just created.
501 TextureInfo& textureInfo( mTextureInfoContainer[ cacheIndex ] );
502 textureInfo.maskTextureId = maskTextureId;
503 textureInfo.storageType = storageType;
504 textureInfo.orientationCorrection = orientationCorrection;
506 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n",
507 GET_LOAD_STATE_STRING(textureInfo.loadState ) );
509 // Force reloading of texture by setting loadState unless already loading or cancelled.
510 if ( TextureManager::ReloadPolicy::FORCED == reloadPolicy &&
511 TextureManager::LOADING != textureInfo.loadState &&
512 TextureManager::WAITING_FOR_MASK != textureInfo.loadState &&
513 TextureManager::MASK_APPLYING != textureInfo.loadState &&
514 TextureManager::MASK_APPLIED != textureInfo.loadState &&
515 TextureManager::CANCELLED != textureInfo.loadState )
517 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d\n",
518 url.GetUrl().c_str(), observer, cacheIndex, textureId );
520 textureInfo.loadState = TextureManager::NOT_STARTED;
523 // Check if we should add the observer.
524 // Only do this if we have not loaded yet and it will not have loaded by the end of this method.
525 switch( textureInfo.loadState )
527 case TextureManager::LOAD_FAILED: // Failed notifies observer which then stops observing.
528 case TextureManager::NOT_STARTED:
530 LoadOrQueueTexture( textureInfo, observer ); // If called inside NotifyObservers, queues until afterwards
533 case TextureManager::LOADING:
534 case TextureManager::WAITING_FOR_MASK:
535 case TextureManager::MASK_APPLYING:
536 case TextureManager::MASK_APPLIED:
538 ObserveTexture( textureInfo, observer );
541 case TextureManager::UPLOADED:
545 LoadOrQueueTexture( textureInfo, observer );
549 case TextureManager::CANCELLED:
551 // A cancelled texture hasn't finished loading yet. Treat as a loading texture
552 // (it's ref count has already been incremented, above)
553 textureInfo.loadState = TextureManager::LOADING;
554 ObserveTexture( textureInfo, observer );
557 case TextureManager::LOAD_FINISHED:
559 // Loading has already completed.
560 if( observer && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER )
562 LoadOrQueueTexture( textureInfo, observer );
568 // Return the TextureId for which this Texture can now be referenced by externally.
572 void TextureManager::Remove( const TextureManager::TextureId textureId, TextureUploadObserver* observer )
574 int textureInfoIndex = GetCacheIndexFromId( textureId );
575 if( textureInfoIndex != INVALID_INDEX )
577 TextureInfo& textureInfo( mTextureInfoContainer[ textureInfoIndex ] );
579 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise,
580 "TextureManager::Remove(%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n",
581 textureId, textureInfo.url.GetUrl().c_str(),
582 textureInfoIndex, GET_LOAD_STATE_STRING( textureInfo.loadState ), textureInfo.referenceCount );
584 // Decrement the reference count and check if this is the last user of this Texture.
585 if( --textureInfo.referenceCount <= 0 )
587 // This is the last remove for this Texture.
588 textureInfo.referenceCount = 0;
589 bool removeTextureInfo = false;
591 // If loaded, we can remove the TextureInfo and the Atlas (if atlased).
592 if( textureInfo.loadState == UPLOADED )
594 if( textureInfo.atlas )
596 textureInfo.atlas.Remove( textureInfo.atlasRect );
598 removeTextureInfo = true;
600 else if( textureInfo.loadState == LOADING )
602 // We mark the textureInfo for removal.
603 // Once the load has completed, this method will be called again.
604 textureInfo.loadState = CANCELLED;
608 // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data.
609 removeTextureInfo = true;
612 // If the state allows us to remove the TextureInfo data, we do so.
613 if( removeTextureInfo )
615 // Permanently remove the textureInfo struct.
616 mTextureInfoContainer.erase( mTextureInfoContainer.begin() + textureInfoIndex );
622 // Remove element from the LoadQueue
623 for( auto&& element : mLoadQueue )
625 if( element.mObserver == observer )
627 mLoadQueue.Erase( &element );
635 VisualUrl TextureManager::GetVisualUrl( TextureId textureId )
637 VisualUrl visualUrl("");
638 int cacheIndex = GetCacheIndexFromId( textureId );
640 if( cacheIndex != INVALID_CACHE_INDEX )
642 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::GetVisualUrl. Using cached texture id=%d, textureId=%d\n",
643 cacheIndex, textureId );
645 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
646 visualUrl = cachedTextureInfo.url;
651 TextureManager::LoadState TextureManager::GetTextureState( TextureId textureId )
653 LoadState loadState = TextureManager::NOT_STARTED;
655 int cacheIndex = GetCacheIndexFromId( textureId );
656 if( cacheIndex != INVALID_CACHE_INDEX )
658 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
659 loadState = cachedTextureInfo.loadState;
663 for( auto&& elem : mExternalTextures )
665 if( elem.textureId == textureId )
667 loadState = LoadState::UPLOADED;
675 TextureManager::LoadState TextureManager::GetTextureStateInternal( TextureId textureId )
677 LoadState loadState = TextureManager::NOT_STARTED;
679 int cacheIndex = GetCacheIndexFromId( textureId );
680 if( cacheIndex != INVALID_CACHE_INDEX )
682 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
683 loadState = cachedTextureInfo.loadState;
689 TextureSet TextureManager::GetTextureSet( TextureId textureId )
691 TextureSet textureSet;// empty handle
693 int cacheIndex = GetCacheIndexFromId( textureId );
694 if( cacheIndex != INVALID_CACHE_INDEX )
696 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
697 textureSet = cachedTextureInfo.textureSet;
701 for( auto&& elem : mExternalTextures )
703 if( elem.textureId == textureId )
705 textureSet = elem.textureSet;
713 std::string TextureManager::AddExternalTexture( TextureSet& textureSet )
715 TextureManager::ExternalTextureInfo info;
716 info.textureId = GenerateUniqueTextureId();
717 info.textureSet = textureSet;
718 mExternalTextures.emplace_back( info );
719 return VisualUrl::CreateTextureUrl( std::to_string( info.textureId ) );
722 TextureSet TextureManager::RemoveExternalTexture( const std::string& url )
724 if( url.size() > 0u )
726 // get the location from the Url
727 VisualUrl parseUrl( url );
728 if( VisualUrl::TEXTURE == parseUrl.GetProtocolType() )
730 std::string location = parseUrl.GetLocation();
731 if( location.size() > 0u )
733 TextureId id = std::stoi( location );
734 const auto end = mExternalTextures.end();
735 for( auto iter = mExternalTextures.begin(); iter != end; ++iter )
737 if( iter->textureId == id )
739 auto textureSet = iter->textureSet;
740 mExternalTextures.erase( iter );
750 void TextureManager::AddObserver( TextureManager::LifecycleObserver& observer )
752 // make sure an observer doesn't observe the same object twice
753 // otherwise it will get multiple calls to ObjectDestroyed()
754 DALI_ASSERT_DEBUG( mLifecycleObservers.End() == std::find( mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
755 mLifecycleObservers.PushBack( &observer );
758 void TextureManager::RemoveObserver( TextureManager::LifecycleObserver& observer)
760 // Find the observer...
761 auto endIter = mLifecycleObservers.End();
762 for( auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
764 if( (*iter) == &observer)
766 mLifecycleObservers.Erase( iter );
770 DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
773 void TextureManager::LoadOrQueueTexture( TextureInfo& textureInfo, TextureUploadObserver* observer )
775 switch( textureInfo.loadState )
782 QueueLoadTexture( textureInfo, observer );
786 LoadTexture( textureInfo, observer );
794 QueueLoadTexture( textureInfo, observer );
798 // The Texture has already loaded. The other observers have already been notified.
799 // We need to send a "late" loaded notification for this observer.
800 observer->UploadComplete( true, textureInfo.textureId, textureInfo.textureSet,
801 textureInfo.useAtlas, textureInfo.atlasRect,
802 textureInfo.preMultiplied );
809 case WAITING_FOR_MASK:
818 void TextureManager::QueueLoadTexture( TextureInfo& textureInfo, TextureUploadObserver* observer )
820 auto textureId = textureInfo.textureId;
821 mLoadQueue.PushBack( LoadQueueElement( textureId, observer) );
824 void TextureManager::LoadTexture( TextureInfo& textureInfo, TextureUploadObserver* observer )
826 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n",
827 textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously?"T":"F" );
829 textureInfo.loadState = LOADING;
830 if( !textureInfo.loadSynchronously )
832 auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
833 auto loadingHelperIt = loadersContainer.GetNext();
834 auto premultiplyOnLoad = ( textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID ) ?
835 DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
836 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
837 if( textureInfo.animatedImageLoading )
839 loadingHelperIt->LoadAnimatedImage( textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex );
843 loadingHelperIt->Load(textureInfo.textureId, textureInfo.url,
844 textureInfo.desiredSize, textureInfo.fittingMode,
845 textureInfo.samplingMode, textureInfo.orientationCorrection,
849 ObserveTexture( textureInfo, observer );
852 void TextureManager::ProcessQueuedTextures()
854 for( auto&& element : mLoadQueue )
856 int cacheIndex = GetCacheIndexFromId( element.mTextureId );
857 if( cacheIndex != INVALID_CACHE_INDEX )
859 TextureInfo& textureInfo( mTextureInfoContainer[cacheIndex] );
860 if( textureInfo.loadState == UPLOADED )
862 element.mObserver->UploadComplete( true, textureInfo.textureId, textureInfo.textureSet,
863 textureInfo.useAtlas, textureInfo.atlasRect,
864 textureInfo.preMultiplied );
866 else if ( textureInfo.loadState == LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER )
868 element.mObserver->LoadComplete( true, textureInfo.pixelBuffer, textureInfo.url, textureInfo.preMultiplied );
872 LoadTexture( textureInfo, element.mObserver );
879 void TextureManager::ObserveTexture( TextureInfo& textureInfo,
880 TextureUploadObserver* observer )
882 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::ObserveTexture(): url:%s observer:%p\n",
883 textureInfo.url.GetUrl().c_str(), observer );
887 textureInfo.observerList.PushBack( observer );
888 observer->DestructionSignal().Connect( this, &TextureManager::ObserverDestroyed );
892 void TextureManager::AsyncLoadComplete( AsyncLoadingInfoContainerType& loadingContainer, uint32_t id,
893 Devel::PixelBuffer pixelBuffer )
895 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( id:%d )\n", id );
897 if( loadingContainer.size() >= 1u )
899 AsyncLoadingInfo loadingInfo = loadingContainer.front();
901 if( loadingInfo.loadId == id )
903 int cacheIndex = GetCacheIndexFromId( loadingInfo.textureId );
904 if( cacheIndex != INVALID_CACHE_INDEX )
906 TextureInfo& textureInfo( mTextureInfoContainer[cacheIndex] );
908 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise,
909 " textureId:%d Url:%s CacheIndex:%d LoadState: %d\n",
910 textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex, textureInfo.loadState );
912 if( textureInfo.loadState != CANCELLED )
914 // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
915 PostLoad( textureInfo, pixelBuffer );
919 Remove( textureInfo.textureId, nullptr );
924 loadingContainer.pop_front();
928 void TextureManager::PostLoad( TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer )
930 // Was the load successful?
931 if( pixelBuffer && ( pixelBuffer.GetWidth() != 0 ) && ( pixelBuffer.GetHeight() != 0 ) )
933 // No atlas support for now
934 textureInfo.useAtlas = NO_ATLAS;
935 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
937 if( textureInfo.storageType == UPLOAD_TO_TEXTURE )
939 // If there is a mask texture ID associated with this texture, then apply the mask
940 // if it's already loaded. If it hasn't, and the mask is still loading,
941 // wait for the mask to finish loading.
942 if( textureInfo.maskTextureId != INVALID_TEXTURE_ID )
944 if( textureInfo.loadState == MASK_APPLYING )
946 textureInfo.loadState = MASK_APPLIED;
947 UploadTexture( pixelBuffer, textureInfo );
948 NotifyObservers( textureInfo, true );
952 LoadState maskLoadState = GetTextureStateInternal( textureInfo.maskTextureId );
953 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
954 if( maskLoadState == LOADING )
956 textureInfo.loadState = WAITING_FOR_MASK;
958 else if( maskLoadState == LOAD_FINISHED )
960 // Send New Task to Thread
961 ApplyMask( textureInfo, textureInfo.maskTextureId );
967 UploadTexture( pixelBuffer, textureInfo );
968 NotifyObservers( textureInfo, true );
973 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
974 textureInfo.loadState = LOAD_FINISHED;
976 if( textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER )
978 NotifyObservers( textureInfo, true );
982 // Check if there was another texture waiting for this load to complete
983 // (e.g. if this was an image mask, and its load is on a different thread)
984 CheckForWaitingTexture( textureInfo );
990 // @todo If the load was unsuccessful, upload the broken image.
991 textureInfo.loadState = LOAD_FAILED;
992 CheckForWaitingTexture( textureInfo );
993 NotifyObservers( textureInfo, false );
997 void TextureManager::CheckForWaitingTexture( TextureInfo& maskTextureInfo )
999 // Search the cache, checking if any texture has this texture id as a
1001 const unsigned int size = mTextureInfoContainer.size();
1003 for( unsigned int cacheIndex = 0; cacheIndex < size; ++cacheIndex )
1005 if( mTextureInfoContainer[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
1006 mTextureInfoContainer[cacheIndex].loadState == WAITING_FOR_MASK )
1008 TextureInfo& textureInfo( mTextureInfoContainer[cacheIndex] );
1010 if( maskTextureInfo.loadState == LOAD_FINISHED )
1012 // Send New Task to Thread
1013 ApplyMask( textureInfo, maskTextureInfo.textureId );
1017 textureInfo.pixelBuffer.Reset();
1018 textureInfo.loadState = LOAD_FAILED;
1019 NotifyObservers( textureInfo, false );
1025 void TextureManager::ApplyMask( TextureInfo& textureInfo, TextureId maskTextureId )
1027 int maskCacheIndex = GetCacheIndexFromId( maskTextureId );
1028 if( maskCacheIndex != INVALID_CACHE_INDEX )
1030 Devel::PixelBuffer maskPixelBuffer = mTextureInfoContainer[maskCacheIndex].pixelBuffer;
1031 Devel::PixelBuffer pixelBuffer = textureInfo.pixelBuffer;
1032 textureInfo.pixelBuffer.Reset();
1034 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n",
1035 textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously?"T":"F" );
1037 textureInfo.loadState = MASK_APPLYING;
1038 auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
1039 auto loadingHelperIt = loadersContainer.GetNext();
1040 auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
1041 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
1042 loadingHelperIt->ApplyMask( textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad );
1046 void TextureManager::UploadTexture( Devel::PixelBuffer& pixelBuffer, TextureInfo& textureInfo )
1048 if( textureInfo.useAtlas != USE_ATLAS )
1050 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, " TextureManager::UploadTexture() New Texture for textureId:%d\n", textureInfo.textureId );
1052 // Check if this pixelBuffer is premultiplied
1053 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
1055 auto& renderingAddOn = RenderingAddOn::Get();
1056 if( renderingAddOn.IsValid() )
1058 renderingAddOn.CreateGeometry( textureInfo.textureId, pixelBuffer );
1061 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(),
1062 pixelBuffer.GetWidth(), pixelBuffer.GetHeight() );
1064 PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
1065 texture.Upload( pixelData );
1066 if ( ! textureInfo.textureSet )
1068 textureInfo.textureSet = TextureSet::New();
1070 textureInfo.textureSet.SetTexture( 0u, texture );
1073 // Update the load state.
1074 // Note: This is regardless of success as we care about whether a
1075 // load attempt is in progress or not. If unsuccessful, a broken
1076 // image is still loaded.
1077 textureInfo.loadState = UPLOADED;
1080 void TextureManager::NotifyObservers( TextureInfo& textureInfo, bool success )
1082 TextureId textureId = textureInfo.textureId;
1084 // If there is an observer: Notify the load is complete, whether successful or not,
1085 // and erase it from the list
1086 TextureInfo* info = &textureInfo;
1088 mQueueLoadFlag = true;
1090 while( info->observerList.Count() )
1092 TextureUploadObserver* observer = info->observerList[0];
1094 // During UploadComplete() a Control ResourceReady() signal is emitted.
1095 // During that signal the app may add remove /add Textures (e.g. via
1097 // It is possible for observers to be removed from the observer list,
1098 // and it is also possible for the mTextureInfoContainer to be modified,
1099 // invalidating the reference to the textureInfo struct.
1100 // Texture load requests for the same URL are deferred until the end of this
1102 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "NotifyObservers() url:%s loadState:%s\n",
1103 textureInfo.url.GetUrl().c_str(), GET_LOAD_STATE_STRING(textureInfo.loadState ) );
1105 // It is possible for the observer to be deleted.
1106 // Disconnect and remove the observer first.
1107 observer->DestructionSignal().Disconnect( this, &TextureManager::ObserverDestroyed );
1109 info->observerList.Erase( info->observerList.begin() );
1111 if( info->storageType == StorageType::RETURN_PIXEL_BUFFER )
1113 observer->LoadComplete( success, info->pixelBuffer, info->url, info->preMultiplied );
1117 observer->UploadComplete( success, info->textureId, info->textureSet, info->useAtlas, info->atlasRect,
1118 info->preMultiplied );
1121 // Get the textureInfo from the container again as it may have been invalidated.
1122 int textureInfoIndex = GetCacheIndexFromId( textureId );
1123 if( textureInfoIndex == INVALID_CACHE_INDEX)
1125 break; // texture has been removed - can stop.
1127 info = &mTextureInfoContainer[ textureInfoIndex ];
1130 mQueueLoadFlag = false;
1131 ProcessQueuedTextures();
1133 if( info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0 )
1135 Remove( info->textureId, nullptr );
1139 TextureManager::TextureId TextureManager::GenerateUniqueTextureId()
1141 return mCurrentTextureId++;
1144 int TextureManager::GetCacheIndexFromId( const TextureId textureId )
1146 const unsigned int size = mTextureInfoContainer.size();
1148 for( unsigned int i = 0; i < size; ++i )
1150 if( mTextureInfoContainer[i].textureId == textureId )
1156 return INVALID_CACHE_INDEX;
1159 TextureManager::TextureHash TextureManager::GenerateHash(
1160 const std::string& url,
1161 const ImageDimensions size,
1162 const FittingMode::Type fittingMode,
1163 const Dali::SamplingMode::Type samplingMode,
1164 const UseAtlas useAtlas,
1165 TextureId maskTextureId,
1166 StorageType storageType,
1167 bool isAnimationImage,
1168 uint32_t frameIndex )
1170 std::string hashTarget( url );
1171 const size_t urlLength = hashTarget.length();
1172 const uint16_t width = size.GetWidth();
1173 const uint16_t height = size.GetWidth();
1175 // If either the width or height has been specified, include the resizing options in the hash
1176 if( width != 0 || height != 0 )
1178 // We are appending 5 bytes to the URL to form the hash input.
1179 hashTarget.resize( urlLength + 5u );
1180 char* hashTargetPtr = &( hashTarget[ urlLength ] );
1182 // Pack the width and height (4 bytes total).
1183 *hashTargetPtr++ = size.GetWidth() & 0xff;
1184 *hashTargetPtr++ = ( size.GetWidth() >> 8u ) & 0xff;
1185 *hashTargetPtr++ = size.GetHeight() & 0xff;
1186 *hashTargetPtr++ = ( size.GetHeight() >> 8u ) & 0xff;
1188 // Bit-pack the FittingMode, SamplingMode and atlasing.
1189 // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit, storageType=2bits
1190 *hashTargetPtr = ( fittingMode << 6u ) | ( samplingMode << 3 ) | ( useAtlas << 2 ) | storageType;
1194 // We are not including sizing information, but we still need an extra byte for atlasing.
1195 hashTarget.resize( urlLength + 1u );
1197 // Add the atlasing to the hash input.
1200 case UseAtlas::NO_ATLAS:
1202 hashTarget[ urlLength ] = 'f';
1205 case UseAtlas::USE_ATLAS:
1207 hashTarget[ urlLength ] = 't';
1213 if( isAnimationImage )
1215 auto textureIdIndex = hashTarget.length();
1216 hashTarget.resize( hashTarget.length() + sizeof( uint32_t ) );
1217 char* hashTargetPtr = &( hashTarget[ textureIdIndex ] );
1219 for( size_t byteIter = 0; byteIter < sizeof( uint32_t ); ++byteIter )
1221 *hashTargetPtr++ = frameIndex & 0xff;
1226 if( maskTextureId != INVALID_TEXTURE_ID )
1228 auto textureIdIndex = hashTarget.length();
1229 hashTarget.resize( hashTarget.length() + sizeof( TextureId ) );
1230 unsigned char* hashTargetPtr = reinterpret_cast<unsigned char*>(&( hashTarget[ textureIdIndex ] ));
1232 // Append the texture id to the end of the URL byte by byte:
1233 // (to avoid SIGBUS / alignment issues)
1234 for( size_t byteIter = 0; byteIter < sizeof( TextureId ); ++byteIter )
1236 *hashTargetPtr++ = maskTextureId & 0xff;
1237 maskTextureId >>= 8u;
1241 return Dali::CalculateHash( hashTarget );
1244 int TextureManager::FindCachedTexture(
1245 const TextureManager::TextureHash hash,
1246 const std::string& url,
1247 const ImageDimensions size,
1248 const FittingMode::Type fittingMode,
1249 const Dali::SamplingMode::Type samplingMode,
1250 const bool useAtlas,
1251 TextureId maskTextureId,
1252 TextureManager::MultiplyOnLoad preMultiplyOnLoad,
1253 StorageType storageType,
1254 bool isAnimatedImage,
1255 uint32_t frameIndex )
1257 // Default to an invalid ID, in case we do not find a match.
1258 int cacheIndex = INVALID_CACHE_INDEX;
1260 // Iterate through our hashes to find a match.
1261 const unsigned int count = mTextureInfoContainer.size();
1262 for( unsigned int i = 0u; i < count; ++i )
1264 if( mTextureInfoContainer[i].hash == hash )
1266 // We have a match, now we check all the original parameters in case of a hash collision.
1267 TextureInfo& textureInfo( mTextureInfoContainer[i] );
1269 if( ( url == textureInfo.url.GetUrl() ) &&
1270 ( useAtlas == textureInfo.useAtlas ) &&
1271 ( maskTextureId == textureInfo.maskTextureId ) &&
1272 ( size == textureInfo.desiredSize ) &&
1273 ( ( size.GetWidth() == 0 && size.GetHeight() == 0 ) ||
1274 ( fittingMode == textureInfo.fittingMode &&
1275 samplingMode == textureInfo.samplingMode ) ) &&
1276 ( storageType == textureInfo.storageType ) &&
1277 ( isAnimatedImage == ( ( textureInfo.animatedImageLoading ) ? true : false ) ) &&
1278 ( frameIndex == textureInfo.frameIndex ) )
1280 // 1. If preMultiplyOnLoad is MULTIPLY_ON_LOAD, then textureInfo.preMultiplyOnLoad should be true. The premultiplication result can be different.
1281 // 2. If preMultiplyOnLoad is LOAD_WITHOUT_MULTIPLY, then textureInfo.preMultiplied should be false.
1282 if( ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD && textureInfo.preMultiplyOnLoad )
1283 || ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY && !textureInfo.preMultiplied ) )
1285 // The found Texture is a match.
1296 void TextureManager::ObserverDestroyed( TextureUploadObserver* observer )
1298 const unsigned int count = mTextureInfoContainer.size();
1299 for( unsigned int i = 0; i < count; ++i )
1301 TextureInfo& textureInfo( mTextureInfoContainer[i] );
1302 for( TextureInfo::ObserverListType::Iterator j = textureInfo.observerList.Begin();
1303 j != textureInfo.observerList.End(); )
1305 if( *j == observer )
1307 j = textureInfo.observerList.Erase( j );
1318 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(TextureManager& textureManager)
1319 : AsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager,
1320 AsyncLoadingInfoContainerType())
1324 void TextureManager::AsyncLoadingHelper::LoadAnimatedImage( TextureId textureId,
1325 Dali::AnimatedImageLoading animatedImageLoading,
1326 uint32_t frameIndex )
1328 mLoadingInfoContainer.push_back( AsyncLoadingInfo( textureId ) );
1329 auto id = DevelAsyncImageLoader::LoadAnimatedImage( mLoader, animatedImageLoading, frameIndex );
1330 mLoadingInfoContainer.back().loadId = id;
1333 void TextureManager::AsyncLoadingHelper::Load( TextureId textureId,
1334 const VisualUrl& url,
1335 ImageDimensions desiredSize,
1336 FittingMode::Type fittingMode,
1337 SamplingMode::Type samplingMode,
1338 bool orientationCorrection,
1339 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad )
1341 mLoadingInfoContainer.push_back( AsyncLoadingInfo( textureId ) );
1342 auto id = DevelAsyncImageLoader::Load( mLoader, url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad );
1343 mLoadingInfoContainer.back().loadId = id;
1346 void TextureManager::AsyncLoadingHelper::ApplyMask( TextureId textureId,
1347 Devel::PixelBuffer pixelBuffer,
1348 Devel::PixelBuffer maskPixelBuffer,
1351 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad )
1353 mLoadingInfoContainer.push_back( AsyncLoadingInfo( textureId ) );
1354 auto id = DevelAsyncImageLoader::ApplyMask( mLoader, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad );
1355 mLoadingInfoContainer.back().loadId = id;
1358 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(AsyncLoadingHelper&& rhs)
1359 : AsyncLoadingHelper(rhs.mLoader, rhs.mTextureManager, std::move(rhs.mLoadingInfoContainer))
1363 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(
1364 Toolkit::AsyncImageLoader loader,
1365 TextureManager& textureManager,
1366 AsyncLoadingInfoContainerType&& loadingInfoContainer)
1368 mTextureManager(textureManager),
1369 mLoadingInfoContainer(std::move(loadingInfoContainer))
1371 DevelAsyncImageLoader::PixelBufferLoadedSignal(mLoader).Connect(
1372 this, &AsyncLoadingHelper::AsyncLoadComplete);
1375 void TextureManager::AsyncLoadingHelper::AsyncLoadComplete(uint32_t id,
1376 Devel::PixelBuffer pixelBuffer )
1378 mTextureManager.AsyncLoadComplete( mLoadingInfoContainer, id, pixelBuffer );
1381 void TextureManager::SetBrokenImageUrl(const std::string& brokenImageUrl)
1383 mBrokenImageUrl = brokenImageUrl;
1386 Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements )
1388 return RenderingAddOn::Get().IsValid() ?
1389 RenderingAddOn::Get().GetGeometry( textureId, frontElements, backElements) :
1393 } // namespace Internal
1395 } // namespace Toolkit