X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Fatlas-glyph-manager-impl.cpp;h=38412292c7a3bcbb4d0f9afd0c34ec33dc683062;hb=cacac45f98aade99ec9bda47d126c3fb02eef79a;hp=cb90d039c7d30c7a74e11cdb6359c4fab45bda7d;hpb=b79345b4ba7ac5e959d6ee913555e3436ca005f2;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 cb90d03..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,34 +96,48 @@ AtlasGlyphManager::AtlasGlyphManager() mShadowShader = Shader::New( VERTEX_SHADER_SHADOW, FRAGMENT_SHADER_SHADOW, Dali::Shader::HINT_MODIFIES_GEOMETRY ); } -AtlasGlyphManager::~AtlasGlyphManager() -{ -} - -AtlasGlyphManagerPtr AtlasGlyphManager::New() -{ - AtlasGlyphManagerPtr internal = new AtlasGlyphManager(); - return internal; -} - void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph, const BufferImage& bitmap, Dali::Toolkit::AtlasManager::AtlasSlot& slot ) { - GlyphRecord record; - record.mFontId = glyph.fontId; - record.mIndex = glyph.index; + DALI_LOG_INFO( gLogFilter, Debug::General, "Added glyph, font: %d index: %d\n", glyph.fontId, glyph.index ); mAtlasManager.Add( bitmap, slot ); + + GlyphRecordEntry record; + record.mIndex = glyph.index; record.mImageId = slot.mImageId; - mGlyphRecords.PushBack( record ); + record.mCount = 1; + + // Have glyph records been created for this fontId ? + bool foundGlyph = false; + for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); ++fontGlyphRecordIt ) + { + if ( fontGlyphRecordIt->mFontId == glyph.fontId ) + { + fontGlyphRecordIt->mGlyphRecords.PushBack( record ); + foundGlyph = true; + break; + } + } + + if ( !foundGlyph ) + { + // We need to add a new font entry + FontGlyphRecord fontGlyphRecord; + fontGlyphRecord.mFontId = glyph.fontId; + fontGlyphRecord.mGlyphRecords.PushBack( record ); + mFontGlyphRecords.push_back( fontGlyphRecord ); + } } void AtlasGlyphManager::GenerateMeshData( uint32_t imageId, const Vector2& position, Toolkit::AtlasManager::Mesh2D& mesh ) { - mAtlasManager.GenerateMeshData( imageId, position, mesh ); + // Generate mesh data and tell Atlas Manager not to handle reference counting ( we'll do it ) + mAtlasManager.GenerateMeshData( imageId, position, mesh, false ); } void AtlasGlyphManager::StitchMesh( Toolkit::AtlasManager::Mesh2D& first, @@ -131,20 +146,31 @@ void AtlasGlyphManager::StitchMesh( Toolkit::AtlasManager::Mesh2D& first, mAtlasManager.StitchMesh( first, second ); } -void AtlasGlyphManager::Cached( Text::FontId fontId, - uint32_t index, +bool AtlasGlyphManager::Cached( Text::FontId fontId, + Text::GlyphIndex index, Dali::Toolkit::AtlasManager::AtlasSlot& slot ) { - for ( uint32_t i = 0; i < mGlyphRecords.Size(); ++i ) + for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); + ++fontGlyphRecordIt ) { - if ( fontId == mGlyphRecords[ i ].mFontId && index == mGlyphRecords[ i ].mIndex ) + if ( fontGlyphRecordIt->mFontId == fontId ) { - slot.mImageId = mGlyphRecords[ i ].mImageId; - slot.mAtlasId = mAtlasManager.GetAtlas( slot.mImageId ); - return; + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordIt ) + { + if ( glyphRecordIt->mIndex == index ) + { + slot.mImageId = glyphRecordIt->mImageId; + slot.mAtlasId = mAtlasManager.GetAtlas( slot.mImageId ); + return true; + } + } } } slot.mImageId = 0; + return false; } Vector2 AtlasGlyphManager::GetAtlasSize( uint32_t atlasId ) @@ -163,24 +189,73 @@ void AtlasGlyphManager::SetNewAtlasSize( uint32_t width, uint32_t height, uint32 mAtlasManager.SetNewAtlasSize( size ); } -void AtlasGlyphManager::Remove( uint32_t imageId ) +Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId ) +{ + return mAtlasManager.GetPixelFormat( atlasId ); +} + +const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() { - if ( mAtlasManager.Remove( imageId ) ) + std::ostringstream verboseMetrics; + + mMetrics.mGlyphCount = 0u; + for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); + ++fontGlyphRecordIt ) { - for ( uint32_t i = 0; i < mGlyphRecords.Size(); ++i ) + mMetrics.mGlyphCount += fontGlyphRecordIt->mGlyphRecords.Size(); + + verboseMetrics << "[FontId " << fontGlyphRecordIt->mFontId << " Glyph "; + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordEntryIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordEntryIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordEntryIt ) { - if ( mGlyphRecords[ i ].mImageId == imageId ) - { - mGlyphRecords.Remove( mGlyphRecords.Begin() + i ); - return; - } + verboseMetrics << glyphRecordEntryIt->mIndex << "(" << glyphRecordEntryIt->mCount << ") "; } + verboseMetrics << "] "; } + mMetrics.mVerboseGlyphCounts = verboseMetrics.str(); + + mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics ); + + return mMetrics; } -Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId ) +void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta ) { - return mAtlasManager.GetPixelFormat( atlasId ); + if( 0 != delta ) + { + 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 ) + { + if ( fontGlyphRecordIt->mFontId == fontId ) + { + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordIt ) + { + if ( glyphRecordIt->mIndex == index ) + { + 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; + } + } + } + } + + // Should not arrive here + DALI_ASSERT_DEBUG( false && "Failed to adjust ref-count" ); + } } Material AtlasGlyphManager::GetMaterial( uint32_t atlasId ) const @@ -193,11 +268,9 @@ Sampler AtlasGlyphManager::GetSampler( uint32_t atlasId ) const return mAtlasManager.GetSampler( atlasId ); } -const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() +AtlasGlyphManager::~AtlasGlyphManager() { - mMetrics.mGlyphCount = mGlyphRecords.Size(); - mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics ); - return mMetrics; + // mAtlasManager handle is automatically released here } } // namespace Internal