X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Fatlas-glyph-manager-impl.cpp;h=bc2a146c56bacd790da473ff81310a93129048d2;hb=f0a677dd7b2485269f34dad6f519c7304da6e0eb;hp=12d39a51b30532f3c176abd91db7e2a70442c9f0;hpb=3320153709e9409873ee708680b1b9eed8cb1060;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 12d39a5..bc2a146 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,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,142 +22,106 @@ namespace { - #if defined(DEBUG_ENABLED) - Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING"); +Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING"); #endif -#define MAKE_SHADER(A)#A - -const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition; -attribute mediump vec2 aTexCoord; -attribute mediump vec4 aColor; -uniform mediump vec2 uOffset; -uniform mediump mat4 uMvpMatrix; -varying mediump vec2 vTexCoord; -varying mediump vec4 vColor; - -void main() -{ - mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 ); - gl_Position = uMvpMatrix * position; - vTexCoord = aTexCoord; - vColor = aColor; -} -); - -const char* FRAGMENT_SHADER_L8 = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; -varying mediump vec4 vColor; - -void main() -{ - mediump vec4 color = texture2D( sTexture, vTexCoord ); - gl_FragColor = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a * color.r ); -} -); - -const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; - -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; -} -); - } // unnamed namespace namespace Dali { - namespace Toolkit { - namespace Internal { - AtlasGlyphManager::AtlasGlyphManager() { - mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 ); - mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA ); mAtlasManager = Dali::Toolkit::AtlasManager::New(); + mSampler = Sampler::New(); + mSampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR); } -void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph, - const PixelData& bitmap, - Dali::Toolkit::AtlasManager::AtlasSlot& slot ) +void AtlasGlyphManager::Add(const Text::GlyphInfo& glyph, + const Toolkit::AtlasGlyphManager::GlyphStyle& style, + const PixelData& bitmap, + Dali::Toolkit::AtlasManager::AtlasSlot& slot) { - DALI_LOG_INFO( gLogFilter, Debug::General, "Added glyph, font: %d index: %d\n", glyph.fontId, glyph.index ); + DALI_LOG_INFO(gLogFilter, Debug::General, "Added glyph, font: %d index: %d\n", glyph.fontId, glyph.index); - if ( 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 ); + Dali::Texture atlas = mAtlasManager.GetAtlasContainer(slot.mAtlasId); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture(0u, atlas); + textureSet.SetSampler(0u, mSampler); + mAtlasManager.SetTextures(slot.mAtlasId, textureSet); } GlyphRecordEntry record; - record.mIndex = glyph.index; - record.mImageId = slot.mImageId; - record.mCount = 1; + record.mIndex = glyph.index; + record.mImageId = slot.mImageId; + record.mCount = 1; + record.mOutlineWidth = style.outline; + record.isItalic = style.isItalic; + record.isBold = style.isBold; // Have glyph records been created for this fontId ? bool foundGlyph = false; - for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); - fontGlyphRecordIt != mFontGlyphRecords.end(); ++fontGlyphRecordIt ) + for(std::vector::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); + ++fontGlyphRecordIt) { - if ( fontGlyphRecordIt->mFontId == glyph.fontId ) + if(fontGlyphRecordIt->mFontId == glyph.fontId) { - fontGlyphRecordIt->mGlyphRecords.PushBack( record ); + fontGlyphRecordIt->mGlyphRecords.PushBack(record); foundGlyph = true; break; } } - if ( !foundGlyph ) + if(!foundGlyph) { // We need to add a new font entry FontGlyphRecord fontGlyphRecord; fontGlyphRecord.mFontId = glyph.fontId; - fontGlyphRecord.mGlyphRecords.PushBack( record ); - mFontGlyphRecords.push_back( fontGlyphRecord ); + fontGlyphRecord.mGlyphRecords.PushBack(record); + mFontGlyphRecords.push_back(fontGlyphRecord); } } -void AtlasGlyphManager::GenerateMeshData( uint32_t imageId, - const Vector2& position, - Toolkit::AtlasManager::Mesh2D& mesh ) +void AtlasGlyphManager::GenerateMeshData(uint32_t imageId, + const Vector2& position, + Toolkit::AtlasManager::Mesh2D& mesh) { // Generate mesh data and tell Atlas Manager not to handle reference counting ( we'll do it ) - mAtlasManager.GenerateMeshData( imageId, position, mesh, false ); + mAtlasManager.GenerateMeshData(imageId, position, mesh, false); } -bool AtlasGlyphManager::IsCached( Text::FontId fontId, - Text::GlyphIndex index, - Dali::Toolkit::AtlasManager::AtlasSlot& slot ) +bool AtlasGlyphManager::IsCached(Text::FontId fontId, + Text::GlyphIndex index, + const Toolkit::AtlasGlyphManager::GlyphStyle& style, + Dali::Toolkit::AtlasManager::AtlasSlot& slot) { - for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); - fontGlyphRecordIt != mFontGlyphRecords.end(); - ++fontGlyphRecordIt ) + for(std::vector::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); + ++fontGlyphRecordIt) { - if ( fontGlyphRecordIt->mFontId == fontId ) + if(fontGlyphRecordIt->mFontId == fontId) { - for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); - glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); - ++glyphRecordIt ) + for(Vector::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordIt) { - if ( glyphRecordIt->mIndex == index ) + if((glyphRecordIt->mIndex == index) && + (glyphRecordIt->mOutlineWidth == style.outline) && + (glyphRecordIt->isItalic == style.isItalic) && + (glyphRecordIt->isBold == style.isBold)) { slot.mImageId = glyphRecordIt->mImageId; - slot.mAtlasId = mAtlasManager.GetAtlas( slot.mImageId ); + slot.mAtlasId = mAtlasManager.GetAtlas(slot.mImageId); return true; } } @@ -167,25 +131,25 @@ bool AtlasGlyphManager::IsCached( Text::FontId fontId, return false; } -Vector2 AtlasGlyphManager::GetAtlasSize( uint32_t atlasId ) +Vector2 AtlasGlyphManager::GetAtlasSize(uint32_t atlasId) { - Toolkit::AtlasManager::AtlasSize size = mAtlasManager.GetAtlasSize( atlasId ); - return Vector2( static_cast< float >( size.mWidth ), static_cast< float >( size.mHeight ) ); + Toolkit::AtlasManager::AtlasSize size = mAtlasManager.GetAtlasSize(atlasId); + return Vector2(static_cast(size.mWidth), static_cast(size.mHeight)); } -void AtlasGlyphManager::SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight ) +void AtlasGlyphManager::SetNewAtlasSize(uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight) { Toolkit::AtlasManager::AtlasSize size; - size.mWidth = width; - size.mHeight = height; - size.mBlockWidth = blockWidth; + size.mWidth = width; + size.mHeight = height; + size.mBlockWidth = blockWidth; size.mBlockHeight = blockHeight; - mAtlasManager.SetNewAtlasSize( size ); + mAtlasManager.SetNewAtlasSize(size); } -Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId ) +Pixel::Format AtlasGlyphManager::GetPixelFormat(uint32_t atlasId) { - return mAtlasManager.GetPixelFormat( atlasId ); + return mAtlasManager.GetPixelFormat(atlasId); } const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() @@ -193,16 +157,16 @@ 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(std::vector::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 ) + for(Vector::Iterator glyphRecordEntryIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordEntryIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordEntryIt) { verboseMetrics << glyphRecordEntryIt->mIndex << "(" << glyphRecordEntryIt->mCount << ") "; } @@ -210,36 +174,39 @@ const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() } mMetrics.mVerboseGlyphCounts = verboseMetrics.str(); - mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics ); + mAtlasManager.GetMetrics(mMetrics.mAtlasMetrics); return mMetrics; } -void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta ) +void AtlasGlyphManager::AdjustReferenceCount(Text::FontId fontId, Text::GlyphIndex index, const Toolkit::AtlasGlyphManager::GlyphStyle& style, int32_t delta) { - if( 0 != delta ) + if(0 != delta) { - DALI_LOG_INFO( gLogFilter, Debug::General, "AdjustReferenceCount %d, font: %d index: %d\n", delta, fontId, index ); + 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(std::vector::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); + fontGlyphRecordIt != mFontGlyphRecords.end(); + ++fontGlyphRecordIt) { - if ( fontGlyphRecordIt->mFontId == fontId ) + if(fontGlyphRecordIt->mFontId == fontId) { - for ( Vector< GlyphRecordEntry >::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); - glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); - ++glyphRecordIt ) + for(Vector::Iterator glyphRecordIt = fontGlyphRecordIt->mGlyphRecords.Begin(); + glyphRecordIt != fontGlyphRecordIt->mGlyphRecords.End(); + ++glyphRecordIt) { - if ( glyphRecordIt->mIndex == index ) + if((glyphRecordIt->mIndex == index) && + (glyphRecordIt->mOutlineWidth == style.outline) && + (glyphRecordIt->isItalic == style.isItalic) && + (glyphRecordIt->isBold == style.isBold)) { glyphRecordIt->mCount += delta; - DALI_ASSERT_DEBUG( glyphRecordIt->mCount >= 0 && "Glyph ref-count should not be negative" ); + DALI_ASSERT_DEBUG(glyphRecordIt->mCount >= 0 && "Glyph ref-count should not be negative"); - if ( !glyphRecordIt->mCount ) + if(!glyphRecordIt->mCount) { - mAtlasManager.Remove( glyphRecordIt->mImageId ); - fontGlyphRecordIt->mGlyphRecords.Remove( glyphRecordIt ); + mAtlasManager.Remove(glyphRecordIt->mImageId); + fontGlyphRecordIt->mGlyphRecords.Remove(glyphRecordIt); } return; } @@ -248,19 +215,13 @@ void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIn } // Should not arrive here - DALI_ASSERT_DEBUG( false && "Failed to adjust ref-count" ); + DALI_ASSERT_DEBUG(false && "Failed to adjust ref-count"); } } -TextureSet AtlasGlyphManager::GetTextures( uint32_t atlasId ) const -{ - return mAtlasManager.GetTextures( atlasId ); -} - -Shader AtlasGlyphManager::GetShader( uint32_t atlasId ) const +TextureSet AtlasGlyphManager::GetTextures(uint32_t atlasId) const { - Pixel::Format pixelFormat = mAtlasManager.GetPixelFormat( atlasId ); - return pixelFormat == Pixel::L8 ? mShaderL8 : mShaderRgba; + return mAtlasManager.GetTextures(atlasId); } AtlasGlyphManager::~AtlasGlyphManager()