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/public-api/images/frame-buffer-image.h>
25 #include <dali/devel-api/text-abstraction/font-client.h>
26 #include <dali/integration-api/debug.h>
29 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
30 #include <dali-toolkit/internal/text/glyph-run.h>
31 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
32 #include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
33 #include <dali-toolkit/internal/text/text-view.h>
36 using namespace Dali::Toolkit;
37 using namespace Dali::Toolkit::Text;
41 #if defined(DEBUG_ENABLED)
42 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
45 #define MAKE_SHADER(A)#A
47 const char* VERTEX_SHADER = MAKE_SHADER(
48 attribute mediump vec2 aPosition;
49 attribute mediump vec2 aTexCoord;
50 attribute mediump vec4 aColor;
51 uniform mediump vec2 uOffset;
52 uniform mediump mat4 uMvpMatrix;
53 varying mediump vec2 vTexCoord;
54 varying mediump vec4 vColor;
58 mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
59 gl_Position = uMvpMatrix * position;
60 vTexCoord = aTexCoord;
65 const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
66 uniform lowp vec4 uColor;
67 uniform sampler2D sTexture;
68 varying mediump vec2 vTexCoord;
69 varying mediump vec4 vColor;
73 mediump vec4 color = texture2D( sTexture, vTexCoord );
74 gl_FragColor = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a * color.r );
78 const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER(
79 uniform lowp vec4 uColor;
80 uniform sampler2D sTexture;
81 varying mediump vec2 vTexCoord;
85 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
89 const float ZERO( 0.0f );
90 const float HALF( 0.5f );
91 const float ONE( 1.0f );
92 const uint32_t DEFAULT_ATLAS_WIDTH = 512u;
93 const uint32_t DEFAULT_ATLAS_HEIGHT = 512u;
96 struct AtlasRenderer::Impl
112 AtlasManager::Mesh2D mMesh;
113 FrameBufferImage mBuffer;
117 * brief Struct used to generate the underline mesh.
118 * There is one Extent per line of text.
126 mUnderlinePosition( 0.0f ),
127 mUnderlineThickness( 0.0f ),
128 mMeshRecordIndex( 0u )
135 float mUnderlinePosition;
136 float mUnderlineThickness;
137 uint32_t mMeshRecordIndex;
144 mNeededBlockWidth( 0 ),
145 mNeededBlockHeight( 0 )
150 uint32_t mNeededBlockWidth;
151 uint32_t mNeededBlockHeight;
163 Text::GlyphIndex mIndex;
166 struct TextCacheEntry
176 Text::GlyphIndex mIndex;
183 mGlyphManager = AtlasGlyphManager::Get();
184 mFontClient = TextAbstraction::FontClient::Get();
186 mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
187 mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
188 mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
191 bool IsGlyphUnderlined( GlyphIndex index,
192 const Vector<GlyphRun>& underlineRuns )
194 for( Vector<GlyphRun>::ConstIterator it = underlineRuns.Begin(),
195 endIt = underlineRuns.End();
199 const GlyphRun& run = *it;
201 if( ( run.glyphIndex <= index ) && ( index < run.glyphIndex + run.numberOfGlyphs ) )
210 void AddGlyphs( Text::ViewInterface& view,
211 const Vector<Vector2>& positions,
212 const Vector<GlyphInfo>& glyphs,
213 const Vector4& defaultColor,
214 const Vector4* const colorsBuffer,
215 const ColorIndex* const colorIndicesBuffer,
217 float minLineOffset )
219 AtlasManager::AtlasSlot slot;
220 std::vector< MeshRecord > meshContainer;
221 Vector< Extent > extents;
222 TextCacheEntry textCacheEntry;
225 const Vector2& textSize( view.GetLayoutSize() );
226 const Vector2 halfTextSize( textSize * 0.5f );
227 const Vector2& shadowOffset( view.GetShadowOffset() );
228 const Vector4& shadowColor( view.GetShadowColor() );
229 const bool underlineEnabled( view.IsUnderlineEnabled() );
230 const Vector4& underlineColor( view.GetUnderlineColor() );
231 const float underlineHeight( view.GetUnderlineHeight() );
233 const bool useDefaultColor = ( NULL == colorsBuffer );
235 // Get the underline runs.
236 const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
237 Vector<GlyphRun> underlineRuns;
238 underlineRuns.Resize( numberOfUnderlineRuns );
239 view.GetUnderlineRuns( underlineRuns.Begin(),
241 numberOfUnderlineRuns );
243 bool thereAreUnderlinedGlyphs = false;
245 float currentUnderlinePosition = ZERO;
246 float currentUnderlineThickness = underlineHeight;
247 uint32_t currentBlockSize = 0;
248 FontId lastFontId = 0;
249 FontId lastUnderlinedFontId = 0;
250 Style style = STYLE_NORMAL;
252 if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 )
254 style = STYLE_DROP_SHADOW;
257 CalculateBlocksSize( glyphs );
259 // Avoid emptying mTextCache (& removing references) until after incremented references for the new text
260 Vector< TextCacheEntry > newTextCache;
261 const GlyphInfo* const glyphsBuffer = glyphs.Begin();
262 const Vector2* const positionsBuffer = positions.Begin();
263 const Vector2 lineOffsetPosition( minLineOffset, 0.f );
265 for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
267 const GlyphInfo& glyph = *( glyphsBuffer + i );
268 const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined( i, underlineRuns );
269 thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph;
271 // No operation for white space
272 if( glyph.width && glyph.height )
274 // Are we still using the same fontId as previous
275 if( underlineGlyph && ( glyph.fontId != lastUnderlinedFontId ) )
277 // We need to fetch fresh font underline metrics
278 FontMetrics fontMetrics;
279 mFontClient.GetFontMetrics( glyph.fontId, fontMetrics );
280 currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) );
281 const float descender = ceil( fabsf( fontMetrics.descender ) );
283 if( fabsf( underlineHeight ) < Math::MACHINE_EPSILON_1000 )
285 currentUnderlineThickness = fontMetrics.underlineThickness;
287 // Ensure underline will be at least a pixel high
288 if ( currentUnderlineThickness < ONE )
290 currentUnderlineThickness = ONE;
294 currentUnderlineThickness = ceil( currentUnderlineThickness );
298 // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
299 if( currentUnderlinePosition > descender )
301 currentUnderlinePosition = descender;
304 if( fabsf( currentUnderlinePosition ) < Math::MACHINE_EPSILON_1000 )
306 // Move offset down by one ( EFL behavior )
307 currentUnderlinePosition = ONE;
310 lastUnderlinedFontId = glyph.fontId;
313 if( !mGlyphManager.IsCached( glyph.fontId, glyph.index, slot ) )
315 // Select correct size for new atlas if needed....?
316 if( lastFontId != glyph.fontId )
319 for( std::vector<MaxBlockSize>::const_iterator it = mBlockSizes.begin(),
320 endIt = mBlockSizes.end();
324 const MaxBlockSize& blockSize = *it;
325 if( blockSize.mFontId == glyph.fontId )
327 currentBlockSize = index;
328 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
329 DEFAULT_ATLAS_HEIGHT,
330 blockSize.mNeededBlockWidth,
331 blockSize.mNeededBlockHeight );
336 // Create a new image for the glyph
339 // Whether the current glyph is a color one.
340 const bool isColorGlyph = mFontClient.IsColorGlyph( glyph.fontId, glyph.index );
342 // Retrieve the emoji's bitmap.
343 TextAbstraction::FontClient::GlyphBufferData glyphBufferData;
344 glyphBufferData.width = isColorGlyph ? glyph.width : 0; // Desired width and height.
345 glyphBufferData.height = isColorGlyph ? glyph.height : 0;
347 mFontClient.CreateBitmap( glyph.fontId,
351 // Create the pixel data.
352 bitmap = PixelData::New( glyphBufferData.buffer,
353 glyph.width * glyph.height * GetBytesPerPixel( glyphBufferData.format ),
356 glyphBufferData.format,
357 PixelData::DELETE_ARRAY );
361 MaxBlockSize& blockSize = mBlockSizes[currentBlockSize];
363 // Ensure that the next image will fit into the current block size
364 bool setSize = false;
365 if( bitmap.GetWidth() > blockSize.mNeededBlockWidth )
368 blockSize.mNeededBlockWidth = bitmap.GetWidth();
370 if( bitmap.GetHeight() > blockSize.mNeededBlockHeight )
373 blockSize.mNeededBlockHeight = bitmap.GetHeight();
378 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
379 DEFAULT_ATLAS_HEIGHT,
380 blockSize.mNeededBlockWidth,
381 blockSize.mNeededBlockHeight );
384 // Locate a new slot for our glyph
385 mGlyphManager.Add( glyph, bitmap, slot );
390 // We have 2+ copies of the same glyph
391 mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, 1/*increment*/ );
394 // Move the origin (0,0) of the mesh to the center of the actor
395 const Vector2 position = *( positionsBuffer + i ) - halfTextSize - lineOffsetPosition;
397 // Generate mesh data for this quad, plugging in our supplied position
398 AtlasManager::Mesh2D newMesh;
399 mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
400 textCacheEntry.mFontId = glyph.fontId;
401 textCacheEntry.mImageId = slot.mImageId;
402 textCacheEntry.mIndex = glyph.index;
403 newTextCache.PushBack( textCacheEntry );
405 AtlasManager::Vertex2D* verticesBuffer = newMesh.mVertices.Begin();
407 // Get the color of the character.
408 const ColorIndex colorIndex = useDefaultColor ? 0u : *( colorIndicesBuffer + i );
409 const Vector4& color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + colorIndex - 1u );
411 for( unsigned int index = 0u, size = newMesh.mVertices.Count();
415 AtlasManager::Vertex2D& vertex = *( verticesBuffer + index );
417 // Set the color of the vertex.
418 vertex.mColor = color;
421 // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
422 StitchTextMesh( meshContainer,
425 position.y + glyph.yBearing,
427 currentUnderlinePosition,
428 currentUnderlineThickness,
430 lastFontId = glyph.fontId;
434 // Now remove references for the old text
436 mTextCache.Swap( newTextCache );
438 if( thereAreUnderlinedGlyphs )
440 // Check to see if any of the text needs an underline
441 GenerateUnderlines( meshContainer, extents, underlineColor );
444 // For each MeshData object, create a mesh actor and add to the renderable actor
445 if( !meshContainer.empty() )
449 // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
450 mActor = Actor::New();
451 mActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
452 mActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
453 mActor.SetSize( textSize );
454 mActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
457 for( std::vector< MeshRecord >::iterator it = meshContainer.begin(),
458 endIt = meshContainer.end();
461 MeshRecord& meshRecord = *it;
463 Actor actor = CreateMeshActor( meshRecord, textSize, STYLE_NORMAL );
465 // Whether the actor has renderers.
466 const bool hasRenderer = actor.GetRendererCount() > 0u;
468 // Create an effect if necessary
470 ( style == STYLE_DROP_SHADOW ) )
472 // Change the color of the vertices.
473 for( Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
474 vEndIt = meshRecord.mMesh.mVertices.End();
478 AtlasManager::Vertex2D& vertex = *vIt;
480 vertex.mColor = shadowColor;
483 Actor shadowActor = CreateMeshActor( meshRecord, textSize, STYLE_DROP_SHADOW );
484 #if defined(DEBUG_ENABLED)
485 shadowActor.SetName( "Text Shadow renderable actor" );
487 // Offset shadow in x and y
488 shadowActor.RegisterProperty("uOffset", shadowOffset );
489 Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
490 int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
491 renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 );
492 mActor.Add( shadowActor );
501 #if defined(DEBUG_ENABLED)
502 Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
503 DALI_LOG_INFO( gLogFilter, Debug::General, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n",
505 metrics.mAtlasMetrics.mAtlasCount,
506 metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 );
508 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%s\n", metrics.mVerboseGlyphCounts.c_str() );
510 for( uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i )
512 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n",
513 i + 1, i > 8 ? "" : " ",
514 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mPixelFormat == Pixel::L8 ? "L8 " : "BGRA",
515 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mWidth,
516 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mHeight,
517 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockWidth,
518 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockHeight,
519 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlocksUsed,
520 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mTotalBlocks );
527 for( Vector< TextCacheEntry >::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter )
529 mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, -1/*decrement*/ );
531 mTextCache.Resize( 0 );
534 Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize, Style style )
536 PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
537 quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
539 Geometry quadGeometry = Geometry::New();
540 quadGeometry.AddVertexBuffer( quadVertices );
541 quadGeometry.SetIndexBuffer( &meshRecord.mMesh.mIndices[0], meshRecord.mMesh.mIndices.Size() );
543 TextureSet textureSet( mGlyphManager.GetTextures( meshRecord.mAtlasId ) );
545 // Choose the shader to use.
546 const bool isColorShader = ( STYLE_DROP_SHADOW != style ) && ( Pixel::BGRA8888 == mGlyphManager.GetPixelFormat( meshRecord.mAtlasId ) );
550 // The glyph is an emoji and is not a shadow.
553 mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA );
555 shader = mShaderRgba;
559 // The glyph is text or a shadow.
562 mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 );
567 Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader );
568 renderer.SetTextures( textureSet );
569 renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON );
570 renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth );
572 Actor actor = Actor::New();
573 #if defined(DEBUG_ENABLED)
574 actor.SetName( "Text renderable actor" );
576 actor.AddRenderer( renderer );
577 // Keep all of the origins aligned
578 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
579 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
580 actor.SetSize( actorSize );
581 actor.RegisterProperty("uOffset", Vector2::ZERO );
582 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
586 void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
587 AtlasManager::Mesh2D& newMesh,
588 Vector< Extent >& extents,
591 float underlinePosition,
592 float underlineThickness,
593 AtlasManager::AtlasSlot& slot )
597 float left = newMesh.mVertices[ 0 ].mPosition.x;
598 float right = newMesh.mVertices[ 1 ].mPosition.x;
600 // Check to see if there's a mesh data object that references the same atlas ?
602 for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(),
603 mEndIt = meshContainer.end();
607 if( slot.mAtlasId == mIt->mAtlasId )
609 // Append the mesh to the existing mesh and adjust any extents
610 Toolkit::Internal::AtlasMeshFactory::AppendMesh( mIt->mMesh, newMesh );
614 AdjustExtents( extents,
621 underlineThickness );
628 // No mesh data object currently exists that references this atlas, so create a new one
629 MeshRecord meshRecord;
630 meshRecord.mAtlasId = slot.mAtlasId;
631 meshRecord.mMesh = newMesh;
632 meshContainer.push_back( meshRecord );
636 // Adjust extents for this new meshrecord
637 AdjustExtents( extents,
639 meshContainer.size() - 1u,
644 underlineThickness );
649 void AdjustExtents( Vector< Extent >& extents,
650 std::vector< MeshRecord>& meshRecords,
655 float underlinePosition,
656 float underlineThickness )
658 bool foundExtent = false;
659 for ( Vector< Extent >::Iterator eIt = extents.Begin(),
660 eEndIt = extents.End();
664 if ( Equals( baseLine, eIt->mBaseLine ) )
667 if ( left < eIt->mLeft )
671 if ( right > eIt->mRight )
676 if ( underlinePosition > eIt->mUnderlinePosition )
678 eIt->mUnderlinePosition = underlinePosition;
680 if ( underlineThickness > eIt->mUnderlineThickness )
682 eIt->mUnderlineThickness = underlineThickness;
690 extent.mRight = right;
691 extent.mBaseLine = baseLine;
692 extent.mUnderlinePosition = underlinePosition;
693 extent.mUnderlineThickness = underlineThickness;
694 extent.mMeshRecordIndex = index;
695 extents.PushBack( extent );
699 void CalculateBlocksSize( const Vector<GlyphInfo>& glyphs )
701 for( Vector<GlyphInfo>::ConstIterator glyphIt = glyphs.Begin(),
702 glyphEndIt = glyphs.End();
703 glyphIt != glyphEndIt;
706 const FontId fontId = (*glyphIt).fontId;
707 bool foundFont = false;
709 for( std::vector< MaxBlockSize >::const_iterator blockIt = mBlockSizes.begin(),
710 blockEndIt = mBlockSizes.end();
711 blockIt != blockEndIt;
714 if( (*blockIt).mFontId == fontId )
723 FontMetrics fontMetrics;
724 mFontClient.GetFontMetrics( fontId, fontMetrics );
726 MaxBlockSize maxBlockSize;
727 maxBlockSize.mNeededBlockWidth = static_cast< uint32_t >( fontMetrics.height );
728 maxBlockSize.mNeededBlockHeight = maxBlockSize.mNeededBlockWidth;
729 maxBlockSize.mFontId = fontId;
731 mBlockSizes.push_back( maxBlockSize );
736 void GenerateUnderlines( std::vector< MeshRecord >& meshRecords,
737 Vector< Extent >& extents,
738 const Vector4& underlineColor )
740 AtlasManager::Mesh2D newMesh;
741 unsigned short faceIndex = 0;
742 for ( Vector< Extent >::ConstIterator eIt = extents.Begin(),
743 eEndIt = extents.End();
747 AtlasManager::Vertex2D vert;
748 uint32_t index = eIt->mMeshRecordIndex;
749 Vector2 uv = mGlyphManager.GetAtlasSize( meshRecords[ index ].mAtlasId );
751 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
752 float u = HALF / uv.x;
753 float v = HALF / uv.y;
754 float thickness = eIt->mUnderlineThickness;
755 float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ( thickness * HALF );
756 float tlx = eIt->mLeft;
757 float brx = eIt->mRight;
759 vert.mPosition.x = tlx;
760 vert.mPosition.y = baseLine;
761 vert.mTexCoords.x = ZERO;
762 vert.mTexCoords.y = ZERO;
763 vert.mColor = underlineColor;
764 newMesh.mVertices.PushBack( vert );
766 vert.mPosition.x = brx;
767 vert.mPosition.y = baseLine;
768 vert.mTexCoords.x = u;
769 vert.mColor = underlineColor;
770 newMesh.mVertices.PushBack( vert );
772 vert.mPosition.x = tlx;
773 vert.mPosition.y = baseLine + thickness;
774 vert.mTexCoords.x = ZERO;
775 vert.mTexCoords.y = v;
776 vert.mColor = underlineColor;
777 newMesh.mVertices.PushBack( vert );
779 vert.mPosition.x = brx;
780 vert.mPosition.y = baseLine + thickness;
781 vert.mTexCoords.x = u;
782 vert.mColor = underlineColor;
783 newMesh.mVertices.PushBack( vert );
785 // Six indices in counter clockwise winding
786 newMesh.mIndices.PushBack( faceIndex + 1u );
787 newMesh.mIndices.PushBack( faceIndex );
788 newMesh.mIndices.PushBack( faceIndex + 2u );
789 newMesh.mIndices.PushBack( faceIndex + 2u );
790 newMesh.mIndices.PushBack( faceIndex + 3u );
791 newMesh.mIndices.PushBack( faceIndex + 1u );
794 Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
798 Actor mActor; ///< The actor parent which renders the text
799 AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching
800 TextAbstraction::FontClient mFontClient; ///< The font client used to supply glyph information
801 Shader mShaderL8; ///< The shader for glyphs and emoji's shadows.
802 Shader mShaderRgba; ///< The shader for emojis.
803 std::vector< MaxBlockSize > mBlockSizes; ///< Maximum size needed to contain a glyph in a block within a new atlas
804 Vector< TextCacheEntry > mTextCache; ///< Caches data from previous render
805 Property::Map mQuadVertexFormat; ///< Describes the vertex format for text
806 int mDepth; ///< DepthIndex passed by control when connect to stage
809 Text::RendererPtr AtlasRenderer::New()
811 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Text::AtlasRenderer::New()\n" );
813 return Text::RendererPtr( new AtlasRenderer() );
816 Actor AtlasRenderer::Render( Text::ViewInterface& view,
817 float& alignmentOffset,
820 DALI_LOG_INFO( gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n" );
822 UnparentAndReset( mImpl->mActor );
824 Length numberOfGlyphs = view.GetNumberOfGlyphs();
826 if( numberOfGlyphs > 0u )
828 Vector<GlyphInfo> glyphs;
829 glyphs.Resize( numberOfGlyphs );
831 Vector<Vector2> positions;
832 positions.Resize( numberOfGlyphs );
834 numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
840 glyphs.Resize( numberOfGlyphs );
841 positions.Resize( numberOfGlyphs );
843 const Vector4* const colorsBuffer = view.GetColors();
844 const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
845 const Vector4& defaultColor = view.GetTextColor();
847 mImpl->AddGlyphs( view,
856 /* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
857 /* 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. */
858 if ( !mImpl->mActor )
860 mImpl->mActor = Actor::New();
864 return mImpl->mActor;
867 AtlasRenderer::AtlasRenderer()
873 AtlasRenderer::~AtlasRenderer()