/*
- * Copyright (c) 2019 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.
namespace
{
+ const uint32_t THRESHOLD_SWAPBUFFER_COUNT = 5;
+ const uint32_t CHECK_EXTENSION_NUMBER = 4;
+ const uint32_t EGL_VERSION_SUPPORT_SURFACELESS_CONTEXT = 15;
const std::string EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context";
+ const std::string EGL_KHR_CREATE_CONTEXT = "EGL_KHR_create_context";
+ const std::string EGL_KHR_PARTIAL_UPDATE = "EGL_KHR_partial_update";
+ const std::string EGL_KHR_SWAP_BUFFERS_WITH_DAMAGE = "EGL_KHR_swap_buffers_with_damage";
+
}
namespace Dali
EglImplementation::EglImplementation( int multiSamplingLevel,
Integration::DepthBufferAvailable depthBufferRequired,
- Integration::StencilBufferAvailable stencilBufferRequired )
+ Integration::StencilBufferAvailable stencilBufferRequired ,
+ Integration::PartialUpdateAvailable partialUpdateRequired )
: mContextAttribs(),
mEglNativeDisplay( 0 ),
mEglNativeWindow( 0 ),
mIsWindow( true ),
mDepthBufferRequired( depthBufferRequired == Integration::DepthBufferAvailable::TRUE ),
mStencilBufferRequired( stencilBufferRequired == Integration::StencilBufferAvailable::TRUE ),
- mIsSurfacelessContextSupported( false )
+ mPartialUpdateRequired( partialUpdateRequired == Integration::PartialUpdateAvailable::TRUE ),
+ mIsSurfacelessContextSupported( false ),
+ mIsKhrCreateContextSupported( false ),
+ mSwapBufferCountAfterResume( 0 ),
+ mEglSetDamageRegionKHR( 0 ),
+ mEglSwapBuffersWithDamageKHR( 0 )
{
}
{
mEglNativeDisplay = display;
- //@todo see if we can just EGL_DEFAULT_DISPLAY instead
- mEglDisplay = eglGetDisplay(mEglNativeDisplay);
- EGLint error = eglGetError();
+ // Try to get the display connection for the native display first
+ mEglDisplay = eglGetDisplay( mEglNativeDisplay );
- if( mEglDisplay == NULL && error != EGL_SUCCESS )
+ if( mEglDisplay == EGL_NO_DISPLAY )
{
+ // If failed, try to get the default display connection
+ mEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
+ }
+
+ if( mEglDisplay == EGL_NO_DISPLAY )
+ {
+ // Still failed to get a display connection
throw Dali::DaliException( "", "OpenGL ES is not supported");
}
}
eglBindAPI(EGL_OPENGL_ES_API);
- mGlesInitialized = true;
mIsOwnSurface = isOwnSurface;
}
- // Query EGL extensions to check whether surfaceless context is supported
+ const char* const versionStr = eglQueryString( mEglDisplay, EGL_VERSION );
const char* const extensionStr = eglQueryString( mEglDisplay, EGL_EXTENSIONS );
+
+ // Query EGL extensions to check whether required extensions are supported
+ std::istringstream versionStream( versionStr );
+ std::string majorVersion, minorVersion;
+ std::getline( versionStream, majorVersion, '.' );
+ std::getline( versionStream, minorVersion );
+ uint32_t extensionCheckCount = 0;
+ if( stoul( majorVersion ) * 10 + stoul( minorVersion ) >= EGL_VERSION_SUPPORT_SURFACELESS_CONTEXT )
+ {
+ mIsSurfacelessContextSupported = true;
+ mIsKhrCreateContextSupported = true;
+ extensionCheckCount += 2;
+ }
+
std::istringstream stream(extensionStr);
std::string currentExtension;
- while ( std::getline( stream, currentExtension, ' ' ) )
+ bool isKhrPartialUpdateSupported = false;
+ bool isKhrSwapBuffersWithDamageSupported = false;
+ while(std::getline(stream, currentExtension, ' ') && extensionCheckCount < CHECK_EXTENSION_NUMBER)
{
- if ( currentExtension == EGL_KHR_SURFACELESS_CONTEXT )
+ if(currentExtension == EGL_KHR_SURFACELESS_CONTEXT && !mIsSurfacelessContextSupported)
{
mIsSurfacelessContextSupported = true;
- break;
+ extensionCheckCount++;
+ }
+ if(currentExtension == EGL_KHR_CREATE_CONTEXT && !mIsKhrCreateContextSupported)
+ {
+ mIsKhrCreateContextSupported = true;
+ extensionCheckCount++;
+ }
+ if(currentExtension == EGL_KHR_PARTIAL_UPDATE)
+ {
+ isKhrPartialUpdateSupported = true;
+ extensionCheckCount++;
}
+ if(currentExtension == EGL_KHR_SWAP_BUFFERS_WITH_DAMAGE)
+ {
+ isKhrSwapBuffersWithDamageSupported = true;
+ extensionCheckCount++;
+ }
+ }
+
+ if(!isKhrPartialUpdateSupported || !isKhrSwapBuffersWithDamageSupported)
+ {
+ mPartialUpdateRequired = false;
}
+ 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"
+ " PartialUpdate %d\n"
" Vendor: %s\n"
" Version: %s\n"
" Client APIs: %s\n"
" Extensions: %s\n",
+ mPartialUpdateRequired,
eglQueryString( mEglDisplay, EGL_VENDOR ),
- eglQueryString( mEglDisplay, EGL_VERSION ),
+ versionStr,
eglQueryString( mEglDisplay, EGL_CLIENT_APIS ),
extensionStr);
DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_SHADING_LANGUAGE_VERSION : %s***\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** Supported Extensions ***\n%s\n\n", glGetString(GL_EXTENSIONS));
+ mEglSetDamageRegionKHR = reinterpret_cast<PFNEGLSETDAMAGEREGIONKHRPROC>(eglGetProcAddress("eglSetDamageRegionKHR"));
+ if (!mEglSetDamageRegionKHR)
+ {
+ DALI_LOG_ERROR("Coudn't find eglSetDamageRegionKHR!\n");
+ mPartialUpdateRequired = false;
+ }
+ mEglSwapBuffersWithDamageKHR = reinterpret_cast<PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC>(eglGetProcAddress("eglSwapBuffersWithDamageKHR"));
+ if (!mEglSwapBuffersWithDamageKHR)
+ {
+ DALI_LOG_ERROR("Coudn't find eglSwapBuffersWithDamageKHR!\n");
+ mPartialUpdateRequired = false;
+ }
return true;
}
mEglWindowContexts.push_back( eglContext );
+ mEglSetDamageRegionKHR = reinterpret_cast<PFNEGLSETDAMAGEREGIONKHRPROC>(eglGetProcAddress("eglSetDamageRegionKHR"));
+ if (!mEglSetDamageRegionKHR)
+ {
+ DALI_LOG_ERROR("Coudn't find eglSetDamageRegionKHR!\n");
+ mPartialUpdateRequired = false;
+ }
+ mEglSwapBuffersWithDamageKHR = reinterpret_cast<PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC>(eglGetProcAddress("eglSwapBuffersWithDamageKHR"));
+ if (!mEglSwapBuffersWithDamageKHR)
+ {
+ DALI_LOG_ERROR("Coudn't find eglSwapBuffersWithDamageKHR!\n");
+ mPartialUpdateRequired = false;
+ }
return true;
}
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 )
if(mIsOwnSurface)
{
- glFinish();
-
eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, eglContext );
mCurrentEglContext = eglContext;
if(mIsOwnSurface)
{
- glFinish();
-
eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, mEglContext );
mCurrentEglContext = mEglContext;
{
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
+
+ // DALI_LOG_ERROR("EglImplementation::SwapBuffers()\n");
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
+ }
+}
+
+EGLint EglImplementation::GetBufferAge(EGLSurface& eglSurface) const
+{
+ EGLint age = 0;
+ eglQuerySurface(mEglDisplay, eglSurface, EGL_BUFFER_AGE_EXT, &age);
+ if (age < 0)
+ {
+ DALI_LOG_ERROR("eglQuerySurface(%d)\n", eglGetError());
+ age = 0;
+ }
+
+ // 0 - invalid buffer
+ // 1, 2, 3
+ if (age > 3)
+ {
+ DALI_LOG_ERROR("EglImplementation::GetBufferAge() buffer age %d > 3\n", age);
+ age = 0; // shoudn't be more than 3 back buffers, if there is just reset, I don't want to add extra history level
+ }
+
+ return age;
+}
+
+void EglImplementation::SetDamageRegion( EGLSurface& eglSurface, std::vector< Rect< int > >& damagedRects )
+{
+ if( !mPartialUpdateRequired )
+ {
+ return;
+ }
+
+ if( eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
+ {
+ EGLBoolean result = mEglSetDamageRegionKHR( mEglDisplay, eglSurface, reinterpret_cast< int* >( damagedRects.data() ), 1 );
+ if (result == EGL_FALSE)
+ {
+ DALI_LOG_ERROR( "eglSetDamageRegionKHR(%d)\n", eglGetError() );
+ }
+ }
+}
+
+void EglImplementation::SwapBuffers(EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects)
+{
+ if (eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
+ {
+ if (!mPartialUpdateRequired )
+ {
+ SwapBuffers(eglSurface);
+ return;
+ }
+
+#ifndef DALI_PROFILE_UBUNTU
+ if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
+ {
+ DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers started.\n" );
+ }
+#endif //DALI_PROFILE_UBUNTU
+
+ EGLBoolean result = mEglSwapBuffersWithDamageKHR(mEglDisplay, eglSurface, reinterpret_cast<int*>(const_cast< std::vector< Rect< int > >& >( damagedRects ).data()), damagedRects.size());
+ if (result == EGL_FALSE)
+ {
+ DALI_LOG_ERROR("eglSwapBuffersWithDamageKHR(%d)\n", eglGetError());
+ }
+
+#ifndef DALI_PROFILE_UBUNTU
+ if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
+ {
+ DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers finished.\n" );
+ mSwapBufferCountAfterResume++;
+ }
+#endif //DALI_PROFILE_UBUNTU
}
}
return true;
}
- bool isTransparent = ( depth == COLOR_DEPTH_32 );
-
mColorDepth = depth;
mIsWindow = isWindowType;
if( mGlesVersion >= 30 )
{
-#ifdef _ARCH_ARM_
configAttribs.PushBack( EGL_OPENGL_ES3_BIT_KHR );
-#else
- configAttribs.PushBack( EGL_OPENGL_ES2_BIT );
-#endif // _ARCH_ARM_
}
else
{
configAttribs.PushBack( EGL_BLUE_SIZE );
configAttribs.PushBack( 8 );
- if ( isTransparent )
- {
- configAttribs.PushBack( EGL_ALPHA_SIZE );
-#ifdef _ARCH_ARM_
- // For underlay video playback, we also need to set the alpha value of the 24/32bit window.
- configAttribs.PushBack( 8 );
-#else
- // There is a bug in the desktop emulator
- // setting EGL_ALPHA_SIZE to 8 results in eglChooseConfig failing
- configAttribs.PushBack( 8 );
-#endif // _ARCH_ARM_
- }
+// For underlay video playback, we also need to set the alpha value of the 24/32bit window.
+ configAttribs.PushBack( EGL_ALPHA_SIZE );
+ configAttribs.PushBack( 8 );
configAttribs.PushBack( EGL_DEPTH_SIZE );
configAttribs.PushBack( mDepthBufferRequired ? 24 : 0 );
if( mGlesVersion >= 30 )
{
mEglConfig = NULL;
- DALI_LOG_ERROR("Fail to use OpenGL es 3.0. Retring to use OpenGL es 2.0.");
+ DALI_LOG_ERROR("Fail to use OpenGL es 3.0. Retrying to use OpenGL es 2.0.");
return false;
}
Integration::Log::LogMessage(Integration::Log::DebugInfo, "Using OpenGL es %d.%d.\n", mGlesVersion / 10, mGlesVersion % 10 );
mContextAttribs.Clear();
- if( mGlesVersion >= 30 )
+ if( mIsKhrCreateContextSupported )
{
mContextAttribs.Reserve(5);
mContextAttribs.PushBack( EGL_CONTEXT_MAJOR_VERSION_KHR );
{
mContextAttribs.Reserve(3);
mContextAttribs.PushBack( EGL_CONTEXT_CLIENT_VERSION );
- mContextAttribs.PushBack( 2 );
+ mContextAttribs.PushBack( mGlesVersion / 10 );
}
mContextAttribs.PushBack( EGL_NONE );
// 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 );
mGlesVersion = glesVersion;
}
+void EglImplementation::SetFirstFrameAfterResume()
+{
+ mSwapBufferCountAfterResume = 0;
+}
+
EGLDisplay EglImplementation::GetDisplay() const
{
return mEglDisplay;
return mIsSurfacelessContextSupported;
}
+void EglImplementation::WaitClient()
+{
+ // Wait for EGL to finish executing all rendering calls for the current context
+ if ( eglWaitClient() != EGL_TRUE )
+ {
+ TEST_EGL_ERROR("eglWaitClient");
+ }
+}
+
+bool EglImplementation::IsPartialUpdateRequired() const
+{
+ return mPartialUpdateRequired;
+}
+
} // namespace Adaptor
} // namespace Internal