Changed Atlas manager to use Dali::Texture instead of Dali::Atlas
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / text-atlas-renderer.cpp
index f4692dc..3ee577f 100644 (file)
@@ -38,7 +38,7 @@ using namespace Dali::Toolkit::Text;
 namespace
 {
 #if defined(DEBUG_ENABLED)
-  Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_RENDERING");
+  Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
 #endif
 
 const float ZERO( 0.0f );
@@ -141,7 +141,6 @@ struct AtlasRenderer::Impl
     mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
     mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
     mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
-    mQuadIndexFormat[ "indices" ] = Property::INTEGER;
   }
 
   bool IsGlyphUnderlined( GlyphIndex index,
@@ -166,7 +165,9 @@ struct AtlasRenderer::Impl
   void AddGlyphs( Text::ViewInterface& view,
                   const Vector<Vector2>& positions,
                   const Vector<GlyphInfo>& glyphs,
-                  const Vector<Vector4>& colors,
+                  const Vector4& defaultColor,
+                  const Vector4* const colorsBuffer,
+                  const ColorIndex* const colorIndicesBuffer,
                   int depth )
   {
     AtlasManager::AtlasSlot slot;
@@ -176,13 +177,16 @@ struct AtlasRenderer::Impl
     mDepth = depth;
 
     const Vector2& actorSize( view.GetControlSize() );
-    const Vector2 halfActorSize( actorSize * 0.5f );
+    const Vector2& textSize( view.GetLayoutSize() );
+    const Vector2 halfTextSize( textSize * 0.5f );
     const Vector2& shadowOffset( view.GetShadowOffset() );
     const Vector4& shadowColor( view.GetShadowColor() );
     const bool underlineEnabled( view.IsUnderlineEnabled() );
     const Vector4& underlineColor( view.GetUnderlineColor() );
     const float underlineHeight( view.GetUnderlineHeight() );
 
+    const bool useDefaultColor = ( NULL == colorsBuffer );
+
     // Get the underline runs.
     const Length numberOfUnderlineRuns = view.GetNumberOfUnderlineRuns();
     Vector<GlyphRun> underlineRuns;
@@ -211,7 +215,6 @@ struct AtlasRenderer::Impl
     Vector< TextCacheEntry > newTextCache;
     const GlyphInfo* const glyphsBuffer = glyphs.Begin();
     const Vector2* const positionsBuffer = positions.Begin();
-    const Vector4* const colorsBuffer = colors.Begin();
 
     for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
     {
@@ -286,7 +289,7 @@ struct AtlasRenderer::Impl
           }
 
           // Create a new image for the glyph
-          BufferImage bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
+          PixelData bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
           if( bitmap )
           {
             MaxBlockSize& blockSize = mBlockSizes[currentBlockSize];
@@ -323,7 +326,7 @@ struct AtlasRenderer::Impl
         }
 
         // Move the origin (0,0) of the mesh to the center of the actor
-        const Vector2 position = *( positionsBuffer + i ) - halfActorSize;
+        const Vector2 position = *( positionsBuffer + i ) - halfTextSize;
 
         // Generate mesh data for this quad, plugging in our supplied position
         AtlasManager::Mesh2D newMesh;
@@ -351,7 +354,8 @@ struct AtlasRenderer::Impl
         }
 
         // Get the color of the character.
-        const Vector4& color = *( colorsBuffer + i );
+        const ColorIndex colorIndex = useDefaultColor ? 0u : *( colorIndicesBuffer + i );
+        const Vector4& color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + colorIndex - 1u );
 
         for( unsigned int index = 0u, size = newMesh.mVertices.Count();
              index < size;
@@ -395,7 +399,7 @@ struct AtlasRenderer::Impl
       {
         MeshRecord& meshRecord = *it;
 
-        Actor actor = CreateMeshActor( meshRecord, actorSize );
+        Actor actor = CreateMeshActor( meshRecord, textSize );
 
         // Create an effect if necessary
         if( style == STYLE_DROP_SHADOW )
@@ -416,7 +420,7 @@ struct AtlasRenderer::Impl
           containerActor.SetParentOrigin( ParentOrigin::CENTER );
           containerActor.SetSize( actorSize );
 
-          Actor shadowActor = CreateMeshActor( meshRecord, actorSize );
+          Actor shadowActor = CreateMeshActor( meshRecord, textSize );
 #if defined(DEBUG_ENABLED)
           shadowActor.SetName( "Text Shadow renderable actor" );
 #endif
@@ -427,10 +431,11 @@ struct AtlasRenderer::Impl
             Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
             int depthIndex = renderer.GetProperty<int>(Dali::Renderer::Property::DEPTH_INDEX);
             renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 );
-            shadowActor.SetParentOrigin( ParentOrigin::CENTER );
-            shadowActor.SetSize( actorSize );
             containerActor.Add( shadowActor );
             containerActor.Add( actor );
+#if defined(DEBUG_ENABLED)
+            containerActor.SetName("TextContainer");
+#endif
             actor = containerActor;
           }
         }
@@ -481,24 +486,27 @@ struct AtlasRenderer::Impl
   Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize )
   {
     PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
-    PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat );
     quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
-    quadIndices.SetData(  const_cast< unsigned int* >(           &meshRecord.mMesh.mIndices[ 0 ] ),  meshRecord.mMesh.mIndices.Size() );
 
     Geometry quadGeometry = Geometry::New();
     quadGeometry.AddVertexBuffer( quadVertices );
-    quadGeometry.SetIndexBuffer( quadIndices );
+    quadGeometry.SetIndexBuffer( &meshRecord.mMesh.mIndices[0],  meshRecord.mMesh.mIndices.Size() );
 
-    Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
-    Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
-    renderer.SetProperty( Dali::Renderer::Property::BLENDING_MODE, BlendingMode::ON );
+    TextureSet textureSet( mGlyphManager.GetTextures( meshRecord.mAtlasId ) );
+    Shader shader( mGlyphManager.GetShader( meshRecord.mAtlasId ) );
+    Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader );
+    renderer.SetTextures( textureSet );
+    renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON );
     renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth );
     Actor actor = Actor::New();
 #if defined(DEBUG_ENABLED)
     actor.SetName( "Text renderable actor" );
 #endif
     actor.AddRenderer( renderer );
-    actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
+
+    // Keep all of the origins aligned
+    actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     actor.SetSize( actorSize );
     actor.RegisterProperty("uOffset", Vector2::ZERO );
     return actor;
@@ -681,22 +689,26 @@ struct AtlasRenderer::Impl
       vert.mPosition.y = baseLine;
       vert.mTexCoords.x = ZERO;
       vert.mTexCoords.y = ZERO;
+      vert.mColor = underlineColor;
       newMesh.mVertices.PushBack( vert );
 
       vert.mPosition.x = brx;
       vert.mPosition.y = baseLine;
       vert.mTexCoords.x = u;
+      vert.mColor = underlineColor;
       newMesh.mVertices.PushBack( vert );
 
       vert.mPosition.x = tlx;
       vert.mPosition.y = baseLine + thickness;
       vert.mTexCoords.x = ZERO;
       vert.mTexCoords.y = v;
+      vert.mColor = underlineColor;
       newMesh.mVertices.PushBack( vert );
 
       vert.mPosition.x = brx;
       vert.mPosition.y = baseLine + thickness;
       vert.mTexCoords.x = u;
+      vert.mColor = underlineColor;
       newMesh.mVertices.PushBack( vert );
 
       // Six indices in counter clockwise winding
@@ -708,8 +720,6 @@ struct AtlasRenderer::Impl
       newMesh.mIndices.PushBack( faceIndex + 1u );
       faceIndex += 4;
 
-      vert.mColor = underlineColor;
-
       Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
     }
   }
@@ -720,7 +730,6 @@ struct AtlasRenderer::Impl
   std::vector< MaxBlockSize > mBlockSizes;            ///> Maximum size needed to contain a glyph in a block within a new atlas
   Vector< TextCacheEntry > mTextCache;                ///> Caches data from previous render
   Property::Map mQuadVertexFormat;                    ///> Describes the vertex format for text
-  Property::Map mQuadIndexFormat;                     ///> Describes the index format for text
   int mDepth;                                         ///> DepthIndex passed by control when connect to stage
 };
 
@@ -733,6 +742,8 @@ Text::RendererPtr AtlasRenderer::New()
 
 Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
 {
+  DALI_LOG_INFO( gLogFilter, Debug::General, "Text::AtlasRenderer::Render()\n" );
+
   UnparentAndReset( mImpl->mActor );
 
   Length numberOfGlyphs = view.GetNumberOfGlyphs();
@@ -745,23 +756,24 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
     Vector<Vector2> positions;
     positions.Resize( numberOfGlyphs );
 
-    Vector<Vector4> colors;
-    colors.Resize( numberOfGlyphs, view.GetTextColor() );
-
     numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
                                      positions.Begin(),
-                                     colors.Begin(),
                                      0u,
                                      numberOfGlyphs );
 
     glyphs.Resize( numberOfGlyphs );
     positions.Resize( numberOfGlyphs );
-    colors.Resize( numberOfGlyphs );
+
+    const Vector4* const colorsBuffer = view.GetColors();
+    const ColorIndex* const colorIndicesBuffer = view.GetColorIndices();
+    const Vector4& defaultColor = view.GetTextColor();
 
     mImpl->AddGlyphs( view,
                       positions,
                       glyphs,
-                      colors,
+                      defaultColor,
+                      colorsBuffer,
+                      colorIndicesBuffer,
                       depth );
 
     /* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */