Merge "Fix for cursor. Avoid the jump of the grab handle when there is a mix of...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / text-atlas-renderer.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/dali.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/text-abstraction/font-client.h>
25 #include <dali/devel-api/actors/mesh-actor.h>
26 #include <dali/devel-api/geometry/mesh.h>
27
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/internal/atlas-manager/atlas-manager.h>
31 #include <dali-toolkit/internal/text/line-run.h>
32 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
33 #include <dali-toolkit/internal/text/rendering/shaders/text-basic-shader.h>
34 #include <dali-toolkit/internal/text/rendering/shaders/text-bgra-shader.h>
35 #include <dali-toolkit/internal/text/rendering/shaders/text-basic-shadow-shader.h>
36
37 using namespace Dali;
38 using namespace Dali::Toolkit;
39 using namespace Dali::Toolkit::Text;
40
41 namespace
42 {
43 #if defined(DEBUG_ENABLED)
44   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING");
45 #endif
46
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;
53 }
54
55 struct AtlasRenderer::Impl : public ConnectionTracker
56 {
57
58   enum Style
59   {
60     STYLE_NORMAL,
61     STYLE_DROP_SHADOW
62   };
63
64   struct MeshRecord
65   {
66     Vector4 mColor;
67     uint32_t mAtlasId;
68     MeshData mMeshData;
69     FrameBufferImage mBuffer;
70     bool mIsUnderline;
71   };
72
73   struct Extent
74   {
75     float mBaseLine;
76     float mLeft;
77     float mRight;
78     float mUnderlinePosition;
79     float mUnderlineThickness;
80     uint32_t mMeshRecordIndex;
81   };
82
83   struct AtlasRecord
84   {
85     uint32_t mImageId;
86     Text::GlyphIndex mIndex;
87   };
88
89   struct MaxBlockSize
90   {
91     FontId mFontId;
92     uint32_t mNeededBlockWidth;
93     uint32_t mNeededBlockHeight;
94   };
95
96   Impl()
97   {
98     mGlyphManager = AtlasGlyphManager::Get();
99     mFontClient = TextAbstraction::FontClient::Get();
100     mBasicShader = BasicShader::New();
101     mBgraShader = BgraShader::New();
102     mBasicShadowShader = BasicShadowShader::New();
103
104     mFace.reserve( 6u );
105     mFace.push_back( 0 ); mFace.push_back( 2u ); mFace.push_back( 1u );
106     mFace.push_back( 1u ); mFace.push_back( 2u ); mFace.push_back( 3u );
107   }
108
109   void AddGlyphs( const std::vector<Vector2>& positions,
110                   const Vector<GlyphInfo>& glyphs,
111                   const Vector4& textColor,
112                   const Vector2& shadowOffset,
113                   const Vector4& shadowColor,
114                   bool underlineEnabled,
115                   const Vector4& underlineColor,
116                   float underlineHeight )
117   {
118     AtlasManager::AtlasSlot slot;
119     std::vector< MeshRecord > meshContainer;
120     Vector< Extent > extents;
121
122     float currentUnderlinePosition = ZERO;
123     float currentUnderlineThickness = underlineHeight;
124     uint32_t currentBlockSize = 0;
125     FontId lastFontId = 0;
126     Style style = STYLE_NORMAL;
127
128     if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 )
129     {
130       style = STYLE_DROP_SHADOW;
131     }
132
133     if ( mImageIds.Size() )
134     {
135       // Unreference any currently used glyphs
136       RemoveText();
137     }
138
139     CalculateBlocksSize( glyphs );
140
141     for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
142     {
143       const GlyphInfo& glyph = glyphs[ i ];
144
145       // No operation for white space
146       if ( glyph.width && glyph.height )
147       {
148         // Are we still using the same fontId as previous
149         if ( glyph.fontId != lastFontId )
150         {
151           // We need to fetch fresh font underline metrics
152           FontMetrics fontMetrics;
153           mFontClient.GetFontMetrics( glyph.fontId, fontMetrics );
154           currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) );
155           float descender = ceil( fabsf( fontMetrics.descender ) );
156
157           if ( underlineHeight == ZERO )
158           {
159             currentUnderlineThickness = fontMetrics.underlineThickness;
160
161             // Ensure underline will be at least a pixel high
162             if ( currentUnderlineThickness < ONE )
163             {
164               currentUnderlineThickness = ONE;
165             }
166             else
167             {
168               currentUnderlineThickness = ceil( currentUnderlineThickness );
169             }
170           }
171
172           // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
173           if ( currentUnderlinePosition > descender )
174           {
175             currentUnderlinePosition = descender;
176           }
177           if ( ZERO == currentUnderlinePosition )
178           {
179             // Move offset down by one ( EFL behavior )
180             currentUnderlinePosition = ONE;
181           }
182         }
183
184         const Vector2& position = positions[ i ];
185         MeshData newMeshData;
186         mGlyphManager.Cached( glyph.fontId, glyph.index, slot );
187
188         if ( slot.mImageId )
189         {
190           // This glyph already exists so generate mesh data plugging in our supplied position
191           mGlyphManager.GenerateMeshData( slot.mImageId, position, newMeshData );
192           mImageIds.PushBack( slot.mImageId );
193         }
194         else
195         {
196
197           // Select correct size for new atlas if needed....?
198           if ( lastFontId != glyph.fontId )
199           {
200             for ( uint32_t j = 0; j < mBlockSizes.size(); ++j )
201             {
202               if ( mBlockSizes[ j ].mFontId == glyph.fontId )
203               {
204                 currentBlockSize = j;
205                 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
206                                                DEFAULT_ATLAS_HEIGHT,
207                                                mBlockSizes[ j ].mNeededBlockWidth,
208                                                mBlockSizes[ j ].mNeededBlockHeight );
209               }
210             }
211           }
212
213           // Create a new image for the glyph
214           BufferImage bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
215           if ( bitmap )
216           {
217             // Ensure that the next image will fit into the current block size
218             bool setSize = false;
219             if ( bitmap.GetWidth() > mBlockSizes[ currentBlockSize ].mNeededBlockWidth )
220             {
221               setSize = true;
222               mBlockSizes[ currentBlockSize ].mNeededBlockWidth = bitmap.GetWidth();
223             }
224             if ( bitmap.GetHeight() > mBlockSizes[ currentBlockSize ].mNeededBlockHeight )
225             {
226               setSize = true;
227               mBlockSizes[ currentBlockSize ].mNeededBlockHeight = bitmap.GetHeight();
228             }
229
230             if ( setSize )
231             {
232               mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
233                                              DEFAULT_ATLAS_HEIGHT,
234                                              mBlockSizes[ currentBlockSize ].mNeededBlockWidth,
235                                              mBlockSizes[ currentBlockSize ].mNeededBlockHeight );
236             }
237
238             // Locate a new slot for our glyph
239             mGlyphManager.Add( glyph, bitmap, slot );
240
241             // Generate mesh data for this quad, plugging in our supplied position
242             if ( slot.mImageId )
243             {
244               mGlyphManager.GenerateMeshData( slot.mImageId, position, newMeshData );
245               mImageIds.PushBack( slot.mImageId );
246             }
247           }
248         }
249         // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
250         StitchTextMesh( meshContainer,
251                         newMeshData,
252                         extents,
253                         textColor,
254                         position.y + glyph.yBearing,
255                         currentUnderlinePosition,
256                         currentUnderlineThickness,
257                         slot );
258         lastFontId = glyph.fontId;
259       }
260     }
261
262     if ( underlineEnabled )
263     {
264       // Check to see if any of the text needs an underline
265       GenerateUnderlines( meshContainer, extents, underlineColor, textColor );
266     }
267
268     // For each MeshData object, create a mesh actor and add to the renderable actor
269     if ( meshContainer.size() )
270     {
271       for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt )
272       {
273         MeshActor actor = MeshActor::New( Mesh::New( mIt->mMeshData ) );
274         actor.SetColor( mIt->mColor );
275
276         // Ensure that text rendering is unfiltered
277         actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
278         if ( mIt->mIsUnderline )
279         {
280           actor.SetColorMode( USE_OWN_COLOR );
281         }
282         else
283         {
284           actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
285         }
286
287         // Check to see what pixel format the shader should be
288         if ( mGlyphManager.GetPixelFormat( mIt->mAtlasId ) == Pixel::L8 )
289         {
290           // Create an effect if necessary
291           if ( style == STYLE_DROP_SHADOW )
292           {
293             actor.Add( GenerateShadow( *mIt, shadowOffset, shadowColor ) );
294           }
295           actor.SetShaderEffect( mBasicShader );
296         }
297         else
298         {
299           actor.SetShaderEffect( mBgraShader );
300         }
301
302         if ( mActor )
303         {
304           mActor.Add( actor );
305         }
306         else
307         {
308           mActor = actor;
309         }
310       }
311       mActor.OffStageSignal().Connect( this, &AtlasRenderer::Impl::OffStageDisconnect );
312     }
313 #if defined(DEBUG_ENABLED)
314     Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
315     DALI_LOG_INFO( gLogFilter, Debug::General, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n",
316                                                 metrics.mGlyphCount,
317                                                 metrics.mAtlasMetrics.mAtlasCount,
318                                                 metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 );
319     for ( uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i )
320     {
321       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n",
322                                                  i + 1, i > 8 ? "" : " ",
323                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mPixelFormat == Pixel::L8 ? "L8  " : "BGRA",
324                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mWidth,
325                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mHeight,
326                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockWidth,
327                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockHeight,
328                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlocksUsed,
329                                                  metrics.mAtlasMetrics.mAtlasMetrics[ i ].mTotalBlocks );
330     }
331 #endif
332   }
333
334   void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
335                        MeshData& newMeshData,
336                        Vector< Extent >& extents,
337                        const Vector4& color,
338                        float baseLine,
339                        float underlinePosition,
340                        float underlineThickness,
341                        AtlasManager::AtlasSlot& slot )
342   {
343     if ( slot.mImageId )
344     {
345       MeshData::VertexContainer verts = newMeshData.GetVertices();
346       float left = verts[ 0 ].x;
347       float right = verts[ 1 ].x;
348
349       // Check to see if there's a mesh data object that references the same atlas ?
350       uint32_t index = 0;
351       for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt, ++index )
352       {
353         if ( slot.mAtlasId == mIt->mAtlasId && color == mIt->mColor )
354         {
355           // Stitch the mesh to the existing mesh and adjust any extents
356           mGlyphManager.StitchMesh( mIt->mMeshData, newMeshData );
357           AdjustExtents( extents,
358                          meshContainer,
359                          index,
360                          left,
361                          right,
362                          baseLine,
363                          underlinePosition,
364                          underlineThickness );
365           return;
366         }
367       }
368
369       // No mesh data object currently exists that references this atlas, so create a new one
370       MeshRecord meshRecord;
371       meshRecord.mAtlasId = slot.mAtlasId;
372       meshRecord.mMeshData = newMeshData;
373       meshRecord.mColor = color;
374       meshRecord.mIsUnderline = false;
375       meshContainer.push_back( meshRecord );
376
377       // Adjust extents for this new meshrecord
378       AdjustExtents( extents,
379                      meshContainer,
380                      meshContainer.size() - 1u,
381                      left,
382                      right,
383                      baseLine,
384                      underlinePosition,
385                      underlineThickness );
386
387     }
388   }
389
390   void AdjustExtents( Vector< Extent >& extents,
391                       std::vector< MeshRecord>& meshRecords,
392                       uint32_t index,
393                       float left,
394                       float right,
395                       float baseLine,
396                       float underlinePosition,
397                       float underlineThickness )
398   {
399     bool foundExtent = false;
400     for ( Vector< Extent >::Iterator eIt = extents.Begin(); eIt != extents.End(); ++eIt )
401     {
402       if ( Equals( baseLine, eIt->mBaseLine ) )
403       {
404         foundExtent = true;
405         if ( left < eIt->mLeft )
406         {
407           eIt->mLeft = left;
408         }
409         if ( right > eIt->mRight  )
410         {
411           eIt->mRight = right;
412         }
413
414         if ( underlinePosition > eIt->mUnderlinePosition )
415         {
416           eIt->mUnderlinePosition = underlinePosition;
417         }
418         if ( underlineThickness > eIt->mUnderlineThickness )
419         {
420           eIt->mUnderlineThickness = underlineThickness;
421         }
422       }
423     }
424     if ( !foundExtent )
425     {
426       Extent extent;
427       extent.mLeft = left;
428       extent.mRight = right;
429       extent.mBaseLine = baseLine;
430       extent.mUnderlinePosition = underlinePosition;
431       extent.mUnderlineThickness = underlineThickness;
432       extent.mMeshRecordIndex = index;
433       extents.PushBack( extent );
434     }
435   }
436
437   // Unreference any glyphs that were used with this actor
438   void OffStageDisconnect( Dali::Actor actor )
439   {
440     RemoveText();
441   }
442
443   void RemoveText()
444   {
445     for ( uint32_t i = 0; i < mImageIds.Size(); ++i )
446     {
447       mGlyphManager.Remove( mImageIds[ i ] );
448     }
449     mImageIds.Resize( 0 );
450   }
451
452   void CalculateBlocksSize( const Vector<GlyphInfo>& glyphs )
453   {
454     MaxBlockSize maxBlockSize;
455     for ( uint32_t i = 0; i < glyphs.Size(); ++i )
456     {
457       FontId fontId = glyphs[ i ].fontId;
458       bool foundFont = false;
459       for ( uint32_t j = 0; j < mBlockSizes.size(); ++j )
460       {
461         if ( mBlockSizes[ j ].mFontId == fontId )
462         {
463           foundFont = true;
464         }
465       }
466       if ( !foundFont )
467       {
468         FontMetrics fontMetrics;
469         mFontClient.GetFontMetrics( fontId, fontMetrics );
470         maxBlockSize.mNeededBlockWidth = static_cast< uint32_t >( fontMetrics.height );
471         maxBlockSize.mNeededBlockHeight = static_cast< uint32_t >( fontMetrics.height );
472         maxBlockSize.mFontId = fontId;
473         mBlockSizes.push_back( maxBlockSize );
474       }
475     }
476   }
477
478   void GenerateUnderlines( std::vector< MeshRecord>& meshRecords,
479                            Vector< Extent >& extents,
480                            const Vector4& underlineColor,
481                            const Vector4& textColor )
482   {
483     MeshData newMeshData;
484     for ( Vector< Extent >::ConstIterator eIt = extents.Begin(); eIt != extents.End(); ++eIt )
485     {
486       MeshData::VertexContainer newVerts;
487       newVerts.reserve( 4u );
488       uint32_t index = eIt->mMeshRecordIndex;
489       Vector2 uv = mGlyphManager.GetAtlasSize( meshRecords[ index ].mAtlasId );
490
491       // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
492       float u = HALF / uv.x;
493       float v = HALF / uv.y;
494       float thickness = eIt->mUnderlineThickness;
495       float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ( thickness * HALF );
496       float tlx = eIt->mLeft;
497       float brx = eIt->mRight;
498
499       newVerts.push_back( MeshData::Vertex( Vector3( tlx, baseLine, ZERO ),
500                                             Vector2::ZERO,
501                                             Vector3::ZERO ) );
502
503       newVerts.push_back( MeshData::Vertex( Vector3( brx, baseLine, ZERO ),
504                                             Vector2( u, ZERO ),
505                                             Vector3::ZERO ) );
506
507       newVerts.push_back( MeshData::Vertex( Vector3( tlx, baseLine + thickness, ZERO ),
508                                             Vector2( ZERO, v ),
509                                             Vector3::ZERO ) );
510
511       newVerts.push_back( MeshData::Vertex( Vector3( brx, baseLine + thickness, ZERO ),
512                                             Vector2( u, v ),
513                                             Vector3::ZERO ) );
514
515       newMeshData.SetVertices( newVerts );
516       newMeshData.SetFaceIndices( mFace );
517
518       if ( underlineColor == textColor )
519       {
520         mGlyphManager.StitchMesh( meshRecords[ index ].mMeshData, newMeshData );
521       }
522       else
523       {
524         MeshRecord record;
525         newMeshData.SetMaterial( meshRecords[ index ].mMeshData.GetMaterial() );
526         newMeshData.SetHasNormals( true );
527         newMeshData.SetHasColor( false );
528         newMeshData.SetHasTextureCoords( true );
529         record.mMeshData = newMeshData;
530         record.mAtlasId = meshRecords[ index ].mAtlasId;
531         record.mColor = underlineColor;
532         record.mIsUnderline = true;
533         meshRecords.push_back( record );
534       }
535     }
536   }
537
538   MeshActor GenerateShadow( MeshRecord& meshRecord,
539                             const Vector2& shadowOffset,
540                             const Vector4& shadowColor )
541   {
542     // Scan vertex buffer to determine width and height of effect buffer needed
543     MeshData::VertexContainer verts = meshRecord.mMeshData.GetVertices();
544     float tlx = verts[ 0 ].x;
545     float tly = verts[ 0 ].y;
546     float brx = ZERO;
547     float bry = ZERO;
548
549     for ( uint32_t i = 0; i < verts.size(); ++i )
550     {
551       if ( verts[ i ].x < tlx )
552       {
553         tlx = verts[ i ].x;
554       }
555       if ( verts[ i ].y < tly )
556       {
557         tly = verts[ i ].y;
558       }
559       if ( verts[ i ].x > brx )
560       {
561         brx = verts[ i ].x;
562       }
563       if ( verts[ i ].y > bry )
564       {
565         bry = verts[ i ].y;
566       }
567     }
568
569     float width = brx - tlx;
570     float height = bry - tly;
571     float divWidth = TWO / width;
572     float divHeight = TWO / height;
573
574     // Create a buffer to render to
575     meshRecord.mBuffer = FrameBufferImage::New( width, height );
576
577     // Create a mesh actor to contain the post-effect render
578     MeshData::VertexContainer vertices;
579     MeshData::FaceIndices face;
580
581     vertices.push_back( MeshData::Vertex( Vector3( tlx + shadowOffset.x, tly + shadowOffset.y, ZERO ),
582                                           Vector2::ZERO,
583                                           Vector3::ZERO ) );
584
585     vertices.push_back( MeshData::Vertex( Vector3( brx + shadowOffset.x, tly + shadowOffset.y, ZERO ),
586                                           Vector2( ONE, ZERO ),
587                                           Vector3::ZERO ) );
588
589     vertices.push_back( MeshData::Vertex( Vector3( tlx + shadowOffset.x, bry + shadowOffset.y, ZERO ),
590                                           Vector2( ZERO, ONE ),
591                                           Vector3::ZERO ) );
592
593     vertices.push_back( MeshData::Vertex( Vector3( brx + shadowOffset.x, bry + shadowOffset.y, ZERO ),
594                                           Vector2::ONE,
595                                           Vector3::ZERO ) );
596
597     MeshData meshData;
598     Material newMaterial = Material::New("effect buffer");
599     newMaterial.SetDiffuseTexture( meshRecord.mBuffer );
600     meshData.SetMaterial( newMaterial );
601     meshData.SetVertices( vertices );
602     meshData.SetFaceIndices( mFace );
603     meshData.SetHasNormals( true );
604     meshData.SetHasColor( false );
605     meshData.SetHasTextureCoords( true );
606     MeshActor actor = MeshActor::New( Mesh::New( meshData ) );
607     actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
608     actor.SetShaderEffect( mBgraShader );
609     actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
610     actor.SetSortModifier( 0.1f ); // force behind main text
611
612     // Create a sub actor to render once with normalized vertex positions
613     MeshData newMeshData;
614     MeshData::VertexContainer newVerts;
615     MeshData::FaceIndices newFaces;
616     MeshData::FaceIndices faces = meshRecord.mMeshData.GetFaces();
617     for ( uint32_t i = 0; i < verts.size(); ++i )
618     {
619       MeshData::Vertex vertex = verts[ i ];
620       vertex.x = ( ( vertex.x - tlx ) * divWidth ) - ONE;
621       vertex.y = ( ( vertex.y - tly ) * divHeight ) - ONE;
622       newVerts.push_back( vertex );
623     }
624
625     // Reverse triangle winding order
626     uint32_t faceCount = faces.size() / 3;
627     for ( uint32_t i = 0; i < faceCount; ++i )
628     {
629       uint32_t index = i * 3;
630       newFaces.push_back( faces[ index + 2 ] );
631       newFaces.push_back( faces[ index + 1 ] );
632       newFaces.push_back( faces[ index ] );
633     }
634
635     newMeshData.SetMaterial( meshRecord.mMeshData.GetMaterial() );
636     newMeshData.SetVertices( newVerts );
637     newMeshData.SetFaceIndices( newFaces );
638     newMeshData.SetHasNormals( true );
639     newMeshData.SetHasColor( false );
640     newMeshData.SetHasTextureCoords( true );
641
642     MeshActor subActor = MeshActor::New( Mesh::New( newMeshData ) );
643     subActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
644     subActor.SetColor( shadowColor );
645     subActor.SetShaderEffect( mBasicShadowShader );
646     subActor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
647
648     // Create a render task to render the effect
649     RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
650     task.SetTargetFrameBuffer( meshRecord.mBuffer );
651     task.SetSourceActor( subActor );
652     task.SetClearEnabled( true );
653     task.SetClearColor( Vector4::ZERO );
654     task.SetExclusive( true );
655     task.SetRefreshRate( RenderTask::REFRESH_ONCE );
656     task.FinishedSignal().Connect( this, &AtlasRenderer::Impl::RenderComplete );
657     actor.Add( subActor );
658     return actor;
659   }
660
661   void RenderComplete( RenderTask& renderTask )
662   {
663     // Disconnect and remove this single shot render task
664     renderTask.FinishedSignal().Disconnect( this, &AtlasRenderer::Impl::RenderComplete );
665     Stage::GetCurrent().GetRenderTaskList().RemoveTask( renderTask );
666
667     // Get the actor used for render to buffer and remove it from the parent
668     Actor renderActor = renderTask.GetSourceActor();
669     if ( renderActor )
670     {
671       Actor parent = renderActor.GetParent();
672       if ( parent )
673       {
674         parent.Remove( renderActor );
675       }
676     }
677   }
678
679   RenderableActor mActor;                             ///< The actor parent which renders the text
680   AtlasGlyphManager mGlyphManager;                    ///< Glyph Manager to handle upload and caching
681   Vector< uint32_t > mImageIds;                       ///< A list of imageIDs used by the renderer
682   TextAbstraction::FontClient mFontClient;            ///> The font client used to supply glyph information
683   ShaderEffect mBasicShader;                          ///> Shader used to render L8 glyphs
684   ShaderEffect mBgraShader;                           ///> Shader used to render BGRA glyphs
685   ShaderEffect mBasicShadowShader;                    ///> Shader used to render drop shadow into buffer
686   std::vector< MaxBlockSize > mBlockSizes;            ///> Maximum size needed to contain a glyph in a block within a new atlas
687   std::vector< MeshData::FaceIndex > mFace;           ///> Face indices for a quad
688 };
689
690 Text::RendererPtr AtlasRenderer::New()
691 {
692   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Text::AtlasRenderer::New()\n" );
693
694   return Text::RendererPtr( new AtlasRenderer() );
695 }
696
697 RenderableActor AtlasRenderer::Render( Text::ViewInterface& view )
698 {
699   UnparentAndReset( mImpl->mActor );
700
701   Length numberOfGlyphs = view.GetNumberOfGlyphs();
702
703   if( numberOfGlyphs > 0u )
704   {
705     Vector<GlyphInfo> glyphs;
706     glyphs.Resize( numberOfGlyphs );
707
708     std::vector<Vector2> positions;
709     positions.resize( numberOfGlyphs );
710
711     numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
712                                      &positions[0],
713                                      0u,
714                                      numberOfGlyphs );
715     glyphs.Resize( numberOfGlyphs );
716     positions.resize( numberOfGlyphs );
717
718     mImpl->AddGlyphs( positions,
719                       glyphs,
720                       view.GetTextColor(),
721                       view.GetShadowOffset(),
722                       view.GetShadowColor(),
723                       view.IsUnderlineEnabled(),
724                       view.GetUnderlineColor(),
725                       view.GetUnderlineHeight() );
726   }
727
728   return mImpl->mActor;
729 }
730
731 AtlasRenderer::AtlasRenderer()
732 {
733   mImpl = new Impl();
734
735 }
736
737 AtlasRenderer::~AtlasRenderer()
738 {
739   delete mImpl;
740 }