From: sunghyun kim Date: Tue, 16 May 2023 06:26:14 +0000 (+0900) Subject: Modified to use the appropriate TextureSet in external texture X-Git-Tag: dali_2.2.27~5^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=refs%2Fchanges%2F73%2F292873%2F2 Modified to use the appropriate TextureSet in external texture Change-Id: Id3b81f769fad02e90a5b5fd311e13bbe9692d200 --- diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp index 8c63d53..bd3d5ed 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp @@ -28,6 +28,8 @@ #include #include #include ///< For VisualFactory's member TextureManager. +#include +#include #include #include @@ -435,6 +437,152 @@ int UtcTextureManagerEncodedImageBuffer(void) END_TEST; } +int UtcTextureManagerExternalTexture(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcTextureManagerExternalTexture check TextureManager using external texture works well"); + + auto visualFactory = Toolkit::VisualFactory::Get(); + auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager + + TestObserver observer1; + TestObserver observer2; + + auto textureId1(TextureManager::INVALID_TEXTURE_ID); + auto textureId2(TextureManager::INVALID_TEXTURE_ID); + std::string maskname(TEST_MASK_FILE_NAME); + TextureManager::MaskingDataPointer maskInfo = nullptr; + maskInfo.reset(new TextureManager::MaskingData()); + maskInfo->mAlphaMaskUrl = maskname; + maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; + maskInfo->mCropToMask = true; + maskInfo->mContentScaleFactor = 1.0f; + Vector4 atlasRect(0.f, 0.f, 1.f, 1.f); + Dali::ImageDimensions atlasRectSize(0, 0); + bool synchronousLoading(false); + bool atlasingStatus(false); + bool loadingStatus(false); + auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + ImageAtlasManagerPtr atlasManager = nullptr; + Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr; + + uint32_t width(64); + uint32_t height(64); + uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888); + + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE); + + DALI_TEST_CHECK(pixelData); + + Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true); + std::string url = imageUrl.GetUrl(); + + TextureSet texture1 = textureManager.LoadTexture( + url, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId1, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + &observer1, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + TextureSet texture2 = textureManager.LoadTexture( + url, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId2, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + &observer2, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(observer1.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + DALI_TEST_EQUALS(observer2.mLoaded, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mObserverCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(observer2.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION); + + DALI_TEST_EQUALS(textureId1 == textureId2, true, TEST_LOCATION); + + texture1 = textureManager.LoadTexture( + url, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId1, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + &observer1, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + texture2 = textureManager.LoadTexture( + url, + ImageDimensions(), + FittingMode::SCALE_TO_FILL, + SamplingMode::BOX_THEN_LINEAR, + maskInfo, + synchronousLoading, + textureId2, + atlasRect, + atlasRectSize, + atlasingStatus, + loadingStatus, + &observer2, + atlasUploadObserver, + atlasManager, + true, + TextureManager::ReloadPolicy::CACHED, + preMultiply); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(textureId1 == textureId2, true, TEST_LOCATION); + DALI_TEST_EQUALS(texture1 != texture2, true, TEST_LOCATION); + + END_TEST; +} + int UtcTextureManagerEncodedImageBufferReferenceCount(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp b/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp index 99620f0..74463da 100644 --- a/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp +++ b/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp @@ -326,16 +326,16 @@ TextureSet TextureManager::LoadTexture( alphaMaskId = maskInfo->mAlphaMaskId; textureId = RequestLoad(url, alphaMaskId, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad, synchronousLoading); - if(synchronousLoading) + TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId); + if(loadState == TextureManager::LoadState::UPLOADED) { - auto textureSet = GetTextureSet(textureId); - textureSet.SetTexture(MASK_TEXTURE_INDEX, GetTextureSet(alphaMaskId).GetTexture(TEXTURE_INDEX)); - return textureSet; + textureSet = GetTextureSet(textureId); } } else { - return externalTextureInfo.textureSet; + textureSet = TextureSet::New(); + textureSet.SetTexture(TEXTURE_INDEX, externalTextureInfo.textureSet.GetTexture(TEXTURE_INDEX)); } } } @@ -707,14 +707,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal( TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId); if(maskCacheIndex != INVALID_CACHE_INDEX) { - if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_TEXTURE) - { - if(!mTextureCacheManager[maskCacheIndex].textures.empty()) - { - maskTexture = mTextureCacheManager[maskCacheIndex].textures[0]; - } - } - else if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER) + if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER) { Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer; if(maskPixelBuffer) @@ -1204,6 +1197,7 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex TextureId id = std::stoi(location); auto externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id); textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0)); + textureInfo.loadState = LoadState::UPLOADED; } } else