X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Fatlas-glyph-manager-impl.cpp;h=a3f7efd5eecccc25299680e1bd850de1b19bfbc4;hb=01c086f17e2af89f6c6b1bd30a0240da2fda1e75;hp=c8ea1e2c959a58ae7889076880d1bce55330e7db;hpb=a0a33727b8aa3ba5f32d4541f07718151f9574af;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 old mode 100644 new mode 100755 index c8ea1e2..a3f7efd --- 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) 2019 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. @@ -27,49 +27,6 @@ namespace 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 sampler2D sTexture; -varying mediump vec2 vTexCoord; - -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ); -} -); - } // unnamed namespace namespace Dali @@ -83,32 +40,37 @@ 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 BufferImage& bitmap, + 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 ); + // 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 material details for the atlas - Dali::Atlas atlas = mAtlasManager.GetAtlasContainer( slot.mAtlasId ); - Pixel::Format pixelFormat = mAtlasManager.GetPixelFormat( slot.mAtlasId ); - Material material = Material::New( pixelFormat == Pixel::L8 ? mShaderL8 : mShaderRgba ); - material.AddTexture( atlas, "sTexture" ); - material.SetBlendMode( BlendingMode::ON ); - mAtlasManager.SetMaterial( slot.mAtlasId, material ); + // 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 ); + textureSet.SetSampler( 0u, mSampler); + mAtlasManager.SetTextures( slot.mAtlasId, textureSet ); } GlyphRecordEntry record; 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; @@ -142,8 +104,9 @@ void AtlasGlyphManager::GenerateMeshData( uint32_t imageId, } bool AtlasGlyphManager::IsCached( Text::FontId fontId, - Text::GlyphIndex index, - Dali::Toolkit::AtlasManager::AtlasSlot& slot ) + Text::GlyphIndex index, + const Toolkit::AtlasGlyphManager::GlyphStyle& style, + Dali::Toolkit::AtlasManager::AtlasSlot& slot ) { for ( std::vector< FontGlyphRecord >::iterator fontGlyphRecordIt = mFontGlyphRecords.begin(); fontGlyphRecordIt != mFontGlyphRecords.end(); @@ -155,7 +118,10 @@ bool AtlasGlyphManager::IsCached( Text::FontId fontId, 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 ); @@ -216,7 +182,7 @@ const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics() 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 ) { @@ -232,7 +198,10 @@ void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIn 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" ); @@ -253,9 +222,9 @@ void AtlasGlyphManager::AdjustReferenceCount( Text::FontId fontId, Text::GlyphIn } } -Material AtlasGlyphManager::GetMaterial( uint32_t atlasId ) const +TextureSet AtlasGlyphManager::GetTextures( uint32_t atlasId ) const { - return mAtlasManager.GetMaterial( atlasId ); + return mAtlasManager.GetTextures( atlasId ); } AtlasGlyphManager::~AtlasGlyphManager()