/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
-#include "texture-manager-impl.h"
+#include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
// EXTERNAL HEADERS
#include <dali/devel-api/adaptor-framework/environment-variable.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/rendering/geometry.h>
namespace
{
-constexpr auto INITIAL_HASH_NUMBER = size_t{0u};
+constexpr auto INITIAL_HASH_NUMBER = size_t{0u};
constexpr auto TEXTURE_INDEX = 0u; ///< The Index for texture
constexpr auto MASK_TEXTURE_INDEX = 1u; ///< The Index for mask texture
mAsyncLoader(std::unique_ptr<TextureAsyncLoadingHelper>(new TextureAsyncLoadingHelper(*this))),
mLifecycleObservers(),
mLoadQueue(),
- mRemoveQueue(),
mLoadingQueueTextureId(INVALID_TEXTURE_ID),
- mLoadYuvPlanes(NeedToLoadYuvPlanes())
+ mRemoveQueue(),
+ mLoadYuvPlanes(NeedToLoadYuvPlanes()),
+ mRemoveProcessorRegistered(false)
{
// Initialize the AddOn
RenderingAddOn::Get();
TextureManager::~TextureManager()
{
+ if(mRemoveProcessorRegistered && Adaptor::IsAvailable())
+ {
+ Adaptor::Get().UnregisterProcessor(*this, true);
+ mRemoveProcessorRegistered = false;
+ }
+
for(auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
{
(*iter)->TextureManagerDestroyed();
const uint32_t& frameIndex,
TextureManager::TextureId& textureId,
MaskingDataPointer& maskInfo,
+ const Dali::ImageDimensions& desiredSize,
+ const Dali::FittingMode::Type& fittingMode,
const Dali::SamplingMode::Type& samplingMode,
const bool& synchronousLoading,
TextureUploadObserver* textureObserver,
Devel::PixelBuffer pixelBuffer;
if(animatedImageLoading)
{
- pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
+ pixelBuffer = animatedImageLoading.LoadFrame(frameIndex, desiredSize, fittingMode, samplingMode);
}
if(!pixelBuffer)
{
Texture maskTexture;
if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
{
- Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
+ Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), desiredSize, fittingMode, samplingMode, true);
if(maskPixelBuffer)
{
if(!maskInfo->mPreappliedMasking)
}
}
- textureId = RequestLoadInternal(url, alphaMaskId, contentScaleFactor, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, cropToMask, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
+ textureId = RequestLoadInternal(url, alphaMaskId, textureId, contentScaleFactor, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, cropToMask, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
if(loadState == TextureManager::LoadState::UPLOADED)
}
else
{
- RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
+ RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
}
return pixelBuffer;
std::string location = url.GetLocation();
if(location.size() > 0u)
{
- TextureId id = std::stoi(location);
- textureSet = mTextureCacheManager.GetExternalTextureSet(id);
- if(textureSet)
+ TextureId id = std::stoi(location);
+ auto externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+ if(externalTextureInfo.textureSet)
{
- preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- textureId = id;
- return textureSet;
+ if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
+ {
+ // Change preMultiplyOnLoad value so make caller determine to preMultiplyAlpha or not.
+ // TODO : Should we seperate input and output value?
+ preMultiplyOnLoad = externalTextureInfo.preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+ }
+
+ TextureId alphaMaskId = INVALID_TEXTURE_ID;
+ if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+ {
+ maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, StorageType::KEEP_TEXTURE, synchronousLoading);
+ alphaMaskId = maskInfo->mAlphaMaskId;
+
+ // Create new textureId. this textureId is not same as location
+ textureId = RequestLoad(url, alphaMaskId, textureId, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad, synchronousLoading);
+
+ TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
+ if(loadState == TextureManager::LoadState::UPLOADED)
+ {
+ textureSet = GetTextureSet(textureId);
+ }
+ }
+ else
+ {
+ // TextureId is same as location
+ textureId = id;
+
+ textureSet = TextureSet::New();
+ textureSet.SetTexture(TEXTURE_INDEX, externalTextureInfo.textureSet.GetTexture(TEXTURE_INDEX));
+ }
}
}
}
textureId = RequestLoad(
url,
alphaMaskId,
+ textureId,
contentScaleFactor,
desiredSize,
fittingMode,
TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
const bool& synchronousLoading)
{
- return RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+ return RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
}
TextureManager::TextureId TextureManager::RequestLoad(
const VisualUrl& url,
const TextureManager::TextureId& maskTextureId,
+ const TextureManager::TextureId& previousTextureId,
const float& contentScale,
const Dali::ImageDimensions& desiredSize,
const Dali::FittingMode::Type& fittingMode,
TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
const bool& synchronousLoading)
{
- return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+ return RequestLoadInternal(url, maskTextureId, previousTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
}
TextureManager::TextureId TextureManager::RequestMaskLoad(
{
// Use the normal load procedure to get the alpha mask.
auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+ return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
}
TextureManager::TextureId TextureManager::RequestLoadInternal(
const VisualUrl& url,
const TextureManager::TextureId& maskTextureId,
+ const TextureManager::TextureId& previousTextureId,
const float& contentScale,
const Dali::ImageDimensions& desiredSize,
const Dali::FittingMode::Type& fittingMode,
// Check if the requested Texture exists in the cache.
if(cacheIndex != INVALID_CACHE_INDEX)
{
- if(TextureManager::ReloadPolicy::CACHED == reloadPolicy)
+ if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
{
- // Mark this texture being used by another client resource. Forced reload would replace the current texture
+ // Mark this texture being used by another client resource, or Reload forced without request load before.
+ // Forced reload which have current texture before, would replace the current texture.
// without the need for incrementing the reference count.
++(mTextureCacheManager[cacheIndex].referenceCount);
}
// 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, maskTextureId=%d, frameindex=%d, premultiplied=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, frameIndex, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d, maskTextureId=%d, prevTextureId=%d, frameindex=%d, premultiplied=%d, refCount=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, previousTextureId, frameIndex, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0, static_cast<int>(mTextureCacheManager[cacheIndex].referenceCount));
}
if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
textureInfo.storageType = storageType;
textureInfo.orientationCorrection = orientationCorrection;
+ // the case using external texture has already been loaded texture, so change its status to WAITING_FOR_MASK.
+ if(url.GetProtocolType() == VisualUrl::TEXTURE)
+ {
+ if(textureInfo.loadState != LoadState::UPLOADED)
+ {
+ textureInfo.loadState = TextureManager::LoadState::WAITING_FOR_MASK;
+ }
+ }
+
DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n", GET_LOAD_STATE_STRING(textureInfo.loadState));
// Force reloading of texture by setting loadState unless already loading or cancelled.
TextureManager::LoadState::CANCELLED != textureInfo.loadState &&
TextureManager::LoadState::MASK_CANCELLED != textureInfo.loadState)
{
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d, maskTextureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d, maskTextureId=%d, prevTextureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, previousTextureId);
textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
}
case TextureManager::LoadState::MASK_APPLYING:
case TextureManager::LoadState::MASK_APPLIED:
{
- ObserveTexture(textureInfo, observer);
+ // Do not observe even we reload forced when texture is already loading state.
+ if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
+ {
+ ObserveTexture(textureInfo, observer);
+ }
break;
}
case TextureManager::LoadState::UPLOADED:
if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
{
- std::vector<Devel::PixelBuffer> pixelBuffers;
- LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
-
- if(pixelBuffers.empty())
+ if(url.GetProtocolType() == VisualUrl::TEXTURE)
{
- // If pixelBuffer loading is failed in synchronously, call Remove() method.
- Remove(textureId, nullptr);
- return INVALID_TEXTURE_ID;
- }
-
- if(storageType == StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
- {
- textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
- textureInfo.loadState = LoadState::LOAD_FINISHED;
+ // Get external textureSet from cacheManager.
+ std::string location = textureInfo.url.GetLocation();
+ if(!location.empty())
+ {
+ TextureId id = std::stoi(location);
+ auto externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+ textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
+ textureInfo.loadState = LoadState::UPLOADED;
+ }
}
- else // For the image loading.
+ else
{
- Texture maskTexture;
- if(maskTextureId != INVALID_TEXTURE_ID)
+ std::vector<Devel::PixelBuffer> pixelBuffers;
+ LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
+
+ if(pixelBuffers.empty())
+ {
+ // If pixelBuffer loading is failed in synchronously, call RequestRemove() method.
+ RequestRemove(textureId, nullptr);
+ return INVALID_TEXTURE_ID;
+ }
+
+ if(storageType == StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
+ {
+ textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
+ textureInfo.loadState = LoadState::LOAD_FINISHED;
+ }
+ else // For the image loading.
{
- TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
- if(maskCacheIndex != INVALID_CACHE_INDEX)
+ Texture maskTexture;
+ if(maskTextureId != INVALID_TEXTURE_ID)
{
- if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_TEXTURE)
+ TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
+ if(maskCacheIndex != INVALID_CACHE_INDEX)
{
- if(!mTextureCacheManager[maskCacheIndex].textures.empty())
+ if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER)
{
- maskTexture = mTextureCacheManager[maskCacheIndex].textures[0];
+ Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
+ if(maskPixelBuffer)
+ {
+ pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
+ }
+ else
+ {
+ DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
+ }
}
}
- else if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER)
+ else
{
- Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
- if(maskPixelBuffer)
- {
- pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
- }
- else
- {
- DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
- }
+ DALI_LOG_ERROR("Mask image is not stored in cache.\n");
}
}
- else
- {
- DALI_LOG_ERROR("Mask image is not stored in cache.\n");
- }
- }
- PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
+ PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
- // Upload texture
- UploadTextures(pixelBuffers, textureInfo);
+ // Upload texture
+ UploadTextures(pixelBuffers, textureInfo);
+ }
}
}
}
return textureId;
}
-void TextureManager::Remove(const TextureManager::TextureId& textureId, TextureUploadObserver* observer)
+void TextureManager::RequestRemove(const TextureManager::TextureId& textureId, TextureUploadObserver* observer)
+{
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestRemove( textureId=%d observer=%p )\n", textureId, observer);
+
+ // Queue to remove.
+ if(textureId != INVALID_TEXTURE_ID)
+ {
+ TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+ if(textureCacheIndex != INVALID_CACHE_INDEX)
+ {
+ if(observer)
+ {
+ // Remove observer from cached texture info
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ RemoveTextureObserver(textureInfo, observer);
+ }
+
+ mRemoveQueue.PushBack(textureId);
+
+ if(!mRemoveProcessorRegistered && Adaptor::IsAvailable())
+ {
+ mRemoveProcessorRegistered = true;
+ Adaptor::Get().RegisterProcessor(*this, true);
+ }
+ }
+ }
+}
+
+void TextureManager::Remove(const TextureManager::TextureId& textureId)
{
if(textureId != INVALID_TEXTURE_ID)
{
}
}
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove( textureId=%d observer=%p ) cacheIndex:%d removal maskTextureId=%d, loadingQueueTextureId=%d, loadState=%s\n", textureId, observer, textureCacheIndex.GetIndex(), maskTextureId, mLoadingQueueTextureId, GET_LOAD_STATE_STRING(textureInfo.loadState));
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove( textureId=%d ) cacheIndex:%d removal maskTextureId=%d, loadState=%s\n", textureId, textureCacheIndex.GetIndex(), maskTextureId, GET_LOAD_STATE_STRING(textureInfo.loadState));
- // the case that LoadingQueue is working.
- if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
- {
- // If textureId is not same, this observer need to delete when ProcessRemoveQueue() is called.
- // If textureId is same, we should not call RemoveTextureObserver.
- // Because ObserverDestroyed signal already disconnected in NotifyObservers
- TextureUploadObserver* queueObserver = observer;
- if(mLoadingQueueTextureId == textureId)
- {
- queueObserver = nullptr;
- }
+ // Remove textureId in CacheManager. Now, textureInfo is invalidate.
+ mTextureCacheManager.RemoveCache(textureInfo);
- // Remove element from the mLoadQueue
- for(auto&& element : mLoadQueue)
- {
- if(element.mTextureId == textureId && element.mObserver == observer)
- {
- // Do not erase the item. We will clear it later in ProcessLoadQueue().
- element.mTextureId = INVALID_TEXTURE_ID;
- element.mObserver = nullptr;
- break;
- }
- }
-
- mRemoveQueue.PushBack(QueueElement(textureId, queueObserver));
- }
- else
+ // Remove maskTextureId in CacheManager
+ if(maskTextureId != INVALID_TEXTURE_ID)
{
- // Remove its observer
- RemoveTextureObserver(textureInfo, observer);
+ TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
+ if(maskCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
- // Remove textureId in CacheManager. Now, textureInfo is invalidate.
- mTextureCacheManager.RemoveCache(textureInfo);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove mask texture( maskTextureId=%d ) cacheIndex:%d, loadState=%s\n", maskTextureId, maskCacheIndex.GetIndex(), GET_LOAD_STATE_STRING(maskTextureInfo.loadState));
- // Remove maskTextureId in CacheManager
- if(maskTextureId != INVALID_TEXTURE_ID)
- {
- TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
- if(maskCacheIndex != INVALID_CACHE_INDEX)
- {
- TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
- mTextureCacheManager.RemoveCache(maskTextureInfo);
- }
+ mTextureCacheManager.RemoveCache(maskTextureInfo);
}
}
}
}
}
+void TextureManager::ProcessRemoveQueue()
+{
+ // Note that RemoveQueue is not be changed during Remove().
+ for(auto&& textureId : mRemoveQueue)
+ {
+ if(textureId != INVALID_TEXTURE_ID)
+ {
+ Remove(textureId);
+ }
+ }
+ mRemoveQueue.Clear();
+}
+
+void TextureManager::Process(bool postProcessor)
+{
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Process()\n");
+
+ ProcessRemoveQueue();
+
+ if(Adaptor::IsAvailable())
+ {
+ Adaptor::Get().UnregisterProcessor(*this, true);
+ mRemoveProcessorRegistered = false;
+ }
+}
+
void TextureManager::LoadImageSynchronously(
const VisualUrl& url,
const Dali::ImageDimensions& desiredSize,
{
// The Texture has already loaded. The other observers have already been notified.
// We need to send a "late" loaded notification for this observer.
- EmitLoadComplete(observer, textureInfo, true);
+ if(observer)
+ {
+ EmitLoadComplete(observer, textureInfo, true);
+ }
}
break;
}
if(observer)
{
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, " Connect DestructionSignal to observer:%p\n", observer);
observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
}
}
textureInfo.loadState = LoadState::LOADING;
if(!textureInfo.loadSynchronously)
{
- auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
+ auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
if(textureInfo.animatedImageLoading)
{
- mAsyncLoader->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, premultiplyOnLoad);
+ mAsyncLoader->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, premultiplyOnLoad);
}
else
{
if(cacheIndex != INVALID_CACHE_INDEX)
{
TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
+
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::ProcessLoadQueue() textureId=%d, observer=%p, cacheIndex=@%d, loadState:%s\n", element.mTextureId, element.mObserver, cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
+
if((textureInfo.loadState == LoadState::UPLOADED) || (textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER))
{
if(element.mObserver)
mLoadQueue.Clear();
}
-void TextureManager::ProcessRemoveQueue()
-{
- for(auto&& element : mRemoveQueue)
- {
- if(element.mTextureId != INVALID_TEXTURE_ID)
- {
- Remove(element.mTextureId, element.mObserver);
- }
- }
- mRemoveQueue.Clear();
-}
-
void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
TextureUploadObserver* observer)
{
if(observer)
{
textureInfo.observerList.PushBack(observer);
+
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, " Connect DestructionSignal to observer:%p\n", observer);
observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
}
}
}
else
{
- Remove(textureInfo.textureId, nullptr);
+ Remove(textureInfo.textureId);
}
}
}
{
if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
{
- // Upload image texture. textureInfo.loadState will be UPLOADED.
- std::vector<Devel::PixelBuffer> pixelBuffers;
- pixelBuffers.push_back(textureInfo.pixelBuffer);
- UploadTextures(pixelBuffers, textureInfo);
+ if(textureInfo.url.GetProtocolType() == VisualUrl::TEXTURE)
+ {
+ // Get external textureSet from cacheManager.
+ std::string location = textureInfo.url.GetLocation();
+ if(!location.empty())
+ {
+ TextureId id = std::stoi(location);
+ auto externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
+ textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
+ textureInfo.loadState = LoadState::UPLOADED;
+ }
+ }
+ else
+ {
+ // Upload image texture. textureInfo.loadState will be UPLOADED.
+ std::vector<Devel::PixelBuffer> pixelBuffers;
+ pixelBuffers.push_back(textureInfo.pixelBuffer);
+ UploadTextures(pixelBuffers, textureInfo);
+ }
// Increase reference counts for notify required textureId.
// Now we can assume that we don't remove & re-assign this textureId
// Decrease reference count
for(const auto textureId : notifyRequiredTextureIds)
{
- Remove(textureId, nullptr);
+ RequestRemove(textureId, nullptr);
}
}
DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
- textureInfo.loadState = LoadState::MASK_APPLYING;
+ textureInfo.loadState = LoadState::MASK_APPLYING;
auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
mAsyncLoader->ApplyMask(textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad);
}
// 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, info->url.GetUrl().c_str(), GET_LOAD_STATE_STRING(info->loadState));
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() observer:%p textureId:%d url:%s loadState:%s\n", observer, 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.
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, " Disconnect DestructionSignal to observer:%p\n", observer);
observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
info->observerList.Erase(info->observerList.End() - 1u);
mLoadingQueueTextureId = INVALID_TEXTURE_ID;
ProcessLoadQueue();
- ProcessRemoveQueue();
if(info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
{
- Remove(info->textureId, nullptr);
+ RequestRemove(info->textureId, nullptr);
}
}
void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
{
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::ObserverDestroyed() observer:%p\n", observer);
+
const std::size_t size = mTextureCacheManager.size();
for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
{
if(iter != iterEnd)
{
// Disconnect and remove the observer.
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, " Disconnect DestructionSignal to observer:%p\n", observer);
observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
textureInfo.observerList.Erase(iter);
}