constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS = size_t{4u};
constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
+constexpr auto TEXTURE_INDEX = 0u; ///< The Index for texture
+constexpr auto MASK_TEXTURE_INDEX = 1u; ///< The Index for mask texture
+
constexpr auto NUMBER_OF_LOCAL_LOADER_THREADS_ENV = "DALI_TEXTURE_LOCAL_THREADS";
constexpr auto NUMBER_OF_REMOTE_LOADER_THREADS_ENV = "DALI_TEXTURE_REMOTE_THREADS";
+constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES";
size_t GetNumberOfThreads(const char* environmentVariable, size_t defaultValue)
{
return GetNumberOfThreads(NUMBER_OF_REMOTE_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS);
}
+bool NeedToLoadYuvPlanes()
+{
+ auto loadYuvPlanesString = Dali::EnvironmentVariable::GetEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV);
+ bool loadYuvPlanes = loadYuvPlanesString ? std::atoi(loadYuvPlanesString) : false;
+ return loadYuvPlanes;
+}
} // namespace
namespace Dali
loadState == TextureManagerType::LoadState::MASK_APPLIED ? "MASK_APPLIED" : \
loadState == TextureManagerType::LoadState::UPLOADED ? "UPLOADED" : \
loadState == TextureManagerType::LoadState::CANCELLED ? "CANCELLED" : \
+ loadState == TextureManagerType::LoadState::MASK_CANCELLED ? "MASK_CANCELLED" : \
loadState == TextureManagerType::LoadState::LOAD_FAILED ? "LOAD_FAILED" : \
"Unknown"
// clang-format on
: mAlphaMaskUrl(),
mAlphaMaskId(INVALID_TEXTURE_ID),
mContentScaleFactor(1.0f),
- mCropToMask(true)
+ mCropToMask(true),
+ mPreappliedMasking(true),
+ mMaskImageLoadingFailed(false)
{
}
mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
mLifecycleObservers(),
mLoadQueue(),
- mQueueLoadFlag(false)
+ mRemoveQueue(),
+ mLoadingQueueTextureId(INVALID_TEXTURE_ID),
+ mLoadYuvPlanes(NeedToLoadYuvPlanes())
{
// Initialize the AddOn
RenderingAddOn::Get();
}
}
-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(
+ const VisualUrl& url,
+ Dali::AnimatedImageLoading animatedImageLoading,
+ const uint32_t& frameIndex,
+ TextureManager::TextureId& textureId,
+ MaskingDataPointer& maskInfo,
+ const Dali::SamplingMode::Type& samplingMode,
+ const bool& synchronousLoading,
+ TextureUploadObserver* textureObserver,
+ TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
{
TextureSet textureSet;
}
else
{
+ Texture maskTexture;
+ if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+ {
+ Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
+ if(maskPixelBuffer)
+ {
+ if(!maskInfo->mPreappliedMasking)
+ {
+ PixelData maskPixelData = Devel::PixelBuffer::Convert(maskPixelBuffer); // takes ownership of buffer
+ maskTexture = Texture::New(Dali::TextureType::TEXTURE_2D, maskPixelData.GetPixelFormat(), maskPixelData.GetWidth(), maskPixelData.GetHeight());
+ maskTexture.Upload(maskPixelData);
+ }
+ else
+ {
+ pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
+ }
+ }
+ else
+ {
+ DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous mask image loading is failed\n");
+ }
+ }
+
+ if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
+ {
+ PreMultiply(pixelBuffer, preMultiplyOnLoad);
+ }
+
PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
if(!textureSet)
{
Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
texture.Upload(pixelData);
textureSet = TextureSet::New();
- textureSet.SetTexture(0u, texture);
+ textureSet.SetTexture(TEXTURE_INDEX, texture);
+ if(maskTexture)
+ {
+ textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTexture);
+ }
}
}
}
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, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE);
+ alphaMaskId = maskInfo->mAlphaMaskId;
+ if(maskInfo->mPreappliedMasking)
+ {
+ contentScaleFactor = maskInfo->mContentScaleFactor;
+ cropToMask = maskInfo->mCropToMask;
+ }
+ }
+
+ 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);
+
TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
if(loadState == TextureManager::LoadState::UPLOADED)
{
}
}
- if(textureSet)
- {
- Sampler sampler = Sampler::New();
- sampler.SetWrapMode(wrapModeU, wrapModeV);
- textureSet.SetSampler(0u, sampler);
- }
-
return textureSet;
}
{
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);
}
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, false);
+ 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);
}
return pixelBuffer;
Dali::ImageDimensions& textureRectSize,
bool& atlasingStatus,
bool& loadingStatus,
- const Dali::WrapMode::Type& wrapModeU,
- const Dali::WrapMode::Type& wrapModeV,
TextureUploadObserver* textureObserver,
AtlasUploadObserver* atlasObserver,
ImageAtlasManagerPtr imageAtlasManager,
else
{
// For Atlas
- if(synchronousLoading && atlasingStatus && imageAtlasManager->CheckAtlasAvailable(url, desiredSize))
+ if(synchronousLoading && atlasingStatus)
{
- Devel::PixelBuffer pixelBuffer = LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection);
-
- if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+ const bool synchronousAtlasAvaliable = (desiredSize != ImageDimensions() || url.IsLocalResource()) ? imageAtlasManager->CheckAtlasAvailable(url, desiredSize)
+ : false;
+ if(synchronousAtlasAvaliable)
{
- Devel::PixelBuffer maskPixelBuffer = LoadImageSynchronously(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
- if(maskPixelBuffer)
+ std::vector<Devel::PixelBuffer> pixelBuffers;
+ LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, false, pixelBuffers);
+
+ if(!pixelBuffers.empty() && maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
{
- pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
+ std::vector<Devel::PixelBuffer> maskPixelBuffers;
+ LoadImageSynchronously(maskInfo->mAlphaMaskUrl, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true, false, maskPixelBuffers);
+ if(!maskPixelBuffers.empty())
+ {
+ pixelBuffers[0].ApplyMask(maskPixelBuffers[0], maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
+ }
}
- }
- PixelData data;
- if(pixelBuffer)
- {
- PreMultiply(pixelBuffer, preMultiplyOnLoad);
- data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
-
- if(data)
+ PixelData data;
+ if(!pixelBuffers.empty())
{
- textureSet = imageAtlasManager->Add(textureRect, data);
- if(textureSet)
+ PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
+ data = Devel::PixelBuffer::Convert(pixelBuffers[0]); // takes ownership of buffer
+
+ if(data)
{
- textureRectSize.SetWidth(data.GetWidth());
- textureRectSize.SetHeight(data.GetHeight());
+ textureSet = imageAtlasManager->Add(textureRect, data);
+ if(textureSet)
+ {
+ textureRectSize.SetWidth(data.GetWidth());
+ textureRectSize.SetHeight(data.GetHeight());
+ }
+ }
+ else
+ {
+ DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous Texture loading with atlasing is failed.\n");
}
}
- else
+ if(!textureSet)
{
- DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous Texture loading with atlasing is failed.\n");
+ atlasingStatus = false;
}
}
- if(!textureSet)
- {
- atlasingStatus = false;
- }
}
if(!textureSet)
Dali::ImageDimensions atlasDesiredSize = desiredSize;
if(atlasingStatus)
{
- textureSet = imageAtlasManager->Add(textureRect, url.GetUrl(), atlasDesiredSize, fittingMode, true, atlasObserver);
+ if(url.IsBufferResource())
+ {
+ const EncodedImageBuffer& encodedImageBuffer = GetEncodedImageBuffer(url.GetUrl());
+ if(encodedImageBuffer)
+ {
+ textureSet = imageAtlasManager->Add(textureRect, encodedImageBuffer, desiredSize, fittingMode, true, atlasObserver);
+ }
+ }
+ else
+ {
+ textureSet = imageAtlasManager->Add(textureRect, url, atlasDesiredSize, fittingMode, true, atlasObserver);
+ }
}
if(!textureSet) // big image, no atlasing or atlasing failed
{
atlasingStatus = false;
- if(!maskInfo || !maskInfo->mAlphaMaskUrl.IsValid())
- {
- textureId = RequestLoad(
- url,
- desiredSize,
- fittingMode,
- samplingMode,
- UseAtlas::NO_ATLAS,
- textureObserver,
- orientationCorrection,
- reloadPolicy,
- preMultiplyOnLoad,
- synchronousLoading);
- }
- else
+
+ TextureId alphaMaskId = INVALID_TEXTURE_ID;
+ float contentScaleFactor = 1.0f;
+ bool cropToMask = false;
+ if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
{
- maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, synchronousLoading);
- textureId = RequestLoad(
- url,
- maskInfo->mAlphaMaskId,
- maskInfo->mContentScaleFactor,
- desiredSize,
- fittingMode,
- samplingMode,
- UseAtlas::NO_ATLAS,
- maskInfo->mCropToMask,
- textureObserver,
- orientationCorrection,
- reloadPolicy,
- preMultiplyOnLoad,
- synchronousLoading);
+ maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE, synchronousLoading);
+ alphaMaskId = maskInfo->mAlphaMaskId;
+ if(maskInfo && maskInfo->mPreappliedMasking)
+ {
+ contentScaleFactor = maskInfo->mContentScaleFactor;
+ cropToMask = maskInfo->mCropToMask;
+ }
}
+ textureId = RequestLoad(
+ url,
+ alphaMaskId,
+ contentScaleFactor,
+ desiredSize,
+ fittingMode,
+ samplingMode,
+ UseAtlas::NO_ATLAS,
+ cropToMask,
+ textureObserver,
+ orientationCorrection,
+ reloadPolicy,
+ preMultiplyOnLoad,
+ synchronousLoading);
+
TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
if(loadState == TextureManager::LoadState::UPLOADED)
{
// LoadComplete has already been called - keep the same texture set
- textureSet = mTextureCacheManager.GetTextureSet(textureId);
+ textureSet = GetTextureSet(textureId);
}
// If we are loading the texture, or waiting for the ready signal handler to complete, inform
loadState == TextureManager::LoadState::MASK_APPLYING ||
loadState == TextureManager::LoadState::MASK_APPLIED ||
loadState == TextureManager::LoadState::NOT_STARTED ||
- mQueueLoadFlag);
+ mLoadingQueueTextureId != INVALID_TEXTURE_ID);
}
else
{
}
}
- if(!atlasingStatus && textureSet)
- {
- Sampler sampler = Sampler::New();
- sampler.SetWrapMode(wrapModeU, wrapModeV);
- textureSet.SetSampler(0u, sampler);
- }
-
if(synchronousLoading)
{
loadingStatus = false;
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, true);
+ 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);
}
TextureManager::TextureId TextureManager::RequestLoad(
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, true);
+ return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
}
TextureManager::TextureId TextureManager::RequestMaskLoad(
const VisualUrl& maskUrl,
+ StorageType storageType,
const bool& synchronousLoading)
{
// 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::KEEP_PIXEL_BUFFER, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading, true);
+ 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);
}
TextureManager::TextureId TextureManager::RequestLoadInternal(
TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
Dali::AnimatedImageLoading animatedImageLoading,
const std::uint32_t& frameIndex,
- const bool& synchronousLoading,
- const bool& useCache)
+ const bool& synchronousLoading)
{
- TextureHash textureHash = INITIAL_HASH_NUMBER;
- TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX;
- if(storageType != StorageType::RETURN_PIXEL_BUFFER && useCache)
+ TextureHash textureHash = INITIAL_HASH_NUMBER;
+ TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX;
+ bool loadYuvPlanes = (mLoadYuvPlanes && maskTextureId == INVALID_TEXTURE_ID && storageType == StorageType::UPLOAD_TO_TEXTURE);
+
+ if(storageType != StorageType::RETURN_PIXEL_BUFFER)
{
- textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask);
+ textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask, frameIndex);
// 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, cropToMask);
+ cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, useAtlas, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
}
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, maskTextureId=%d, frameindex=%d, premultiplied=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, frameIndex, 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));
+ cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, useAtlas, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex, loadYuvPlanes));
- 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, maskTextureId=%d, frameindex=%d premultiply=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, frameIndex, preMultiply);
}
// The below code path is common whether we are using the cache or not.
TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
- TextureManager::LoadState::CANCELLED != textureInfo.loadState)
+ 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\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, maskTextureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId);
textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
}
ObserveTexture(textureInfo, observer);
break;
}
+ case TextureManager::LoadState::MASK_CANCELLED:
+ {
+ // A cancelled texture hasn't finished mask applying yet. Treat as a mask applying texture
+ // (it's ref count has already been incremented, above)
+ textureInfo.loadState = TextureManager::LoadState::MASK_APPLYING;
+ ObserveTexture(textureInfo, observer);
+ break;
+ }
case TextureManager::LoadState::LOAD_FINISHED:
{
// Loading has already completed.
if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
{
- Devel::PixelBuffer pixelBuffer = LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection);
+ std::vector<Devel::PixelBuffer> pixelBuffers;
+ LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
- if(!pixelBuffer)
+ if(pixelBuffers.empty())
{
// If pixelBuffer loading is failed in synchronously, call Remove() method.
Remove(textureId, nullptr);
if(storageType == StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
{
- textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
+ textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
textureInfo.loadState = LoadState::LOAD_FINISHED;
}
else // For the image loading.
{
+ Texture maskTexture;
if(maskTextureId != INVALID_TEXTURE_ID)
{
TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
if(maskCacheIndex != INVALID_CACHE_INDEX)
{
- Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
- if(maskPixelBuffer)
+ if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_TEXTURE)
{
- pixelBuffer.ApplyMask(maskPixelBuffer, contentScale, cropToMask);
+ if(!mTextureCacheManager[maskCacheIndex].textures.empty())
+ {
+ maskTexture = mTextureCacheManager[maskCacheIndex].textures[0];
+ }
}
- else
+ else if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER)
{
- DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
+ 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
DALI_LOG_ERROR("Mask image is not stored in cache.\n");
}
}
- PreMultiply(pixelBuffer, preMultiplyOnLoad);
+ PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
// Upload texture
- UploadTexture(pixelBuffer, textureInfo);
+ UploadTextures(pixelBuffers, textureInfo);
}
}
}
+
return textureId;
}
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)
+ TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+ if(textureCacheIndex != INVALID_CACHE_INDEX)
{
- if(element.mObserver == observer)
+ TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ // We only need to consider maskTextureId when texture's loadState is not cancelled. Because it is already deleted.
+ if(textureInfo.loadState != LoadState::CANCELLED && textureInfo.loadState != LoadState::MASK_CANCELLED)
{
- // Do not erase the item. We will clear it later in ProcessQueuedTextures().
- element.mObserver = nullptr;
- break;
+ if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
+ {
+ maskTextureId = textureInfo.maskTextureId;
+ }
+ }
+
+ 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));
+
+ // 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 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 its observer
+ RemoveTextureObserver(textureInfo, observer);
+
+ // Remove textureId in CacheManager. Now, textureInfo is invalidate.
+ mTextureCacheManager.RemoveCache(textureInfo);
+
+ // 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);
+ }
+ }
}
}
}
}
-Devel::PixelBuffer TextureManager::LoadImageSynchronously(
- const VisualUrl& url,
- const Dali::ImageDimensions& desiredSize,
- const Dali::FittingMode::Type& fittingMode,
- const Dali::SamplingMode::Type& samplingMode,
- const bool& orientationCorrection)
+void TextureManager::LoadImageSynchronously(
+ const VisualUrl& url,
+ const Dali::ImageDimensions& desiredSize,
+ const Dali::FittingMode::Type& fittingMode,
+ const Dali::SamplingMode::Type& samplingMode,
+ const bool& orientationCorrection,
+ const bool& loadYuvPlanes,
+ std::vector<Devel::PixelBuffer>& pixelBuffers)
{
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);
}
else
{
- pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
+ if(loadYuvPlanes)
+ {
+ Dali::LoadImagePlanesFromFile(url.GetUrl(), pixelBuffers, desiredSize, fittingMode, samplingMode, orientationCorrection);
+ }
+ else
+ {
+ pixelBuffer = Dali::LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
+ }
+ }
+
+ if(pixelBuffer)
+ {
+ pixelBuffers.push_back(pixelBuffer);
}
- return pixelBuffer;
}
void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
case LoadState::NOT_STARTED:
case LoadState::LOAD_FAILED:
{
- if(mQueueLoadFlag)
+ if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
{
QueueLoadTexture(textureInfo, observer);
}
}
case LoadState::UPLOADED:
{
- if(mQueueLoadFlag)
+ if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
{
QueueLoadTexture(textureInfo, observer);
}
}
case LoadState::LOADING:
case LoadState::CANCELLED:
+ case LoadState::MASK_CANCELLED:
case LoadState::LOAD_FINISHED:
case LoadState::WAITING_FOR_MASK:
case LoadState::MASK_APPLYING:
void TextureManager::QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
{
const auto& textureId = textureInfo.textureId;
- mLoadQueue.PushBack(LoadQueueElement(textureId, observer));
+ mLoadQueue.PushBack(QueueElement(textureId, observer));
- observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
+ if(observer)
+ {
+ observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
+ }
}
void TextureManager::LoadTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
if(textureInfo.animatedImageLoading)
{
- loadingHelperIt->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex);
+ loadingHelperIt->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, premultiplyOnLoad);
}
else
{
- loadingHelperIt->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad);
+ loadingHelperIt->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad, textureInfo.loadYuvPlanes);
}
}
ObserveTexture(textureInfo, observer);
}
-void TextureManager::ProcessQueuedTextures()
+void TextureManager::ProcessLoadQueue()
{
for(auto&& element : mLoadQueue)
{
- if(!element.mObserver)
+ if(element.mTextureId == INVALID_TEXTURE_ID)
{
continue;
}
TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
if((textureInfo.loadState == LoadState::UPLOADED) || (textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER))
{
- EmitLoadComplete(element.mObserver, textureInfo, true);
+ if(element.mObserver)
+ {
+ EmitLoadComplete(element.mObserver, textureInfo, true);
+ }
+ }
+ else if(textureInfo.loadState == LoadState::LOADING)
+ {
+ // Note : LOADING state texture cannot be queue.
+ // This case be occured when same texture id are queue in mLoadQueue.
+ ObserveTexture(textureInfo, element.mObserver);
}
else
{
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)
{
}
}
-void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureId, Devel::PixelBuffer pixelBuffer)
+void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureId, std::vector<Devel::PixelBuffer>& pixelBuffers)
{
- 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)
+ if(textureInfo.loadState != LoadState::CANCELLED && textureInfo.loadState != LoadState::MASK_CANCELLED)
{
// textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
- PostLoad(textureInfo, pixelBuffer);
+ PostLoad(textureInfo, pixelBuffers);
}
else
{
}
}
-void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer)
+void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vector<Devel::PixelBuffer>& pixelBuffers)
{
// Was the load successful?
- if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
+ if(!pixelBuffers.empty())
{
- // No atlas support for now
- textureInfo.useAtlas = UseAtlas::NO_ATLAS;
- textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
-
- if(textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE)
+ if(pixelBuffers.size() == 1)
{
- // If there is a mask texture ID associated with this texture, then apply the mask
- // if it's already loaded. If it hasn't, and the mask is still loading,
- // wait for the mask to finish loading.
- // note, If the texture is already uploaded synchronously during loading,
- // we don't need to apply mask.
- if(textureInfo.loadState != LoadState::UPLOADED &&
- textureInfo.maskTextureId != INVALID_TEXTURE_ID)
+ Devel::PixelBuffer pixelBuffer = pixelBuffers[0];
+ if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
{
- if(textureInfo.loadState == LoadState::MASK_APPLYING)
- {
- textureInfo.loadState = LoadState::MASK_APPLIED;
- UploadTexture(pixelBuffer, textureInfo);
- NotifyObservers(textureInfo, true);
- }
- else
+ // No atlas support for now
+ textureInfo.useAtlas = UseAtlas::NO_ATLAS;
+ textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
+
+ if(textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE)
{
- LoadState maskLoadState = mTextureCacheManager.GetTextureStateInternal(textureInfo.maskTextureId);
- textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
- if(maskLoadState == LoadState::LOADING)
+ // If there is a mask texture ID associated with this texture, then apply the mask
+ // if it's already loaded. If it hasn't, and the mask is still loading,
+ // wait for the mask to finish loading.
+ // note, If the texture is already uploaded synchronously during loading,
+ // we don't need to apply mask.
+ if(textureInfo.loadState != LoadState::UPLOADED &&
+ textureInfo.maskTextureId != INVALID_TEXTURE_ID)
{
- textureInfo.loadState = LoadState::WAITING_FOR_MASK;
+ if(textureInfo.loadState == LoadState::MASK_APPLYING)
+ {
+ textureInfo.loadState = LoadState::MASK_APPLIED;
+ UploadTextures(pixelBuffers, textureInfo);
+ NotifyObservers(textureInfo, true);
+ }
+ else
+ {
+ LoadState maskLoadState = mTextureCacheManager.GetTextureStateInternal(textureInfo.maskTextureId);
+ textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
+ if(maskLoadState == LoadState::LOADING)
+ {
+ textureInfo.loadState = LoadState::WAITING_FOR_MASK;
+ }
+ else if(maskLoadState == LoadState::LOAD_FINISHED || maskLoadState == LoadState::UPLOADED)
+ {
+ // Send New Task to Thread
+ TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
+ if(maskCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
+ if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
+ {
+ // Send New Task to Thread
+ ApplyMask(textureInfo, textureInfo.maskTextureId);
+ }
+ else if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
+ {
+ // Upload image texture. textureInfo.loadState will be UPLOADED.
+ UploadTextures(pixelBuffers, textureInfo);
+
+ // notify mask texture set.
+ NotifyObservers(textureInfo, true);
+ }
+ }
+ }
+ 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");
+ UploadTextures(pixelBuffers, textureInfo);
+ NotifyObservers(textureInfo, true);
+ }
+ }
}
- else if(maskLoadState == LoadState::LOAD_FINISHED)
+ else
{
- // Send New Task to Thread
- ApplyMask(textureInfo, textureInfo.maskTextureId);
+ UploadTextures(pixelBuffers, textureInfo);
+ NotifyObservers(textureInfo, true);
}
- else // maskLoadState == LoadState::LOAD_FAILED
+ }
+ else
+ {
+ textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
+ textureInfo.loadState = LoadState::LOAD_FINISHED;
+
+ if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
{
- // 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 // for the StorageType::KEEP_PIXEL_BUFFER and StorageType::KEEP_TEXTURE
+ {
+ // 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);
+ }
}
}
- else
- {
- UploadTexture(pixelBuffer, textureInfo);
- NotifyObservers(textureInfo, true);
- }
}
else
{
- textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
- textureInfo.loadState = LoadState::LOAD_FINISHED;
+ // YUV case
+ // No atlas support for now
+ textureInfo.useAtlas = UseAtlas::NO_ATLAS;
+ textureInfo.preMultiplied = false;
- if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
- {
- NotifyObservers(textureInfo, true);
- }
- else
- {
- // 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);
- }
+ UploadTextures(pixelBuffers, textureInfo);
+ NotifyObservers(textureInfo, true);
}
}
else
{
textureInfo.loadState = LoadState::LOAD_FAILED;
- if(textureInfo.storageType != StorageType::KEEP_PIXEL_BUFFER)
- {
- NotifyObservers(textureInfo, false);
- }
- else // if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER) // image mask case
+ if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER || textureInfo.storageType == StorageType::KEEP_TEXTURE)
{
// 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);
}
+ else
+ {
+ NotifyObservers(textureInfo, false);
+ }
}
}
void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTextureInfo)
{
- // Search the cache, checking if any texture has this texture id as a
- // maskTextureId:
- const TextureCacheIndex size = static_cast<TextureCacheIndex>(mTextureCacheManager.size());
+ if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED &&
+ maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
+ {
+ // Upload mask texture. textureInfo.loadState will be UPLOADED.
+ std::vector<Devel::PixelBuffer> pixelBuffers;
+ pixelBuffers.push_back(maskTextureInfo.pixelBuffer);
+ UploadTextures(pixelBuffers, maskTextureInfo);
+ }
- const bool maskLoadSuccess = maskTextureInfo.loadState == LoadState::LOAD_FINISHED ? true : false;
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): maskTextureId=%d, maskTextureUrl=%s\n", maskTextureInfo.textureId, maskTextureInfo.url.GetUrl().c_str());
- for(TextureCacheIndex cacheIndex = 0; cacheIndex < size; ++cacheIndex)
+ // Search the cache, checking if any texture has this texture id as a maskTextureId
+ const std::size_t size = mTextureCacheManager.size();
+
+ // Keep notify observer required textureIds.
+ // Note : NotifyObservers can change mTextureCacheManager cache struct. We should check id's validation before notify.
+ std::vector<TextureId> notifyRequiredTextureIds;
+
+ // 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(maskLoadSuccess)
+ if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
{
- // Send New Task to Thread
- ApplyMask(textureInfo, maskTextureInfo.textureId);
+ if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
+ {
+ // Send New Task to Thread
+ ApplyMask(textureInfo, maskTextureInfo.textureId);
+ }
}
- else
+ else if(maskTextureInfo.loadState == LoadState::UPLOADED)
+ {
+ 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);
+
+ // Increase reference counts for notify required textureId.
+ // Now we can assume that we don't remove & re-assign this textureId
+ // during NotifyObserver signal emit.
+ maskTextureInfo.referenceCount++;
+ textureInfo.referenceCount++;
+
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): Ready to notify textureId=%d\n", textureInfo.textureId);
+
+ notifyRequiredTextureIds.push_back(textureInfo.textureId);
+ }
+ }
+ else // maskTextureInfo.loadState == 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(textureInfo.pixelBuffer, textureInfo);
- NotifyObservers(textureInfo, true);
+ 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
+ // during NotifyObserver signal emit.
+ maskTextureInfo.referenceCount++;
+ textureInfo.referenceCount++;
+
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): Ready to notify textureId=%d\n", textureInfo.textureId);
+
+ notifyRequiredTextureIds.push_back(textureInfo.textureId);
}
}
}
+
+ // Notify textures are masked
+ for(const auto textureId : notifyRequiredTextureIds)
+ {
+ TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+ if(textureCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ NotifyObservers(textureInfo, true);
+ }
+ }
+
+ // Decrease reference count
+ for(const auto textureId : notifyRequiredTextureIds)
+ {
+ Remove(textureId, nullptr);
+ }
}
void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId& maskTextureId)
}
}
-void TextureManager::UploadTexture(Devel::PixelBuffer& pixelBuffer, TextureManager::TextureInfo& textureInfo)
+void TextureManager::UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffers, TextureManager::TextureInfo& textureInfo)
{
- if(textureInfo.loadState != LoadState::UPLOADED && textureInfo.useAtlas != UseAtlas::USE_ATLAS)
+ if(!pixelBuffers.empty() && textureInfo.loadState != LoadState::UPLOADED && textureInfo.useAtlas != UseAtlas::USE_ATLAS)
{
- DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, " TextureManager::UploadTexture() New Texture for textureId:%d\n", textureInfo.textureId);
+ DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, " TextureManager::UploadTextures() New Texture for textureId:%d\n", textureInfo.textureId);
// Check if this pixelBuffer is premultiplied
- textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
+ textureInfo.preMultiplied = pixelBuffers[0].IsAlphaPreMultiplied();
auto& renderingAddOn = RenderingAddOn::Get();
if(renderingAddOn.IsValid())
{
- renderingAddOn.CreateGeometry(textureInfo.textureId, pixelBuffer);
+ renderingAddOn.CreateGeometry(textureInfo.textureId, pixelBuffers[0]);
}
- Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
+ // Remove previous textures and insert new textures
+ textureInfo.textures.clear();
- PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
- texture.Upload(pixelData);
- if(!textureInfo.textureSet)
+ for(auto&& pixelBuffer : pixelBuffers)
{
- textureInfo.textureSet = TextureSet::New();
+ Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
+ PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
+ texture.Upload(pixelData);
+ textureInfo.textures.push_back(texture);
}
- textureInfo.textureSet.SetTexture(0u, texture);
}
// Update the load state.
info->animatedImageLoading.Reset();
}
- mQueueLoadFlag = true;
+ mLoadingQueueTextureId = textureId;
+
+ // Reverse observer list that we can pop_back the observer.
+ std::reverse(info->observerList.Begin(), info->observerList.End());
while(info->observerList.Count())
{
- TextureUploadObserver* observer = info->observerList[0];
+ TextureUploadObserver* observer = *(info->observerList.End() - 1u);
// During LoadComplete() a Control ResourceReady() signal is emitted.
// During that signal the app may add remove /add Textures (e.g. via
// 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.
observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
- info->observerList.Erase(info->observerList.Begin());
+ info->observerList.Erase(info->observerList.End() - 1u);
EmitLoadComplete(observer, *info, success);
info = &mTextureCacheManager[textureInfoIndex];
}
- mQueueLoadFlag = false;
- ProcessQueuedTextures();
+ mLoadingQueueTextureId = INVALID_TEXTURE_ID;
+ 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();)
{
{
if(element.mObserver == observer)
{
- element.mObserver = nullptr;
+ element.mTextureId = INVALID_TEXTURE_ID;
+ element.mObserver = nullptr;
}
}
}
{
observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied));
}
- else if(textureInfo.isAnimatedImageFormat)
+ else
+ {
+ TextureSet textureSet = GetTextureSet(textureInfo);
+ if(textureInfo.isAnimatedImageFormat)
+ {
+ observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureSet, textureInfo.frameCount, textureInfo.frameInterval));
+ }
+ else
+ {
+ observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
+ }
+ }
+}
+
+TextureSet TextureManager::GetTextureSet(const TextureManager::TextureId& textureId)
+{
+ TextureSet textureSet;
+ TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
+ if(loadState == TextureManager::LoadState::UPLOADED)
{
- observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureInfo.frameCount, textureInfo.frameInterval));
+ // LoadComplete has already been called - keep the same texture set
+ TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
+ if(textureCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ textureSet = GetTextureSet(textureInfo);
+ }
}
else
{
- observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
+ DALI_LOG_ERROR("GetTextureSet is failed. texture is not uploaded \n");
+ }
+ return textureSet;
+}
+
+TextureSet TextureManager::GetTextureSet(const TextureManager::TextureInfo& textureInfo)
+{
+ TextureSet textureSet;
+
+ // LoadComplete has already been called - keep the same texture set
+ textureSet = TextureSet::New();
+ if(!textureInfo.textures.empty())
+ {
+ if(textureInfo.textures.size() > 1) // For YUV case
+ {
+ uint32_t index = 0u;
+ for(auto&& texture : textureInfo.textures)
+ {
+ textureSet.SetTexture(index++, texture);
+ }
+ }
+ else
+ {
+ textureSet.SetTexture(TEXTURE_INDEX, textureInfo.textures[0]);
+ TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
+ if(maskCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
+ if(maskTextureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE || maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
+ {
+ if(!maskTextureInfo.textures.empty())
+ {
+ textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTextureInfo.textures[0]);
+ }
+ }
+ }
+ }
+ }
+ return textureSet;
+}
+
+void TextureManager::RemoveTextureObserver(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
+{
+ // Remove its observer
+ if(observer)
+ {
+ const auto iterEnd = textureInfo.observerList.End();
+ const auto iter = std::find(textureInfo.observerList.Begin(), iterEnd, observer);
+ if(iter != iterEnd)
+ {
+ // Disconnect and remove the observer.
+ observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
+ textureInfo.observerList.Erase(iter);
+ }
}
}