From 57f2c014e61cff22236c0459757c41134fc7785f Mon Sep 17 00:00:00 2001 From: seungho Date: Fri, 17 Dec 2021 13:03:52 +0900 Subject: [PATCH] Refactoring TextureUploadObserver. - Use unified method for any request. Change-Id: Ief4b744cd42b9184f83ba0ac0ba3436befd2aa61 Signed-off-by: seungho --- .../utc-Dali-TextureManager.cpp | 21 +++++---- .../src/dali-toolkit/utc-Dali-ImageView.cpp | 2 +- .../visuals/animated-image/fixed-image-cache.cpp | 27 +++--------- .../visuals/animated-image/fixed-image-cache.h | 14 +----- .../rolling-animated-image-cache.cpp | 25 ++--------- .../animated-image/rolling-animated-image-cache.h | 14 +----- .../visuals/animated-image/rolling-image-cache.cpp | 29 +++---------- .../visuals/animated-image/rolling-image-cache.h | 14 +----- .../internal/visuals/image/image-visual.cpp | 14 +++--- dali-toolkit/internal/visuals/image/image-visual.h | 14 +----- dali-toolkit/internal/visuals/npatch-data.cpp | 6 +-- dali-toolkit/internal/visuals/npatch-data.h | 12 +----- .../internal/visuals/npatch/npatch-visual.cpp | 44 ++++++++++--------- .../internal/visuals/npatch/npatch-visual.h | 12 +----- .../internal/visuals/texture-manager-impl.cpp | 16 +++---- .../internal/visuals/texture-manager-impl.h | 14 ++---- .../internal/visuals/texture-upload-observer.cpp | 27 ++++++++++++ .../internal/visuals/texture-upload-observer.h | 50 +++++++++++++--------- 18 files changed, 136 insertions(+), 219 deletions(-) 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 1553f97..d279482 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp @@ -76,20 +76,19 @@ public: { } - virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet, - bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override + virtual void LoadComplete( bool loadSuccess, TextureInformation textureInformation ) override { - mCompleteType = CompleteType::UPLOAD_COMPLETE; - mLoaded = loadSuccess; - mObserverCalled = true; - mTextureSet = textureSet; - } - - virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override - { - mCompleteType = CompleteType::LOAD_COMPLETE; + if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE) + { + mCompleteType = CompleteType::UPLOAD_COMPLETE; + } + else + { + mCompleteType = CompleteType::LOAD_COMPLETE; + } mLoaded = loadSuccess; mObserverCalled = true; + mTextureSet = textureInformation.textureSet; } CompleteType mCompleteType; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index e8dd77e..96f4536 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -3048,7 +3048,7 @@ void OnResourceReadySignal03( Control control ) if(gResourceReadySignalCounter == 0) { // Queue loading - // 1. Use cached image, then UploadComplete will be called right after OnResourceReadySignal03. + // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03. gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA; // 2. Load a new image diff --git a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp index 4593bc7..dcb6621 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp @@ -131,9 +131,9 @@ void FixedImageCache::LoadBatch() mReadyFlags.push_back(false); - // Note, if the image is already loaded, then UploadComplete will get called + // Note, if the image is already loaded, then LoadComplete will get called // from within this method. This means it won't yet have a texture id, so we - // need to account for this inside the UploadComplete method using mRequestingLoad. + // need to account for this inside the LoadComplete method using mRequestingLoad. mRequestingLoad = true; bool synchronousLoading = false; @@ -186,42 +186,25 @@ void FixedImageCache::CheckFrontFrame(bool wasReady) } } -void FixedImageCache::UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect, - bool preMultiplied) +void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation) { bool frontFrameReady = IsFrontReady(); if(!mRequestingLoad) { - SetImageFrameReady(textureId); + SetImageFrameReady(textureInformation.textureId); CheckFrontFrame(frontFrameReady); } else { - // UploadComplete has been called from within RequestLoad. TextureManager must + // LoadComplete has been called from within RequestLoad. TextureManager must // therefore already have the texture cached, so make the texture ready. // (Use the last texture, as the texture id hasn't been assigned yet) mReadyFlags.back() = true; } } -void FixedImageCache::LoadComplete( - bool loadSuccess, - Devel::PixelBuffer pixelBuffer, - const VisualUrl& url, - bool preMultiplied) -{ - // LoadComplete is called if this TextureUploadObserver requested to load - // an image that will be returned as a type of PixelBuffer by using a method - // TextureManager::LoadPixelBuffer. -} - } //namespace Internal } //namespace Toolkit } //namespace Dali \ No newline at end of file diff --git a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h index 63212df..dc19937 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h @@ -110,19 +110,7 @@ private: void CheckFrontFrame(bool wasReady); protected: - void UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect, - bool premultiplied) override; - - void LoadComplete( - bool loadSuccess, - Devel::PixelBuffer pixelBuffer, - const VisualUrl& url, - bool preMultiplied) override; + void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override; private: std::vector& mImageUrls; diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp index eba9341..490c3be 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp @@ -274,28 +274,22 @@ void RollingAnimatedImageCache::CheckFrontFrame(bool wasReady) } } -void RollingAnimatedImageCache::UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect, - bool preMultiplied) +void RollingAnimatedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation) { - DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::UploadComplete(textureId:%d) start\n", textureId); + DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadComplete(textureId:%d) start\n", textureInformation.textureId); LOG_CACHE; bool frontFrameReady = IsFrontReady(); if(!mRequestingLoad) { - SetImageFrameReady(textureId); + SetImageFrameReady(textureInformation.textureId); CheckFrontFrame(frontFrameReady); } else { - // UploadComplete has been called from within RequestLoad. TextureManager must + // LoadComplete has been called from within RequestLoad. TextureManager must // therefore already have the texture cached, so make the texture ready. // (Use the last texture, as the texture id hasn't been assigned yet) mQueue.Back().mReady = true; @@ -316,17 +310,6 @@ void RollingAnimatedImageCache::UploadComplete( LOG_CACHE; } -void RollingAnimatedImageCache::LoadComplete( - bool loadSuccess, - Devel::PixelBuffer pixelBuffer, - const VisualUrl& url, - bool preMultiplied) -{ - // LoadComplete is called if this TextureUploadObserver requested to load - // an image that will be returned as a type of PixelBuffer by using a method - // TextureManager::LoadPixelBuffer. -} - } //namespace Internal } //namespace Toolkit } //namespace Dali diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h index b1b4afc..e1d201b 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h @@ -138,19 +138,7 @@ private: void CheckFrontFrame(bool wasReady); protected: - void UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect, - bool preMultiplied) override; - - void LoadComplete( - bool loadSuccess, - Devel::PixelBuffer pixelBuffer, - const VisualUrl& url, - bool preMultiplied) override; + void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override; private: /** diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp index 9bcf8e4..caecf39 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp @@ -190,9 +190,9 @@ void RollingImageCache::LoadBatch() mQueue.PushBack(imageFrame); - // Note, if the image is already loaded, then UploadComplete will get called + // Note, if the image is already loaded, then LoadComplete will get called // from within this method. This means it won't yet have a texture id, so we - // need to account for this inside the UploadComplete method using mRequestingLoad. + // need to account for this inside the LoadComplete method using mRequestingLoad. mRequestingLoad = true; bool synchronousLoading = false; @@ -246,28 +246,22 @@ void RollingImageCache::CheckFrontFrame(bool wasReady) } } -void RollingImageCache::UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect, - bool preMultiplied) +void RollingImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation) { - DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::UploadComplete(textureId:%d) start\n", textureId); + DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadComplete(textureId:%d) start\n", textureInformation.textureId); LOG_CACHE; bool frontFrameReady = IsFrontReady(); if(!mRequestingLoad) { - SetImageFrameReady(textureId); + SetImageFrameReady(textureInformation.textureId); CheckFrontFrame(frontFrameReady); } else { - // UploadComplete has been called from within RequestLoad. TextureManager must + // LoadComplete has been called from within RequestLoad. TextureManager must // therefore already have the texture cached, so make the texture ready. // (Use the last texture, as the texture id hasn't been assigned yet) mQueue.Back().mReady = true; @@ -276,17 +270,6 @@ void RollingImageCache::UploadComplete( LOG_CACHE; } -void RollingImageCache::LoadComplete( - bool loadSuccess, - Devel::PixelBuffer pixelBuffer, - const VisualUrl& url, - bool preMultiplied) -{ - // LoadComplete is called if this TextureUploadObserver requested to load - // an image that will be returned as a type of PixelBuffer by using a method - // TextureManager::LoadPixelBuffer. -} - } //namespace Internal } //namespace Toolkit } //namespace Dali diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h index 1fcbe88..1490c41 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h @@ -126,19 +126,7 @@ private: void CheckFrontFrame(bool wasReady); protected: - void UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect, - bool preMultiplied) override; - - void LoadComplete( - bool loadSuccess, - Devel::PixelBuffer pixelBuffer, - const VisualUrl& url, - bool preMultiplied) override; + void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override; private: /** diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 7676bf8..39b18ee 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -853,17 +853,17 @@ void ImageVisual::UploadCompleted() } // From Texture Manager -void ImageVisual::UploadComplete(bool loadingSuccess, int32_t textureId, TextureSet textureSet, bool usingAtlas, const Vector4& atlasRectangle, bool preMultiplied) +void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureInformation) { Toolkit::Visual::ResourceStatus resourceStatus; if(mImpl->mRenderer) { - if(usingAtlas) + if(textureInformation.useAtlasing) { mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect); } - EnablePreMultipliedAlpha(preMultiplied); + EnablePreMultipliedAlpha(textureInformation.preMultiplied); Actor actor = mPlacementActor.GetHandle(); if(!loadingSuccess) @@ -874,14 +874,14 @@ void ImageVisual::UploadComplete(bool loadingSuccess, int32_t textureId, Texture imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); } mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); - textureSet = mImpl->mRenderer.GetTextures(); + textureInformation.textureSet = mImpl->mRenderer.GetTextures(); } else { Sampler sampler = Sampler::New(); sampler.SetWrapMode(mWrapModeU, mWrapModeV); - textureSet.SetSampler(0u, sampler); - mImpl->mRenderer.SetTextures(textureSet); + textureInformation.textureSet.SetSampler(0u, sampler); + mImpl->mRenderer.SetTextures(textureInformation.textureSet); } if(actor) @@ -895,7 +895,7 @@ void ImageVisual::UploadComplete(bool loadingSuccess, int32_t textureId, Texture // Storing TextureSet needed when renderer staged. if(!mImpl->mRenderer) { - mTextures = textureSet; + mTextures = textureInformation.textureSet; } // Image loaded, set status regardless of staged status. diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index 55fb59b..bc94ffb 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -248,25 +248,15 @@ public: void UploadCompleted() override; /** - * @copydoc TextureUploadObserver::UploadCompleted + * @copydoc TextureUploadObserver::LoadCompleted * * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. * This callback is the place to add the renderer as it would be called once the loading is finished. */ - void UploadComplete(bool success, int32_t textureId, TextureSet textureSet, bool usingAtlas, const Vector4& atlasRectangle, bool preMultiplied) override; + void LoadComplete(bool success, TextureInformation textureInformation) override; private: /** - * @copydoc TextureUploadObserver::LoadComplete - * - * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. - * This callback is the place to add the renderer as it would be called once the PixelBuffer loading is finished. - */ - void LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied) override - { - } - - /** * Allocate the mask data when a masking property is defined in the property map */ void AllocateMaskData(); diff --git a/dali-toolkit/internal/visuals/npatch-data.cpp b/dali-toolkit/internal/visuals/npatch-data.cpp index cb144b8..e8a6042 100644 --- a/dali-toolkit/internal/visuals/npatch-data.cpp +++ b/dali-toolkit/internal/visuals/npatch-data.cpp @@ -224,11 +224,11 @@ void NPatchData::SetLoadedNPatchData(Devel::PixelBuffer& pixelBuffer, bool preMu mLoadingState = LoadingState::LOAD_COMPLETE; } -void NPatchData::LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied) +void NPatchData::LoadComplete(bool loadSuccess, TextureInformation textureInformation) { if(loadSuccess) { - SetLoadedNPatchData(pixelBuffer, preMultiplied); + SetLoadedNPatchData(textureInformation.pixelBuffer, textureInformation.preMultiplied); } else { @@ -238,7 +238,7 @@ void NPatchData::LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, for(uint32_t index = 0; index < mObserverList.Count(); ++index) { TextureUploadObserver* observer = mObserverList[index]; - observer->UploadComplete(loadSuccess, TextureManager::INVALID_TEXTURE_ID, mTextureSet, false, Vector4(), preMultiplied); + observer->LoadComplete(loadSuccess, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, TextureManager::INVALID_TEXTURE_ID, mTextureSet, false, Vector4(), textureInformation.preMultiplied)); } } diff --git a/dali-toolkit/internal/visuals/npatch-data.h b/dali-toolkit/internal/visuals/npatch-data.h index 7a052c4..94d7f2b 100644 --- a/dali-toolkit/internal/visuals/npatch-data.h +++ b/dali-toolkit/internal/visuals/npatch-data.h @@ -253,22 +253,12 @@ public: private: /** - * @copydoc TextureUploadObserver::UploadCompleted - * - * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. - * This callback is the place to add the renderer as it would be called once the loading is finished. - */ - void UploadComplete(bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied) override - { - } - - /** * @copydoc TextureUploadObserver::LoadComplete * * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. * This callback is the place to add the renderer as it would be called once the loading is finished. */ - void LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied) override; + void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override; private: using ObserverListType = Dali::Vector; diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 1f48eca..b9e046a 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -777,32 +777,34 @@ void NPatchVisual::SetResource() } } -void NPatchVisual::UploadComplete(bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied) +void NPatchVisual::LoadComplete(bool loadSuccess, TextureInformation textureInformation) { - EnablePreMultipliedAlpha(preMultiplied); - if(!loadSuccess) + if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE) { - // Image loaded and ready to display - ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); - } - - if(mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid()) - { - SetResource(); - } -} + EnablePreMultipliedAlpha(textureInformation.preMultiplied); + if(!loadSuccess) + { + // Image loaded and ready to display + ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); + } -void NPatchVisual::LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied) -{ - if(loadSuccess && url.GetUrl() == mAuxiliaryUrl.GetUrl()) - { - mAuxiliaryPixelBuffer = pixelBuffer; - SetResource(); + if(mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid()) + { + SetResource(); + } } - else + else // for the ReturnType::PIXEL_BUFFER { - // Image loaded and ready to display - ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); + if(loadSuccess && textureInformation.url == mAuxiliaryUrl.GetUrl()) + { + mAuxiliaryPixelBuffer = textureInformation.pixelBuffer; + SetResource(); + } + else + { + // Image loaded and ready to display + ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); + } } } diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index 02db5a4..a266edc 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -207,20 +207,12 @@ private: private: /** - * @copydoc TextureUploadObserver::UploadCompleted + * @copydoc TextureUploadObserver::LoadCompleted * * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. * This callback is the place to add the renderer as it would be called once the loading is finished. */ - void UploadComplete(bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied) override; - - /** - * @copydoc TextureUploadObserver::LoadComplete - * - * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. - * This callback is the place to add the renderer as it would be called once the loading is finished. - */ - void LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied) override; + void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override; private: WeakHandle mPlacementActor; ///< Weakhandle to contain Actor during texture loading diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.cpp b/dali-toolkit/internal/visuals/texture-manager-impl.cpp index 49867c4..3578ede 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.cpp +++ b/dali-toolkit/internal/visuals/texture-manager-impl.cpp @@ -179,7 +179,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture( TextureManager::LoadState loadState = GetTextureStateInternal(textureId); if(loadState == TextureManager::LoadState::UPLOADED) { - // UploadComplete has already been called - keep the same texture set + // LoadComplete has already been called - keep the same texture set textureSet = GetTextureSet(textureId); } } @@ -330,7 +330,7 @@ TextureSet TextureManager::LoadTexture( TextureManager::LoadState loadState = GetTextureStateInternal(textureId); if(loadState == TextureManager::LoadState::UPLOADED) { - // UploadComplete has already been called - keep the same texture set + // LoadComplete has already been called - keep the same texture set textureSet = GetTextureSet(textureId); } @@ -978,7 +978,7 @@ void TextureManager::LoadOrQueueTexture(TextureInfo& textureInfo, TextureUploadO { // The Texture has already loaded. The other observers have already been notified. // We need to send a "late" loaded notification for this observer. - observer->UploadComplete(true, textureInfo.textureId, textureInfo.textureSet, textureInfo.useAtlas, textureInfo.atlasRect, textureInfo.preMultiplied); + observer->LoadComplete(true, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, textureInfo.useAtlas, textureInfo.atlasRect, textureInfo.preMultiplied)); } break; } @@ -1040,11 +1040,11 @@ void TextureManager::ProcessQueuedTextures() TextureInfo& textureInfo(mTextureInfoContainer[cacheIndex]); if(textureInfo.loadState == LoadState::UPLOADED) { - element.mObserver->UploadComplete(true, textureInfo.textureId, textureInfo.textureSet, textureInfo.useAtlas, textureInfo.atlasRect, textureInfo.preMultiplied); + element.mObserver->LoadComplete(true, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, textureInfo.useAtlas, textureInfo.atlasRect, textureInfo.preMultiplied)); } else if(textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER) { - element.mObserver->LoadComplete(true, textureInfo.pixelBuffer, textureInfo.url, textureInfo.preMultiplied); + element.mObserver->LoadComplete(true, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied)); } else { @@ -1266,7 +1266,7 @@ void TextureManager::NotifyObservers(TextureInfo& textureInfo, bool success) { TextureUploadObserver* observer = info->observerList[0]; - // During UploadComplete() a Control ResourceReady() signal is emitted. + // During LoadComplete() a Control ResourceReady() signal is emitted. // During that signal the app may add remove /add Textures (e.g. via // ImageViews). // It is possible for observers to be removed from the observer list, @@ -1284,11 +1284,11 @@ void TextureManager::NotifyObservers(TextureInfo& textureInfo, bool success) if(info->storageType == StorageType::RETURN_PIXEL_BUFFER) { - observer->LoadComplete(success, info->pixelBuffer, info->url, info->preMultiplied); + observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, info->pixelBuffer, info->url.GetUrl(), info->preMultiplied)); } else { - observer->UploadComplete(success, info->textureId, info->textureSet, info->useAtlas, info->atlasRect, info->preMultiplied); + observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, info->textureId, info->textureSet, info->useAtlas, info->atlasRect, info->preMultiplied)); } // Get the textureInfo from the container again as it may have been invalidated. diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.h b/dali-toolkit/internal/visuals/texture-manager-impl.h index 7730d28..7ca7a05 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.h +++ b/dali-toolkit/internal/visuals/texture-manager-impl.h @@ -219,7 +219,7 @@ public: * @brief Requests an image load of the given URL. * * The parameters are used to specify how the image is loaded. - * The observer has the UploadComplete method called when the load is ready. + * The observer has the LoadComplete method called when the load is ready. * * When the client has finished with the Texture, Remove() should be called. * @@ -276,7 +276,7 @@ public: * @brief Requests an image load of the given URL. * * The parameters are used to specify how the image is loaded. - * The observer has the UploadComplete method called when the load is ready. + * The observer has the LoadComplete method called when the load is ready. * * When the client has finished with the Texture, Remove() should be called. * @@ -311,7 +311,7 @@ public: * the blended texture. * * The parameters are used to specify how the image is loaded. - * The observer has the UploadComplete method called when the load is ready. + * The observer has the LoadComplete method called when the load is ready. * * When the client has finished with the Texture, Remove() should be called. * @@ -469,7 +469,7 @@ private: * CPU blend with the mask, and upload the blend texture. * * The parameters are used to specify how the image is loaded. - * The observer has the UploadComplete method called when the load is ready. + * The observer has the LoadComplete method called when the load is ready. * * When the client has finished with the Texture, Remove() should be called. * @@ -752,12 +752,6 @@ private: bool CreateTiledGeometry(const Devel::PixelBuffer& pixelBuffer, TextureInfo& textureInfo); /** - * Mark the texture as complete, and inform observers - * @param[in] textureInfo The struct associated with this Texture - */ - void UploadComplete(TextureInfo& textureInfo); - - /** * Notify the current observers that the texture upload is complete, * then remove the observers from the list. * @param[in] textureInfo The struct associated with this Texture diff --git a/dali-toolkit/internal/visuals/texture-upload-observer.cpp b/dali-toolkit/internal/visuals/texture-upload-observer.cpp index 5c46ff2..6e18175 100644 --- a/dali-toolkit/internal/visuals/texture-upload-observer.cpp +++ b/dali-toolkit/internal/visuals/texture-upload-observer.cpp @@ -18,10 +18,37 @@ // CLASS HEADER #include "texture-upload-observer.h" +// INTERNAL INCLUDES +#include + namespace Dali { namespace Toolkit { +TextureUploadObserver::TextureInformation::TextureInformation(ReturnType returnType, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied) +: returnType(returnType), + textureId(textureId), + textureSet(textureSet), + useAtlasing(useAtlasing), + atlasRect(atlasRect), + preMultiplied(preMultiplied), + pixelBuffer(), + url() +{ +} + +TextureUploadObserver::TextureInformation::TextureInformation(ReturnType returnType, Devel::PixelBuffer pixelBuffer, const std::string& url, bool preMultiplied) +: returnType(returnType), + textureId(Internal::TextureManager::INVALID_TEXTURE_ID), + textureSet(), + useAtlasing(false), + atlasRect(Vector4::ZERO), + preMultiplied(preMultiplied), + pixelBuffer(pixelBuffer), + url(url) +{ +} + TextureUploadObserver::TextureUploadObserver() { } diff --git a/dali-toolkit/internal/visuals/texture-upload-observer.h b/dali-toolkit/internal/visuals/texture-upload-observer.h index d6657a2..4bb21e8 100644 --- a/dali-toolkit/internal/visuals/texture-upload-observer.h +++ b/dali-toolkit/internal/visuals/texture-upload-observer.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -28,14 +29,13 @@ namespace Dali { -class TextureSet; namespace Toolkit { /** * @brief Base class used to observe the upload status of a texture. * - * Derived class must implement the UploadComplete method which is + * Derived class must implement the LoadComplete method which is * executed once the texture is ready to draw. */ class TextureUploadObserver @@ -43,6 +43,30 @@ class TextureUploadObserver public: typedef Signal DestructionSignalType; ///< Signal prototype for the Destruction Signal. + enum class ReturnType + { + TEXTURE = 0, + PIXEL_BUFFER + }; + + struct TextureInformation + { + TextureInformation(ReturnType returnType, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied); + TextureInformation(ReturnType returnType, Devel::PixelBuffer pixelBuffer, const std::string& url, bool preMultiplied); + + TextureInformation(); + + ReturnType returnType; ///< Returned Texture type. + int32_t textureId; ///< The textureId of the loaded texture in the TextureManager + TextureSet textureSet; ///< The TextureSet containing the Texture + bool useAtlasing; ///< True if atlasing was used (note: this may be different to what was requested) + const Vector4& atlasRect; ///< If using atlasing, this is the rectangle within the atlas to use. + bool preMultiplied; ///< True if the image had pre-multiplied alpha applied + Devel::PixelBuffer pixelBuffer; ///< The PixelBuffer of the loaded image. + std::string_view url; ///< The url address of the loaded image. + }; + +public: /** * @brief Constructor. */ @@ -54,28 +78,14 @@ public: virtual ~TextureUploadObserver(); /** - * The action to be taken once the async load has finished and the upload to GPU is completed. - * This should be overridden by the deriving class. - * - * @param[in] loadSuccess True if the texture load was successful (i.e. the resource is available). If false, then the resource failed to load. In future, this will automatically upload a "broken" image. - * @param[in] textureId The textureId of the loaded texture in the TextureManager - * @param[in] textureSet The TextureSet containing the Texture - * @param[in] useAtlasing True if atlasing was used (note: this may be different to what was requested) - * @param[in] atlasRect If using atlasing, this is the rectangle within the atlas to use. - * @param[in] preMultiplied True if the image had pre-multiplied alpha applied - */ - virtual void UploadComplete(bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied) = 0; - - /** * The action to be taken once the async load has finished. + * And in case of texture loading, this method is called after uploading. * This should be overridden by the deriving class. * - * @param[in] loadSuccess True if the image load was successful (i.e. the resource is available). If false, then the resource failed to load. - * @param[in] pixelBuffer The PixelBuffer of the loaded image. - * @param[in] url The url address of the loaded image. - * @param[in] preMultiplied True if the image had pre-multiplied alpha applied + * @param[in] loadSuccess True if the texture load was successful (i.e. the resource is available). If false, then the resource failed to load. In future, this will automatically upload a "broken" image. + * @param[in] textureInformation Structure that contains loaded texture information. */ - virtual void LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const Internal::VisualUrl& url, bool preMultiplied) = 0; + virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) = 0; /** * @brief Returns the destruction signal. -- 2.7.4