FixedImageCache::~FixedImageCache()
{
- for( std::size_t i = 0; i < mImageUrls.size() ; ++i )
+ if( mTextureManagerAlive )
{
- mTextureManager.Remove( mImageUrls[i].mTextureId );
+ for( std::size_t i = 0; i < mImageUrls.size() ; ++i )
+ {
+ mTextureManager.Remove( mImageUrls[i].mTextureId );
+ }
}
}
mBatchSize( batchSize ),
mUrlIndex(0u),
mWaitingForReadyFrame(false),
- mRequestingLoad(false)
+ mRequestingLoad(false),
+ mTextureManagerAlive(true)
{
+ mTextureManager.AddObserver( *this );
}
ImageCache::~ImageCache()
{
+ if( mTextureManagerAlive )
+ {
+ mTextureManager.RemoveObserver( *this );
+ }
+}
+
+void ImageCache::TextureManagerDestroyed()
+{
+ mTextureManagerAlive = false;
}
} //namespace Internal
namespace Internal
{
-class ImageCache
+class ImageCache : public TextureManager::LifecycleObserver
{
public:
/**
*/
virtual TextureSet NextFrame() = 0;
+private:
+ /**
+ * Called before the texture manager is destroyed.
+ */
+ virtual void TextureManagerDestroyed() override final;
+
protected:
TextureManager& mTextureManager;
FrameReadyObserver& mObserver;
unsigned int mUrlIndex;
bool mWaitingForReadyFrame:1;
bool mRequestingLoad:1;
+ bool mTextureManagerAlive:1;
};
} //namespace Internal
RollingGifImageCache::~RollingGifImageCache()
{
- while( !mQueue.IsEmpty() )
+ if( mTextureManagerAlive )
{
- ImageFrame imageFrame = mQueue.PopFront();
- Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl );
+ while( !mQueue.IsEmpty() )
+ {
+ ImageFrame imageFrame = mQueue.PopFront();
+ Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl );
+ }
}
}
+
TextureSet RollingGifImageCache::FirstFrame()
{
return GetFrontTextureSet();
RollingImageCache::~RollingImageCache()
{
- while( !mQueue.IsEmpty() )
+ if( mTextureManagerAlive )
{
- ImageFrame imageFrame = mQueue.PopFront();
- mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId );
+ while( !mQueue.IsEmpty() )
+ {
+ ImageFrame imageFrame = mQueue.PopFront();
+ mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId );
+ }
}
}
{
}
+TextureManager::~TextureManager()
+{
+ for( auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
+ {
+ (*iter)->TextureManagerDestroyed();
+ }
+}
+
TextureSet TextureManager::LoadTexture(
const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
Dali::SamplingMode::Type samplingMode, const MaskingDataPointer& maskInfo,
return TextureSet();
}
+
+void TextureManager::AddObserver( TextureManager::LifecycleObserver& observer )
+{
+ // make sure an observer doesn't observe the same object twice
+ // otherwise it will get multiple calls to ObjectDestroyed()
+ DALI_ASSERT_DEBUG( mLifecycleObservers.End() == std::find( mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
+ mLifecycleObservers.PushBack( &observer );
+}
+
+void TextureManager::RemoveObserver( TextureManager::LifecycleObserver& observer)
+{
+ // Find the observer...
+ auto endIter = mLifecycleObservers.End();
+ for( auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
+ {
+ if( (*iter) == &observer)
+ {
+ mLifecycleObservers.Erase( iter );
+ break;
+ }
+ }
+ DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
+}
+
+
bool TextureManager::LoadTexture( TextureInfo& textureInfo )
{
bool success = true;
};
using MaskingDataPointer = std::unique_ptr<MaskingData>;
+
+ /**
+ * Class to provide lifecycle event on destruction of texture manager.
+ */
+ struct LifecycleObserver
+ {
+ /**
+ * Called shortly before the texture manager is destroyed.
+ */
+ virtual void TextureManagerDestroyed() = 0;
+ };
+
/**
* Constructor.
*/
/**
* Destructor.
*/
- ~TextureManager() = default;
-
+ ~TextureManager();
// TextureManager Main API:
*/
TextureSet RemoveExternalTexture( const std::string& url );
+ /**
+ * Add an observer to the object.
+ * @param[in] observer The observer to add.
+ */
+ void AddObserver( TextureManager::LifecycleObserver& observer );
+
+ /**
+ * Remove an observer from the object
+ * @pre The observer has already been added.
+ * @param[in] observer The observer to remove.
+ */
+ void RemoveObserver( TextureManager::LifecycleObserver& observer );
+
private:
/**
RoundRobinContainerView< AsyncLoadingHelper > mAsyncLocalLoaders; ///< The Asynchronous image loaders used to provide all local async loads
RoundRobinContainerView< AsyncLoadingHelper > mAsyncRemoteLoaders; ///< The Asynchronous image loaders used to provide all remote async loads
std::vector< ExternalTextureInfo > mExternalTextures; ///< Externally provided textures
+ Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
TextureId mCurrentTextureId; ///< The current value used for the unique Texture Id generation
};
const unsigned int TOOLKIT_MAJOR_VERSION = 1;
const unsigned int TOOLKIT_MINOR_VERSION = 3;
-const unsigned int TOOLKIT_MICRO_VERSION = 11;
+const unsigned int TOOLKIT_MICRO_VERSION = 12;
const char * const TOOLKIT_BUILD_DATE = __DATE__ " " __TIME__;
#ifdef DEBUG_ENABLED
Name: dali-toolkit
Summary: Dali 3D engine Toolkit
-Version: 1.3.11
+Version: 1.3.12
Release: 1
Group: System/Libraries
License: Apache-2.0 and BSD-3-Clause and MIT