2 * Copyright (c) 2015 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/integration-api/debug.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/images/frame-buffer-image.h>
25 #include <dali/public-api/render-tasks/render-task.h>
26 #include <dali/public-api/render-tasks/render-task-list.h>
27 #include <dali/devel-api/rendering/renderer.h>
28 #include <dali/devel-api/rendering/geometry.h>
29 #include <dali/devel-api/text-abstraction/font-client.h>
32 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
33 #include <dali-toolkit/internal/text/glyph-run.h>
34 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
35 #include <dali-toolkit/internal/text/text-view.h>
38 using namespace Dali::Toolkit;
39 using namespace Dali::Toolkit::Text;
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING");
47 const float ZERO( 0.0f );
48 const float HALF( 0.5f );
49 const float ONE( 1.0f );
50 const float TWO( 2.0f );
51 const uint32_t DEFAULT_ATLAS_WIDTH = 512u;
52 const uint32_t DEFAULT_ATLAS_HEIGHT = 512u;
54 struct AtlasRenderer::Impl : public ConnectionTracker
65 : mColor( Color::BLACK ),
72 AtlasManager::Mesh2D mMesh;
73 FrameBufferImage mBuffer;
77 * brief Struct used to generate the underline mesh.
78 * There is one Extent per line of text.
86 mUnderlinePosition( 0.0f ),
87 mUnderlineThickness( 0.0f ),
95 float mUnderlinePosition;
96 float mUnderlineThickness;
97 uint32_t mMeshRecordIndex;
104 mNeededBlockWidth( 0 ),
105 mNeededBlockHeight( 0 )
110 uint32_t mNeededBlockWidth;
111 uint32_t mNeededBlockHeight;
123 Text::GlyphIndex mIndex;
126 struct TextCacheEntry
136 Text::GlyphIndex mIndex;
143 mGlyphManager = AtlasGlyphManager::Get();
144 mFontClient = TextAbstraction::FontClient::Get();
146 mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
147 mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
148 mQuadIndexFormat[ "indices" ] = Property::INTEGER;
151 bool IsGlyphUnderlined( GlyphIndex index,
152 const Vector<GlyphRun>& underlineRuns )
154 // TODO: At the moment it works because we always traverse the glyphs starting from the beginning
155 // and there is only one glyph run! If there are more they should be ordered.
157 for( Vector<GlyphRun>::ConstIterator it = underlineRuns.Begin(),
158 endIt = underlineRuns.End();
162 const GlyphRun& run = *it;
164 if( ( run.glyphIndex <= index ) && ( index < run.glyphIndex + run.numberOfGlyphs ) )
173 void AddGlyphs( Text::ViewInterface& view,
174 const Vector<Vector2>& positions,
175 const Vector<GlyphInfo>& glyphs,
178 AtlasManager::AtlasSlot slot;
179 std::vector< MeshRecord > meshContainer;
180 Vector< Extent > extents;
181 TextCacheEntry textCacheEntry;
184 const Vector2& actorSize( view.GetControlSize() );
185 const Vector2 halfActorSize( actorSize * 0.5f );
186 const Vector4& textColor( view.GetTextColor() );
187 const Vector2& shadowOffset( view.GetShadowOffset() );
188 const Vector4& shadowColor( view.GetShadowColor() );
189 const bool underlineEnabled( view.IsUnderlineEnabled() );
190 const Vector4& underlineColor( view.GetUnderlineColor() );
191 const float underlineHeight( view.GetUnderlineHeight() );
193 // Get the underline runs.
194 const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
195 Vector<GlyphRun> underlineRuns;
196 underlineRuns.Resize( numberOfUnderlineRuns );
197 view.GetUnderlineRuns( underlineRuns.Begin(),
199 numberOfUnderlineRuns );
201 bool thereAreUnderlinedGlyphs = false;
203 float currentUnderlinePosition = ZERO;
204 float currentUnderlineThickness = underlineHeight;
205 uint32_t currentBlockSize = 0;
206 FontId lastFontId = 0;
207 FontId lastUnderlinedFontId = 0;
208 Style style = STYLE_NORMAL;
210 if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 )
212 style = STYLE_DROP_SHADOW;
215 CalculateBlocksSize( glyphs );
217 // Avoid emptying mTextCache (& removing references) until after incremented references for the new text
218 Vector< TextCacheEntry > newTextCache;
219 const GlyphInfo* const glyphsBuffer = glyphs.Begin();
220 const Vector2* const positionsBuffer = positions.Begin();
222 for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
224 const GlyphInfo& glyph = *( glyphsBuffer + i );
226 const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined( i, underlineRuns );
227 thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph;
229 // No operation for white space
230 if ( glyph.width && glyph.height )
232 // Are we still using the same fontId as previous
233 if ( underlineGlyph && ( glyph.fontId != lastUnderlinedFontId ) )
235 // We need to fetch fresh font underline metrics
236 FontMetrics fontMetrics;
237 mFontClient.GetFontMetrics( glyph.fontId, fontMetrics );
238 currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) );
239 const float descender = ceil( fabsf( fontMetrics.descender ) );
241 if ( underlineHeight == ZERO )
243 currentUnderlineThickness = fontMetrics.underlineThickness;
245 // Ensure underline will be at least a pixel high
246 if ( currentUnderlineThickness < ONE )
248 currentUnderlineThickness = ONE;
252 currentUnderlineThickness = ceil( currentUnderlineThickness );
256 // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
257 if ( currentUnderlinePosition > descender )
259 currentUnderlinePosition = descender;
261 if ( ZERO == currentUnderlinePosition )
263 // Move offset down by one ( EFL behavior )
264 currentUnderlinePosition = ONE;
267 lastUnderlinedFontId = glyph.fontId;
270 if ( !mGlyphManager.Cached( glyph.fontId, glyph.index, slot ) )
272 // Select correct size for new atlas if needed....?
273 if ( lastFontId != glyph.fontId )
275 for ( uint32_t j = 0; j < mBlockSizes.size(); ++j )
277 if ( mBlockSizes[ j ].mFontId == glyph.fontId )
279 currentBlockSize = j;
280 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
281 DEFAULT_ATLAS_HEIGHT,
282 mBlockSizes[ j ].mNeededBlockWidth,
283 mBlockSizes[ j ].mNeededBlockHeight );
288 // Create a new image for the glyph
289 BufferImage bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
292 // Ensure that the next image will fit into the current block size
293 bool setSize = false;
294 if ( bitmap.GetWidth() > mBlockSizes[ currentBlockSize ].mNeededBlockWidth )
297 mBlockSizes[ currentBlockSize ].mNeededBlockWidth = bitmap.GetWidth();
299 if ( bitmap.GetHeight() > mBlockSizes[ currentBlockSize ].mNeededBlockHeight )
302 mBlockSizes[ currentBlockSize ].mNeededBlockHeight = bitmap.GetHeight();
307 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
308 DEFAULT_ATLAS_HEIGHT,
309 mBlockSizes[ currentBlockSize ].mNeededBlockWidth,
310 mBlockSizes[ currentBlockSize ].mNeededBlockHeight );
313 // Locate a new slot for our glyph
314 mGlyphManager.Add( glyph, bitmap, slot );
319 // We have 2+ copies of the same glyph
320 mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, 1/*increment*/ );
323 // Move the origin (0,0) of the mesh to the center of the actor
324 Vector2 position = *( positionsBuffer + i ) - halfActorSize;
326 // Generate mesh data for this quad, plugging in our supplied position
327 AtlasManager::Mesh2D newMesh;
328 mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
329 textCacheEntry.mFontId = glyph.fontId;
330 textCacheEntry.mImageId = slot.mImageId;
331 textCacheEntry.mIndex = glyph.index;
332 newTextCache.PushBack( textCacheEntry );
334 // Adjust the vertices if the fixed-size font should be down-scaled
335 if( glyph.scaleFactor > 0 )
337 for( unsigned int i=0; i<newMesh.mVertices.Count(); ++i )
339 newMesh.mVertices[i].mPosition.x = position.x + ( ( newMesh.mVertices[i].mPosition.x - position.x ) * glyph.scaleFactor );
340 newMesh.mVertices[i].mPosition.y = position.y + ( ( newMesh.mVertices[i].mPosition.y - position.y ) * glyph.scaleFactor );
344 // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
345 StitchTextMesh( meshContainer,
349 position.y + glyph.yBearing,
351 currentUnderlinePosition,
352 currentUnderlineThickness,
354 lastFontId = glyph.fontId;
358 // Now remove references for the old text
360 mTextCache.Swap( newTextCache );
361 RemoveAllShadowRenderTasks();
363 if( thereAreUnderlinedGlyphs )
365 // Check to see if any of the text needs an underline
366 GenerateUnderlines( meshContainer, extents, underlineColor, textColor );
369 // For each MeshData object, create a mesh actor and add to the renderable actor
370 if ( meshContainer.size() )
372 for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt )
374 Actor actor = CreateMeshActor( *mIt, actorSize );
376 // Create an effect if necessary
377 if ( style == STYLE_DROP_SHADOW )
379 Actor shadowActor = GenerateShadow( *mIt, actorSize, shadowOffset, shadowColor );
380 shadowActor.Add( actor );
394 #if defined(DEBUG_ENABLED)
395 Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
396 DALI_LOG_INFO( gLogFilter, Debug::General, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n",
398 metrics.mAtlasMetrics.mAtlasCount,
399 metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 );
401 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%s\n", metrics.mVerboseGlyphCounts.c_str() );
403 for ( uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i )
405 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n",
406 i + 1, i > 8 ? "" : " ",
407 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mPixelFormat == Pixel::L8 ? "L8 " : "BGRA",
408 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mWidth,
409 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mHeight,
410 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockWidth,
411 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockHeight,
412 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlocksUsed,
413 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mTotalBlocks );
420 for ( Vector< TextCacheEntry >::Iterator oldTextIter = mTextCache.Begin(); oldTextIter != mTextCache.End(); ++oldTextIter )
422 mGlyphManager.AdjustReferenceCount( oldTextIter->mFontId, oldTextIter->mIndex, -1/*decrement*/ );
424 mTextCache.Resize( 0 );
427 Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize )
429 PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() );
430 PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() );
431 quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ) );
432 quadIndices.SetData( const_cast< unsigned int* >( &meshRecord.mMesh.mIndices[ 0 ] ) );
434 Geometry quadGeometry = Geometry::New();
435 quadGeometry.AddVertexBuffer( quadVertices );
436 quadGeometry.SetIndexBuffer( quadIndices );
438 Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
439 Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
440 renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth );
441 Actor actor = Actor::New();
442 #if defined(DEBUG_ENABLED)
443 actor.SetName( "Text renderable actor" );
445 actor.AddRenderer( renderer );
446 actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
447 actor.SetSize( actorSize );
448 actor.SetColor( meshRecord.mColor );
452 void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
453 AtlasManager::Mesh2D& newMesh,
454 Vector< Extent >& extents,
455 const Vector4& color,
458 float underlinePosition,
459 float underlineThickness,
460 AtlasManager::AtlasSlot& slot )
464 float left = newMesh.mVertices[ 0 ].mPosition.x;
465 float right = newMesh.mVertices[ 1 ].mPosition.x;
467 // Check to see if there's a mesh data object that references the same atlas ?
469 for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(),
470 mEndIt = meshContainer.end();
474 if ( slot.mAtlasId == mIt->mAtlasId && color == mIt->mColor )
476 // Stitch the mesh to the existing mesh and adjust any extents
477 mGlyphManager.StitchMesh( mIt->mMesh, newMesh );
481 AdjustExtents( extents,
488 underlineThickness );
495 // No mesh data object currently exists that references this atlas, so create a new one
496 MeshRecord meshRecord;
497 meshRecord.mAtlasId = slot.mAtlasId;
498 meshRecord.mMesh = newMesh;
499 meshRecord.mColor = color;
500 meshContainer.push_back( meshRecord );
504 // Adjust extents for this new meshrecord
505 AdjustExtents( extents,
507 meshContainer.size() - 1u,
512 underlineThickness );
517 void AdjustExtents( Vector< Extent >& extents,
518 std::vector< MeshRecord>& meshRecords,
523 float underlinePosition,
524 float underlineThickness )
526 bool foundExtent = false;
527 for ( Vector< Extent >::Iterator eIt = extents.Begin(),
528 eEndIt = extents.End();
532 if ( Equals( baseLine, eIt->mBaseLine ) )
535 if ( left < eIt->mLeft )
539 if ( right > eIt->mRight )
544 if ( underlinePosition > eIt->mUnderlinePosition )
546 eIt->mUnderlinePosition = underlinePosition;
548 if ( underlineThickness > eIt->mUnderlineThickness )
550 eIt->mUnderlineThickness = underlineThickness;
558 extent.mRight = right;
559 extent.mBaseLine = baseLine;
560 extent.mUnderlinePosition = underlinePosition;
561 extent.mUnderlineThickness = underlineThickness;
562 extent.mMeshRecordIndex = index;
563 extents.PushBack( extent );
567 void CalculateBlocksSize( const Vector<GlyphInfo>& glyphs )
569 MaxBlockSize maxBlockSize;
570 for ( uint32_t i = 0; i < glyphs.Size(); ++i )
572 FontId fontId = glyphs[ i ].fontId;
573 bool foundFont = false;
574 for ( uint32_t j = 0; j < mBlockSizes.size(); ++j )
576 if ( mBlockSizes[ j ].mFontId == fontId )
583 FontMetrics fontMetrics;
584 mFontClient.GetFontMetrics( fontId, fontMetrics );
585 maxBlockSize.mNeededBlockWidth = static_cast< uint32_t >( fontMetrics.height );
586 maxBlockSize.mNeededBlockHeight = static_cast< uint32_t >( fontMetrics.height );
587 maxBlockSize.mFontId = fontId;
588 mBlockSizes.push_back( maxBlockSize );
593 void GenerateUnderlines( std::vector< MeshRecord >& meshRecords,
594 Vector< Extent >& extents,
595 const Vector4& underlineColor,
596 const Vector4& textColor )
598 AtlasManager::Mesh2D newMesh;
599 unsigned short faceIndex = 0;
600 for ( Vector< Extent >::ConstIterator eIt = extents.Begin(),
601 eEndIt = extents.End();
605 AtlasManager::Vertex2D vert;
606 uint32_t index = eIt->mMeshRecordIndex;
607 Vector2 uv = mGlyphManager.GetAtlasSize( meshRecords[ index ].mAtlasId );
609 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
610 float u = HALF / uv.x;
611 float v = HALF / uv.y;
612 float thickness = eIt->mUnderlineThickness;
613 float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ( thickness * HALF );
614 float tlx = eIt->mLeft;
615 float brx = eIt->mRight;
617 vert.mPosition.x = tlx;
618 vert.mPosition.y = baseLine;
619 vert.mTexCoords.x = ZERO;
620 vert.mTexCoords.y = ZERO;
621 newMesh.mVertices.PushBack( vert );
623 vert.mPosition.x = brx;
624 vert.mPosition.y = baseLine;
625 vert.mTexCoords.x = u;
626 newMesh.mVertices.PushBack( vert );
628 vert.mPosition.x = tlx;
629 vert.mPosition.y = baseLine + thickness;
630 vert.mTexCoords.x = ZERO;
631 vert.mTexCoords.y = v;
632 newMesh.mVertices.PushBack( vert );
634 vert.mPosition.x = brx;
635 vert.mPosition.y = baseLine + thickness;
636 vert.mTexCoords.x = u;
637 newMesh.mVertices.PushBack( vert );
639 // Six indices in counter clockwise winding
640 newMesh.mIndices.PushBack( faceIndex + 1u );
641 newMesh.mIndices.PushBack( faceIndex );
642 newMesh.mIndices.PushBack( faceIndex + 2u );
643 newMesh.mIndices.PushBack( faceIndex + 2u );
644 newMesh.mIndices.PushBack( faceIndex + 3u );
645 newMesh.mIndices.PushBack( faceIndex + 1u );
648 if ( underlineColor == textColor )
650 mGlyphManager.StitchMesh( meshRecords[ index ].mMesh, newMesh );
655 record.mMesh = newMesh;
656 record.mAtlasId = meshRecords[ index ].mAtlasId;
657 record.mColor = underlineColor;
658 meshRecords.push_back( record );
663 Actor GenerateShadow( MeshRecord& meshRecord,
664 const Vector2& actorSize,
665 const Vector2& shadowOffset,
666 const Vector4& shadowColor )
668 // Scan vertex buffer to determine width and height of effect buffer needed
669 const Vector< AtlasManager::Vertex2D >& verts = meshRecord.mMesh.mVertices;
670 float tlx = verts[ 0 ].mPosition.x;
671 float tly = verts[ 0 ].mPosition.y;
675 for ( uint32_t i = 0; i < verts.Size(); ++i )
677 if ( verts[ i ].mPosition.x < tlx )
679 tlx = verts[ i ].mPosition.x;
681 if ( verts[ i ].mPosition.y < tly )
683 tly = verts[ i ].mPosition.y;
685 if ( verts[ i ].mPosition.x > brx )
687 brx = verts[ i ].mPosition.x;
689 if ( verts[ i ].mPosition.y > bry )
691 bry = verts[ i ].mPosition.y;
695 float width = brx - tlx;
696 float height = bry - tly;
697 float divWidth = TWO / width;
698 float divHeight = TWO / height;
700 // Create a buffer to render to
701 meshRecord.mBuffer = FrameBufferImage::New( width, height );
703 // We will render a quad into this buffer
704 unsigned int indices[ 6 ] = { 1, 0, 2, 2, 3, 1 };
705 PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, 4u );
706 PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat, sizeof(indices)/sizeof(indices[0]) );
708 AtlasManager::Vertex2D vertices[ 4 ] = {
709 { Vector2( tlx + shadowOffset.x, tly + shadowOffset.y ), Vector2( ZERO, ZERO ) },
710 { Vector2( brx + shadowOffset.x, tly + shadowOffset.y ), Vector2( ONE, ZERO ) },
711 { Vector2( tlx + shadowOffset.x, bry + shadowOffset.y ), Vector2( ZERO, ONE ) },
712 { Vector2( brx + shadowOffset.x, bry + shadowOffset.y ), Vector2( ONE, ONE ) } };
714 quadVertices.SetData( vertices );
715 quadIndices.SetData( indices );
717 Geometry quadGeometry = Geometry::New();
718 quadGeometry.AddVertexBuffer( quadVertices );
719 quadGeometry.SetIndexBuffer( quadIndices );
721 Material material = Material::New( mGlyphManager.GetEffectBufferShader() );
722 material.AddTexture(meshRecord.mBuffer, "sTexture");
724 Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
726 // Set depth index to -1.0 to make sure shadow is rendered first in 3D layers
727 renderer.SetDepthIndex( -1.0f );
728 Actor actor = Actor::New();
729 actor.AddRenderer( renderer );
730 actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
731 actor.SetSize( actorSize );
733 // Create a sub actor to render the source with normalized vertex positions
734 Vector< AtlasManager::Vertex2D > normVertexList;
735 for ( uint32_t i = 0; i < verts.Size(); ++i )
737 AtlasManager::Vertex2D vertex = verts[ i ];
738 vertex.mPosition.x = ( ( vertex.mPosition.x - tlx ) * divWidth ) - ONE;
739 vertex.mPosition.y = ( ( vertex.mPosition.y - tly ) * divHeight ) - ONE;
740 normVertexList.PushBack( vertex );
743 PropertyBuffer normVertices = PropertyBuffer::New( mQuadVertexFormat, normVertexList.Size() );
744 PropertyBuffer normIndices = PropertyBuffer::New( mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() );
745 normVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &normVertexList[ 0 ] ) );
746 normIndices.SetData( const_cast< unsigned int* >( &meshRecord.mMesh.mIndices[ 0 ] ) );
748 Geometry normGeometry = Geometry::New();
749 normGeometry.AddVertexBuffer( normVertices );
750 normGeometry.SetIndexBuffer( normIndices );
752 Material normMaterial = Material::New( mGlyphManager.GetGlyphShadowShader() );
753 Image normImage = mGlyphManager.GetImage( meshRecord.mAtlasId );
754 normMaterial.AddTexture( normImage, "sTexture" );
755 Dali::Renderer normRenderer = Dali::Renderer::New( normGeometry, normMaterial );
756 Actor subActor = Actor::New();
757 subActor.AddRenderer( normRenderer );
758 subActor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
759 subActor.SetSize( actorSize );
760 subActor.SetColor( shadowColor );
762 // Create a render task to render the effect
763 RenderTask shadowTask = Stage::GetCurrent().GetRenderTaskList().CreateTask();
764 shadowTask.SetTargetFrameBuffer( meshRecord.mBuffer );
765 shadowTask.SetSourceActor( subActor );
766 shadowTask.SetClearEnabled( true );
767 shadowTask.SetClearColor( Vector4::ZERO );
768 shadowTask.SetExclusive( true );
769 shadowTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
770 shadowTask.FinishedSignal().Connect( this, &AtlasRenderer::Impl::RenderComplete );
771 mShadowTasks.push_back( shadowTask );
772 actor.Add( subActor );
777 void RemoveShadowRenderTask( RenderTask renderTask )
781 renderTask.FinishedSignal().Disconnect( this, &AtlasRenderer::Impl::RenderComplete );
783 // Guard to prevent accessing Stage after dali-core destruction
784 if( Stage::IsInstalled() )
786 Stage::GetCurrent().GetRenderTaskList().RemoveTask( renderTask );
792 void RenderComplete( RenderTask& renderTask )
794 // Get the actor used for render to buffer and remove it from the parent
795 Actor renderActor = renderTask.GetSourceActor();
798 Actor parent = renderActor.GetParent();
801 parent.Remove( renderActor );
805 RemoveShadowRenderTask( renderTask );
808 void RemoveAllShadowRenderTasks()
810 for ( std::vector< RenderTask >::iterator shadowIterator = mShadowTasks.begin();
811 shadowIterator != mShadowTasks.end(); ++shadowIterator )
813 RemoveShadowRenderTask( *shadowIterator );
817 Actor mActor; ///< The actor parent which renders the text
818 AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching
819 std::vector< RenderTask > mShadowTasks; ///< Used to render shadows
820 TextAbstraction::FontClient mFontClient; ///> The font client used to supply glyph information
821 std::vector< MaxBlockSize > mBlockSizes; ///> Maximum size needed to contain a glyph in a block within a new atlas
822 std::vector< uint32_t > mFace; ///> Face indices for a quad
823 Vector< TextCacheEntry > mTextCache;
824 Property::Map mQuadVertexFormat;
825 Property::Map mQuadIndexFormat;
829 Text::RendererPtr AtlasRenderer::New()
831 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Text::AtlasRenderer::New()\n" );
833 return Text::RendererPtr( new AtlasRenderer() );
836 Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
838 UnparentAndReset( mImpl->mActor );
840 Length numberOfGlyphs = view.GetNumberOfGlyphs();
842 if( numberOfGlyphs > 0u )
844 Vector<GlyphInfo> glyphs;
845 glyphs.Resize( numberOfGlyphs );
847 Vector<Vector2> positions;
848 positions.Resize( numberOfGlyphs );
850 numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
854 glyphs.Resize( numberOfGlyphs );
855 positions.Resize( numberOfGlyphs );
857 mImpl->AddGlyphs( view,
863 return mImpl->mActor;
866 AtlasRenderer::AtlasRenderer()
872 AtlasRenderer::~AtlasRenderer()
874 mImpl->RemoveAllShadowRenderTasks();