From 0f548619463110abcd5c2b8d6787491110188da8 Mon Sep 17 00:00:00 2001 From: Richard Underhill Date: Wed, 18 Mar 2015 13:54:12 +0000 Subject: [PATCH] Added metrics logging to TextAtlasRenderer Enable Logging with environment variable for concise logging LOG_TEXT_ATLAS_RENDERER=2,true for verbose logging LOG_TEXT_ATLAS_RENDERER=4,true Change-Id: Ica0d01174c642f7b6b538d4f09933656c4d26ec9 Signed-off-by: Richard Underhill --- .../internal/atlas-manager/atlas-manager-impl.cpp | 66 ++++++++++++++++---- .../internal/atlas-manager/atlas-manager-impl.h | 16 ++++- .../internal/atlas-manager/atlas-manager.cpp | 16 ++++- .../internal/atlas-manager/atlas-manager.h | 70 ++++++++++++++++++---- .../rendering/atlas/atlas-glyph-manager-impl.cpp | 13 +++- .../rendering/atlas/atlas-glyph-manager-impl.h | 12 +++- .../text/rendering/atlas/atlas-glyph-manager.cpp | 11 +++- .../text/rendering/atlas/atlas-glyph-manager.h | 23 ++++++- .../text/rendering/atlas/text-atlas-renderer.cpp | 30 +++++++++- 9 files changed, 210 insertions(+), 47 deletions(-) diff --git a/dali-toolkit/internal/atlas-manager/atlas-manager-impl.cpp b/dali-toolkit/internal/atlas-manager/atlas-manager-impl.cpp index 15e9684..34cc0c1 100644 --- a/dali-toolkit/internal/atlas-manager/atlas-manager-impl.cpp +++ b/dali-toolkit/internal/atlas-manager/atlas-manager-impl.cpp @@ -67,7 +67,7 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( SizeType width, // Check to see if the atlas is large enough to hold a single block even ? if ( blockWidth > width || blockHeight > height ) { - DALI_LOG_ERROR("Atlas %i x %i too small. Dimensions need to be at least %i x %i\n", + DALI_LOG_ERROR("Atlas %i x %i too small. Dimensions need to be at least %ix%i\n", width, height, blockWidth, blockHeight ); return 0; } @@ -693,8 +693,8 @@ AtlasManager::AtlasId AtlasManager::GetAtlas( ImageId id ) const } } -void AtlasManager::SetAtlasSize( const Vector2& size, - const Vector2& blockSize ) +void AtlasManager::SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ) { mNewAtlasSize = size; mNewBlockSize = blockSize; @@ -713,6 +713,19 @@ Vector2 AtlasManager::GetBlockSize( AtlasId atlas ) } } +Vector2 AtlasManager::GetAtlasSize( AtlasId atlas ) +{ + if ( atlas && atlas <= mAtlasList.size() ) + { + return Vector2( static_cast< float >( mAtlasList[ atlas - 1u ].mWidth ), + static_cast< float >( mAtlasList[ atlas - 1u ].mHeight ) ); + } + else + { + return Vector2( 0.0f, 0.0f ); + } +} + AtlasManager::SizeType AtlasManager::GetFreeBlocks( AtlasId atlas ) const { if ( atlas && atlas <= mAtlasList.size() ) @@ -723,18 +736,8 @@ AtlasManager::SizeType AtlasManager::GetFreeBlocks( AtlasId atlas ) const uint32_t blockWidth = mAtlasList[ index ].mBlockWidth; uint32_t blockHeight = mAtlasList[ index ].mBlockHeight; - //Work out how many blocks wide and high our bitmap is in the atlas' block size SizeType widthInBlocks = width / blockWidth; - if ( width % blockWidth ) - { - widthInBlocks++; - } SizeType heightInBlocks = height / blockHeight; - if ( height % blockHeight ) - { - heightInBlocks++; - } - uint32_t blockCount = widthInBlocks * heightInBlocks; // Check free previously unallocated blocks and any free blocks @@ -763,6 +766,43 @@ Pixel::Format AtlasManager::GetPixelFormat( AtlasId atlas ) return mAtlasList[ atlas -1u ].mPixelFormat; } +void AtlasManager::GetMetrics( Toolkit::AtlasManager::Metrics& metrics ) +{ + Toolkit::AtlasManager::AtlasMetricsEntry entry; + uint32_t textureMemoryUsed = 0; + uint32_t atlasCount = mAtlasList.size(); + metrics.mAtlasCount = atlasCount; + metrics.mAtlasMetrics.Resize(0); + + for ( uint32_t i = 0; i < atlasCount; ++i ) + { + SizeType width = mAtlasList[ i ].mWidth; + SizeType height = mAtlasList[ i ].mHeight; + SizeType blockWidth = mAtlasList[ i ].mBlockWidth; + SizeType blockHeight = mAtlasList[ i ].mBlockHeight; + + entry.mWidth = width; + entry.mHeight = height; + entry.mBlockWidth = blockWidth; + entry.mBlockHeight = blockHeight; + entry.mTotalBlocks = ( width / blockWidth ) * ( height / blockHeight ); + entry.mBlocksUsed = mAtlasList[ i ].mNextFreeBlock ? mAtlasList[ i ].mNextFreeBlock : entry.mTotalBlocks - mAtlasList[ i ].mFreeBlocksList.Size(); + entry.mPixelFormat = GetPixelFormat( i + 1 ); + + metrics.mAtlasMetrics.PushBack( entry ); + + uint32_t size = width * height; + if ( entry.mPixelFormat == Pixel::BGRA8888 ) + { + size <<= 2; + } + + textureMemoryUsed += size; + + } + metrics.mTextureMemoryUsed = textureMemoryUsed; +} + } // namespace Internal diff --git a/dali-toolkit/internal/atlas-manager/atlas-manager-impl.h b/dali-toolkit/internal/atlas-manager/atlas-manager-impl.h index 6393762..d120f4f 100644 --- a/dali-toolkit/internal/atlas-manager/atlas-manager-impl.h +++ b/dali-toolkit/internal/atlas-manager/atlas-manager-impl.h @@ -148,10 +148,15 @@ public: AtlasId GetAtlas( ImageId id ) const; /** - * @copydoc Toolkit::AtlasManager::SetAtlasSize + * @copydoc Toolkit::AtlasManager::SetNewAtlasSize */ - void SetAtlasSize( const Vector2& size, - const Vector2& blockSize ); + void SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ); + + /** + * @copydoc Toolkit::AtlasManager::GetAtlasSize + */ + Vector2 GetAtlasSize( AtlasId atlas ); /** * @copydoc Toolkit::AtlasManager::GetBlockSize @@ -173,6 +178,11 @@ public: */ Pixel::Format GetPixelFormat( AtlasId atlas ); + /** + * @copydoc Toolkit::AtlasManager::GetMetrics + */ + void GetMetrics( Toolkit::AtlasManager::Metrics& metrics ); + private: std::vector< AtlasDescriptor > mAtlasList; // List of atlases created diff --git a/dali-toolkit/internal/atlas-manager/atlas-manager.cpp b/dali-toolkit/internal/atlas-manager/atlas-manager.cpp index 85d6cba..6d21245 100644 --- a/dali-toolkit/internal/atlas-manager/atlas-manager.cpp +++ b/dali-toolkit/internal/atlas-manager/atlas-manager.cpp @@ -110,15 +110,20 @@ Vector2 AtlasManager::GetBlockSize( AtlasId atlas ) return GetImplementation(*this).GetBlockSize( atlas ); } +Vector2 AtlasManager::GetAtlasSize( AtlasId atlas ) +{ + return GetImplementation(*this).GetAtlasSize( atlas ); +} + AtlasManager::SizeType AtlasManager::GetFreeBlocks( AtlasId atlas ) { return GetImplementation(*this).GetFreeBlocks( atlas ); } -void AtlasManager::SetAtlasSize( const Vector2& size, - const Vector2& blockSize ) +void AtlasManager::SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ) { - GetImplementation(*this).SetAtlasSize( size, blockSize ); + GetImplementation(*this).SetNewAtlasSize( size, blockSize ); } AtlasManager::SizeType AtlasManager::GetAtlasCount() const @@ -131,6 +136,11 @@ Pixel::Format AtlasManager::GetPixelFormat( AtlasId atlas ) return GetImplementation(*this).GetPixelFormat( atlas ); } +void AtlasManager::GetMetrics( Metrics& metrics ) +{ + return GetImplementation(*this).GetMetrics( metrics ); +} + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/internal/atlas-manager/atlas-manager.h b/dali-toolkit/internal/atlas-manager/atlas-manager.h index 55612ff..9263ea4 100644 --- a/dali-toolkit/internal/atlas-manager/atlas-manager.h +++ b/dali-toolkit/internal/atlas-manager/atlas-manager.h @@ -161,6 +161,28 @@ public: static const bool MESH_OPTIMIZE = true; /** + * Metrics structures to describe Atlas Manager state + * + */ + struct AtlasMetricsEntry + { + SizeType mWidth; // width of the atlas in pixels + SizeType mHeight;; // height of the atlas in pixels + SizeType mBlockWidth; // width of a block in pixels + SizeType mBlockHeight; // height of a block in pixels + SizeType mBlocksUsed; // number of blocks used in the atlas + SizeType mTotalBlocks; // total blocks used by atlas + Pixel::Format mPixelFormat; // pixel format of the atlas + }; + + struct Metrics + { + SizeType mAtlasCount; // number of atlases + SizeType mTextureMemoryUsed; // texture memory used by atlases + Dali::Vector< AtlasMetricsEntry > mAtlasMetrics; // container of atlas information + }; + + /** * Create an AtlasManager handle; this can be initialised with AtlasManager::New() * Calling member functions with an uninitialised handle is not allowed. */ @@ -203,11 +225,11 @@ public: /** * @brief Create a blank atlas of specific dimensions and pixel format with a certain block size * - * @param width desired atlas width in pixels - * @param height desired atlas height in pixels - * @param blockWidth block width to use in atlas in pixels - * @param blockHeight block height to use in atlas in pixels - * @param pixelformat format of a pixel in atlas + * @param[in] width desired atlas width in pixels + * @param[in] height desired atlas height in pixels + * @param[in] blockWidth block width to use in atlas in pixels + * @param[in] blockHeight block height to use in atlas in pixels + * @param[in] pixelformat format of a pixel in atlas * * @return atlas Id */ @@ -286,7 +308,8 @@ public: /** * @brief Get the BufferImage containing an atlas * - * @param atlas AtlasId returned when atlas was created + * @param[in] atlas AtlasId returned when atlas was created + * * @return Atlas Handle */ Dali::Atlas GetAtlasContainer( AtlasId atlas ) const; @@ -294,7 +317,8 @@ public: /** * @brief Get the Id of the atlas containing an image * - * @param id ImageId + * @param[in] id ImageId + * * @return Atlas Id */ AtlasId GetAtlas( ImageId id ); @@ -302,15 +326,26 @@ public: /** * @brief Get the size of the blocks used in an atlas * - * @param atlas AtlasId + * @param[in] atlas AtlasId + * * @return width and height of the blocks used */ Vector2 GetBlockSize( AtlasId atlas ); /** + * @brief Get the current size of an atlas + * + * @param[in] atlas AtlasId + * + * @return width and height of the atlas + */ + Vector2 GetAtlasSize( AtlasId atlas ); + + /** * @brief Get the number of blocks available in an atlas * - * @param atlas AtlasId + * @param[in] atlas AtlasId + * * @return Number of blocks free in this atlas */ SizeType GetFreeBlocks( AtlasId atlas ); @@ -318,11 +353,12 @@ public: /** * @brief Sets the pixel area of any new atlas and also the individual block size * - * @param size pixel area of atlas + * @param[in] size pixel area of atlas + * * @param blockSize pixel area in atlas for a block */ - void SetAtlasSize( const Vector2& size, - const Vector2& blockSize ); + void SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ); /** * @brief Get the number of atlases created @@ -334,11 +370,19 @@ public: /** * @brief Get the pixel format used by an atlas * - * @param atlas AtlasId + * @param[in] atlas AtlasId + * * @return Pixel format used by this atlas */ Pixel::Format GetPixelFormat( AtlasId atlas ); + /** + * @brief Fill in a metrics structure showing current status of this Atlas Manager + * + * @param[in] metrics metrics structure to be filled + */ + void GetMetrics( Metrics& metrics ); + private: explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl); diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp index 001281e..03091e5 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp @@ -108,10 +108,10 @@ void AtlasGlyphManager::Cached( Text::FontId fontId, slot.mImageId = 0; } -void AtlasGlyphManager::SetAtlasSize( const Vector2& size, - const Vector2& blockSize ) +void AtlasGlyphManager::SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ) { - mAtlasManager.SetAtlasSize( size, blockSize ); + mAtlasManager.SetNewAtlasSize( size, blockSize ); } void AtlasGlyphManager::Remove( uint32_t imageId ) @@ -134,6 +134,13 @@ Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId ) return mAtlasManager.GetPixelFormat( atlasId ); } +const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() +{ + mMetrics.mGlyphCount = mGlyphRecords.Size(); + mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics ); + return mMetrics; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h index c4da1ba..868add6 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h @@ -93,10 +93,10 @@ public: Dali::Toolkit::AtlasManager::AtlasSlot& slot ); /** - * @copydoc Toolkit::AtlasGlyphManager::SetAtlasSize + * @copydoc Toolkit::AtlasGlyphManager::SetNewAtlasSize */ - void SetAtlasSize( const Vector2& size, - const Vector2& blockSize ); + void SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ); /** * @copydoc Toolkit::AtlasGlyphManager::Remove @@ -108,11 +108,17 @@ public: */ Pixel::Format GetPixelFormat( uint32_t atlasId ); + /** + * @copydoc toolkit::AtlasGlyphManager::GetMetrics + */ + const Toolkit::AtlasGlyphManager::Metrics& GetMetrics(); + private: Dali::Toolkit::AtlasManager mAtlasManager; Vector< GlyphRecord > mGlyphRecords; uint32_t mCount; + Toolkit::AtlasGlyphManager::Metrics mMetrics; }; } // namespace Internal diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp index 9ca3773..275836c 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp @@ -98,10 +98,10 @@ void AtlasGlyphManager::Cached( Text::FontId fontId, GetImplementation(*this).Cached( fontId, index, slot ); } -void AtlasGlyphManager::SetAtlasSize( const Vector2& size, - const Vector2& blockSize ) +void AtlasGlyphManager::SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ) { - GetImplementation(*this).SetAtlasSize( size, blockSize ); + GetImplementation(*this).SetNewAtlasSize( size, blockSize ); } void AtlasGlyphManager::Remove( uint32_t imageId ) @@ -114,6 +114,11 @@ Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId ) return GetImplementation(*this).GetPixelFormat( atlasId ); } +const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() +{ + return GetImplementation(*this).GetMetrics(); +} + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h index a90efdb..6a53481 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h @@ -39,6 +39,15 @@ class DALI_IMPORT_API AtlasGlyphManager : public BaseHandle public: /** + * Description of GlyphManager state + */ + struct Metrics + { + uint32_t mGlyphCount; // number of glyphs being managed + AtlasManager::Metrics mAtlasMetrics; // metrics from the Atlas Manager + }; + + /** * @brief Create a AtlasGlyphManager handle. * * Calling member functions with an uninitialised handle is not allowed. @@ -107,8 +116,8 @@ public: * @param[in] size size of the atlas in pixels * @param[in] blockSize size of a block in this atlas in pixels */ - void SetAtlasSize( const Vector2& size, - const Vector2& blockSize ); + void SetNewAtlasSize( const Vector2& size, + const Vector2& blockSize ); /** * @brief Unreference an image from the atlas and remove from cache if no longer needed @@ -120,11 +129,19 @@ public: /** * @brief Get the Pixel Format used by an atlas * - * @param atlasId Id of atlas to check + * @param[in] atlasId Id of atlas to check + * * @return The pixel format of the atlas */ Pixel::Format GetPixelFormat( uint32_t atlasId ); + /** + * @brief Get Glyph Manager metrics + * + * @return const reference to glyph manager metrics + */ + const Metrics& GetMetrics(); + private: explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager *impl); diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index 77c6732..41dfac9 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -27,6 +28,10 @@ #include #include +#if defined(DEBUG_ENABLED) +Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_ATLAS_RENDERER"); +#endif + using namespace Dali; using namespace Dali::Toolkit; using namespace Dali::Toolkit::Text; @@ -35,7 +40,7 @@ namespace { const Vector2 DEFAULT_ATLAS_SIZE( 512.0f, 512.0f ); const Vector2 DEFAULT_BLOCK_SIZE( 16.0f, 16.0f ); - const Vector2 PADDING( 2.0f, 2.0f ); + const Vector2 PADDING( 4.0f, 4.0f ); // Allow for variation in font glyphs } struct AtlasRenderer::Impl @@ -64,7 +69,7 @@ struct AtlasRenderer::Impl { mGlyphManager = AtlasGlyphManager::Get(); mFontClient = TextAbstraction::FontClient::Get(); - mGlyphManager.SetAtlasSize( DEFAULT_ATLAS_SIZE, DEFAULT_BLOCK_SIZE ); + mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_SIZE, DEFAULT_BLOCK_SIZE ); mBasicShader = BasicShader::New(); mBGRAShader = BgraShader::New(); } @@ -110,7 +115,7 @@ struct AtlasRenderer::Impl { if ( mBlockSizes[ j ].mFontId == glyph.fontId ) { - mGlyphManager.SetAtlasSize( DEFAULT_ATLAS_SIZE, mBlockSizes[ j ].mNeededBlockSize ); + mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_SIZE, mBlockSizes[ j ].mNeededBlockSize ); } } lastFontId = glyph.fontId; @@ -165,6 +170,25 @@ struct AtlasRenderer::Impl } mActor.OffStageSignal().Connect( mSlotDelegate, &AtlasRenderer::Impl::OffStageDisconnect ); } +#if defined(DEBUG_ENABLED) + Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics(); + DALI_LOG_INFO( gLogFilter, Debug::Concise, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n", + metrics.mGlyphCount, + metrics.mAtlasMetrics.mAtlasCount, + metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 ); + for ( uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i ) + { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n", + i + 1, i > 8 ? "" : " ", + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mPixelFormat == Pixel::L8 ? "L8 " : "BGRA", + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mWidth, + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mHeight, + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlockWidth, + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlockHeight, + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlocksUsed, + metrics.mAtlasMetrics.mAtlasMetrics[ i ].mTotalBlocks ); + } +#endif } void StitchTextMesh( std::vector< MeshRecord >& meshContainer, -- 2.7.4