Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / integration-api / bitmap.cpp
index 836c3be..1eb95b4 100644 (file)
@@ -1,18 +1,19 @@
-//
-// 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>
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.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/integration-api/gl-defines.h>
 
 namespace Dali
 {
@@ -240,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);
 
@@ -252,20 +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:
     {
-      Bitmap * const bitmap = 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( bool discardable, Dali::Integration::PixelBuffer* pixBuf)
+
+Bitmap::Bitmap( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
 : mImageWidth(0),
   mImageHeight(0),
   mPixelFormat(Pixel::RGBA8888),
@@ -278,7 +284,7 @@ Bitmap::Bitmap( bool discardable, Dali::Integration::PixelBuffer* pixBuf)
 
 void Bitmap::DiscardBuffer()
 {
-  if ( mDiscardable )
+  if( mDiscardable == ResourcePolicy::DISCARD )
   {
     DeletePixelBuffer();
   }
@@ -297,7 +303,10 @@ PixelBuffer* Bitmap::ReleaseBuffer()
 Bitmap::~Bitmap()
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
-  DeletePixelBuffer();
+  if( mDiscardable == ResourcePolicy::DISCARD )
+  {
+    DeletePixelBuffer();
+  }
 }
 
 /**
@@ -328,4 +337,3 @@ void Bitmap::Initialize( Pixel::Format pixelFormat,
 } //namespace Integration
 
 } //namespace Dali
-