SVG support for ImageView ( CPU rendering version )
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / image / image-renderer.cpp
index b9fcec9..b8c6343 100644 (file)
@@ -46,7 +46,7 @@ const char HTTP_URL[] = "http://";
 const char HTTPS_URL[] = "https://";
 
 const char * const RENDERER_TYPE("rendererType");
-const char * const RENDERER_TYPE_VALUE("imageRenderer");
+const char * const RENDERER_TYPE_VALUE("image");
 
 // property names
 const char * const IMAGE_URL_NAME( "imageUrl" );
@@ -75,9 +75,6 @@ const std::string TEXTURE_UNIFORM_NAME = "sTexture";
 const std::string ATLAS_RECT_UNIFORM_NAME = "uAtlasRect";
 const std::string PIXEL_AREA_UNIFORM_NAME = "pixelArea";
 
-// Set this uniform to 1.0 for conventional alpha blending; if pre-multiplied alpha blending, set this uniform to 0.0
-const std::string ALPHA_BLENDING_UNIFORM_NAME = "uAlphaBlending";
-
 const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
 
 const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D";
@@ -105,11 +102,10 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
   varying mediump vec2 vTexCoord;\n
   uniform sampler2D sTexture;\n
   uniform lowp vec4 uColor;\n
-  uniform lowp float uAlphaBlending; // Set to 1.0 for conventional alpha blending; if pre-multiplied alpha blending, set to 0.0
   \n
   void main()\n
   {\n
-    gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4( uColor.rgb*max( uAlphaBlending, uColor.a ), uColor.a );\n
+    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
   }\n
 );
 
@@ -118,18 +114,18 @@ Geometry GenerateGeometry( const Vector< Vector2 >& vertices, const Vector< unsi
 {
   Property::Map vertexFormat;
   vertexFormat[ "aPosition" ] = Property::VECTOR2;
-  PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat, vertices.Size() );
+  PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat );
   if( vertices.Size() > 0 )
   {
-    vertexPropertyBuffer.SetData( &vertices[ 0 ] );
+    vertexPropertyBuffer.SetData( &vertices[ 0 ], vertices.Size() );
   }
 
   Property::Map indexFormat;
   indexFormat[ "indices" ] = Property::INTEGER;
-  PropertyBuffer indexPropertyBuffer = PropertyBuffer::New( indexFormat, indices.Size() );
+  PropertyBuffer indexPropertyBuffer = PropertyBuffer::New( indexFormat );
   if( indices.Size() > 0 )
   {
-    indexPropertyBuffer.SetData( &indices[ 0 ] );
+    indexPropertyBuffer.SetData( &indices[ 0 ], indices.Size() );
   }
 
   // Create the geometry object
@@ -211,7 +207,6 @@ ImageRenderer::ImageRenderer( RendererFactoryCache& factoryCache, ImageAtlasMana
   mDesiredSize(),
   mFittingMode( FittingMode::DEFAULT ),
   mSamplingMode( SamplingMode::DEFAULT ),
-  mIsAlphaPreMultiplied( false ),
   mNativeFragmentShaderCode( ),
   mNativeImageFlag( false )
 {
@@ -429,7 +424,6 @@ Renderer ImageRenderer::CreateRenderer() const
       {
         shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT );
         shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
-        shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f );
       }
     }
   }
@@ -450,7 +444,6 @@ Renderer ImageRenderer::CreateNativeImageRenderer() const
     shader  = Shader::New( VERTEX_SHADER, mNativeFragmentShaderCode );
     shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT );
     shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
-    shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f );
   }
   else
   {
@@ -468,7 +461,6 @@ Renderer ImageRenderer::CreateNativeImageRenderer() const
       {
         shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT );
         shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
-        shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f );
       }
     }
   }
@@ -553,7 +545,6 @@ void ImageRenderer::DoSetOnStage( Actor& actor )
     InitializeRenderer( mImage );
   }
 
-  EnablePreMultipliedAlpha( mIsAlphaPreMultiplied );
 }
 
 void ImageRenderer::DoSetOffStage( Actor& actor )
@@ -563,7 +554,6 @@ void ImageRenderer::DoSetOffStage( Actor& actor )
   {
     actor.RemoveRenderer( mImpl->mRenderer );
     CleanCache(mImageUrl);
-
     mImage.Reset();
   }
   else
@@ -678,7 +668,6 @@ Shader ImageRenderer::GetImageShader( RendererFactoryCache& factoryCache )
     factoryCache.SaveShader( RendererFactoryCache::IMAGE_SHADER, shader );
     shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT );
     shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
-    shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f );
   }
   return shader;
 }
@@ -804,37 +793,6 @@ void ImageRenderer::SetImage( Actor& actor, const Image& image )
   }
 }
 
-void ImageRenderer::EnablePreMultipliedAlpha( bool preMultipled )
-{
-  mIsAlphaPreMultiplied = preMultipled;
-  if( mImpl->mRenderer )
-  {
-    Material material = mImpl->mRenderer.GetMaterial();
-
-    if( preMultipled )
-    {
-      material.SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA,
-                             BlendingFactor::ONE, BlendingFactor::ONE );
-      if( !mImpl->mCustomShader || mImpl->mCustomShader->mVertexShader.empty())
-      {
-        material.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 0.f );
-      }
-    }
-    else
-    {
-      // using default blend func
-      material.SetBlendFunc( BlendingFactor::SRC_ALPHA, BlendingFactor::ONE_MINUS_SRC_ALPHA,
-                              BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA );
-
-      Property::Index index = material.GetPropertyIndex( ALPHA_BLENDING_UNIFORM_NAME );
-      if( index != Property::INVALID_INDEX ) // only set value when the property already exist on the Material
-      {
-        material.SetProperty( index, 1.f );
-      }
-    }
-  }
-}
-
 void ImageRenderer::ApplyImageToSampler( const Image& image )
 {
   if( image )