Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / integration-api / bitmap.cpp
index 12e5e07..1eb95b4 100644 (file)
@@ -1,33 +1,34 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/integration-api/bitmap.h>
 
 // EXTERNAL INCLUDES
-#include <cstring>
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
-#include <dali/integration-api/image-data.h>
+#include <dali/integration-api/platform-abstraction.h>
+#include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/images/bitmap-packed-pixel.h>
 #include <dali/internal/event/images/bitmap-compressed.h>
 #include <dali/internal/event/images/bitmap-external.h>
 #include <dali/integration-api/gl-abstraction.h>
-#include <dali/public-api/images/pixel-extras.h>
+#include <dali/integration-api/gl-defines.h>
 
 namespace Dali
 {
@@ -243,7 +244,8 @@ void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& i
   }
 }
 
-Bitmap* Bitmap::New(const Profile profile = BITMAP_2D_PACKED_PIXELS, const bool managePixelBuffer = true)
+Bitmap* Bitmap::New( const Profile profile = BITMAP_2D_PACKED_PIXELS,
+                     ResourcePolicy::Discardable discardable = ResourcePolicy::DISCARD )
 {
   DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
 
@@ -255,31 +257,21 @@ Bitmap* Bitmap::New(const Profile profile = BITMAP_2D_PACKED_PIXELS, const bool
      * scanlines past the bottom of the image in the buffer if requested.*/
     case BITMAP_2D_PACKED_PIXELS:
     {
-      return new Dali::Internal::BitmapPackedPixel(managePixelBuffer);
+      Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel( discardable );
+      return bitmap;
     }
 
     /** The data for the bitmap is buffered in an opaque form.*/
     case BITMAP_COMPRESSED:
     {
-      return new Dali::Internal::BitmapCompressed(managePixelBuffer);
+      return new Dali::Internal::BitmapCompressed( discardable );
     }
   }
   return 0;
 }
 
-Bitmap* Bitmap::New(const Pixel::Format format)
-{
-  if( Pixel::IsEncoded( format ) )
-  {
-    return new Dali::Internal::BitmapCompressed(true);
-  }
-  else
-  {
-    return new Dali::Internal::BitmapPackedPixel(true);
-  }
-}
 
-Bitmap::Bitmap( bool discardable, Dali::Integration::PixelBuffer* pixBuf)
+Bitmap::Bitmap( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
 : mImageWidth(0),
   mImageHeight(0),
   mPixelFormat(Pixel::RGBA8888),
@@ -292,7 +284,7 @@ Bitmap::Bitmap( bool discardable, Dali::Integration::PixelBuffer* pixBuf)
 
 void Bitmap::DiscardBuffer()
 {
-  if ( mDiscardable )
+  if( mDiscardable == ResourcePolicy::DISCARD )
   {
     DeletePixelBuffer();
   }
@@ -311,7 +303,10 @@ PixelBuffer* Bitmap::ReleaseBuffer()
 Bitmap::~Bitmap()
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
-  DeletePixelBuffer();
+  if( mDiscardable == ResourcePolicy::DISCARD )
+  {
+    DeletePixelBuffer();
+  }
 }
 
 /**
@@ -329,7 +324,7 @@ void Bitmap::DeletePixelBuffer()
 
 void Bitmap::Initialize( Pixel::Format pixelFormat,
                           unsigned int width,
-                          unsigned int height )
+                          unsigned int height)
 {
   DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
   mImageWidth   = width;
@@ -339,36 +334,6 @@ void Bitmap::Initialize( Pixel::Format pixelFormat,
   mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
 }
 
-BitmapPtr ConvertToBitmap( ImageData& imageData )
-{
-  BitmapPtr bitmap = Bitmap::New( imageData.pixelFormat );
-  Bitmap::PackedPixelsProfile* packedBitmap = bitmap->GetPackedPixelsProfile();
-  if( packedBitmap )
-  {
-    // Pass the buffer of pixels into the new Bitmap:
-    packedBitmap->AssignBuffer( imageData.pixelFormat, imageData.ReleaseImageBuffer(), imageData.dataSize, imageData.imageWidth, imageData.imageHeight, imageData.imageWidth, imageData.imageHeight );
-
-    // Convert the info about the alpha channel:
-    bitmap->SetAlphaChannelUsed( imageData.GetAlphaUsage() == ImageData::ALPHA_USAGE_SOME_TRANSLUCENT );
-  }
-  else
-  {
-    ///@Todo: In one of the follow-on patches, the copy here will be replaced with a buffer ownership assignment, after the Bitmap classes are refactored, rather than enhancing BitmapCompressed in this one.
-    Bitmap::CompressedProfile * compressedBitmap = bitmap->GetCompressedProfile();
-    if( compressedBitmap )
-    {
-      compressedBitmap->ReserveBufferOfSize( imageData.pixelFormat, imageData.imageWidth, imageData.imageHeight, imageData.dataSize );
-      memcpy( bitmap->GetBuffer(), imageData.GetBuffer(), imageData.dataSize );
-    }
-    else
-    {
-      DALI_ASSERT_DEBUG( 0 == "Unknown bitmap profile." );
-    }
-  }
-  return bitmap;
-}
-
 } //namespace Integration
 
 } //namespace Dali
-