X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Ftext-atlas-renderer.cpp;h=d0cedf42a5dae24f43d8f33dbb4ccbc44b6be83a;hb=92b10025ec96178e1c64fbb62d3ad095a39ae114;hp=457959fea9aa2a65de585183be4b2223a1eb8d69;hpb=d3a00dc1c24ece2488696c0b518013ad6d97969b;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 457959f..d0cedf4 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -97,13 +97,14 @@ struct AtlasRenderer::Impl : public ConnectionTracker }; Impl() + : mDepth( 0 ) { mGlyphManager = AtlasGlyphManager::Get(); mFontClient = TextAbstraction::FontClient::Get(); mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2; mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2; - mQuadIndexFormat[ "indices" ] = Property::UNSIGNED_INTEGER; + mQuadIndexFormat[ "indices" ] = Property::INTEGER; } void AddGlyphs( const std::vector& positions, @@ -114,13 +115,13 @@ struct AtlasRenderer::Impl : public ConnectionTracker bool underlineEnabled, const Vector4& underlineColor, float underlineHeight, - unsigned int depth ) + int depth ) { AtlasManager::AtlasSlot slot; std::vector< MeshRecord > meshContainer; Vector< Extent > extents; TextCacheEntry textCacheEntry; - mDepth = static_cast< int >( depth ); + mDepth = depth; float currentUnderlinePosition = ZERO; float currentUnderlineThickness = underlineHeight; @@ -133,14 +134,11 @@ struct AtlasRenderer::Impl : public ConnectionTracker style = STYLE_DROP_SHADOW; } - if ( mTextCache.Size() ) - { - // Update the glyph cache with any changes to current text - RemoveText( glyphs ); - } - CalculateBlocksSize( glyphs ); + // Avoid emptying mTextCache (& removing references) until after incremented references for the new text + Vector< TextCacheEntry > newTextCache; + for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i ) { const GlyphInfo& glyph = glyphs[ i ]; @@ -231,16 +229,21 @@ struct AtlasRenderer::Impl : public ConnectionTracker } // Locate a new slot for our glyph - mGlyphManager.Add( glyph.fontId, glyph, bitmap, slot ); + mGlyphManager.Add( glyph, bitmap, slot ); } } + else + { + // We have 2+ copies of the same glyph + mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, 1/*increment*/ ); + } // Generate mesh data for this quad, plugging in our supplied position mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh ); textCacheEntry.mFontId = glyph.fontId; textCacheEntry.mImageId = slot.mImageId; textCacheEntry.mIndex = glyph.index; - mTextCache.PushBack( textCacheEntry ); + newTextCache.PushBack( textCacheEntry ); // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas) StitchTextMesh( meshContainer, @@ -251,10 +254,14 @@ struct AtlasRenderer::Impl : public ConnectionTracker currentUnderlinePosition, currentUnderlineThickness, slot ); - lastFontId = glyph.fontId; + lastFontId = glyph.fontId; } } + // Now remove references for the old text + RemoveText(); + mTextCache.Swap( newTextCache ); + if ( underlineEnabled ) { // Check to see if any of the text needs an underline @@ -274,8 +281,9 @@ struct AtlasRenderer::Impl : public ConnectionTracker actor.Add( GenerateShadow( *mIt, shadowOffset, shadowColor ) ); } - if ( mActor ) + if( mActor ) { + actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned mActor.Add( actor ); } else @@ -290,9 +298,12 @@ struct AtlasRenderer::Impl : public ConnectionTracker metrics.mGlyphCount, metrics.mAtlasMetrics.mAtlasCount, metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 ); + + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%s\n", metrics.mVerboseGlyphCounts.c_str() ); + 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", + 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 ].mSize.mWidth, @@ -305,6 +316,15 @@ struct AtlasRenderer::Impl : public ConnectionTracker #endif } + void RemoveText() + { + for ( Vector< TextCacheEntry >::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter ) + { + mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, -1/*decrement*/ ); + } + mTextCache.Resize( 0 ); + } + Actor CreateMeshActor( const MeshRecord& meshRecord ) { PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() ); @@ -318,8 +338,11 @@ struct AtlasRenderer::Impl : public ConnectionTracker Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId ); Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); - renderer.SetDepthIndex( mDepth ); + renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth ); Actor actor = Actor::New(); +#if defined(DEBUG_ENABLED) + actor.SetName( "Text renderable actor" ); +#endif actor.AddRenderer( renderer ); actor.SetSize( 1.0f, 1.0f ); actor.SetColor( meshRecord.mColor ); @@ -437,58 +460,6 @@ struct AtlasRenderer::Impl : public ConnectionTracker } } - void RemoveText( const Vector& glyphs ) - { - Vector< CheckEntry > checked; - CheckEntry checkEntry; - - for ( Vector< TextCacheEntry >::Iterator tCit = mTextCache.Begin(); tCit != mTextCache.End(); ++tCit ) - { - uint32_t index = tCit->mIndex; - uint32_t fontId = tCit->mFontId; - - // Check that this character has not already been checked... - bool wasChecked = false; - for ( Vector< CheckEntry >::Iterator cEit = checked.Begin(); cEit != checked.End(); ++cEit ) - { - if ( fontId == cEit->mFontId && index == cEit->mIndex ) - { - wasChecked = true; - } - } - - if ( !wasChecked ) - { - - int32_t newCount = 0; - int32_t oldCount = 0; - - // How many times does this character occur in the old text ? - for ( Vector< TextCacheEntry >::Iterator oTcit = mTextCache.Begin(); oTcit != mTextCache.End(); ++oTcit ) - { - if ( fontId == oTcit->mFontId && index == oTcit->mIndex ) - { - oldCount++; - } - } - - // And how many times in the new ? - for ( Vector< GlyphInfo >::Iterator cGit = glyphs.Begin(); cGit != glyphs.End(); ++cGit ) - { - if ( fontId == cGit->fontId && index == cGit->index ) - { - newCount++; - } - } - mGlyphManager.AdjustReferenceCount( fontId, tCit->mImageId, newCount - oldCount ); - checkEntry.mIndex = index; - checkEntry.mFontId = fontId; - checked.PushBack( checkEntry ); - } - } - mTextCache.Resize( 0 ); - } - void CalculateBlocksSize( const Vector& glyphs ) { MaxBlockSize maxBlockSize; @@ -647,7 +618,7 @@ struct AtlasRenderer::Impl : public ConnectionTracker Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); // Ensure shadow is behind the text... - renderer.SetDepthIndex( mDepth + CONTENT_DEPTH_INDEX - 1 ); + renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth - 1 ); Actor actor = Actor::New(); actor.AddRenderer( renderer ); actor.SetSize( 1.0f, 1.0f ); @@ -731,7 +702,7 @@ Text::RendererPtr AtlasRenderer::New() return Text::RendererPtr( new AtlasRenderer() ); } -Actor AtlasRenderer::Render( Text::ViewInterface& view, unsigned int depth ) +Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth ) { UnparentAndReset( mImpl->mActor ); @@ -774,7 +745,6 @@ AtlasRenderer::AtlasRenderer() AtlasRenderer::~AtlasRenderer() { - Vector< GlyphInfo > emptyGlyphs; - mImpl->RemoveText( emptyGlyphs ); + mImpl->RemoveText(); delete mImpl; }