Merge "Automated test fix for framebuffer creation" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / pixmap-image-impl-wl.cpp
index 870bddd..3ebc0e7 100644 (file)
 #include "pixmap-image-impl.h"
 
 // EXTERNAL INCLUDES
-#include <Ecore.h>
-#include <Ecore_Wayland.h>
 #include <dali/integration-api/debug.h>
-#include <render-surface.h>
 
 // INTERNAL INCLUDES
 #include <gl/egl-image-extensions.h>
 #include <gl/egl-factory.h>
 #include <adaptor-impl.h>
+#include <render-surface.h>
 
 // Allow this to be encoded and saved:
-#include <platform-abstractions/slp/resource-loader/resource-loader.h>
+#include <platform-abstractions/tizen/resource-loader/resource-loader.h>
 #include <bitmap-saver.h>
 
 namespace Dali
@@ -43,9 +41,9 @@ namespace Adaptor
 {
 using Dali::Integration::PixelBuffer;
 
-PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Dali::Adaptor& adaptor,  Any pixmap )
+PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
 {
-  PixmapImage* image = new PixmapImage( width, height, depth, adaptor, pixmap );
+  PixmapImage* image = new PixmapImage( width, height, depth, pixmap );
   DALI_ASSERT_DEBUG( image && "PixmapImage allocation failed." );
 
   // 2nd phase construction
@@ -57,15 +55,20 @@ PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::Pix
   return image;
 }
 
-PixmapImage::PixmapImage(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Dali::Adaptor& adaptor, Any pixmap)
-: mWidth(width),
-  mHeight(height),
-  mOwnPixmap(true),
-  mPixelFormat(Pixel::RGB888),
-  mColorDepth(depth),
-  mAdaptor(Internal::Adaptor::Adaptor::GetImplementation(adaptor)),
-  mEglImageKHR(NULL)
+PixmapImage::PixmapImage( unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
+: mWidth( width ),
+  mHeight( height ),
+  mOwnPixmap( true ),
+  mColorDepth( depth ),
+  mEglImageKHR( NULL ),
+  mEglImageExtensions( NULL )
 {
+  DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
+  EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
+  mEglImageExtensions = eglFactory.GetImageExtensions();
+  SetBlending( mColorDepth );
+
+  DALI_ASSERT_DEBUG( mEglImageExtensions );
 }
 
 void PixmapImage::Initialize()
@@ -74,24 +77,12 @@ void PixmapImage::Initialize()
 
 PixmapImage::~PixmapImage()
 {
-  // Lost the opportunity to call GlExtensionDestroy() if Adaptor is destroyed first
-  if( Adaptor::IsAvailable() )
-  {
-    // GlExtensionDestroy() called from GLCleanup on the render thread. Checking this is done here.
-    // (mEglImageKHR is now read/written from different threads although ref counted destruction
-    //  should mean this isnt concurrent)
-    DALI_ASSERT_ALWAYS( NULL == mEglImageKHR && "NativeImage GL resources have not been properly cleaned up" );
-  }
 }
 
-Any PixmapImage::GetPixmap(Dali::PixmapImage::PixmapAPI api) const
+Any PixmapImage::GetPixmap() const
 {
-    return NULL;
-}
-
-Any PixmapImage::GetDisplay() const
-{
-    return NULL;
+  DALI_ASSERT_ALWAYS( false && "PixmapImage::GetPixmap() is not supported for Wayland." );
+  return Any();
 }
 
 bool PixmapImage::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
@@ -119,75 +110,37 @@ bool PixmapImage::GlExtensionCreate()
 
 void PixmapImage::GlExtensionDestroy()
 {
-  EglImageExtensions* eglImageExtensions = GetEglImageExtensions();
-
-  eglImageExtensions->DestroyImageKHR(mEglImageKHR);
+  mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
 
   mEglImageKHR = NULL;
 }
 
 unsigned int PixmapImage::TargetTexture()
 {
-  EglImageExtensions* eglImageExtensions = GetEglImageExtensions();
-
-  eglImageExtensions->TargetTextureKHR(mEglImageKHR);
+  mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
 
   return 0;
 }
 
-int PixmapImage::GetPixelDepth(Dali::PixmapImage::ColorDepth depth) const
-{
-  switch (depth)
-  {
-    case Dali::PixmapImage::COLOR_DEPTH_8:
-    {
-      return 8;
-    }
-    case Dali::PixmapImage::COLOR_DEPTH_16:
-    {
-      return 16;
-    }
-    case Dali::PixmapImage::COLOR_DEPTH_24:
-    {
-      return 24;
-    }
-    case Dali::PixmapImage::COLOR_DEPTH_32:
-    {
-      return 32;
-    }
-    default:
-    {
-      DALI_ASSERT_DEBUG(0 && "unknown color enum");
-      return 0;
-    }
-  }
-}
-
-void PixmapImage::SetPixelFormat(int depth)
+void PixmapImage::SetBlending(Dali::PixmapImage::ColorDepth depth)
 {
-  // store the pixel format based on the depth
   switch (depth)
   {
-    case 8:
+    case Dali::PixmapImage::COLOR_DEPTH_16: //Pixel::RGB565
+    case Dali::PixmapImage::COLOR_DEPTH_24: // Pixel::RGB888
     {
-      mPixelFormat = Pixel::A8;
+      mBlendingRequired = false;
       break;
     }
-    case 16:
+    case Dali::PixmapImage::COLOR_DEPTH_8: //Pixel::A8
+    case Dali::PixmapImage::COLOR_DEPTH_32: // Pixel::RGBA8888
     {
-      mPixelFormat = Pixel::RGB565;
+      mBlendingRequired = true;
       break;
     }
-    case 32:
-    {
-      mPixelFormat = Pixel::RGBA8888;
-      break;
-    }
-    case 24:
     default:
     {
-      mPixelFormat = Pixel::RGB888;
-      break;
+      DALI_ASSERT_DEBUG(0 && "unknown color enum");
     }
   }
 }
@@ -196,14 +149,6 @@ void PixmapImage::GetPixmapDetails()
 {
 }
 
-EglImageExtensions* PixmapImage::GetEglImageExtensions() const
-{
-  EglFactory& factory = mAdaptor.GetEGLFactory();
-  EglImageExtensions* egl = factory.GetImageExtensions();
-  DALI_ASSERT_DEBUG( egl && "EGL Image Extensions not initialized" );
-  return egl;
-}
-
 } // namespace Adaptor
 
 } // namespace internal