+ Devel::PixelBuffer pixelBuffer;
+ if(synchronousLoading)
+ {
+ if(url.IsValid())
+ {
+ if(url.IsBufferResource())
+ {
+ const EncodedImageBuffer& encodedImageBuffer = GetEncodedImageBuffer(url.GetUrl());
+ if(encodedImageBuffer)
+ {
+ pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
+ }
+ }
+ else
+ {
+ pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
+ }
+ if(pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
+ {
+ PreMultiply(pixelBuffer, preMultiplyOnLoad);
+ }
+ }
+ }
+ else
+ {
+ RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
+ }
+
+ return pixelBuffer;
+}
+
+TextureSet TextureManager::LoadTexture(
+ const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, MaskingDataPointer& maskInfo, bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect, Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus, Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver, AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection, TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
+{
+ TextureSet textureSet;
+
+ loadingStatus = false;
+ textureRect = FULL_ATLAS_RECT;
+
+ if(VisualUrl::TEXTURE == url.GetProtocolType())
+ {
+ std::string location = url.GetLocation();
+ if(location.size() > 0u)
+ {
+ TextureId id = std::stoi(location);
+ for(auto&& elem : mExternalTextures)
+ {
+ if(elem.textureId == id)
+ {
+ preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+ textureId = elem.textureId;
+ return elem.textureSet;
+ }
+ }
+ }
+ }
+ else
+ {
+ // For Atlas
+ if(synchronousLoading && atlasingStatus && imageAtlasManager->CheckAtlasAvailable(url, desiredSize))
+ {
+ Devel::PixelBuffer pixelBuffer = LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection);
+
+ if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
+ {
+ Devel::PixelBuffer maskPixelBuffer = LoadImageSynchronously(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
+ if(maskPixelBuffer)
+ {
+ pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
+ }
+ }
+
+ PixelData data;
+ if(pixelBuffer)
+ {
+ PreMultiply(pixelBuffer, preMultiplyOnLoad);
+ data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
+
+ if(data)
+ {
+ 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");
+ }
+ }
+ if(!textureSet)
+ {
+ atlasingStatus = false;
+ }
+ }
+
+ if(!textureSet)
+ {
+ loadingStatus = true;
+ if(atlasingStatus)
+ {
+ textureSet = imageAtlasManager->Add(textureRect, url.GetUrl(), desiredSize, 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, TextureManager::NO_ATLAS, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad, synchronousLoading);
+ }
+ else
+ {
+ maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, synchronousLoading);
+ textureId = RequestLoad(url,
+ maskInfo->mAlphaMaskId,
+ maskInfo->mContentScaleFactor,
+ desiredSize,
+ fittingMode,
+ samplingMode,
+ TextureManager::NO_ATLAS,
+ maskInfo->mCropToMask,
+ textureObserver,
+ orientationCorrection,
+ reloadPolicy,
+ preMultiplyOnLoad,
+ synchronousLoading);
+ }
+
+ TextureManager::LoadState loadState = GetTextureStateInternal(textureId);
+ if(loadState == TextureManager::LoadState::UPLOADED)
+ {
+ // UploadComplete has already been called - keep the same texture set
+ textureSet = GetTextureSet(textureId);
+ }
+
+ // If we are loading the texture, or waiting for the ready signal handler to complete, inform
+ // caller that they need to wait.
+ loadingStatus = (loadState == TextureManager::LoadState::LOADING ||
+ loadState == TextureManager::LoadState::WAITING_FOR_MASK ||
+ loadState == TextureManager::LoadState::MASK_APPLYING ||
+ loadState == TextureManager::LoadState::MASK_APPLIED ||
+ loadState == TextureManager::LoadState::NOT_STARTED ||
+ mQueueLoadFlag);
+ }
+ else
+ {
+ textureRectSize = desiredSize;
+ }
+ }
+ }
+
+ if(!atlasingStatus && textureSet)
+ {
+ Sampler sampler = Sampler::New();
+ sampler.SetWrapMode(wrapModeU, wrapModeV);
+ textureSet.SetSampler(0u, sampler);
+ }
+
+ if(synchronousLoading)
+ {
+ loadingStatus = false;
+ }
+
+ return textureSet;