Rendering API clean-up
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / image-atlas-manager.cpp
index 4541ae3..03eb4a7 100644 (file)
@@ -37,10 +37,8 @@ const uint32_t MAX_ITEM_SIZE( 512u  );
 const uint32_t MAX_ITEM_AREA( MAX_ITEM_SIZE*MAX_ITEM_SIZE  );
 }
 
-ImageAtlasManager::ImageAtlasManager( Shader shader, const std::string& textureUniformName )
-: mShader( shader ),
-  mTextureUniformName( textureUniformName ),
-  mBrokenImageUrl( "" )
+ImageAtlasManager::ImageAtlasManager()
+: mBrokenImageUrl( "" )
 {
 }
 
@@ -48,7 +46,7 @@ ImageAtlasManager::~ImageAtlasManager()
 {
 }
 
-Material ImageAtlasManager::Add( Vector4& textureRect,
+TextureSet ImageAtlasManager::Add( Vector4& textureRect,
                                  const std::string& url,
                                  ImageDimensions size,
                                  FittingMode::Type fittingMode,
@@ -66,7 +64,7 @@ Material ImageAtlasManager::Add( Vector4& textureRect,
       || dimensions.GetWidth()>DEFAULT_ATLAS_SIZE
       || dimensions.GetHeight()>DEFAULT_ATLAS_SIZE)
   {
-    return Material();
+    return TextureSet();
   }
 
   unsigned int i = 0;
@@ -74,32 +72,50 @@ Material ImageAtlasManager::Add( Vector4& textureRect,
   {
     if( (*iter).Upload( textureRect, url, size, fittingMode, orientationCorrection ) )
     {
-      return mMaterialList[i];
+      return mTextureSetList[i];
     }
     i++;
   }
 
-  Toolkit::ImageAtlas newAtlas = Toolkit::ImageAtlas::New( DEFAULT_ATLAS_SIZE, DEFAULT_ATLAS_SIZE  );
-  if( !mBrokenImageUrl.empty() )
+  CreateNewAtlas();
+  mAtlasList.back().Upload( textureRect, url, size, fittingMode, orientationCorrection );
+  return mTextureSetList.back();
+}
+
+TextureSet ImageAtlasManager::Add( Vector4& textureRect,
+                                 PixelDataPtr pixelData )
+{
+
+  // big buffer, atlasing is not applied
+  if( static_cast<uint32_t>(pixelData->GetWidth()) * static_cast<uint32_t>(pixelData->GetHeight()) > MAX_ITEM_AREA
+      || pixelData->GetWidth()>DEFAULT_ATLAS_SIZE
+      || pixelData->GetHeight()>DEFAULT_ATLAS_SIZE )
   {
-    newAtlas.SetBrokenImage( mBrokenImageUrl );
+    return TextureSet();
   }
-  mAtlasList.push_back( newAtlas );
-  Material newMaterial = Material::New( mShader );
-  newMaterial.AddTexture( newAtlas.GetAtlas(), mTextureUniformName );
-  mMaterialList.push_back( newMaterial );
 
-  newAtlas.Upload( textureRect, url, size, fittingMode, orientationCorrection );
+  unsigned int i = 0;
+  for( AtlasContainer::iterator iter = mAtlasList.begin(); iter != mAtlasList.end(); ++iter)
+  {
+    if( (*iter).Upload( textureRect, pixelData ) )
+    {
+      return mTextureSetList[i];
+    }
+    i++;
+  }
+
+  CreateNewAtlas();
+  mAtlasList.back().Upload( textureRect, pixelData );
+  return mTextureSetList.back();
 
-  return newMaterial;
 }
 
-void ImageAtlasManager::Remove( Material material, const Vector4& textureRect )
+void ImageAtlasManager::Remove( TextureSet textureSet, const Vector4& textureRect )
 {
   unsigned int i = 0;
-  for( MaterialContainer::iterator iter = mMaterialList.begin(); iter != mMaterialList.end(); ++iter)
+  for( TextureSetContainer::iterator iter = mTextureSetList.begin(); iter != mTextureSetList.end(); ++iter)
   {
-    if( (*iter) == material )
+    if( (*iter) == textureSet )
     {
       mAtlasList[i].Remove(textureRect);
       return;
@@ -116,6 +132,19 @@ void ImageAtlasManager::SetBrokenImage( const std::string& brokenImageUrl )
   }
 }
 
+void ImageAtlasManager::CreateNewAtlas()
+{
+  Toolkit::ImageAtlas newAtlas = Toolkit::ImageAtlas::New( DEFAULT_ATLAS_SIZE, DEFAULT_ATLAS_SIZE  );
+  if( !mBrokenImageUrl.empty() )
+  {
+    newAtlas.SetBrokenImage( mBrokenImageUrl );
+  }
+  mAtlasList.push_back( newAtlas );
+  TextureSet textureSet = TextureSet::New();
+  textureSet.SetImage( 0u, newAtlas.GetAtlas() );
+  mTextureSetList.push_back( textureSet );
+}
+
 } // namespace Internal
 
 } // namespace Toolkit