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=1053ea9c0731499ef59b91f31fd7fe94538765b7;hb=bef7b82cd945f4d2fd3b4d776184c1fc0851c8c6;hpb=ca02242b9d6389f6e02a120afb42645c5f2c9557 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 1053ea9..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,66 +18,16 @@ #include // EXTERNAL INCLUDES -#include -#include - -#define MAKE_SHADER(A)#A +#include namespace { -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; -} -); - -const char* FRAGMENT_SHADER = MAKE_SHADER( -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; - -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ); -} -); - -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; -} -); -const char* FRAGMENT_SHADER_SHADOW = MAKE_SHADER( -uniform sampler2D sTexture; -uniform lowp vec4 uColor; -varying mediump vec2 vTexCoord; +#if defined(DEBUG_ENABLED) + Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING"); +#endif -void main() -{ - mediump vec4 color = texture2D( sTexture, vTexCoord ); - gl_FragColor = vec4(uColor.rgb, uColor.a*color.r); -} -); -} +} // unnamed namespace namespace Dali { @@ -91,40 +41,29 @@ namespace Internal AtlasGlyphManager::AtlasGlyphManager() { mAtlasManager = Dali::Toolkit::AtlasManager::New(); - mEffectBufferShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - mShadowShader = Shader::New( VERTEX_SHADER_SHADOW, FRAGMENT_SHADER_SHADOW, Dali::Shader::HINT_MODIFIES_GEOMETRY ); -} - -AtlasGlyphManager::~AtlasGlyphManager() -{ - // Clear up any remaining references - for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); - fontGlyphRecordIt != mFontGlyphRecords.end(); - ++fontGlyphRecordIt ) - { - for ( Vector< GlyphRecordEntry >::Iterator glyphRecordEntryIt = fontGlyphRecordIt->mGlyphRecords.Begin(); - glyphRecordEntryIt != fontGlyphRecordIt->mGlyphRecords.End(); - ++glyphRecordEntryIt ) - { - mAtlasManager.Remove( glyphRecordEntryIt->mImageId ); - } - } -} - -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 ) { - mAtlasManager.Add( bitmap, slot ); + DALI_LOG_INFO( gLogFilter, Debug::General, "Added glyph, font: %d index: %d\n", glyph.fontId, glyph.index ); + + // 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; record.mCount = 1; @@ -159,14 +98,9 @@ void AtlasGlyphManager::GenerateMeshData( uint32_t imageId, mAtlasManager.GenerateMeshData( imageId, position, mesh, false ); } -void AtlasGlyphManager::StitchMesh( Toolkit::AtlasManager::Mesh2D& first, - const Toolkit::AtlasManager::Mesh2D& second ) -{ - mAtlasManager.StitchMesh( first, second ); -} - -bool 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 ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); @@ -179,7 +113,7 @@ bool AtlasGlyphManager::Cached( Text::FontId fontId, glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); ++glyphRecordIt ) { - if ( glyphRecordIt->mIndex == index ) + if ( glyphRecordIt->mIndex == index && glyphRecordIt->mOutlineWidth == outlineWidth ) { slot.mImageId = glyphRecordIt->mImageId; slot.mAtlasId = mAtlasManager.GetAtlas( slot.mImageId ); @@ -215,52 +149,76 @@ Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t 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 ) { mMetrics.mGlyphCount += fontGlyphRecordIt->mGlyphRecords.Size(); + + verboseMetrics << "[FontId " << fontGlyphRecordIt->mFontId << " Glyph "; + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordEntryIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordEntryIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordEntryIt ) + { + verboseMetrics << glyphRecordEntryIt->mIndex << "(" << glyphRecordEntryIt->mCount << ") "; + } + verboseMetrics << "] "; } + mMetrics.mVerboseGlyphCounts = verboseMetrics.str(); + mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics ); + return mMetrics; } -void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, uint32_t imageId, int32_t delta ) +void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, uint32_t outlineWidth, int32_t delta ) { - for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); - fontGlyphRecordIt != mFontGlyphRecords.end(); - ++fontGlyphRecordIt ) + if( 0 != delta ) { - if ( fontGlyphRecordIt->mFontId == fontId ) + 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 ) { - for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); - glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); - ++glyphRecordIt ) + if ( fontGlyphRecordIt->mFontId == fontId ) { - if ( glyphRecordIt->mImageId == imageId ) + for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordIt ) { - glyphRecordIt->mCount += delta; - if ( !glyphRecordIt->mCount ) + if ( glyphRecordIt->mIndex == index && glyphRecordIt->mOutlineWidth == outlineWidth ) { - mAtlasManager.Remove( glyphRecordIt->mImageId ); - fontGlyphRecordIt->mGlyphRecords.Remove( glyphRecordIt ); + 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; } - 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 ); } -Sampler AtlasGlyphManager::GetSampler( uint32_t atlasId ) const +AtlasGlyphManager::~AtlasGlyphManager() { - return mAtlasManager.GetSampler( atlasId ); + // mAtlasManager handle is automatically released here } } // namespace Internal