Delete ImageFactory and ImageFactoryCache as they are unused
[platform/core/uifw/dali-core.git] / dali / internal / event / images / atlas-impl.cpp
index 99665ec..e5e3080 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -24,7 +24,7 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/object/type-registry.h>
 #include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/images/image-factory.h>
+#include <dali/internal/event/images/bitmap-packed-pixel.h>
 #include <dali/internal/event/resources/resource-client.h>
 #include <dali/integration-api/bitmap.h>
 #include <dali/integration-api/platform-abstraction.h>
@@ -61,17 +61,14 @@ bool Atlas::Upload( BufferImage& bufferImage,
 {
   bool uploadSuccess( false );
 
-  if( Compatible(bufferImage.GetPixelFormat(),
-                 xOffset + bufferImage.GetWidth(),
-                 yOffset + bufferImage.GetHeight() ) )
+  if( IsInside( xOffset + bufferImage.GetWidth(),  yOffset + bufferImage.GetHeight() ) )
   {
     AllocateAtlas();
     ResourceId destId = GetResourceId();
-    ResourceId srcId = bufferImage.GetResourceId();
 
-    if( destId && srcId )
+    if( destId )
     {
-      mResourceClient.UploadBitmap( destId, srcId, xOffset, yOffset );
+      bufferImage.UploadBitmap( destId, xOffset, yOffset );
       uploadSuccess = true;
     }
   }
@@ -87,7 +84,7 @@ bool Atlas::Upload( const std::string& url,
 
   Integration::BitmapPtr bitmap = LoadBitmap( url );
 
-  if( bitmap && Compatible(bitmap->GetPixelFormat(), xOffset + bitmap->GetImageWidth(), yOffset + bitmap->GetImageHeight()) )
+  if( bitmap && IsInside( xOffset + bitmap->GetImageWidth(), yOffset + bitmap->GetImageHeight()) )
   {
     AllocateAtlas();
     ResourceId destId = GetResourceId();
@@ -105,6 +102,26 @@ bool Atlas::Upload( const std::string& url,
   return uploadSuccess;
 }
 
+bool Atlas::Upload( PixelDataPtr pixelData,
+                    SizeType xOffset,
+                    SizeType yOffset )
+{
+  bool uploadSuccess( false );
+  if( IsInside( xOffset + pixelData->GetWidth(),  yOffset + pixelData->GetHeight() ) )
+  {
+    AllocateAtlas();
+    ResourceId destId = GetResourceId();
+
+    if( destId )
+    {
+      mResourceClient.UploadBitmap( destId, pixelData, xOffset, yOffset  );
+      uploadSuccess = true;
+    }
+  }
+
+  return uploadSuccess;
+}
+
 void Atlas::RecoverFromContextLoss()
 {
   ResourceId destId = GetResourceId();
@@ -138,7 +155,6 @@ Atlas::Atlas( SizeType width,
               Pixel::Format pixelFormat,
               bool recoverContext )
 : mResourceClient( ThreadLocalStorage::Get().GetResourceClient() ),
-  mImageFactory( ThreadLocalStorage::Get().GetImageFactory() ),
   mClearColor( Vector4::ZERO ),
   mPixelFormat( pixelFormat ),
   mClear( false ),
@@ -164,37 +180,24 @@ void Atlas::Disconnect()
   {
     --mConnectionCount;
 
-    if ( Dali::Image::UNUSED == mReleasePolicy &&
-         mConnectionCount == 0 )
-    {
-      ReleaseAtlas();
-    }
+    // Only release the atlas upon destruction
   }
 }
 
-bool Atlas::Compatible( Pixel::Format pixelFormat,
-                        SizeType x,
-                        SizeType y )
+bool Atlas::IsInside( SizeType x, SizeType y )
 {
-  bool Compatible(false);
+  bool fit(false);
 
-  if( mPixelFormat != pixelFormat )
+  if( x <= mWidth  && y <= mHeight )
   {
-    DALI_LOG_ERROR( "Pixel format %d does not match Atlas format %d\n", pixelFormat, mPixelFormat );
+    fit = true;
   }
   else
   {
-    if( x <= mWidth  && y <= mHeight )
-    {
-      Compatible = true;
-    }
-    else
-    {
-      DALI_LOG_ERROR( "image does not fit within the atlas \n" );
-    }
+    DALI_LOG_ERROR( "image does not fit within the atlas \n" );
   }
 
-  return Compatible;
+  return fit;
 }
 
 void Atlas::AllocateAtlas()
@@ -203,7 +206,6 @@ void Atlas::AllocateAtlas()
   {
     mTicket = mResourceClient.AllocateTexture( mWidth, mHeight, mPixelFormat );
     mTicket->AddObserver( *this );
-    mImageFactory.RegisterForContextRecovery( this );
   }
 }
 
@@ -211,7 +213,6 @@ void Atlas::ReleaseAtlas()
 {
   mTicket.Reset();
   ClearCache();
-  mImageFactory.UnregisterFromContextRecovery( this );
 }
 
 void Atlas::ClearBackground(const Vector4& color )
@@ -225,41 +226,42 @@ void Atlas::ClearBackground(const Vector4& color )
     BufferImagePtr imageData = BufferImage::New( mWidth, mHeight, mPixelFormat );
     PixelBuffer* pixbuf = imageData->GetBuffer();
 
-    // converting color value from float 0.f~1.f to byte 0~255
-    unsigned char r =  static_cast<unsigned char>( 255.f * Clamp( color.r, 0.f, 1.f ) );
-    unsigned char g =  static_cast<unsigned char>( 255.f * Clamp( color.g, 0.f, 1.f ) );
-    unsigned char b =  static_cast<unsigned char>( 255.f * Clamp( color.b, 0.f, 1.f ) );
-    unsigned char a =  static_cast<unsigned char>( 255.f * Clamp( color.a, 0.f, 1.f ) );
-    if( mPixelFormat == Pixel::RGBA8888 )
+    if( pixbuf )
     {
-      // For little-endian byte order, the RGBA channels needs to be reversed for bit shifting.
-      uint32_t clearColor = ( (uint32_t) a<<24 | (uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r );
-      uint32_t* buf = (uint32_t *) pixbuf;
-      for( unsigned int i = 0; i < numPixels; ++i )
+      // converting color value from float 0.f~1.f to byte 0~255
+      unsigned char r =  static_cast<unsigned char>( 255.f * Clamp( color.r, 0.f, 1.f ) );
+      unsigned char g =  static_cast<unsigned char>( 255.f * Clamp( color.g, 0.f, 1.f ) );
+      unsigned char b =  static_cast<unsigned char>( 255.f * Clamp( color.b, 0.f, 1.f ) );
+      unsigned char a =  static_cast<unsigned char>( 255.f * Clamp( color.a, 0.f, 1.f ) );
+      if( mPixelFormat == Pixel::RGBA8888 )
       {
-        buf[i] = clearColor;
+        // For little-endian byte order, the RGBA channels needs to be reversed for bit shifting.
+        uint32_t clearColor = ( (uint32_t) a<<24 | (uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r );
+        uint32_t* buf = (uint32_t *) pixbuf;
+        for( unsigned int i = 0; i < numPixels; ++i )
+        {
+          buf[i] = clearColor;
+        }
       }
-    }
-    else if( mPixelFormat == Pixel::RGB888 )
-    {
-      for( unsigned int i = 0; i < numPixels; ++i )
+      else if( mPixelFormat == Pixel::RGB888 )
       {
-        pixbuf[i*bytesPerPixel] = r;
-        pixbuf[i*bytesPerPixel+1] = g;
-        pixbuf[i*bytesPerPixel+2] = b;
+        for( unsigned int i = 0; i < numPixels; ++i )
+        {
+          pixbuf[i*bytesPerPixel] = r;
+          pixbuf[i*bytesPerPixel+1] = g;
+          pixbuf[i*bytesPerPixel+2] = b;
+        }
+      }
+      else if( mPixelFormat == Pixel::A8 )
+      {
+        memset( pixbuf, a, numPixels );
       }
-    }
-    else if( mPixelFormat == Pixel::A8 )
-    {
-      memset( pixbuf, a, numPixels );
     }
 
-    RectArea area;
-    imageData->Update(area);
-
     mClearColor = color;
     mClear = true;
-    mResourceClient.UploadBitmap( destId, imageData->GetResourceId(), 0, 0 );
+
+    imageData->UploadBitmap( destId, 0, 0 );
   }
 }