Fix DestroyContext bug
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-implementation.cpp
index 3885134..38851f9 100755 (executable)
@@ -35,6 +35,7 @@
 
 namespace
 {
+  const uint32_t THRESHOLD_SWAPBUFFER_COUNT = 5;
   const uint32_t CHECK_EXTENSION_NUMBER = 2;
   const std::string EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context";
   const std::string EGL_KHR_CREATE_CONTEXT = "EGL_KHR_create_context";
@@ -81,7 +82,8 @@ EglImplementation::EglImplementation( int multiSamplingLevel,
   mDepthBufferRequired( depthBufferRequired == Integration::DepthBufferAvailable::TRUE ),
   mStencilBufferRequired( stencilBufferRequired == Integration::StencilBufferAvailable::TRUE ),
   mIsSurfacelessContextSupported( false ),
-  mIsKhrCreateContextSupported( false )
+  mIsKhrCreateContextSupported( false ),
+  mSwapBufferCountAfterResume( 0 )
 {
 }
 
@@ -113,7 +115,6 @@ bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwn
     }
     eglBindAPI(EGL_OPENGL_ES_API);
 
-    mGlesInitialized = true;
     mIsOwnSurface = isOwnSurface;
   }
 
@@ -136,6 +137,8 @@ bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwn
     }
   }
 
+  mGlesInitialized = true;
+
   // We want to display this information all the time, so use the LogMessage directly
   Integration::Log::LogMessage(Integration::Log::DebugInfo, "EGL Information\n"
       "            Vendor:        %s\n"
@@ -192,10 +195,11 @@ bool EglImplementation::CreateWindowContext( EGLContext& eglContext )
 
 void EglImplementation::DestroyContext( EGLContext& eglContext )
 {
-  DALI_ASSERT_ALWAYS( mEglContext && "no EGL context" );
-
-  eglDestroyContext( mEglDisplay, eglContext );
-  eglContext = 0;
+  if( eglContext )
+  {
+    eglDestroyContext( mEglDisplay, eglContext );
+    eglContext = 0;
+  }
 }
 
 void EglImplementation::DestroySurface( EGLSurface& eglSurface )
@@ -310,7 +314,22 @@ void EglImplementation::SwapBuffers( EGLSurface& eglSurface )
 {
   if ( eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
   {
+#ifndef DALI_PROFILE_UBUNTU
+    if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
+    {
+      DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers started.\n" );
+    }
+#endif //DALI_PROFILE_UBUNTU
+
     eglSwapBuffers( mEglDisplay, eglSurface );
+
+#ifndef DALI_PROFILE_UBUNTU
+    if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
+    {
+      DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers finished.\n" );
+      mSwapBufferCountAfterResume++;
+    }
+#endif //DALI_PROFILE_UBUNTU
   }
 }
 
@@ -505,8 +524,11 @@ bool EglImplementation::ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSur
   //  the surface is bound to the context, so set the context to null
   MakeContextNull();
 
-  // destroy the surface
-  DestroySurface( eglSurface );
+  if( eglSurface )
+  {
+    // destroy the surface
+    DestroySurface( eglSurface );
+  }
 
   // create the EGL surface
   EGLSurface newEglSurface = CreateSurfaceWindow( window, mColorDepth );
@@ -536,6 +558,11 @@ void EglImplementation::SetGlesVersion( const int32_t glesVersion )
   mGlesVersion = glesVersion;
 }
 
+void EglImplementation::SetFirstFrameAfterResume()
+{
+  mSwapBufferCountAfterResume = 0;
+}
+
 EGLDisplay EglImplementation::GetDisplay() const
 {
   return mEglDisplay;