Remove RenderSurface from Core
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / tizen / native-image-source-impl-tizen.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 3cd791f..6970fc0
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -26,9 +26,9 @@
 
 // INTERNAL INCLUDES
 #include <dali/internal/graphics/common/egl-image-extensions.h>
-#include <dali/internal/graphics/gles20/egl-factory.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
 #include <dali/internal/adaptor/common/adaptor-impl.h>
-#include <dali/integration-api/render-surface.h>
+#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
 
 // Allow this to be encoded and saved:
 #include <dali/devel-api/adaptor-framework/bitmap-saver.h>
@@ -65,7 +65,7 @@ const int NUM_FORMATS_BLENDING_REQUIRED = 18;
 
 using Dali::Integration::PixelBuffer;
 
-NativeImageSourceTizen* NativeImageSourceTizen::New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource )
+NativeImageSourceTizen* NativeImageSourceTizen::New( uint32_t width, uint32_t height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource )
 {
   NativeImageSourceTizen* image = new NativeImageSourceTizen( width, height, depth, nativeImageSource );
   DALI_ASSERT_DEBUG( image && "NativeImageSource allocation failed." );
@@ -78,7 +78,7 @@ NativeImageSourceTizen* NativeImageSourceTizen::New(unsigned int width, unsigned
   return image;
 }
 
-NativeImageSourceTizen::NativeImageSourceTizen( unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource )
+NativeImageSourceTizen::NativeImageSourceTizen( uint32_t width, uint32_t height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource )
 : mWidth( width ),
   mHeight( height ),
   mOwnTbmSurface( false ),
@@ -87,13 +87,15 @@ NativeImageSourceTizen::NativeImageSourceTizen( unsigned int width, unsigned int
   mBlendingRequired( false ),
   mColorDepth( depth ),
   mEglImageKHR( NULL ),
+  mEglGraphics( NULL ),
   mEglImageExtensions( NULL ),
-  mSetSource( false )
+  mSetSource( false ),
+  mMutex()
 {
   DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
-  EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
-  mEglImageExtensions = eglFactory.GetImageExtensions();
-  DALI_ASSERT_DEBUG( mEglImageExtensions );
+
+  GraphicsInterface* graphics = &( Adaptor::GetImplementation( Adaptor::Get() ).GetGraphicsInterface() );
+  mEglGraphics = static_cast<EglGraphics *>(graphics);
 
   mTbmSurface = GetSurfaceFromAny( nativeImageSource );
 
@@ -208,6 +210,7 @@ Any NativeImageSourceTizen::GetNativeImageSource() const
 
 bool NativeImageSourceTizen::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
 {
+  Dali::Mutex::ScopedLock lock( mMutex );
   if( mTbmSurface != NULL )
   {
     tbm_surface_info_s surface_info;
@@ -314,6 +317,7 @@ bool NativeImageSourceTizen::EncodeToFile(const std::string& filename) const
 
 void NativeImageSourceTizen::SetSource( Any source )
 {
+  Dali::Mutex::ScopedLock lock( mMutex );
   if( mOwnTbmSurface )
   {
     if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
@@ -401,11 +405,14 @@ bool NativeImageSourceTizen::GlExtensionCreate()
   // casting from an unsigned int to a void *, which should then be cast back
   // to an unsigned int in the driver.
   EGLClientBuffer eglBuffer = reinterpret_cast< EGLClientBuffer >(mTbmSurface);
-  if( !eglBuffer )
+  if( !eglBuffer || !tbm_surface_internal_is_valid( mTbmSurface ) )
   {
     return false;
   }
 
+  mEglImageExtensions = mEglGraphics->GetImageExtensions();
+  DALI_ASSERT_DEBUG( mEglImageExtensions );
+
   mEglImageKHR = mEglImageExtensions->CreateImageKHR( eglBuffer );
 
   return mEglImageKHR != NULL;
@@ -413,6 +420,7 @@ bool NativeImageSourceTizen::GlExtensionCreate()
 
 void NativeImageSourceTizen::GlExtensionDestroy()
 {
+  Dali::Mutex::ScopedLock lock( mMutex );
   if( mEglImageKHR )
   {
     mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
@@ -421,7 +429,7 @@ void NativeImageSourceTizen::GlExtensionDestroy()
   }
 }
 
-unsigned int NativeImageSourceTizen::TargetTexture()
+uint32_t NativeImageSourceTizen::TargetTexture()
 {
   mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
 
@@ -430,6 +438,7 @@ unsigned int NativeImageSourceTizen::TargetTexture()
 
 void NativeImageSourceTizen::PrepareTexture()
 {
+  Dali::Mutex::ScopedLock lock( mMutex );
   if( mSetSource )
   {
     void* eglImage = mEglImageKHR;