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=2f7677aa9bbb9e39b199910e299f496271d1f6cd;hpb=b26250b0bc810ebeada606481882102b62cdb3e4;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 2f7677a..d0cedf4 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -20,10 +20,13 @@ // EXTERNAL INCLUDES #include -#include +#include +#include +#include +#include +#include #include - - +#include // INTERNAL INCLUDES #include #include @@ -73,27 +76,35 @@ struct AtlasRenderer::Impl : public ConnectionTracker uint32_t mMeshRecordIndex; }; - struct AtlasRecord + struct MaxBlockSize { - uint32_t mImageId; + FontId mFontId; + uint32_t mNeededBlockWidth; + uint32_t mNeededBlockHeight; + }; + + struct CheckEntry + { + FontId mFontId; Text::GlyphIndex mIndex; }; - struct MaxBlockSize + struct TextCacheEntry { FontId mFontId; - uint32_t mNeededBlockWidth; - uint32_t mNeededBlockHeight; + Text::GlyphIndex mIndex; + uint32_t mImageId; }; 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, @@ -103,11 +114,14 @@ struct AtlasRenderer::Impl : public ConnectionTracker const Vector4& shadowColor, bool underlineEnabled, const Vector4& underlineColor, - float underlineHeight ) + float underlineHeight, + int depth ) { AtlasManager::AtlasSlot slot; std::vector< MeshRecord > meshContainer; Vector< Extent > extents; + TextCacheEntry textCacheEntry; + mDepth = depth; float currentUnderlinePosition = ZERO; float currentUnderlineThickness = underlineHeight; @@ -120,14 +134,11 @@ struct AtlasRenderer::Impl : public ConnectionTracker style = STYLE_DROP_SHADOW; } - if ( mImageIds.Size() ) - { - // Unreference any currently used glyphs - RemoveText(); - } - 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 ]; @@ -173,17 +184,9 @@ struct AtlasRenderer::Impl : public ConnectionTracker const Vector2& position = positions[ i ]; AtlasManager::Mesh2D newMesh; - mGlyphManager.Cached( glyph.fontId, glyph.index, slot ); - if ( slot.mImageId ) - { - // This glyph already exists so generate mesh data plugging in our supplied position - mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh ); - mImageIds.PushBack( slot.mImageId ); - } - else + if ( !mGlyphManager.Cached( glyph.fontId, glyph.index, slot ) ) { - // Select correct size for new atlas if needed....? if ( lastFontId != glyph.fontId ) { @@ -227,15 +230,21 @@ struct AtlasRenderer::Impl : public ConnectionTracker // Locate a new slot for our glyph mGlyphManager.Add( glyph, bitmap, slot ); - - // Generate mesh data for this quad, plugging in our supplied position - if ( slot.mImageId ) - { - mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh ); - mImageIds.PushBack( slot.mImageId ); - } } } + 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; + 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, newMesh, @@ -245,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 @@ -268,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 @@ -277,7 +291,6 @@ struct AtlasRenderer::Impl : public ConnectionTracker mActor = actor; } } - mActor.OffStageSignal().Connect( this, &AtlasRenderer::Impl::OffStageDisconnect ); } #if defined(DEBUG_ENABLED) Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics(); @@ -285,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, @@ -300,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() ); @@ -313,7 +338,11 @@ struct AtlasRenderer::Impl : public ConnectionTracker Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId ); Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); + 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 ); @@ -431,21 +460,6 @@ struct AtlasRenderer::Impl : public ConnectionTracker } } - // Unreference any glyphs that were used with this actor - void OffStageDisconnect( Dali::Actor actor ) - { - RemoveText(); - } - - void RemoveText() - { - for ( uint32_t i = 0; i < mImageIds.Size(); ++i ) - { - mGlyphManager.Remove( mImageIds[ i ] ); - } - mImageIds.Resize( 0 ); - } - void CalculateBlocksSize( const Vector& glyphs ) { MaxBlockSize maxBlockSize; @@ -604,7 +618,7 @@ struct AtlasRenderer::Impl : public ConnectionTracker Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); // Ensure shadow is behind the text... - renderer.SetDepthIndex( CONTENT_DEPTH_INDEX - 1 ); + renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth - 1 ); Actor actor = Actor::New(); actor.AddRenderer( renderer ); actor.SetSize( 1.0f, 1.0f ); @@ -672,12 +686,13 @@ struct AtlasRenderer::Impl : public ConnectionTracker Actor mActor; ///< The actor parent which renders the text AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching - Vector< uint32_t > mImageIds; ///< A list of imageIDs used by the renderer TextAbstraction::FontClient mFontClient; ///> The font client used to supply glyph information std::vector< MaxBlockSize > mBlockSizes; ///> Maximum size needed to contain a glyph in a block within a new atlas std::vector< uint32_t > mFace; ///> Face indices for a quad + Vector< TextCacheEntry > mTextCache; Property::Map mQuadVertexFormat; Property::Map mQuadIndexFormat; + int mDepth; }; Text::RendererPtr AtlasRenderer::New() @@ -687,7 +702,7 @@ Text::RendererPtr AtlasRenderer::New() return Text::RendererPtr( new AtlasRenderer() ); } -Actor AtlasRenderer::Render( Text::ViewInterface& view ) +Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth ) { UnparentAndReset( mImpl->mActor ); @@ -715,7 +730,8 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view ) view.GetShadowColor(), view.IsUnderlineEnabled(), view.GetUnderlineColor(), - view.GetUnderlineHeight() ); + view.GetUnderlineHeight(), + depth ); } return mImpl->mActor; @@ -729,5 +745,6 @@ AtlasRenderer::AtlasRenderer() AtlasRenderer::~AtlasRenderer() { + mImpl->RemoveText(); delete mImpl; }