X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fvisual-factory-cache.cpp;h=594c12fd2479db09d9281959cee675f55752323d;hp=bf6814d0cc331bf301c781f853654f67572e05be;hb=5a6809a40da6a50d2edce9202466aa289ad96162;hpb=d0b03f52573948c53cdca89ec5e3be201737c3bb diff --git a/dali-toolkit/internal/visuals/visual-factory-cache.cpp b/dali-toolkit/internal/visuals/visual-factory-cache.cpp index bf6814d..594c12f 100644 --- a/dali-toolkit/internal/visuals/visual-factory-cache.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-cache.cpp @@ -26,6 +26,7 @@ #include #include + namespace { const char * const BROKEN_VISUAL_IMAGE_URL( DALI_IMAGE_DIR "broken.png"); @@ -40,8 +41,11 @@ namespace Toolkit namespace Internal { -VisualFactoryCache::VisualFactoryCache() -: mSvgRasterizeThread( NULL ) +VisualFactoryCache::VisualFactoryCache( bool preMultiplyOnLoad ) +: mSvgRasterizeThread( NULL ), + mVectorAnimationThread(), + mBrokenImageUrl(""), + mPreMultiplyOnLoad( preMultiplyOnLoad ) { } @@ -52,6 +56,11 @@ VisualFactoryCache::~VisualFactoryCache() Geometry VisualFactoryCache::GetGeometry( GeometryType type ) { + if( !mGeometry[type] && type == QUAD_GEOMETRY ) + { + mGeometry[type] = CreateQuadGeometry(); + } + return mGeometry[type]; } @@ -70,86 +79,6 @@ void VisualFactoryCache::SaveShader( ShaderType type, Shader shader ) mShader[type] = shader; } -int VisualFactoryCache::FindRenderer( const std::string& key ) const -{ - int hash = Dali::CalculateHash( key ); - - HashVector::Iterator startIt = mRendererHashes.Begin(); - HashVector::Iterator it; - - for(;;) - { - it = std::find( startIt, mRendererHashes.End(), hash ); - if( it != mRendererHashes.End() ) - { - int index = it - mRendererHashes.Begin(); - const CachedRenderer* cachedRenderer = mRenderers[ index ]; - - if( cachedRenderer && cachedRenderer->mKey == key ) - { - return index; - } - } - else - { - break; - } - startIt = it + 1; - } - - return -1; -} - -Renderer VisualFactoryCache::GetRenderer( const std::string& key ) const -{ - int index = FindRenderer( key ); - if( index != -1 ) - { - return mRenderers[ index ]->mRenderer.GetHandle(); - } - else - { - return Renderer(); - } -} - -void VisualFactoryCache::SaveRenderer( const std::string& key, Renderer& renderer ) -{ - int hash = Dali::CalculateHash( key ); - const CachedRenderer* cachedRenderer = new CachedRenderer( key, renderer ); - - CachedRenderers::Iterator it = std::find( mRenderers.Begin(), mRenderers.End(), static_cast< CachedRenderer* >( NULL ) ); - if( it != mRenderers.End() ) - { - *it = cachedRenderer; - int index = it - mRenderers.Begin(); - mRendererHashes[ index ] = hash; - } - else - { - mRendererHashes.PushBack( hash ); - mRenderers.PushBack( cachedRenderer ); - } -} - -bool VisualFactoryCache::CleanRendererCache( const std::string& key ) -{ - int index = FindRenderer( key ); - if( index != -1 ) - { - const CachedRenderer*& cachedRenderer = mRenderers[ index ]; - if( !cachedRenderer->mRenderer.GetHandle() ) - { - mRendererHashes[ index ] = Dali::INITIAL_HASH_VALUE; - - delete cachedRenderer; - cachedRenderer = NULL; - return true; - } - } - return false; -} - Geometry VisualFactoryCache::CreateQuadGeometry() { const float halfWidth = 0.5f; @@ -181,12 +110,17 @@ ImageAtlasManagerPtr VisualFactoryCache::GetAtlasManager() if( !mAtlasManager ) { mAtlasManager = new ImageAtlasManager(); - mAtlasManager->SetBrokenImage( BROKEN_VISUAL_IMAGE_URL ); + mAtlasManager->SetBrokenImage( mBrokenImageUrl ); } return mAtlasManager; } +TextureManager& VisualFactoryCache::GetTextureManager() +{ + return mTextureManager; +} + NPatchLoader& VisualFactoryCache::GetNPatchLoader() { return mNPatchLoader; @@ -202,11 +136,21 @@ SvgRasterizeThread* VisualFactoryCache::GetSVGRasterizationThread() return mSvgRasterizeThread; } +VectorAnimationThread& VisualFactoryCache::GetVectorAnimationThread() +{ + if( !mVectorAnimationThread ) + { + mVectorAnimationThread = std::unique_ptr< VectorAnimationThread >( new VectorAnimationThread() ); + mVectorAnimationThread->Start(); + } + return *mVectorAnimationThread; +} + void VisualFactoryCache::ApplyRasterizedSVGToSampler() { while( RasterizingTaskPtr task = mSvgRasterizeThread->NextCompletedTask() ) { - task->GetSvgVisual()->ApplyRasterizedImage( task->GetPixelData() ); + task->GetSvgVisual()->ApplyRasterizedImage( task->GetParsedImage(), task->GetPixelData() ); } } @@ -279,52 +223,32 @@ Geometry VisualFactoryCache::CreateGridGeometry( Uint16Pair gridSize ) return geometry; } -Geometry VisualFactoryCache::CreateBatchQuadGeometry( Vector4 texCoords ) +Image VisualFactoryCache::GetBrokenVisualImage() { - const float halfWidth = 0.5f; - const float halfHeight = 0.5f; - struct QuadVertex { - QuadVertex( const Vector2& vertexPosition, const Vector2& vertexTexCoords ) - : position( vertexPosition ), - texCoords( vertexTexCoords ) - {} - Vector2 position; - Vector2 texCoords; - }; - - // special case, when texture takes whole space - if( texCoords == Vector4::ZERO ) - { - texCoords = Vector4(0.0f, 0.0f, 1.0f, 1.0f); - } - - QuadVertex quadVertexData[6] = - { - QuadVertex( Vector2(-halfWidth, -halfHeight ), Vector2(texCoords.x, texCoords.y) ), - QuadVertex( Vector2( halfWidth, -halfHeight ), Vector2(texCoords.z, texCoords.y) ), - QuadVertex( Vector2(-halfWidth, halfHeight ), Vector2(texCoords.x, texCoords.w) ), - QuadVertex( Vector2( halfWidth, -halfHeight ), Vector2(texCoords.z, texCoords.y) ), - QuadVertex( Vector2(-halfWidth, halfHeight ), Vector2(texCoords.x, texCoords.w) ), - QuadVertex( Vector2( halfWidth, halfHeight ), Vector2(texCoords.z, texCoords.w) ), - }; - - Property::Map vertexFormat; - vertexFormat[ "aPosition" ] = Property::VECTOR2; - vertexFormat[ "aTexCoord" ] = Property::VECTOR2; - PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat ); - vertexBuffer.SetData( quadVertexData, 6 ); + return ResourceImage::New( mBrokenImageUrl ); +} - // create geometry as normal, single quad - Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLES ); +void VisualFactoryCache::SetPreMultiplyOnLoad( bool preMultiply ) +{ + mPreMultiplyOnLoad = preMultiply; +} - return geometry; +bool VisualFactoryCache::GetPreMultiplyOnLoad() +{ + return mPreMultiplyOnLoad; } -Image VisualFactoryCache::GetBrokenVisualImage() +void VisualFactoryCache::SetBrokenImageUrl(const std::string& brokenImageUrl) { - return ResourceImage::New( BROKEN_VISUAL_IMAGE_URL ); + mBrokenImageUrl = brokenImageUrl; + + if( !mAtlasManager ) + { + mAtlasManager = new ImageAtlasManager(); + } + + mAtlasManager->SetBrokenImage( mBrokenImageUrl ); + mTextureManager.SetBrokenImageUrl( mBrokenImageUrl ); } } // namespace Internal @@ -332,4 +256,3 @@ Image VisualFactoryCache::GetBrokenVisualImage() } // namespace Toolkit } // namespace Dali -