X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Ftext-atlas-renderer.cpp;h=5ba07cee2b7c76670238a5d72a9fbcd2b347cf49;hb=d00a250741411c386d988e7ac34525cf94a1918e;hp=7b82d21ffc1f210288b23456ad7f71a2b9529235;hpb=2a8f032f9d3e1a78a31986a95ea72964a5b515b0;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index 7b82d21..5ba07ce 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ #include // EXTERNAL INCLUDES -#include -#include -#include +#include +#include #include +#include // INTERNAL INCLUDES #include @@ -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& positions, const Vector& glyphs, - const Vector& colors, + const Vector4& defaultColor, + const Vector4* const colorsBuffer, + const ColorIndex* const colorIndicesBuffer, int depth ) { AtlasManager::AtlasSlot slot; @@ -175,14 +176,16 @@ struct AtlasRenderer::Impl TextCacheEntry textCacheEntry; 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 underlineRuns; @@ -211,7 +214,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 +288,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 +325,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 +353,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; @@ -389,16 +392,29 @@ struct AtlasRenderer::Impl // For each MeshData object, create a mesh actor and add to the renderable actor if( !meshContainer.empty() ) { + if( !mActor ) + { + // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues. + mActor = Actor::New(); + mActor.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mActor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mActor.SetSize( textSize ); + } + for( std::vector< MeshRecord >::iterator it = meshContainer.begin(), endIt = meshContainer.end(); it != endIt; ++it ) { MeshRecord& meshRecord = *it; - Actor actor = CreateMeshActor( meshRecord, actorSize ); + Actor actor = CreateMeshActor( meshRecord, textSize ); + + // Whether the actor has renderers. + const bool hasRenderer = actor.GetRendererCount() > 0u; // Create an effect if necessary - if( style == STYLE_DROP_SHADOW ) + if( hasRenderer && + ( style == STYLE_DROP_SHADOW ) ) { // Change the color of the vertices. for( Vector::Iterator vIt = meshRecord.mMesh.mVertices.Begin(), @@ -411,38 +427,22 @@ struct AtlasRenderer::Impl vertex.mColor = shadowColor; } - // Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues. - Actor containerActor = Actor::New(); - 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 // Offset shadow in x and y shadowActor.RegisterProperty("uOffset", shadowOffset ); - if( actor.GetRendererCount() ) - { - Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) ); - int depthIndex = renderer.GetProperty(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 ); - actor = containerActor; - } + Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) ); + int depthIndex = renderer.GetProperty(Dali::Renderer::Property::DEPTH_INDEX); + renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 ); + mActor.Add( shadowActor ); } - if( mActor ) + if( hasRenderer ) { mActor.Add( actor ); } - else - { - mActor = actor; - } } } #if defined(DEBUG_ENABLED) @@ -480,25 +480,28 @@ struct AtlasRenderer::Impl Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize ) { - PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() ); - PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() ); - quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ) ); - quadIndices.SetData( const_cast< unsigned int* >( &meshRecord.mMesh.mIndices[ 0 ] ) ); + PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat ); + quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.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 +684,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 +715,6 @@ struct AtlasRenderer::Impl newMesh.mIndices.PushBack( faceIndex + 1u ); faceIndex += 4; - vert.mColor = underlineColor; - Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh ); } } @@ -720,7 +725,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 +737,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 +751,24 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth ) Vector positions; positions.Resize( numberOfGlyphs ); - Vector 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. */