Stop using ImageActor in PageTurnView
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / image / image-renderer.cpp
index b9fcec9..17eae58 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,42 +102,13 @@ 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
 );
 
-
-Geometry GenerateGeometry( const Vector< Vector2 >& vertices, const Vector< unsigned int >& indices )
-{
-  Property::Map vertexFormat;
-  vertexFormat[ "aPosition" ] = Property::VECTOR2;
-  PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat, vertices.Size() );
-  if( vertices.Size() > 0 )
-  {
-    vertexPropertyBuffer.SetData( &vertices[ 0 ] );
-  }
-
-  Property::Map indexFormat;
-  indexFormat[ "indices" ] = Property::INTEGER;
-  PropertyBuffer indexPropertyBuffer = PropertyBuffer::New( indexFormat, indices.Size() );
-  if( indices.Size() > 0 )
-  {
-    indexPropertyBuffer.SetData( &indices[ 0 ] );
-  }
-
-  // Create the geometry object
-  Geometry geometry = Geometry::New();
-  geometry.AddVertexBuffer( vertexPropertyBuffer );
-  geometry.SetIndexBuffer( indexPropertyBuffer );
-  geometry.SetGeometryType( Geometry::TRIANGLE_STRIP );
-
-  return geometry;
-}
-
 Geometry CreateGeometry( RendererFactoryCache& factoryCache, ImageDimensions gridSize )
 {
   Geometry geometry;
@@ -150,54 +118,13 @@ Geometry CreateGeometry( RendererFactoryCache& factoryCache, ImageDimensions gri
     geometry = factoryCache.GetGeometry( RendererFactoryCache::QUAD_GEOMETRY );
     if( !geometry )
     {
-      geometry =  factoryCache.CreateQuadGeometry();
+      geometry =  RendererFactoryCache::CreateQuadGeometry();
       factoryCache.SaveGeometry( RendererFactoryCache::QUAD_GEOMETRY, geometry );
     }
   }
   else
   {
-    uint16_t gridWidth = gridSize.GetWidth();
-    uint16_t gridHeight = gridSize.GetHeight();
-
-    // Create vertices
-    Vector< Vector2 > vertices;
-    vertices.Reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
-
-    for( int y = 0; y < gridHeight + 1; ++y )
-    {
-      for( int x = 0; x < gridWidth + 1; ++x )
-      {
-        vertices.PushBack( Vector2( (float)x/gridWidth - 0.5f, (float)y/gridHeight  - 0.5f) );
-      }
-    }
-
-    // Create indices
-    Vector< unsigned int > indices;
-    indices.Reserve( (gridWidth+2)*gridHeight*2 - 2);
-
-    for( unsigned int row = 0u; row < gridHeight; ++row )
-    {
-      unsigned int rowStartIndex = row*(gridWidth+1u);
-      unsigned int nextRowStartIndex = rowStartIndex + gridWidth +1u;
-
-      if( row != 0u ) // degenerate index on non-first row
-      {
-        indices.PushBack( rowStartIndex );
-      }
-
-      for( unsigned int column = 0u; column < gridWidth+1u; column++) // main strip
-      {
-        indices.PushBack( rowStartIndex + column);
-        indices.PushBack( nextRowStartIndex + column);
-      }
-
-      if( row != gridHeight-1u ) // degenerate index on non-last row
-      {
-        indices.PushBack( nextRowStartIndex + gridWidth );
-      }
-    }
-
-    return GenerateGeometry( vertices, indices );
+    geometry = RendererFactoryCache::CreateGridGeometry( gridSize );
   }
 
   return geometry;
@@ -211,7 +138,6 @@ ImageRenderer::ImageRenderer( RendererFactoryCache& factoryCache, ImageAtlasMana
   mDesiredSize(),
   mFittingMode( FittingMode::DEFAULT ),
   mSamplingMode( SamplingMode::DEFAULT ),
-  mIsAlphaPreMultiplied( false ),
   mNativeFragmentShaderCode( ),
   mNativeImageFlag( false )
 {
@@ -429,7 +355,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 +375,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 +392,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 +476,6 @@ void ImageRenderer::DoSetOnStage( Actor& actor )
     InitializeRenderer( mImage );
   }
 
-  EnablePreMultipliedAlpha( mIsAlphaPreMultiplied );
 }
 
 void ImageRenderer::DoSetOffStage( Actor& actor )
@@ -563,7 +485,6 @@ void ImageRenderer::DoSetOffStage( Actor& actor )
   {
     actor.RemoveRenderer( mImpl->mRenderer );
     CleanCache(mImageUrl);
-
     mImage.Reset();
   }
   else
@@ -678,7 +599,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 +724,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 )