X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fnpatch%2Fnpatch-visual.cpp;h=ccee97d321a1f8a06489b03fee77e70645e7b7ff;hp=c4dc4dff5047f7051c05d1b1fccc09821bed1a9c;hb=ab447436de92a2e8bc8cd1393f4807f19ef6b316;hpb=33f29d762e4410026a85521f05b7b66aa2d087d1 diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp old mode 100755 new mode 100644 index c4dc4df..ccee97d --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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,23 +19,22 @@ #include "npatch-visual.h" // EXTERNAL INCLUDES -#include -#include -#include -#include +#include #include #include // INTERNAL INCLUDES -#include #include -#include +#include +#include #include -#include +#include +#include +#include #include +#include #include -#include -#include +#include namespace Dali { @@ -48,128 +47,6 @@ namespace Internal namespace { -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vMaskTexCoord;\n - uniform highp mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n - uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];\n - uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];\n - \n - - // Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - uniform mediump vec2 extraSize;\n - - void main()\n - {\n - mediump vec2 fixedFactor = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );\n - mediump vec2 stretch = vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );\n - \n - mediump vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );\n - mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );\n - \n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - \n - mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );\n - mediump vec4 vertexPosition = gridPosition;\n - vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );\n - vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;\n - vertexPosition = uMvpMatrix * vertexPosition;\n - \n - vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );\n - vMaskTexCoord = gridPosition.xy / visualSize;\n - \n - gl_Position = vertexPosition;\n - }\n -); - -const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vMaskTexCoord;\n - uniform highp mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n - uniform mediump vec2 uFixed[ 3 ];\n - uniform mediump vec2 uStretchTotal;\n - \n - //Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - uniform mediump vec2 extraSize;\n - \n - void main()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - \n - mediump vec2 size = visualSize.xy;\n - \n - mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );\n - mediump vec2 stretch = floor( aPosition * 0.5 );\n - mediump vec2 fixedTotal = uFixed[ 2 ];\n - \n - mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );\n - mediump vec4 vertexPosition = gridPosition;\n - vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n - vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;\n - \n - vertexPosition = uMvpMatrix * vertexPosition;\n - \n - vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );\n - \n - vMaskTexCoord = gridPosition.xy / size;\n - gl_Position = vertexPosition;\n - }\n -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - \n - void main()\n - {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n - }\n -); - -const char* FRAGMENT_MASK_SHADER = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vMaskTexCoord;\n - uniform sampler2D sTexture;\n - uniform sampler2D sMask;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - uniform mediump float auxiliaryImageAlpha;\n - \n - void main()\n - {\n - // Where mask image is transparent, all of background image must show through. - // where mask image is opaque, only mask should be shown - // where mask is translucent, less of background should be shown. - // auxiliaryImageAlpha controls how much of mask is visible - - mediump vec4 color = texture2D( sTexture, vTexCoord );\n - mediump vec4 mask = texture2D( sMask, vMaskTexCoord );\n - - mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha) - + mask.rgb*mask.a * auxiliaryImageAlpha;\n - gl_FragColor = vec4(mixedColor,1.0) * uColor * vec4( mixColor, 1.0 );\n - }\n -); /** * @brief Creates the geometry formed from the vertices and indices @@ -182,15 +59,15 @@ Geometry GenerateGeometry( const Vector< Vector2 >& vertices, const Vector< unsi { Property::Map vertexFormat; vertexFormat[ "aPosition" ] = Property::VECTOR2; - PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat ); + VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat ); if( vertices.Size() > 0 ) { - vertexPropertyBuffer.SetData( &vertices[ 0 ], vertices.Size() ); + vertexBuffer.SetData( &vertices[ 0 ], vertices.Size() ); } // Create the geometry object Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexPropertyBuffer ); + geometry.AddVertexBuffer( vertexBuffer ); if( indices.Size() > 0 ) { geometry.SetIndexBuffer( &indices[ 0 ], indices.Size() ); @@ -223,13 +100,13 @@ void AddVertex( Vector< Vector2 >& vertices, unsigned int x, unsigned int y ) vertices.PushBack( Vector2( x, y ) ); } -void RegisterStretchProperties( Renderer& renderer, const char * uniformName, const NPatchLoader::StretchRanges& stretchPixels, uint16_t imageExtent) +void RegisterStretchProperties( Renderer& renderer, const char * uniformName, const NPatchUtility::StretchRanges& stretchPixels, uint16_t imageExtent) { uint16_t prevEnd = 0; uint16_t prevFix = 0; uint16_t prevStretch = 0; unsigned int i = 1; - for( NPatchLoader::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i ) + for( NPatchUtility::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i ) { uint16_t start = it->GetX(); uint16_t end = it->GetY(); @@ -258,20 +135,20 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co /////////////////NPatchVisual//////////////// -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) +NPatchVisualPtr NPatchVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties) { - NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); + NPatchVisualPtr nPatchVisual(new NPatchVisual(factoryCache, shaderFactory)); nPatchVisual->mImageUrl = imageUrl; nPatchVisual->SetProperties( properties ); - + nPatchVisual->Initialize(); return nPatchVisual; } -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) +NPatchVisualPtr NPatchVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl) { - NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); + NPatchVisualPtr nPatchVisual(new NPatchVisual(factoryCache, shaderFactory)); nPatchVisual->mImageUrl = imageUrl; - + nPatchVisual->Initialize(); return nPatchVisual; } @@ -280,15 +157,15 @@ void NPatchVisual::LoadImages() TextureManager& textureManager = mFactoryCache.GetTextureManager(); bool synchronousLoading = mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; - if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocalResource() ) + if( mId == NPatchData::INVALID_NPATCH_DATA_ID && mImageUrl.IsLocalResource() ) { bool preMultiplyOnLoad = IsPreMultipliedAlphaEnabled() && !mImpl->mCustomShader ? true : false; mId = mLoader.Load( textureManager, this, mImageUrl.GetUrl(), mBorder, preMultiplyOnLoad, synchronousLoading ); - const NPatchLoader::Data* data; - if( mLoader.GetNPatchData( mId, data ) && data->loadCompleted ) + const NPatchData* data; + if( mLoader.GetNPatchData( mId, data ) && data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE ) { - EnablePreMultipliedAlpha( preMultiplyOnLoad ); + EnablePreMultipliedAlpha( data->IsPreMultiplied() ); } } @@ -308,11 +185,11 @@ void NPatchVisual::GetNaturalSize( Vector2& naturalSize ) naturalSize.y = 0u; // load now if not already loaded - const NPatchLoader::Data* data; - if( mLoader.GetNPatchData( mId, data ) && data->loadCompleted ) + const NPatchData* data; + if( mLoader.GetNPatchData( mId, data ) && data->GetLoadingState() != NPatchData::LoadingState::LOADING ) { - naturalSize.x = data->croppedWidth; - naturalSize.y = data->croppedHeight; + naturalSize.x = data->GetCroppedWidth(); + naturalSize.y = data->GetCroppedHeight(); } else { @@ -388,24 +265,36 @@ void NPatchVisual::DoSetProperties( const Property::Map& propertyMap ) mImpl->mFlags &= ~Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; } } + + Property::Value* releasePolicy = propertyMap.Find( Toolkit::ImageVisual::Property::RELEASE_POLICY, RELEASE_POLICY_NAME ); + if( releasePolicy ) + { + releasePolicy->Get( mReleasePolicy ); + } } -void NPatchVisual::DoSetOnStage( Actor& actor ) +void NPatchVisual::DoSetOnScene( Actor& actor ) { // load when first go on stage LoadImages(); - const NPatchLoader::Data* data; + const NPatchData* data; if( mLoader.GetNPatchData( mId, data ) ) { Geometry geometry = CreateGeometry(); Shader shader = CreateShader(); - mImpl->mRenderer = Renderer::New( geometry, shader ); + mImpl->mRenderer.SetGeometry(geometry); + mImpl->mRenderer.SetShader(shader); mPlacementActor = actor; - if( data->loadCompleted ) + if( data->GetLoadingState() != NPatchData::LoadingState::LOADING ) { + if( RenderingAddOn::Get().IsValid() ) + { + RenderingAddOn::Get().SubmitRenderTask( mImpl->mRenderer, data->GetRenderingMap() ); + } + ApplyTextureAndUniforms(); actor.AddRenderer( mImpl->mRenderer ); mPlacementActor.Reset(); @@ -416,10 +305,16 @@ void NPatchVisual::DoSetOnStage( Actor& actor ) } } -void NPatchVisual::DoSetOffStage( Actor& actor ) +void NPatchVisual::DoSetOffScene( Actor& actor ) { + if((mId != NPatchData::INVALID_NPATCH_DATA_ID) && mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED) + { + mLoader.Remove(mId, this); + mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING; + mId = NPatchData::INVALID_NPATCH_DATA_ID; + } + actor.RemoveRenderer( mImpl->mRenderer ); - mImpl->mRenderer.Reset(); mPlacementActor.Reset(); } @@ -434,10 +329,13 @@ void NPatchVisual::OnSetTransform() void NPatchVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); + bool sync = IsSynchronousLoadingRequired(); + map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, sync ); map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::N_PATCH ); map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() ); map.Insert( Toolkit::ImageVisual::Property::BORDER_ONLY, mBorderOnly ); map.Insert( Toolkit::ImageVisual::Property::BORDER, mBorder ); + map.Insert( Toolkit::ImageVisual::Property::RELEASE_POLICY, mReleasePolicy ); if( mAuxiliaryUrl.IsValid() ) { @@ -455,31 +353,50 @@ void NPatchVisual::DoCreateInstancePropertyMap( Property::Map& map ) const } } -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache, Visual::FittingMode::FILL ), +NPatchVisual::NPatchVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory) +: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::N_PATCH), mPlacementActor(), - mLoader( factoryCache.GetNPatchLoader() ), + mLoader(factoryCache.GetNPatchLoader()), + mImageVisualShaderFactory(shaderFactory), mImageUrl(), mAuxiliaryUrl(), - mId( NPatchLoader::UNINITIALIZED_ID ), - mBorderOnly( false ), + mId(NPatchData::INVALID_NPATCH_DATA_ID), + mBorderOnly(false), mBorder(), - mAuxiliaryImageAlpha( 0.0f ) + mAuxiliaryImageAlpha(0.0f), + mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED) { EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() ); } NPatchVisual::~NPatchVisual() { + if((mId != NPatchData::INVALID_NPATCH_DATA_ID) && ( mReleasePolicy != Toolkit::ImageVisual::ReleasePolicy::NEVER )) + { + mLoader.Remove(mId, this); + mId = NPatchData::INVALID_NPATCH_DATA_ID; + } +} + +void NPatchVisual::OnInitialize() +{ + // Get basic geometry and shader + Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); + Shader shader = mImageVisualShaderFactory.GetShader(mFactoryCache, false, true, false); + + mImpl->mRenderer = Renderer::New(geometry, shader); + + //Register transform properties + mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); } Geometry NPatchVisual::CreateGeometry() { Geometry geometry; - const NPatchLoader::Data* data; - if( mLoader.GetNPatchData( mId, data ) && data->loadCompleted ) + const NPatchData* data; + if( mLoader.GetNPatchData( mId, data ) && data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE ) { - if( data->stretchPixelsX.Size() == 1 && data->stretchPixelsY.Size() == 1 ) + if( data->GetStretchPixelsX().Size() == 1 && data->GetStretchPixelsY().Size() == 1 ) { if( DALI_UNLIKELY( mBorderOnly ) ) { @@ -487,13 +404,38 @@ Geometry NPatchVisual::CreateGeometry() } else { - geometry = GetNinePatchGeometry( VisualFactoryCache::NINE_PATCH_GEOMETRY ); + if( data->GetRenderingMap() ) + { + uint32_t elementCount[2]; + geometry = RenderingAddOn::Get().CreateGeometryGrid(data->GetRenderingMap(), Uint16Pair(3, 3), elementCount ); + if( mImpl->mRenderer ) + { + RenderingAddOn::Get().SubmitRenderTask(mImpl->mRenderer, data->GetRenderingMap()); + } + } + else + { + geometry = GetNinePatchGeometry( VisualFactoryCache::NINE_PATCH_GEOMETRY ); + } } } - else if( data->stretchPixelsX.Size() > 0 || data->stretchPixelsY.Size() > 0) + else if( data->GetStretchPixelsX().Size() > 0 || data->GetStretchPixelsY().Size() > 0) { - Uint16Pair gridSize( 2 * data->stretchPixelsX.Size() + 1, 2 * data->stretchPixelsY.Size() + 1 ); - geometry = !mBorderOnly ? CreateGridGeometry( gridSize ) : CreateBorderGeometry( gridSize ); + Uint16Pair gridSize( 2 * data->GetStretchPixelsX().Size() + 1, 2 * data->GetStretchPixelsY().Size() + 1 ); + if( !data->GetRenderingMap() ) + { + geometry = !mBorderOnly ? CreateGridGeometry( gridSize ) : CreateBorderGeometry( gridSize ); + } + else + { + uint32_t elementCount[2]; + geometry = !mBorderOnly ? + RenderingAddOn::Get().CreateGeometryGrid(data->GetRenderingMap(), gridSize, elementCount ) : CreateBorderGeometry(gridSize ); + if( mImpl->mRenderer ) + { + RenderingAddOn::Get().SubmitRenderTask(mImpl->mRenderer, data->GetRenderingMap()); + } + } } } else @@ -507,22 +449,22 @@ Geometry NPatchVisual::CreateGeometry() Shader NPatchVisual::CreateShader() { Shader shader; - const NPatchLoader::Data* data; + const NPatchData* data; // 0 is either no data (load failed?) or no stretch regions on image // for both cases we use the default shader - NPatchLoader::StretchRanges::SizeType xStretchCount = 0; - NPatchLoader::StretchRanges::SizeType yStretchCount = 0; + NPatchUtility::StretchRanges::SizeType xStretchCount = 0; + NPatchUtility::StretchRanges::SizeType yStretchCount = 0; - auto fragmentShader = mAuxiliaryPixelBuffer ? FRAGMENT_MASK_SHADER - : FRAGMENT_SHADER; + auto fragmentShader = mAuxiliaryPixelBuffer ? SHADER_NPATCH_VISUAL_MASK_SHADER_FRAG + : SHADER_NPATCH_VISUAL_SHADER_FRAG; auto shaderType = mAuxiliaryPixelBuffer ? VisualFactoryCache::NINE_PATCH_MASK_SHADER : VisualFactoryCache::NINE_PATCH_SHADER; // ask loader for the regions if( mLoader.GetNPatchData( mId, data ) ) { - xStretchCount = data->stretchPixelsX.Count(); - yStretchCount = data->stretchPixelsY.Count(); + xStretchCount = data->GetStretchPixelsX().Count(); + yStretchCount = data->GetStretchPixelsY().Count(); } if( DALI_LIKELY( !mImpl->mCustomShader ) ) @@ -533,7 +475,7 @@ Shader NPatchVisual::CreateShader() shader = mFactoryCache.GetShader( shaderType ); if( DALI_UNLIKELY( !shader ) ) { - shader = Shader::New( VERTEX_SHADER_3X3, fragmentShader ); + shader = Shader::New( SHADER_NPATCH_VISUAL_3X3_SHADER_VERT, fragmentShader ); // Only cache vanilla 9 patch shaders mFactoryCache.SaveShader( shaderType, shader ); } @@ -543,7 +485,7 @@ Shader NPatchVisual::CreateShader() std::stringstream vertexShader; vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n" << "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n" - << VERTEX_SHADER; + << SHADER_NPATCH_VISUAL_SHADER_VERT; shader = Shader::New( vertexShader.str(), fragmentShader ); } @@ -562,7 +504,7 @@ Shader NPatchVisual::CreateShader() if( ( xStretchCount == 1 && yStretchCount == 1 ) || ( xStretchCount == 0 && yStretchCount == 0 ) ) { - const char* vertexShader = VERTEX_SHADER_3X3; + const char* vertexShader = SHADER_NPATCH_VISUAL_3X3_SHADER_VERT.data(); if( !mImpl->mCustomShader->mVertexShader.empty() ) { @@ -575,7 +517,7 @@ Shader NPatchVisual::CreateShader() std::stringstream vertexShader; vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n" << "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n" - << VERTEX_SHADER; + << SHADER_NPATCH_VISUAL_SHADER_VERT; shader = Shader::New( vertexShader.str(), fragmentShader, hints ); } @@ -586,25 +528,25 @@ Shader NPatchVisual::CreateShader() void NPatchVisual::ApplyTextureAndUniforms() { - const NPatchLoader::Data* data; + const NPatchData* data; TextureSet textureSet; - if( mLoader.GetNPatchData( mId, data ) && data->loadCompleted ) + if( mLoader.GetNPatchData( mId, data ) && data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE ) { - textureSet = data->textureSet; + textureSet = data->GetTextures(); - if( data->stretchPixelsX.Size() == 1 && data->stretchPixelsY.Size() == 1 ) + if( data->GetStretchPixelsX().Size() == 1 && data->GetStretchPixelsY().Size() == 1 ) { //special case for 9 patch - Uint16Pair stretchX = data->stretchPixelsX[ 0 ]; - Uint16Pair stretchY = data->stretchPixelsY[ 0 ]; + Uint16Pair stretchX = data->GetStretchPixelsX()[ 0 ]; + Uint16Pair stretchY = data->GetStretchPixelsY()[ 0 ]; uint16_t stretchWidth = ( stretchX.GetY() >= stretchX.GetX() ) ? stretchX.GetY() - stretchX.GetX() : 0; uint16_t stretchHeight = ( stretchY.GetY() >= stretchY.GetX() ) ? stretchY.GetY() - stretchY.GetX() : 0; mImpl->mRenderer.RegisterProperty( "uFixed[0]", Vector2::ZERO ); mImpl->mRenderer.RegisterProperty( "uFixed[1]", Vector2( stretchX.GetX(), stretchY.GetX()) ); - mImpl->mRenderer.RegisterProperty( "uFixed[2]", Vector2( data->croppedWidth - stretchWidth, data->croppedHeight - stretchHeight ) ); + mImpl->mRenderer.RegisterProperty( "uFixed[2]", Vector2( data->GetCroppedWidth() - stretchWidth, data->GetCroppedHeight() - stretchHeight ) ); mImpl->mRenderer.RegisterProperty( "uStretchTotal", Vector2( stretchWidth, stretchHeight ) ); } else @@ -612,8 +554,8 @@ void NPatchVisual::ApplyTextureAndUniforms() mImpl->mRenderer.RegisterProperty( "uNinePatchFactorsX[0]", Vector2::ZERO ); mImpl->mRenderer.RegisterProperty( "uNinePatchFactorsY[0]", Vector2::ZERO ); - RegisterStretchProperties( mImpl->mRenderer, "uNinePatchFactorsX", data->stretchPixelsX, data->croppedWidth ); - RegisterStretchProperties( mImpl->mRenderer, "uNinePatchFactorsY", data->stretchPixelsY, data->croppedHeight ); + RegisterStretchProperties( mImpl->mRenderer, "uNinePatchFactorsX", data->GetStretchPixelsX(), data->GetCroppedWidth() ); + RegisterStretchProperties( mImpl->mRenderer, "uNinePatchFactorsY", data->GetStretchPixelsY(), data->GetCroppedHeight() ); } } else @@ -621,8 +563,8 @@ void NPatchVisual::ApplyTextureAndUniforms() DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str() ); textureSet = TextureSet::New(); - Image croppedImage = mFactoryCache.GetBrokenVisualImage(); - TextureSetImage( textureSet, 0u, croppedImage ); + Texture croppedImage = mFactoryCache.GetBrokenVisualImage(); + textureSet.SetTexture( 0u, croppedImage ); mImpl->mRenderer.RegisterProperty( "uFixed[0]", Vector2::ZERO ); mImpl->mRenderer.RegisterProperty( "uFixed[1]", Vector2::ZERO ); mImpl->mRenderer.RegisterProperty( "uFixed[2]", Vector2::ZERO ); @@ -634,10 +576,10 @@ void NPatchVisual::ApplyTextureAndUniforms() // If the auxiliary image is smaller than the un-stretched NPatch, use CPU resizing to enlarge it to the // same size as the unstretched NPatch. This will give slightly higher quality results than just relying // on GL interpolation alone. - if( mAuxiliaryPixelBuffer.GetWidth() < data->croppedWidth && - mAuxiliaryPixelBuffer.GetHeight() < data->croppedHeight ) + if( mAuxiliaryPixelBuffer.GetWidth() < data->GetCroppedWidth() && + mAuxiliaryPixelBuffer.GetHeight() < data->GetCroppedHeight() ) { - mAuxiliaryPixelBuffer.Resize( data->croppedWidth, data->croppedHeight ); + mAuxiliaryPixelBuffer.Resize( data->GetCroppedWidth(), data->GetCroppedHeight() ); } // Note, this resets mAuxiliaryPixelBuffer handle @@ -648,8 +590,8 @@ void NPatchVisual::ApplyTextureAndUniforms() auxiliaryPixelData.GetHeight() ); texture.Upload( auxiliaryPixelData ); textureSet.SetTexture( 1, texture ); - DevelHandle::RegisterProperty( mImpl->mRenderer, DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, - AUXILIARY_IMAGE_ALPHA_NAME, mAuxiliaryImageAlpha ); + mImpl->mRenderer.RegisterProperty( DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, + AUXILIARY_IMAGE_ALPHA_NAME, mAuxiliaryImageAlpha ); } mImpl->mRenderer.SetTextures( textureSet ); @@ -808,7 +750,7 @@ Geometry NPatchVisual::CreateBorderGeometry( Uint16Pair gridSize ) void NPatchVisual::SetResource() { - const NPatchLoader::Data* data; + const NPatchData* data; if( mImpl->mRenderer && mLoader.GetNPatchData( mId, data ) ) { Geometry geometry = CreateGeometry(); @@ -830,29 +772,32 @@ void NPatchVisual::SetResource() } } +void NPatchVisual::UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) +{ + EnablePreMultipliedAlpha( preMultiplied ); + if(!loadSuccess) + { + // Image loaded and ready to display + ResourceReady( Toolkit::Visual::ResourceStatus::FAILED ); + } + + if( mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid() ) + { + SetResource(); + } +} + void NPatchVisual::LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) { - if( url.GetUrl() == mAuxiliaryUrl.GetUrl() ) + if( loadSuccess && url.GetUrl() == mAuxiliaryUrl.GetUrl() ) { mAuxiliaryPixelBuffer = pixelBuffer; - const NPatchLoader::Data* data; - if( mLoader.GetNPatchData( mId, data ) && data->loadCompleted ) - { - SetResource(); - } + SetResource(); } else { - if( loadSuccess ) - { - mLoader.SetNPatchData( mId, pixelBuffer ); - EnablePreMultipliedAlpha( preMultiplied ); - } - - if( mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid() ) - { - SetResource(); - } + // Image loaded and ready to display + ResourceReady( Toolkit::Visual::ResourceStatus::FAILED ); } }