Fix egl surface crash
[platform/core/uifw/dali-adaptor.git] / adaptors / base / render-helper.cpp
index d3a771a..c77d2c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -38,12 +38,20 @@ RenderHelper::RenderHelper( AdaptorInternalServices& adaptorInterfaces )
 : mGLES( adaptorInterfaces.GetGlesInterface() ),
   mEglFactory( &adaptorInterfaces.GetEGLFactoryInterface()),
   mEGL( NULL ),
-  mSurfaceReplaced( false )
+  mSurfaceReplaced( false ),
+  mSurfaceResized( false )
 {
   // set the initial values before render thread starts
   mSurface = adaptorInterfaces.GetRenderSurfaceInterface();
 
-  mDisplayConnection = Dali::DisplayConnection::New();
+  if( mSurface )
+  {
+    mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() );
+  }
+  else
+  {
+    mDisplayConnection = Dali::DisplayConnection::New();
+  }
 }
 
 RenderHelper::~RenderHelper()
@@ -71,9 +79,6 @@ void RenderHelper::Stop()
   {
     // Tell surface we have stopped rendering
     mSurface->StopRender();
-
-    // The surface will be destroyed soon; this pointer will become invalid
-    mSurface = NULL;
   }
 }
 
@@ -121,12 +126,19 @@ void RenderHelper::ReplaceSurface( RenderSurface* newSurface )
   mSurfaceReplaced = true;
 }
 
+void RenderHelper::ResizeSurface()
+{
+  mSurfaceResized = true;
+}
+
 void RenderHelper::ShutdownEgl()
 {
   if( mSurface )
   {
     // give a chance to destroy the OpenGL surface that created externally
     mSurface->DestroyEglSurface( *mEGL );
+
+    mSurface = NULL;
   }
 
   // delete the GL context / egl surface
@@ -137,7 +149,7 @@ bool RenderHelper::PreRender()
 {
   if( mSurface )
   {
-    mSurface->PreRender( *mEGL, mGLES );
+    mSurface->PreRender( *mEGL, mGLES, mSurfaceResized );
   }
   mGLES.PreRender();
   return true;
@@ -151,9 +163,10 @@ void RenderHelper::PostRender()
   if( mSurface )
   {
     // Inform the surface that rendering this frame has finished.
-    mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, mSurfaceReplaced );
+    mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, mSurfaceReplaced, mSurfaceResized );
   }
   mSurfaceReplaced = false;
+  mSurfaceResized = false;
 }
 
 } // namespace Adaptor