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=1def1b1da1e01574cf56cba1727c387730dc155f;hpb=f6e6320c0fce19229bdec06a996433c09b2d8fea;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 1def1b1..d0cedf4 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -76,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, @@ -107,12 +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; - mDepth = static_cast< int >( depth ); + TextCacheEntry textCacheEntry; + mDepth = depth; float currentUnderlinePosition = ZERO; float currentUnderlineThickness = underlineHeight; @@ -125,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 ]; @@ -178,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 ) + if ( !mGlyphManager.Cached( glyph.fontId, glyph.index, slot ) ) { - // This glyph already exists so generate mesh data plugging in our supplied position - mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh ); - mImageIds.PushBack( slot.mImageId ); - } - else - { - // Select correct size for new atlas if needed....? if ( lastFontId != glyph.fontId ) { @@ -232,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, @@ -250,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 @@ -273,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 @@ -282,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(); @@ -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,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; @@ -610,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 ); @@ -678,10 +686,10 @@ 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; @@ -694,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 ); @@ -737,5 +745,6 @@ AtlasRenderer::AtlasRenderer() AtlasRenderer::~AtlasRenderer() { + mImpl->RemoveText(); delete mImpl; }