From: David Steele Date: Thu, 2 Mar 2017 19:22:04 +0000 (+0000) Subject: Removed the renderer cache X-Git-Tag: dali_1.2.30~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=39d4d89a9cc3bcd134922827d7009b2188fe7ffe;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Removed the renderer cache Removing the renderer cache helps prevent bugs with animating properties on one visual affecting other visuals of the same type with the same URL. Change-Id: I683d88fbb3459df85a1df68a4cbc5e0408414fc2 Signed-off-by: David Steele --- diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index aa3c118..812e854 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -499,11 +499,13 @@ void ImageVisual::CreateNativeImageRenderer( NativeImage& nativeImage ) std::string fragmentShader; const char* fragmentPreFix = nativeImage.GetCustomFragmentPreFix(); const char* customSamplerTypename = nativeImage.GetCustomSamplerTypename(); + if( fragmentPreFix ) { fragmentShader = fragmentPreFix; fragmentShader += "\n"; } + if( mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty() ) { fragmentShader += mImpl->mCustomShader->mFragmentShader; @@ -512,6 +514,7 @@ void ImageVisual::CreateNativeImageRenderer( NativeImage& nativeImage ) { fragmentShader += FRAGMENT_SHADER_NO_ATLAS; } + if( customSamplerTypename ) { fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename ); @@ -624,52 +627,27 @@ void ImageVisual::InitializeRenderer( const std::string& imageUrl ) ( strncasecmp( imageUrl.c_str(), HTTPS_URL, sizeof(HTTPS_URL) -1 ) != 0 ) ) { bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE; - bool defaultTransform = mImpl->mTransform.mSize == Vector2::ONE && - mImpl->mTransform.mOffset == Vector2::ZERO && - mImpl->mTransform.mOffsetSizeMode == Vector4::ZERO && - mImpl->mTransform.mOrigin == Toolkit::Align::CENTER && - mImpl->mTransform.mAnchorPoint == Toolkit::Align::CENTER; - - bool cacheable = defaultWrapMode && defaultTransform && mPixelArea == FULL_TEXTURE_RECT; + Vector4 atlasRect; + // texture set has to be created first as we need to know if atlasing succeeded or not + // when selecting the shader + TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true ); + CreateRenderer( textures ); - mImpl->mFlags &= ~Impl::IS_FROM_CACHE; - if( cacheable ) // fetch the renderer from cache if exist - { - mImpl->mRenderer = mFactoryCache.GetRenderer( imageUrl ); - mImpl->mFlags |= Impl::IS_FROM_CACHE; - } - - if( !mImpl->mRenderer ) // new renderer is needed + if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas { - Vector4 atlasRect; - // texture set has to be created first as we need to know if atlasing succeeded or not - // when selecting the shader - TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true ); - CreateRenderer( textures ); - - if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas + mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect ); + if( !defaultWrapMode ) // custom wrap mode, renderer is not cached. { - mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect ); - if( !defaultWrapMode ) // custom wrap mode, renderer is not cached. - { - Vector2 wrapMode(mWrapModeU-WrapMode::CLAMP_TO_EDGE, mWrapModeV-WrapMode::CLAMP_TO_EDGE); - wrapMode.Clamp( Vector2::ZERO, Vector2( 2.f, 2.f ) ); - mImpl->mRenderer.RegisterProperty( WRAP_MODE_UNIFORM_NAME, wrapMode ); - } - } - - // save the renderer to cache only when default wrap mode and default pixel area is used - if( cacheable ) - { - mFactoryCache.SaveRenderer( imageUrl, mImpl->mRenderer ); + Vector2 wrapMode(mWrapModeU-WrapMode::CLAMP_TO_EDGE, mWrapModeV-WrapMode::CLAMP_TO_EDGE); + wrapMode.Clamp( Vector2::ZERO, Vector2( 2.f, 2.f ) ); + mImpl->mRenderer.RegisterProperty( WRAP_MODE_UNIFORM_NAME, wrapMode ); } } } else { - // for custom shader or remote image, renderer is not cached and atlas is not applied - mImpl->mFlags &= ~Impl::IS_FROM_CACHE; + // for custom shader or remote image, atlas is not applied Vector4 atlasRect; // ignored in this case TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), false ); CreateRenderer( textures ); @@ -678,10 +656,9 @@ void ImageVisual::InitializeRenderer( const std::string& imageUrl ) void ImageVisual::InitializeRenderer( const Image& image ) { - mImpl->mFlags &= ~Impl::IS_FROM_CACHE; - // don't reuse CreateTextureSet TextureSet textures = TextureSet::New(); + // Renderer can't be shared if mImage is NativeImage NativeImage nativeImage = NativeImage::DownCast( image ); if( nativeImage ) @@ -748,7 +725,7 @@ void ImageVisual::DoSetOffStage( Actor& actor ) actor.RemoveRenderer( mImpl->mRenderer); if( !mImageUrl.empty() ) { - CleanCache(mImageUrl); + RemoveFromAtlas(mImageUrl); mImage.Reset(); } @@ -879,24 +856,22 @@ void ImageVisual::OnImageLoaded( ResourceImage image ) } } -void ImageVisual::CleanCache(const std::string& url) +void ImageVisual::RemoveFromAtlas(const std::string& url) { - if( IsFromCache() ) + Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f ); + Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME ); + if( index != Property::INVALID_INDEX ) { - Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f ); - Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME ); - if( index != Property::INVALID_INDEX ) - { - Property::Value atlasRectValue = mImpl->mRenderer.GetProperty( index ); - atlasRectValue.Get( atlasRect ); - } + Property::Value atlasRectValue = mImpl->mRenderer.GetProperty( index ); + atlasRectValue.Get( atlasRect ); + } - TextureSet textureSet = mImpl->mRenderer.GetTextures(); - mImpl->mRenderer.Reset(); - if( mFactoryCache.CleanRendererCache( url ) && index != Property::INVALID_INDEX ) - { - mFactoryCache.GetAtlasManager()->Remove( textureSet, atlasRect ); - } + TextureSet textureSet = mImpl->mRenderer.GetTextures(); + mImpl->mRenderer.Reset(); + + if( index != Property::INVALID_INDEX ) + { + mFactoryCache.GetAtlasManager()->Remove( textureSet, atlasRect ); } } diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index b0cc262..bf71048 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -296,9 +296,9 @@ private: void SetTextureRectUniform( const Vector4& textureRect ); /** - * Clean the renderer from cache, and remove the image from atlas if it is not used anymore + * Remove the image from atlas if it is not used anymore. */ - void CleanCache(const std::string& url); + void RemoveFromAtlas(const std::string& url); /** * Helper method to set individual values by index key. diff --git a/dali-toolkit/internal/visuals/visual-base-data-impl.h b/dali-toolkit/internal/visuals/visual-base-data-impl.h index 347cf7d..8b235f8 100644 --- a/dali-toolkit/internal/visuals/visual-base-data-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-data-impl.h @@ -53,10 +53,9 @@ struct Base::Impl enum Flags { IS_ON_STAGE = 1, - IS_FROM_CACHE = 1 << 1, - IS_ATLASING_APPLIED = 1<<2, - IS_PREMULTIPLIED_ALPHA = 1 << 3, - IS_SYNCHRONOUS_RESOURCE_LOADING = 1 << 4 + IS_ATLASING_APPLIED = 1<<1, + IS_PREMULTIPLIED_ALPHA = 1 << 2, + IS_SYNCHRONOUS_RESOURCE_LOADING = 1 << 3 }; struct CustomShader diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index bfd5293..c61aeba 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -334,11 +334,6 @@ bool Visual::Base::IsOnStage() const return mImpl->mFlags & Impl::IS_ON_STAGE; } -bool Visual::Base::IsFromCache() const -{ - return mImpl->mFlags & Impl::IS_FROM_CACHE; -} - void Visual::Base::RegisterMixColor() { // Only register if not already registered. diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 15b2539..ae8a35f 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -278,13 +278,6 @@ protected: */ bool IsOnStage() const; - /** - * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer) - * - * @return Returns true if the renderer is from shared cache, false otherwise - */ - bool IsFromCache() const; - private: /** diff --git a/dali-toolkit/internal/visuals/visual-factory-cache.cpp b/dali-toolkit/internal/visuals/visual-factory-cache.cpp index 03f31de..dd8d306 100644 --- a/dali-toolkit/internal/visuals/visual-factory-cache.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-cache.cpp @@ -75,86 +75,6 @@ void VisualFactoryCache::SaveShader( ShaderType type, Shader shader ) mShader[type] = shader; } -int VisualFactoryCache::FindRenderer( const std::string& key ) const -{ - int hash = Dali::CalculateHash( key ); - - HashVector::Iterator startIt = mRendererHashes.Begin(); - HashVector::Iterator it; - - for(;;) - { - it = std::find( startIt, mRendererHashes.End(), hash ); - if( it != mRendererHashes.End() ) - { - int index = it - mRendererHashes.Begin(); - const CachedRenderer* cachedRenderer = mRenderers[ index ]; - - if( cachedRenderer && cachedRenderer->mKey == key ) - { - return index; - } - } - else - { - break; - } - startIt = it + 1; - } - - return -1; -} - -Renderer VisualFactoryCache::GetRenderer( const std::string& key ) const -{ - int index = FindRenderer( key ); - if( index != -1 ) - { - return mRenderers[ index ]->mRenderer.GetHandle(); - } - else - { - return Renderer(); - } -} - -void VisualFactoryCache::SaveRenderer( const std::string& key, Renderer& renderer ) -{ - int hash = Dali::CalculateHash( key ); - const CachedRenderer* cachedRenderer = new CachedRenderer( key, renderer ); - - CachedRenderers::Iterator it = std::find( mRenderers.Begin(), mRenderers.End(), static_cast< CachedRenderer* >( NULL ) ); - if( it != mRenderers.End() ) - { - *it = cachedRenderer; - int index = it - mRenderers.Begin(); - mRendererHashes[ index ] = hash; - } - else - { - mRendererHashes.PushBack( hash ); - mRenderers.PushBack( cachedRenderer ); - } -} - -bool VisualFactoryCache::CleanRendererCache( const std::string& key ) -{ - int index = FindRenderer( key ); - if( index != -1 ) - { - const CachedRenderer*& cachedRenderer = mRenderers[ index ]; - if( !cachedRenderer->mRenderer.GetHandle() ) - { - mRendererHashes[ index ] = Dali::INITIAL_HASH_VALUE; - - delete cachedRenderer; - cachedRenderer = NULL; - return true; - } - } - return false; -} - Geometry VisualFactoryCache::CreateQuadGeometry() { const float halfWidth = 0.5f; @@ -294,4 +214,3 @@ Image VisualFactoryCache::GetBrokenVisualImage() } // namespace Toolkit } // namespace Dali - diff --git a/dali-toolkit/internal/visuals/visual-factory-cache.h b/dali-toolkit/internal/visuals/visual-factory-cache.h index c674aac..470cf07 100644 --- a/dali-toolkit/internal/visuals/visual-factory-cache.h +++ b/dali-toolkit/internal/visuals/visual-factory-cache.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -139,34 +138,6 @@ public: static Image GetBrokenVisualImage(); public: - - /** - * @brief Request renderer from the url - * - * @return The cached renderer if exist in the cache. Otherwise an empty handle is returned. - */ - Renderer GetRenderer( const std::string& key ) const; - - /** - * @brief Cache the renderer based on the given key. - * - * If the key already exists in the cache, then the cache will save an additional renderer to the cache. - * RemoveRenderer will then need to be called twice to remove both items from the cache. - * - * @param[in] key The key to use for caching - * @param[in] renderer The Renderer to be cached - */ - void SaveRenderer( const std::string& key, Renderer& renderer ); - - /** - * @brief Cleans the renderer cache by removing the renderer from the cache based on the given key if there are no longer any references to it - * - * @param[in] key The key used for caching - * - * @return True if the renderer is no longer used anywhere, false otherwise - */ - bool CleanRendererCache( const std::string& key ); - /** * Get the image atlas manager. * @return A pointer to the atlas manager @@ -210,36 +181,9 @@ protected: VisualFactoryCache& operator=(const VisualFactoryCache& rhs); private: - struct CachedRenderer - { - std::string mKey; - WeakHandle< Renderer > mRenderer; - - CachedRenderer( const std::string& key, Renderer& renderer ) - : mKey( key ), - mRenderer( renderer) - {} - }; - - typedef Dali::Vector< std::size_t > HashVector; - typedef Dali::OwnerContainer< const CachedRenderer* > CachedRenderers; - - /** - * @brief Finds the first index into the cached visuals from the url - * - * @return Returns the first index into the cached renderer from the url if it exists in the cache, otherwise returns -1 - */ - int FindRenderer( const std::string& key ) const; - -private: Geometry mGeometry[GEOMETRY_TYPE_MAX+1]; Shader mShader[SHADER_TYPE_MAX+1]; - HashVector mRendererHashes; - CachedRenderers mRenderers; - - Renderer mWireframeRenderer; - ImageAtlasManagerPtr mAtlasManager; NPatchLoader mNPatchLoader;