X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Ftext-atlas-renderer.cpp;h=80a11115ad11369bbf2f58caa54a179439f0e724;hb=70510385d88cfbd5c232117d8436ca74c523e172;hp=e06b958344d3065ff9421e66b0deb2abd582cdc4;hpb=819320078000efb7807e11b4a23882df441792bc;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 e06b958..80a1111 100755 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 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. @@ -31,6 +31,7 @@ #include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -42,58 +43,12 @@ namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, 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 highp 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 lowp vec4 textColorAnimatable; -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 * textColorAnimatable.rgb, uColor.a * vColor.a * textColorAnimatable.a * color.r ); -} -); - -const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform lowp vec4 textColorAnimatable; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; - -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable; -} -); - const float ZERO( 0.0f ); const float HALF( 0.5f ); const float ONE( 1.0f ); const uint32_t DEFAULT_ATLAS_WIDTH = 512u; const uint32_t DEFAULT_ATLAS_HEIGHT = 512u; -const uint32_t NO_OUTLINE = 0; +const uint16_t NO_OUTLINE = 0u; } struct AtlasRenderer::Impl @@ -168,17 +123,21 @@ struct AtlasRenderer::Impl struct TextCacheEntry { TextCacheEntry() - : mFontId( 0 ), - mIndex( 0 ), - mOutlineWidth( 0 ), - mImageId( 0 ) + : mFontId{ 0u }, + mIndex{ 0u }, + mImageId{ 0u }, + mOutlineWidth{ 0u }, + isItalic{ false }, + isBold{ false } { } FontId mFontId; Text::GlyphIndex mIndex; - uint32_t mOutlineWidth; uint32_t mImageId; + uint16_t mOutlineWidth; + bool isItalic:1; + bool isBold:1; }; Impl() @@ -211,9 +170,9 @@ struct AtlasRenderer::Impl return false; } - void CacheGlyph( const GlyphInfo& glyph, FontId lastFontId, uint32_t outline, AtlasManager::AtlasSlot& slot ) + void CacheGlyph( const GlyphInfo& glyph, FontId lastFontId, const AtlasGlyphManager::GlyphStyle& style, AtlasManager::AtlasSlot& slot ) { - const bool glyphNotCached = !mGlyphManager.IsCached( glyph.fontId, glyph.index, outline, slot ); // Check FontGlyphRecord vector for entry with glyph index and fontId + const bool glyphNotCached = !mGlyphManager.IsCached( glyph.fontId, glyph.index, style, slot ); // Check FontGlyphRecord vector for entry with glyph index and fontId DALI_LOG_INFO( gLogFilter, Debug::Verbose, "AddGlyphs fontID[%u] glyphIndex[%u] [%s]\n", glyph.fontId, glyph.index, (glyphNotCached)?"not cached":"cached" ); @@ -243,7 +202,7 @@ struct AtlasRenderer::Impl PixelData bitmap; // Whether the glyph is an outline. - const bool isOutline = 0u != outline; + const bool isOutline = 0u != style.outline; // Whether the current glyph is a color one. const bool isColorGlyph = mFontClient.IsColorGlyph( glyph.fontId, glyph.index ); @@ -257,10 +216,10 @@ struct AtlasRenderer::Impl mFontClient.CreateBitmap( glyph.fontId, glyph.index, - glyph.softwareItalic, - glyph.softwareBold, + glyph.isItalicRequired, + glyph.isBoldRequired, glyphBufferData, - outline ); + style.outline ); // Create the pixel data. bitmap = PixelData::New( glyphBufferData.buffer, @@ -292,21 +251,21 @@ struct AtlasRenderer::Impl blockSize.mNeededBlockHeight ); // Locate a new slot for our glyph - mGlyphManager.Add( glyph, outline, bitmap, slot ); // slot will be 0 is glyph not added + mGlyphManager.Add( glyph, style, bitmap, slot ); // slot will be 0 is glyph not added } } } else { // We have 2+ copies of the same glyph - mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, outline, 1 ); //increment + mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, style, 1 ); //increment } } void GenerateMesh( const GlyphInfo& glyph, const Vector2& position, const Vector4& color, - uint32_t outline, + uint16_t outline, AtlasManager::AtlasSlot& slot, bool underlineGlyph, float currentUnderlinePosition, @@ -324,6 +283,8 @@ struct AtlasRenderer::Impl textCacheEntry.mImageId = slot.mImageId; textCacheEntry.mIndex = glyph.index; textCacheEntry.mOutlineWidth = outline; + textCacheEntry.isItalic = glyph.isItalicRequired; + textCacheEntry.isBold = glyph.isBoldRequired; newTextCache.PushBack( textCacheEntry ); @@ -363,10 +324,10 @@ struct AtlasRenderer::Impl { // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues. mActor = Actor::New(); - mActor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mActor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mActor.SetSize( textSize ); - mActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); + mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mActor.SetProperty( Actor::Property::SIZE, textSize ); + mActor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR ); } for( std::vector< MeshRecord >::const_iterator it = meshContainer.begin(), @@ -397,7 +358,7 @@ struct AtlasRenderer::Impl Actor shadowActor = CreateMeshActor(textControl, animatablePropertyIndex, color, meshRecord, textSize, STYLE_DROP_SHADOW ); #if defined(DEBUG_ENABLED) - shadowActor.SetName( "Text Shadow renderable actor" ); + shadowActor.SetProperty( Dali::Actor::Property::NAME, "Text Shadow renderable actor" ); #endif // Offset shadow in x and y shadowActor.RegisterProperty("uOffset", shadowOffset ); @@ -445,7 +406,7 @@ struct AtlasRenderer::Impl const bool underlineEnabled = view.IsUnderlineEnabled(); const Vector4& underlineColor( view.GetUnderlineColor() ); const float underlineHeight = view.GetUnderlineHeight(); - const unsigned int outlineWidth = view.GetOutlineWidth(); + const uint16_t outlineWidth = view.GetOutlineWidth(); const Vector4& outlineColor( view.GetOutlineColor() ); const bool isOutline = 0u != outlineWidth; @@ -528,17 +489,23 @@ struct AtlasRenderer::Impl lastUnderlinedFontId = glyph.fontId; } // underline + AtlasGlyphManager::GlyphStyle style; + style.isItalic = glyph.isItalicRequired; + style.isBold = glyph.isBoldRequired; + // Retrieves and caches the glyph's bitmap. - CacheGlyph( glyph, lastFontId, NO_OUTLINE, slot ); + CacheGlyph( glyph, lastFontId, style, slot ); // Retrieves and caches the outline glyph's bitmap. if( isOutline ) { - CacheGlyph( glyph, lastFontId, outlineWidth, slotOutline ); + style.outline = outlineWidth; + CacheGlyph( glyph, lastFontId, style, slotOutline ); } // Move the origin (0,0) of the mesh to the center of the actor - const Vector2 position = *( positionsBuffer + i ) - halfTextSize - lineOffsetPosition; + const Vector2& temp = *( positionsBuffer + i ); + const Vector2 position = Vector2( roundf( temp.x ), temp.y ) - halfTextSize - lineOffsetPosition; // roundf() avoids pixel alignment issues. if ( 0u != slot.mImageId ) // invalid slot id, glyph has failed to be added to atlas { @@ -655,7 +622,11 @@ struct AtlasRenderer::Impl { for( Vector< TextCacheEntry >::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter ) { - mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, oldTextIter->mOutlineWidth, -1/*decrement*/ ); + AtlasGlyphManager::GlyphStyle style; + style.outline = oldTextIter->mOutlineWidth; + style.isItalic = oldTextIter->isItalic; + style.isBold = oldTextIter->isBold; + mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, style, -1/*decrement*/ ); } mTextCache.Resize( 0 ); } @@ -663,7 +634,7 @@ struct AtlasRenderer::Impl Actor CreateMeshActor( Actor textControl, Property::Index animatablePropertyIndex, const Vector4& defaultColor, const MeshRecord& meshRecord, const Vector2& actorSize, Style style ) { - PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat ); + VertexBuffer quadVertices = VertexBuffer::New( mQuadVertexFormat ); quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() ); Geometry quadGeometry = Geometry::New(); @@ -680,7 +651,7 @@ struct AtlasRenderer::Impl // The glyph is an emoji and is not a shadow. if( !mShaderRgba ) { - mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA ); + mShaderRgba = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_RGBA_SHADER_FRAG ); } shader = mShaderRgba; } @@ -689,7 +660,7 @@ struct AtlasRenderer::Impl // The glyph is text or a shadow. if( !mShaderL8 ) { - mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 ); + mShaderL8 = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_L8_SHADER_FRAG ); } shader = mShaderL8; } @@ -721,15 +692,15 @@ struct AtlasRenderer::Impl Actor actor = Actor::New(); #if defined(DEBUG_ENABLED) - actor.SetName( "Text renderable actor" ); + actor.SetProperty( Dali::Actor::Property::NAME, "Text renderable actor" ); #endif actor.AddRenderer( renderer ); // Keep all of the origins aligned - actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - actor.SetSize( actorSize ); + actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + actor.SetProperty( Actor::Property::SIZE, actorSize ); actor.RegisterProperty("uOffset", Vector2::ZERO ); - actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); + actor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR ); return actor; }