2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
22 #include <dali/public-api/rendering/geometry.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/devel-api/text-abstraction/font-client.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
29 #include <dali-toolkit/internal/text/glyph-run.h>
30 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
31 #include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
32 #include <dali-toolkit/internal/text/text-view.h>
35 using namespace Dali::Toolkit;
36 using namespace Dali::Toolkit::Text;
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
44 #define MAKE_SHADER(A)#A
46 const char* VERTEX_SHADER = MAKE_SHADER(
47 attribute mediump vec2 aPosition;
48 attribute mediump vec2 aTexCoord;
49 attribute mediump vec4 aColor;
50 uniform mediump vec2 uOffset;
51 uniform mediump mat4 uMvpMatrix;
52 varying mediump vec2 vTexCoord;
53 varying mediump vec4 vColor;
57 mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
58 gl_Position = uMvpMatrix * position;
59 vTexCoord = aTexCoord;
64 const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
65 uniform lowp vec4 uColor;
66 uniform sampler2D sTexture;
67 varying mediump vec2 vTexCoord;
68 varying mediump vec4 vColor;
72 mediump vec4 color = texture2D( sTexture, vTexCoord );
73 gl_FragColor = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a * color.r );
77 const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER(
78 uniform lowp vec4 uColor;
79 uniform sampler2D sTexture;
80 varying mediump vec2 vTexCoord;
84 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
88 const float ZERO( 0.0f );
89 const float HALF( 0.5f );
90 const float ONE( 1.0f );
91 const uint32_t DEFAULT_ATLAS_WIDTH = 512u;
92 const uint32_t DEFAULT_ATLAS_HEIGHT = 512u;
95 struct AtlasRenderer::Impl
111 AtlasManager::Mesh2D mMesh;
112 FrameBufferImage mBuffer;
116 * brief Struct used to generate the underline mesh.
117 * There is one Extent per line of text.
125 mUnderlinePosition( 0.0f ),
126 mUnderlineThickness( 0.0f ),
127 mMeshRecordIndex( 0u )
134 float mUnderlinePosition;
135 float mUnderlineThickness;
136 uint32_t mMeshRecordIndex;
143 mNeededBlockWidth( 0 ),
144 mNeededBlockHeight( 0 )
149 uint32_t mNeededBlockWidth;
150 uint32_t mNeededBlockHeight;
162 Text::GlyphIndex mIndex;
165 struct TextCacheEntry
175 Text::GlyphIndex mIndex;
182 mGlyphManager = AtlasGlyphManager::Get();
183 mFontClient = TextAbstraction::FontClient::Get();
185 mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
186 mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
187 mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
190 bool IsGlyphUnderlined( GlyphIndex index,
191 const Vector<GlyphRun>& underlineRuns )
193 for( Vector<GlyphRun>::ConstIterator it = underlineRuns.Begin(),
194 endIt = underlineRuns.End();
198 const GlyphRun& run = *it;
200 if( ( run.glyphIndex <= index ) && ( index < run.glyphIndex + run.numberOfGlyphs ) )
209 void AddGlyphs( Text::ViewInterface& view,
210 const Vector<Vector2>& positions,
211 const Vector<GlyphInfo>& glyphs,
212 const Vector4& defaultColor,
213 const Vector4* const colorsBuffer,
214 const ColorIndex* const colorIndicesBuffer,
216 float minLineOffset )
218 AtlasManager::AtlasSlot slot;
219 std::vector< MeshRecord > meshContainer;
220 Vector< Extent > extents;
221 TextCacheEntry textCacheEntry;
224 const Vector2& textSize( view.GetLayoutSize() );
225 const Vector2 halfTextSize( textSize * 0.5f );
226 const Vector2& shadowOffset( view.GetShadowOffset() );
227 const Vector4& shadowColor( view.GetShadowColor() );
228 const bool underlineEnabled( view.IsUnderlineEnabled() );
229 const Vector4& underlineColor( view.GetUnderlineColor() );
230 const float underlineHeight( view.GetUnderlineHeight() );
232 const bool useDefaultColor = ( NULL == colorsBuffer );
234 // Get the underline runs.
235 const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
236 Vector<GlyphRun> underlineRuns;
237 underlineRuns.Resize( numberOfUnderlineRuns );
238 view.GetUnderlineRuns( underlineRuns.Begin(),
240 numberOfUnderlineRuns );
242 bool thereAreUnderlinedGlyphs = false;
244 float currentUnderlinePosition = ZERO;
245 float currentUnderlineThickness = underlineHeight;
246 uint32_t currentBlockSize = 0;
247 FontId lastFontId = 0;
248 FontId lastUnderlinedFontId = 0;
249 Style style = STYLE_NORMAL;
251 if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 )
253 style = STYLE_DROP_SHADOW;
256 CalculateBlocksSize( glyphs );
258 // Avoid emptying mTextCache (& removing references) until after incremented references for the new text
259 Vector< TextCacheEntry > newTextCache;
260 const GlyphInfo* const glyphsBuffer = glyphs.Begin();
261 const Vector2* const positionsBuffer = positions.Begin();
262 const Vector2 lineOffsetPosition( minLineOffset, 0.f );
264 for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
266 const GlyphInfo& glyph = *( glyphsBuffer + i );
267 const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined( i, underlineRuns );
268 thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph;
270 // No operation for white space
271 if( glyph.width && glyph.height )
273 // Are we still using the same fontId as previous
274 if( underlineGlyph && ( glyph.fontId != lastUnderlinedFontId ) )
276 // We need to fetch fresh font underline metrics
277 FontMetrics fontMetrics;
278 mFontClient.GetFontMetrics( glyph.fontId, fontMetrics );
279 currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) );
280 const float descender = ceil( fabsf( fontMetrics.descender ) );
282 if( fabsf( underlineHeight ) < Math::MACHINE_EPSILON_1000 )
284 currentUnderlineThickness = fontMetrics.underlineThickness;
286 // Ensure underline will be at least a pixel high
287 if ( currentUnderlineThickness < ONE )
289 currentUnderlineThickness = ONE;
293 currentUnderlineThickness = ceil( currentUnderlineThickness );
297 // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
298 if( currentUnderlinePosition > descender )
300 currentUnderlinePosition = descender;
303 if( fabsf( currentUnderlinePosition ) < Math::MACHINE_EPSILON_1000 )
305 // Move offset down by one ( EFL behavior )
306 currentUnderlinePosition = ONE;
309 lastUnderlinedFontId = glyph.fontId;
312 if( !mGlyphManager.IsCached( glyph.fontId, glyph.index, slot ) )
314 // Select correct size for new atlas if needed....?
315 if( lastFontId != glyph.fontId )
318 for( std::vector<MaxBlockSize>::const_iterator it = mBlockSizes.begin(),
319 endIt = mBlockSizes.end();
323 const MaxBlockSize& blockSize = *it;
324 if( blockSize.mFontId == glyph.fontId )
326 currentBlockSize = index;
327 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
328 DEFAULT_ATLAS_HEIGHT,
329 blockSize.mNeededBlockWidth,
330 blockSize.mNeededBlockHeight );
335 // Create a new image for the glyph
338 // Whether the current glyph is a color one.
339 const bool isColorGlyph = mFontClient.IsColorGlyph( glyph.fontId, glyph.index );
341 // Retrieve the emoji's bitmap.
342 TextAbstraction::FontClient::GlyphBufferData glyphBufferData;
343 glyphBufferData.width = isColorGlyph ? glyph.width : 0; // Desired width and height.
344 glyphBufferData.height = isColorGlyph ? glyph.height : 0;
346 mFontClient.CreateBitmap( glyph.fontId,
350 // Create the pixel data.
351 bitmap = PixelData::New( glyphBufferData.buffer,
352 glyph.width * glyph.height * GetBytesPerPixel( glyphBufferData.format ),
355 glyphBufferData.format,
356 PixelData::DELETE_ARRAY );
360 MaxBlockSize& blockSize = mBlockSizes[currentBlockSize];
362 // Ensure that the next image will fit into the current block size
363 bool setSize = false;
364 if( bitmap.GetWidth() > blockSize.mNeededBlockWidth )
367 blockSize.mNeededBlockWidth = bitmap.GetWidth();
369 if( bitmap.GetHeight() > blockSize.mNeededBlockHeight )
372 blockSize.mNeededBlockHeight = bitmap.GetHeight();
377 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
378 DEFAULT_ATLAS_HEIGHT,
379 blockSize.mNeededBlockWidth,
380 blockSize.mNeededBlockHeight );
383 // Locate a new slot for our glyph
384 mGlyphManager.Add( glyph, bitmap, slot );
389 // We have 2+ copies of the same glyph
390 mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, 1/*increment*/ );
393 // Move the origin (0,0) of the mesh to the center of the actor
394 const Vector2 position = *( positionsBuffer + i ) - halfTextSize - lineOffsetPosition;
396 // Generate mesh data for this quad, plugging in our supplied position
397 AtlasManager::Mesh2D newMesh;
398 mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
399 textCacheEntry.mFontId = glyph.fontId;
400 textCacheEntry.mImageId = slot.mImageId;
401 textCacheEntry.mIndex = glyph.index;
402 newTextCache.PushBack( textCacheEntry );
404 AtlasManager::Vertex2D* verticesBuffer = newMesh.mVertices.Begin();
406 // Get the color of the character.
407 const ColorIndex colorIndex = useDefaultColor ? 0u : *( colorIndicesBuffer + i );
408 const Vector4& color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + colorIndex - 1u );
410 for( unsigned int index = 0u, size = newMesh.mVertices.Count();
414 AtlasManager::Vertex2D& vertex = *( verticesBuffer + index );
416 // Set the color of the vertex.
417 vertex.mColor = color;
420 // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
421 StitchTextMesh( meshContainer,
424 position.y + glyph.yBearing,
426 currentUnderlinePosition,
427 currentUnderlineThickness,
429 lastFontId = glyph.fontId;
433 // Now remove references for the old text
435 mTextCache.Swap( newTextCache );
437 if( thereAreUnderlinedGlyphs )
439 // Check to see if any of the text needs an underline
440 GenerateUnderlines( meshContainer, extents, underlineColor );
443 // For each MeshData object, create a mesh actor and add to the renderable actor
444 if( !meshContainer.empty() )
448 // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
449 mActor = Actor::New();
450 mActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
451 mActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
452 mActor.SetSize( textSize );
455 for( std::vector< MeshRecord >::iterator it = meshContainer.begin(),
456 endIt = meshContainer.end();
459 MeshRecord& meshRecord = *it;
461 Actor actor = CreateMeshActor( meshRecord, textSize, STYLE_NORMAL );
463 // Whether the actor has renderers.
464 const bool hasRenderer = actor.GetRendererCount() > 0u;
466 // Create an effect if necessary
468 ( style == STYLE_DROP_SHADOW ) )
470 // Change the color of the vertices.
471 for( Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
472 vEndIt = meshRecord.mMesh.mVertices.End();
476 AtlasManager::Vertex2D& vertex = *vIt;
478 vertex.mColor = shadowColor;
481 Actor shadowActor = CreateMeshActor( meshRecord, textSize, STYLE_DROP_SHADOW );
482 #if defined(DEBUG_ENABLED)
483 shadowActor.SetName( "Text Shadow renderable actor" );
485 // Offset shadow in x and y
486 shadowActor.RegisterProperty("uOffset", shadowOffset );
487 Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
488 int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
489 renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 );
490 mActor.Add( shadowActor );
499 #if defined(DEBUG_ENABLED)
500 Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
501 DALI_LOG_INFO( gLogFilter, Debug::General, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n",
503 metrics.mAtlasMetrics.mAtlasCount,
504 metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 );
506 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%s\n", metrics.mVerboseGlyphCounts.c_str() );
508 for( uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i )
510 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n",
511 i + 1, i > 8 ? "" : " ",
512 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mPixelFormat == Pixel::L8 ? "L8 " : "BGRA",
513 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mWidth,
514 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mHeight,
515 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockWidth,
516 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockHeight,
517 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlocksUsed,
518 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mTotalBlocks );
525 for( Vector< TextCacheEntry >::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter )
527 mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, -1/*decrement*/ );
529 mTextCache.Resize( 0 );
532 Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize, Style style )
534 PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
535 quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
537 Geometry quadGeometry = Geometry::New();
538 quadGeometry.AddVertexBuffer( quadVertices );
539 quadGeometry.SetIndexBuffer( &meshRecord.mMesh.mIndices[0], meshRecord.mMesh.mIndices.Size() );
541 TextureSet textureSet( mGlyphManager.GetTextures( meshRecord.mAtlasId ) );
543 // Choose the shader to use.
544 const bool isColorShader = ( STYLE_DROP_SHADOW != style ) && ( Pixel::BGRA8888 == mGlyphManager.GetPixelFormat( meshRecord.mAtlasId ) );
548 // The glyph is an emoji and is not a shadow.
551 mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA );
553 shader = mShaderRgba;
557 // The glyph is text or a shadow.
560 mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 );
565 Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader );
566 renderer.SetTextures( textureSet );
567 renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON );
568 renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth );
569 Actor actor = Actor::New();
570 #if defined(DEBUG_ENABLED)
571 actor.SetName( "Text renderable actor" );
573 actor.AddRenderer( renderer );
575 // Keep all of the origins aligned
576 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
577 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
578 actor.SetSize( actorSize );
579 actor.RegisterProperty("uOffset", Vector2::ZERO );
583 void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
584 AtlasManager::Mesh2D& newMesh,
585 Vector< Extent >& extents,
588 float underlinePosition,
589 float underlineThickness,
590 AtlasManager::AtlasSlot& slot )
594 float left = newMesh.mVertices[ 0 ].mPosition.x;
595 float right = newMesh.mVertices[ 1 ].mPosition.x;
597 // Check to see if there's a mesh data object that references the same atlas ?
599 for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(),
600 mEndIt = meshContainer.end();
604 if( slot.mAtlasId == mIt->mAtlasId )
606 // Append the mesh to the existing mesh and adjust any extents
607 Toolkit::Internal::AtlasMeshFactory::AppendMesh( mIt->mMesh, newMesh );
611 AdjustExtents( extents,
618 underlineThickness );
625 // No mesh data object currently exists that references this atlas, so create a new one
626 MeshRecord meshRecord;
627 meshRecord.mAtlasId = slot.mAtlasId;
628 meshRecord.mMesh = newMesh;
629 meshContainer.push_back( meshRecord );
633 // Adjust extents for this new meshrecord
634 AdjustExtents( extents,
636 meshContainer.size() - 1u,
641 underlineThickness );
646 void AdjustExtents( Vector< Extent >& extents,
647 std::vector< MeshRecord>& meshRecords,
652 float underlinePosition,
653 float underlineThickness )
655 bool foundExtent = false;
656 for ( Vector< Extent >::Iterator eIt = extents.Begin(),
657 eEndIt = extents.End();
661 if ( Equals( baseLine, eIt->mBaseLine ) )
664 if ( left < eIt->mLeft )
668 if ( right > eIt->mRight )
673 if ( underlinePosition > eIt->mUnderlinePosition )
675 eIt->mUnderlinePosition = underlinePosition;
677 if ( underlineThickness > eIt->mUnderlineThickness )
679 eIt->mUnderlineThickness = underlineThickness;
687 extent.mRight = right;
688 extent.mBaseLine = baseLine;
689 extent.mUnderlinePosition = underlinePosition;
690 extent.mUnderlineThickness = underlineThickness;
691 extent.mMeshRecordIndex = index;
692 extents.PushBack( extent );
696 void CalculateBlocksSize( const Vector<GlyphInfo>& glyphs )
698 for( Vector<GlyphInfo>::ConstIterator glyphIt = glyphs.Begin(),
699 glyphEndIt = glyphs.End();
700 glyphIt != glyphEndIt;
703 const FontId fontId = (*glyphIt).fontId;
704 bool foundFont = false;
706 for( std::vector< MaxBlockSize >::const_iterator blockIt = mBlockSizes.begin(),
707 blockEndIt = mBlockSizes.end();
708 blockIt != blockEndIt;
711 if( (*blockIt).mFontId == fontId )
720 FontMetrics fontMetrics;
721 mFontClient.GetFontMetrics( fontId, fontMetrics );
723 MaxBlockSize maxBlockSize;
724 maxBlockSize.mNeededBlockWidth = static_cast< uint32_t >( fontMetrics.height );
725 maxBlockSize.mNeededBlockHeight = maxBlockSize.mNeededBlockWidth;
726 maxBlockSize.mFontId = fontId;
728 mBlockSizes.push_back( maxBlockSize );
733 void GenerateUnderlines( std::vector< MeshRecord >& meshRecords,
734 Vector< Extent >& extents,
735 const Vector4& underlineColor )
737 AtlasManager::Mesh2D newMesh;
738 unsigned short faceIndex = 0;
739 for ( Vector< Extent >::ConstIterator eIt = extents.Begin(),
740 eEndIt = extents.End();
744 AtlasManager::Vertex2D vert;
745 uint32_t index = eIt->mMeshRecordIndex;
746 Vector2 uv = mGlyphManager.GetAtlasSize( meshRecords[ index ].mAtlasId );
748 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
749 float u = HALF / uv.x;
750 float v = HALF / uv.y;
751 float thickness = eIt->mUnderlineThickness;
752 float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ( thickness * HALF );
753 float tlx = eIt->mLeft;
754 float brx = eIt->mRight;
756 vert.mPosition.x = tlx;
757 vert.mPosition.y = baseLine;
758 vert.mTexCoords.x = ZERO;
759 vert.mTexCoords.y = ZERO;
760 vert.mColor = underlineColor;
761 newMesh.mVertices.PushBack( vert );
763 vert.mPosition.x = brx;
764 vert.mPosition.y = baseLine;
765 vert.mTexCoords.x = u;
766 vert.mColor = underlineColor;
767 newMesh.mVertices.PushBack( vert );
769 vert.mPosition.x = tlx;
770 vert.mPosition.y = baseLine + thickness;
771 vert.mTexCoords.x = ZERO;
772 vert.mTexCoords.y = v;
773 vert.mColor = underlineColor;
774 newMesh.mVertices.PushBack( vert );
776 vert.mPosition.x = brx;
777 vert.mPosition.y = baseLine + thickness;
778 vert.mTexCoords.x = u;
779 vert.mColor = underlineColor;
780 newMesh.mVertices.PushBack( vert );
782 // Six indices in counter clockwise winding
783 newMesh.mIndices.PushBack( faceIndex + 1u );
784 newMesh.mIndices.PushBack( faceIndex );
785 newMesh.mIndices.PushBack( faceIndex + 2u );
786 newMesh.mIndices.PushBack( faceIndex + 2u );
787 newMesh.mIndices.PushBack( faceIndex + 3u );
788 newMesh.mIndices.PushBack( faceIndex + 1u );
791 Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
795 Actor mActor; ///< The actor parent which renders the text
796 AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching
797 TextAbstraction::FontClient mFontClient; ///< The font client used to supply glyph information
798 Shader mShaderL8; ///< The shader for glyphs and emoji's shadows.
799 Shader mShaderRgba; ///< The shader for emojis.
800 std::vector< MaxBlockSize > mBlockSizes; ///< Maximum size needed to contain a glyph in a block within a new atlas
801 Vector< TextCacheEntry > mTextCache; ///< Caches data from previous render
802 Property::Map mQuadVertexFormat; ///< Describes the vertex format for text
803 int mDepth; ///< DepthIndex passed by control when connect to stage
806 Text::RendererPtr AtlasRenderer::New()
808 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Text::AtlasRenderer::New()\n" );
810 return Text::RendererPtr( new AtlasRenderer() );
813 Actor AtlasRenderer::Render( Text::ViewInterface& view,
814 float& alignmentOffset,
817 DALI_LOG_INFO( gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n" );
819 UnparentAndReset( mImpl->mActor );
821 Length numberOfGlyphs = view.GetNumberOfGlyphs();
823 if( numberOfGlyphs > 0u )
825 Vector<GlyphInfo> glyphs;
826 glyphs.Resize( numberOfGlyphs );
828 Vector<Vector2> positions;
829 positions.Resize( numberOfGlyphs );
831 numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
837 glyphs.Resize( numberOfGlyphs );
838 positions.Resize( numberOfGlyphs );
840 const Vector4* const colorsBuffer = view.GetColors();
841 const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
842 const Vector4& defaultColor = view.GetTextColor();
844 mImpl->AddGlyphs( view,
853 /* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
854 /* This renderable actor is used to position the text, other "decorations" can rely on there always being an Actor regardless of it is whitespace or regular text. */
855 if ( !mImpl->mActor )
857 mImpl->mActor = Actor::New();
861 return mImpl->mActor;
864 AtlasRenderer::AtlasRenderer()
870 AtlasRenderer::~AtlasRenderer()