mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
mLifecycleObservers(),
mLoadQueue(),
+ mRemoveQueue(),
mQueueLoadFlag(false)
{
// Initialize the AddOn
}
}
-TextureSet TextureManager::LoadAnimatedImageTexture(Dali::AnimatedImageLoading animatedImageLoading,
- const uint32_t& frameIndex,
- TextureManager::TextureId& textureId,
- const Dali::SamplingMode::Type& samplingMode,
- const Dali::WrapMode::Type& wrapModeU,
- const Dali::WrapMode::Type& wrapModeV,
- const bool& synchronousLoading,
- const bool& useCache,
- TextureUploadObserver* textureObserver)
+TextureSet TextureManager::LoadAnimatedImageTexture(
+ Dali::AnimatedImageLoading animatedImageLoading,
+ const uint32_t& frameIndex,
+ TextureManager::TextureId& textureId,
+ MaskingDataPointer& maskInfo,
+ const Dali::SamplingMode::Type& samplingMode,
+ const Dali::WrapMode::Type& wrapModeU,
+ const Dali::WrapMode::Type& wrapModeV,
+ const bool& synchronousLoading,
+ const bool& useCache,
+ TextureUploadObserver* textureObserver)
{
TextureSet textureSet;
}
else
{
+ if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+ {
+ Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
+ if(maskPixelBuffer)
+ {
+ pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
+ }
+ else
+ {
+ DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous mask image loading is failed\n");
+ }
+ }
PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
if(!textureSet)
{
}
else
{
- auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- textureId = RequestLoadInternal(animatedImageLoading.GetUrl(), INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, false, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex, false, useCache);
+ TextureId alphaMaskId = INVALID_TEXTURE_ID;
+ float contentScaleFactor = 1.0f;
+ bool cropToMask = false;
+ if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+ {
+ maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl);
+ alphaMaskId = maskInfo->mAlphaMaskId;
+ contentScaleFactor = maskInfo->mContentScaleFactor;
+ cropToMask = maskInfo->mCropToMask;
+ }
+
+ auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+ textureId = RequestLoadInternal(animatedImageLoading.GetUrl(), alphaMaskId, contentScaleFactor, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, cropToMask, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex, false, useCache);
+
TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
if(loadState == TextureManager::LoadState::UPLOADED)
{
{
if(url.IsBufferResource())
{
- const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url.GetUrl());
+ const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
if(encodedImageBuffer)
{
pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX;
if(storageType != StorageType::RETURN_PIXEL_BUFFER && useCache)
{
- textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId);
+ textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask);
// Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
- cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, (animatedImageLoading) ? true : false);
+ cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false);
}
TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
// Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
preMultiplyOnLoad = mTextureCacheManager[cacheIndex].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- 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);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d premultiplied=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0);
}
if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
{
- if(VisualUrl::BUFFER == url.GetProtocolType())
- {
- std::string location = url.GetLocation();
- if(location.size() > 0u)
- {
- TextureId targetId = std::stoi(location);
- const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(targetId);
- if(encodedImageBuffer)
- {
- textureId = targetId;
-
- // Increase EncodedImageBuffer reference during it contains mTextureInfoContainer.
- // TODO! We should change action when reload policy is FORCE.
- // Eunki Hong will fix it after refactoring patch merged.
- mTextureCacheManager.UseExternalResource(url.GetUrl());
- }
- }
- }
-
- if(textureId == INVALID_TEXTURE_ID)
- {
- textureId = mTextureCacheManager.GenerateUniqueTextureId();
- }
+ textureId = mTextureCacheManager.GenerateTextureId();
bool preMultiply = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
// Cache new texutre, and get cacheIndex.
cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, useAtlas, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex));
- 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);
+ 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.GetIndex(), textureId);
}
// The below code path is common whether we are using the cache or not.
TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
TextureManager::LoadState::CANCELLED != textureInfo.loadState)
{
- 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);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId);
textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
}
{
pixelBuffer.ApplyMask(maskPixelBuffer, contentScale, cropToMask);
}
+ else
+ {
+ DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
+ }
}
else
{
void TextureManager::Remove(const TextureManager::TextureId& textureId, TextureUploadObserver* observer)
{
- // Remove textureId in CacheManager.
- mTextureCacheManager.RemoveCache(textureId);
-
- if(observer)
+ if(textureId != INVALID_TEXTURE_ID)
{
- // Remove element from the LoadQueue
- for(auto&& element : mLoadQueue)
+ if(mQueueLoadFlag)
+ {
+ // Remove textureId after NotifyObserver finished
+ mRemoveQueue.PushBack(textureId);
+ }
+ else
{
- if(element.mObserver == observer)
+ // Remove textureId in CacheManager.
+ mTextureCacheManager.RemoveCache(textureId);
+ }
+
+ if(observer)
+ {
+ // Remove element from the LoadQueue
+ for(auto&& element : mLoadQueue)
{
- // Do not erase the item. We will clear it later in ProcessQueuedTextures().
- element.mObserver = nullptr;
- break;
+ if(element.mObserver == observer)
+ {
+ // Do not erase the item. We will clear it later in ProcessLoadQueue().
+ element.mObserver = nullptr;
+ break;
+ }
}
}
}
Devel::PixelBuffer pixelBuffer;
if(url.IsBufferResource())
{
- const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url.GetUrl());
+ const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
if(encodedImageBuffer)
{
pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
ObserveTexture(textureInfo, observer);
}
-void TextureManager::ProcessQueuedTextures()
+void TextureManager::ProcessLoadQueue()
{
for(auto&& element : mLoadQueue)
{
mLoadQueue.Clear();
}
+void TextureManager::ProcessRemoveQueue()
+{
+ for(const auto& textureId : mRemoveQueue)
+ {
+ mTextureCacheManager.RemoveCache(textureId);
+ }
+ mRemoveQueue.Clear();
+}
+
void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
TextureUploadObserver* observer)
{
void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureId, Devel::PixelBuffer pixelBuffer)
{
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( textureId:%d )\n", textureId);
TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( textureId:%d CacheIndex:%d )\n", textureId, cacheIndex.GetIndex());
if(cacheIndex != INVALID_CACHE_INDEX)
{
TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, " textureId:%d Url:%s CacheIndex:%d LoadState: %s\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex, GET_LOAD_STATE_STRING(textureInfo.loadState));
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, " textureId:%d Url:%s CacheIndex:%d LoadState: %s\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
if(textureInfo.loadState != LoadState::CANCELLED)
{
// Send New Task to Thread
ApplyMask(textureInfo, textureInfo.maskTextureId);
}
+ else // maskLoadState == LoadState::LOAD_FAILED
+ {
+ // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
+ DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
+ UploadTexture(pixelBuffer, textureInfo);
+ NotifyObservers(textureInfo, true);
+ }
}
}
else
else
{
textureInfo.loadState = LoadState::LOAD_FAILED;
- CheckForWaitingTexture(textureInfo);
- NotifyObservers(textureInfo, false);
+ if(textureInfo.storageType != StorageType::KEEP_PIXEL_BUFFER)
+ {
+ NotifyObservers(textureInfo, false);
+ }
+ else // if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER) // image mask case
+ {
+ // Check if there was another texture waiting for this load to complete
+ // (e.g. if this was an image mask, and its load is on a different thread)
+ CheckForWaitingTexture(textureInfo);
+ }
}
}
{
// Search the cache, checking if any texture has this texture id as a
// maskTextureId:
- const TextureCacheIndex size = static_cast<TextureCacheIndex>(mTextureCacheManager.size());
+ const std::size_t size = mTextureCacheManager.size();
- for(TextureCacheIndex cacheIndex = 0; cacheIndex < size; ++cacheIndex)
+ const bool maskLoadSuccess = maskTextureInfo.loadState == LoadState::LOAD_FINISHED ? true : false;
+
+ // TODO : Refactorize here to not iterate whole cached image.
+ for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
{
if(mTextureCacheManager[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
mTextureCacheManager[cacheIndex].loadState == LoadState::WAITING_FOR_MASK)
{
TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
- if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
+ if(maskLoadSuccess)
{
// Send New Task to Thread
ApplyMask(textureInfo, maskTextureInfo.textureId);
}
else
{
- textureInfo.pixelBuffer.Reset();
- textureInfo.loadState = LoadState::LOAD_FAILED;
- NotifyObservers(textureInfo, false);
+ // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
+ DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
+ UploadTexture(textureInfo.pixelBuffer, textureInfo);
+ NotifyObservers(textureInfo, true);
}
}
}
// invalidating the reference to the textureInfo struct.
// Texture load requests for the same URL are deferred until the end of this
// method.
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() textureId:%d url:%s loadState:%s\n", textureId, textureInfo.url.GetUrl().c_str(), GET_LOAD_STATE_STRING(textureInfo.loadState));
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() textureId:%d url:%s loadState:%s\n", textureId, info->url.GetUrl().c_str(), GET_LOAD_STATE_STRING(info->loadState));
// It is possible for the observer to be deleted.
// Disconnect and remove the observer first.
}
mQueueLoadFlag = false;
- ProcessQueuedTextures();
+ ProcessLoadQueue();
+ ProcessRemoveQueue();
if(info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
{
void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
{
- const TextureCacheIndex count = static_cast<TextureCacheIndex>(mTextureCacheManager.size());
- for(TextureCacheIndex i = 0; i < count; ++i)
+ const std::size_t size = mTextureCacheManager.size();
+ for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
{
- TextureInfo& textureInfo(mTextureCacheManager[i]);
+ TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
for(TextureInfo::ObserverListType::Iterator j = textureInfo.observerList.Begin();
j != textureInfo.observerList.End();)
{