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=957fd8eec63c20cb36bcf9fa9674b92accc928e7;hp=7bd8f1883da9ebd3ebb9cadadcc6f2be8d95fee9;hb=bef7b82cd945f4d2fd3b4d776184c1fc0851c8c6;hpb=5f6befa398f1c68fcc8edff409a086f54af4d5f9 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 7bd8f18..957fd8e 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 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,16 @@ #include // EXTERNAL INCLUDES -#include -#include +#include + +namespace +{ + +#if defined(DEBUG_ENABLED) + Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING"); +#endif + +} // unnamed namespace namespace Dali { @@ -30,82 +38,92 @@ namespace Toolkit namespace Internal { -//#define DISPLAY_ATLAS - AtlasGlyphManager::AtlasGlyphManager() -: mCount( 0 ) { mAtlasManager = Dali::Toolkit::AtlasManager::New(); } -AtlasGlyphManager::~AtlasGlyphManager() -{ -} - -AtlasGlyphManagerPtr AtlasGlyphManager::New() -{ - AtlasGlyphManagerPtr internal = new AtlasGlyphManager(); - return internal; -} - void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph, - const BufferImage& bitmap, + const uint32_t outlineWidth, + const PixelData& 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 ); + // If glyph added to an existing or new atlas then a new glyph record is required. + // Check if an existing atlas will fit the image, create a new one if required. + if ( mAtlasManager.Add( bitmap, slot ) ) + { + // A new atlas was created so set the texture set details for the atlas + Dali::Texture atlas = mAtlasManager.GetAtlasContainer( slot.mAtlasId ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, atlas ); + mAtlasManager.SetTextures( slot.mAtlasId, textureSet ); + } + + GlyphRecordEntry record; + record.mIndex = glyph.index; + record.mOutlineWidth = outlineWidth; record.mImageId = slot.mImageId; - mGlyphRecords.PushBack( record ); + record.mCount = 1; -#ifdef DISPLAY_ATLAS + // Have glyph records been created for this fontId ? + bool foundGlyph = false; + for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); ++fontGlyphRecordIt ) { - uint32_t atlasCount = mAtlasManager.GetAtlasCount(); - if ( atlasCount > mCount ) + if ( fontGlyphRecordIt->mFontId == glyph.fontId ) { - for ( uint32_t i = 0; i < atlasCount; ++i ) - { - ImageActor actor = ImageActor::New( mAtlasManager.GetAtlasContainer( i + 1u ) ); - actor.SetParentOrigin( Vector3( 0.5f, 0.25f + ( static_cast< float >( i ) * 0.25f ), 0.5f ) ); - actor.SetAnchorPoint( AnchorPoint::CENTER ); - actor.SetSize( 256.0f, 256.0f ); - Stage::GetCurrent().Add( actor ); - } + fontGlyphRecordIt->mGlyphRecords.PushBack( record ); + foundGlyph = true; + break; } - mCount = atlasCount; } -#endif + + 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, - const Toolkit::AtlasManager::Mesh2D& second ) -{ - mAtlasManager.StitchMesh( first, second ); -} - -void AtlasGlyphManager::Cached( Text::FontId fontId, - uint32_t index, +bool AtlasGlyphManager::IsCached( Text::FontId fontId, + Text::GlyphIndex index, + uint32_t outlineWidth, 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 && glyphRecordIt->mOutlineWidth == outlineWidth ) + { + slot.mImageId = glyphRecordIt->mImageId; + slot.mAtlasId = mAtlasManager.GetAtlas( slot.mImageId ); + return true; + } + } } } slot.mImageId = 0; + return false; } Vector2 AtlasGlyphManager::GetAtlasSize( uint32_t atlasId ) @@ -124,36 +142,83 @@ 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 ) { - if ( mAtlasManager.Remove( imageId ) ) + return mAtlasManager.GetPixelFormat( 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 ) { - 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, uint32_t outlineWidth, 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->mOutlineWidth == outlineWidth ) + { + 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 +TextureSet AtlasGlyphManager::GetTextures( uint32_t atlasId ) const { - return mAtlasManager.GetMaterial( atlasId ); + return mAtlasManager.GetTextures( 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