X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Fatlas-glyph-manager-impl.cpp;h=38412292c7a3bcbb4d0f9afd0c34ec33dc683062;hp=1053ea9c0731499ef59b91f31fd7fe94538765b7;hb=5b3cf0e6742934674bdf62bbe15af00e39eae566;hpb=68398f4bf6958cd60f12b930e240d0d75e9e7d29 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 1053ea9..3841229 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 @@ -18,24 +18,26 @@ #include // EXTERNAL INCLUDES -#include -#include +#include #define MAKE_SHADER(A)#A namespace { + +#if defined(DEBUG_ENABLED) + Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING"); +#endif + const char* VERTEX_SHADER = MAKE_SHADER( attribute mediump vec2 aPosition; attribute mediump vec2 aTexCoord; uniform mediump mat4 uMvpMatrix; -uniform mediump vec3 uSize; varying mediump vec2 vTexCoord; void main() { mediump vec4 position = vec4( aPosition, 0.0, 1.0 ); - position.xyz *= uSize; gl_Position = uMvpMatrix * position; vTexCoord = aTexCoord; } @@ -54,13 +56,11 @@ void main() const char* VERTEX_SHADER_SHADOW = MAKE_SHADER( attribute mediump vec2 aPosition; attribute mediump vec2 aTexCoord; -uniform mediump vec3 uSize; varying mediump vec2 vTexCoord; void main() { mediump vec4 position = vec4( aPosition, 0.0, 1.0 ); - position.xyz *= uSize; gl_Position = position; vTexCoord = aTexCoord; } @@ -77,7 +77,8 @@ void main() gl_FragColor = vec4(uColor.rgb, uColor.a*color.r); } ); -} + +} // unnamed namespace namespace Dali { @@ -95,32 +96,12 @@ AtlasGlyphManager::AtlasGlyphManager() mShadowShader = Shader::New( VERTEX_SHADER_SHADOW, FRAGMENT_SHADER_SHADOW, Dali::Shader::HINT_MODIFIES_GEOMETRY ); } -AtlasGlyphManager::~AtlasGlyphManager() -{ - // Clear up any remaining references - for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); - fontGlyphRecordIt != mFontGlyphRecords.end(); - ++fontGlyphRecordIt ) - { - for ( Vector< GlyphRecordEntry >::Iterator glyphRecordEntryIt = fontGlyphRecordIt->mGlyphRecords.Begin(); - glyphRecordEntryIt != fontGlyphRecordIt->mGlyphRecords.End(); - ++glyphRecordEntryIt ) - { - mAtlasManager.Remove( glyphRecordEntryIt->mImageId ); - } - } -} - -AtlasGlyphManagerPtr AtlasGlyphManager::New() -{ - AtlasGlyphManagerPtr internal = new AtlasGlyphManager(); - return internal; -} - void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph, const BufferImage& bitmap, Dali::Toolkit::AtlasManager::AtlasSlot& slot ) { + DALI_LOG_INFO( gLogFilter, Debug::General, "Added glyph, font: %d index: %d\n", glyph.fontId, glyph.index ); + mAtlasManager.Add( bitmap, slot ); GlyphRecordEntry record; @@ -166,7 +147,7 @@ void AtlasGlyphManager::StitchMesh( Toolkit::AtlasManager::Mesh2D& first, } bool AtlasGlyphManager::Cached( Text::FontId fontId, - uint32_t index, + Text::GlyphIndex index, Dali::Toolkit::AtlasManager::AtlasSlot& slot ) { for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); @@ -215,41 +196,65 @@ Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId ) const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() { + std::ostringstream verboseMetrics; + mMetrics.mGlyphCount = 0u; for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); fontGlyphRecordIt != mFontGlyphRecords.end(); ++fontGlyphRecordIt ) { mMetrics.mGlyphCount += fontGlyphRecordIt->mGlyphRecords.Size(); + + verboseMetrics << "[FontId " << fontGlyphRecordIt->mFontId << " Glyph "; + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordEntryIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordEntryIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordEntryIt ) + { + verboseMetrics << glyphRecordEntryIt->mIndex << "(" << glyphRecordEntryIt->mCount << ") "; + } + verboseMetrics << "] "; } + mMetrics.mVerboseGlyphCounts = verboseMetrics.str(); + mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics ); + return mMetrics; } -void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, uint32_t imageId, int32_t delta ) +void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta ) { - for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); - fontGlyphRecordIt != mFontGlyphRecords.end(); - ++fontGlyphRecordIt ) + if( 0 != delta ) { - if ( fontGlyphRecordIt->mFontId == fontId ) + DALI_LOG_INFO( gLogFilter, Debug::General, "AdjustReferenceCount %d, font: %d index: %d\n", delta, fontId, index ); + + for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); + ++fontGlyphRecordIt ) { - for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); - glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); - ++glyphRecordIt ) + if ( fontGlyphRecordIt->mFontId == fontId ) { - if ( glyphRecordIt->mImageId == imageId ) + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordIt ) { - glyphRecordIt->mCount += delta; - if ( !glyphRecordIt->mCount ) + if ( glyphRecordIt->mIndex == index ) { - mAtlasManager.Remove( glyphRecordIt->mImageId ); - fontGlyphRecordIt->mGlyphRecords.Remove( glyphRecordIt ); + glyphRecordIt->mCount += delta; + DALI_ASSERT_DEBUG( glyphRecordIt->mCount >= 0 && "Glyph ref-count should not be negative" ); + + if ( !glyphRecordIt->mCount ) + { + mAtlasManager.Remove( glyphRecordIt->mImageId ); + fontGlyphRecordIt->mGlyphRecords.Remove( glyphRecordIt ); + } + return; } - return; } } } + + // Should not arrive here + DALI_ASSERT_DEBUG( false && "Failed to adjust ref-count" ); } } @@ -263,6 +268,11 @@ Sampler AtlasGlyphManager::GetSampler( uint32_t atlasId ) const return mAtlasManager.GetSampler( atlasId ); } +AtlasGlyphManager::~AtlasGlyphManager() +{ + // mAtlasManager handle is automatically released here +} + } // namespace Internal } // namespace Toolkit