2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali/internal/graphics/gles/egl-implementation.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/common/dali-vector.h>
28 #include <dali/public-api/dali-adaptor-common.h>
29 #include <dali/internal/graphics/gles/gl-implementation.h>
30 #include <dali/internal/graphics/gles/egl-debug.h>
32 // EGL constants use C style casts
33 #pragma GCC diagnostic push
34 #pragma GCC diagnostic ignored "-Wold-style-cast"
38 const uint32_t THRESHOLD_SWAPBUFFER_COUNT = 5;
39 const uint32_t CHECK_EXTENSION_NUMBER = 2;
40 const std::string EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context";
41 const std::string EGL_KHR_CREATE_CONTEXT = "EGL_KHR_create_context";
53 #define TEST_EGL_ERROR(lastCommand) \
55 EGLint err = eglGetError(); \
56 if (err != EGL_SUCCESS) \
58 DALI_LOG_ERROR("EGL error after %s\n", lastCommand); \
59 Egl::PrintError(err); \
60 DALI_ASSERT_ALWAYS(0 && "EGL error"); \
64 EglImplementation::EglImplementation( int multiSamplingLevel,
65 Integration::DepthBufferAvailable depthBufferRequired,
66 Integration::StencilBufferAvailable stencilBufferRequired ,
67 Integration::PartialUpdateAvailable partialUpdateRequired )
69 mEglNativeDisplay( 0 ),
70 mEglNativeWindow( 0 ),
71 mCurrentEglNativePixmap( 0 ),
75 mCurrentEglSurface( 0 ),
76 mCurrentEglContext( EGL_NO_CONTEXT ),
77 mMultiSamplingLevel( multiSamplingLevel ),
79 mColorDepth( COLOR_DEPTH_24 ),
80 mGlesInitialized( false ),
81 mIsOwnSurface( true ),
83 mDepthBufferRequired( depthBufferRequired == Integration::DepthBufferAvailable::TRUE ),
84 mStencilBufferRequired( stencilBufferRequired == Integration::StencilBufferAvailable::TRUE ),
85 mPartialUpdateRequired( partialUpdateRequired == Integration::PartialUpdateAvailable::TRUE ),
86 mIsSurfacelessContextSupported( false ),
87 mIsKhrCreateContextSupported( false ),
88 mSwapBufferCountAfterResume( 0 ),
89 mEglSetDamageRegionKHR( 0 ),
90 mEglSwapBuffersWithDamageKHR( 0 ),
91 mFullSwapNextFrame( true )
95 EglImplementation::~EglImplementation()
100 bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwnSurface )
102 if ( !mGlesInitialized )
104 mEglNativeDisplay = display;
106 // Try to get the display connection for the native display first
107 mEglDisplay = eglGetDisplay( mEglNativeDisplay );
109 if( mEglDisplay == EGL_NO_DISPLAY )
111 // If failed, try to get the default display connection
112 mEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
115 if( mEglDisplay == EGL_NO_DISPLAY )
117 // Still failed to get a display connection
118 throw Dali::DaliException( "", "OpenGL ES is not supported");
121 EGLint majorVersion = 0;
122 EGLint minorVersion = 0;
123 if ( !eglInitialize( mEglDisplay, &majorVersion, &minorVersion ) )
127 eglBindAPI(EGL_OPENGL_ES_API);
129 mIsOwnSurface = isOwnSurface;
132 // Query EGL extensions to check whether surfaceless context is supported
133 const char* const extensionStr = eglQueryString( mEglDisplay, EGL_EXTENSIONS );
134 std::istringstream stream( extensionStr );
135 std::string currentExtension;
136 uint32_t extensionCheckCount = 0;
137 while( std::getline( stream, currentExtension, ' ' ) && extensionCheckCount < CHECK_EXTENSION_NUMBER )
139 if( currentExtension == EGL_KHR_SURFACELESS_CONTEXT )
141 mIsSurfacelessContextSupported = true;
142 extensionCheckCount++;
144 if( currentExtension == EGL_KHR_CREATE_CONTEXT )
146 mIsKhrCreateContextSupported = true;
147 extensionCheckCount++;
151 mGlesInitialized = true;
153 // We want to display this information all the time, so use the LogMessage directly
154 Integration::Log::LogMessage(Integration::Log::DebugInfo, "EGL Information\n"
155 " PartialUpdate %d\n"
160 mPartialUpdateRequired,
161 eglQueryString( mEglDisplay, EGL_VENDOR ),
162 eglQueryString( mEglDisplay, EGL_VERSION ),
163 eglQueryString( mEglDisplay, EGL_CLIENT_APIS ),
166 return mGlesInitialized;
169 bool EglImplementation::CreateContext()
171 // make sure a context isn't created twice
172 DALI_ASSERT_ALWAYS( (mEglContext == 0) && "EGL context recreated" );
174 mEglContext = eglCreateContext(mEglDisplay, mEglConfig, NULL, &(mContextAttribs[0]));
175 TEST_EGL_ERROR("eglCreateContext render thread");
177 DALI_ASSERT_ALWAYS( EGL_NO_CONTEXT != mEglContext && "EGL context not created" );
179 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VENDOR : %s ***\n", glGetString(GL_VENDOR));
180 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_RENDERER : %s ***\n", glGetString(GL_RENDERER));
181 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VERSION : %s ***\n", glGetString(GL_VERSION));
182 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_SHADING_LANGUAGE_VERSION : %s***\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
183 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** Supported Extensions ***\n%s\n\n", glGetString(GL_EXTENSIONS));
185 mEglSetDamageRegionKHR = reinterpret_cast<PFNEGLSETDAMAGEREGIONKHRPROC>(eglGetProcAddress("eglSetDamageRegionKHR"));
186 if (!mEglSetDamageRegionKHR)
188 DALI_LOG_ERROR("Coudn't find eglSetDamageRegionKHR!\n");
189 mPartialUpdateRequired = false;
191 mEglSwapBuffersWithDamageKHR = reinterpret_cast<PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC>(eglGetProcAddress("eglSwapBuffersWithDamageKHR"));
192 if (!mEglSwapBuffersWithDamageKHR)
194 DALI_LOG_ERROR("Coudn't find eglSwapBuffersWithDamageKHR!\n");
195 mPartialUpdateRequired = false;
200 bool EglImplementation::CreateWindowContext( EGLContext& eglContext )
202 // make sure a context isn't created twice
203 DALI_ASSERT_ALWAYS( (eglContext == 0) && "EGL context recreated" );
205 eglContext = eglCreateContext(mEglDisplay, mEglConfig, mEglContext, &(mContextAttribs[0]));
206 TEST_EGL_ERROR("eglCreateContext render thread");
208 DALI_ASSERT_ALWAYS( EGL_NO_CONTEXT != eglContext && "EGL context not created" );
210 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VENDOR : %s ***\n", glGetString(GL_VENDOR));
211 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_RENDERER : %s ***\n", glGetString(GL_RENDERER));
212 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VERSION : %s ***\n", glGetString(GL_VERSION));
213 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_SHADING_LANGUAGE_VERSION : %s***\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
214 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** Supported Extensions ***\n%s\n\n", glGetString(GL_EXTENSIONS));
216 mEglWindowContexts.push_back( eglContext );
218 mEglSetDamageRegionKHR = reinterpret_cast<PFNEGLSETDAMAGEREGIONKHRPROC>(eglGetProcAddress("eglSetDamageRegionKHR"));
219 if (!mEglSetDamageRegionKHR)
221 DALI_LOG_ERROR("Coudn't find eglSetDamageRegionKHR!\n");
222 mPartialUpdateRequired = false;
224 mEglSwapBuffersWithDamageKHR = reinterpret_cast<PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC>(eglGetProcAddress("eglSwapBuffersWithDamageKHR"));
225 if (!mEglSwapBuffersWithDamageKHR)
227 DALI_LOG_ERROR("Coudn't find eglSwapBuffersWithDamageKHR!\n");
228 mPartialUpdateRequired = false;
233 void EglImplementation::DestroyContext( EGLContext& eglContext )
237 eglDestroyContext( mEglDisplay, eglContext );
242 void EglImplementation::DestroySurface( EGLSurface& eglSurface )
244 if(mIsOwnSurface && eglSurface)
246 // Make context null to prevent crash in driver side
248 eglDestroySurface( mEglDisplay, eglSurface );
253 void EglImplementation::MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext )
255 if (mCurrentEglContext == eglContext)
260 mCurrentEglSurface = eglSurface;
264 eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, eglContext );
266 mCurrentEglContext = eglContext;
269 EGLint error = eglGetError();
271 if ( error != EGL_SUCCESS )
273 Egl::PrintError(error);
275 DALI_ASSERT_ALWAYS(false && "MakeContextCurrent failed!");
279 void EglImplementation::MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface )
281 if (mCurrentEglContext == mEglContext)
286 mCurrentEglNativePixmap = pixmap;
287 mCurrentEglSurface = eglSurface;
291 eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, mEglContext );
293 mCurrentEglContext = mEglContext;
296 EGLint error = eglGetError();
298 if ( error != EGL_SUCCESS )
300 Egl::PrintError(error);
302 DALI_ASSERT_ALWAYS(false && "MakeCurrent failed!");
306 void EglImplementation::MakeContextNull()
308 // clear the current context
309 eglMakeCurrent( mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
310 mCurrentEglContext = EGL_NO_CONTEXT;
313 void EglImplementation::TerminateGles()
315 if ( mGlesInitialized )
317 // Make context null to prevent crash in driver side
320 for ( auto eglSurface : mEglWindowSurfaces )
322 if(mIsOwnSurface && eglSurface)
324 eglDestroySurface(mEglDisplay, eglSurface);
327 eglDestroyContext(mEglDisplay, mEglContext);
328 for ( auto eglContext : mEglWindowContexts )
330 eglDestroyContext(mEglDisplay, eglContext);
333 eglTerminate(mEglDisplay);
338 mCurrentEglSurface = NULL;
339 mCurrentEglContext = EGL_NO_CONTEXT;
341 mGlesInitialized = false;
345 bool EglImplementation::IsGlesInitialized() const
347 return mGlesInitialized;
350 void EglImplementation::SwapBuffers( EGLSurface& eglSurface )
352 if ( eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
354 #ifndef DALI_PROFILE_UBUNTU
355 if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
357 DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers started.\n" );
359 #endif //DALI_PROFILE_UBUNTU
361 // DALI_LOG_ERROR("EglImplementation::SwapBuffers()\n");
362 eglSwapBuffers( mEglDisplay, eglSurface );
363 mFullSwapNextFrame = false;
365 #ifndef DALI_PROFILE_UBUNTU
366 if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
368 DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers finished.\n" );
369 mSwapBufferCountAfterResume++;
371 #endif //DALI_PROFILE_UBUNTU
375 EGLint EglImplementation::GetBufferAge(EGLSurface& eglSurface) const
378 eglQuerySurface(mEglDisplay, eglSurface, EGL_BUFFER_AGE_EXT, &age);
381 DALI_LOG_ERROR("eglQuerySurface(%d)\n", eglGetError());
385 // 0 - invalid buffer
389 DALI_LOG_ERROR("EglImplementation::GetBufferAge() buffer age %d > 3\n", age);
390 age = 0; // shoudn't be more than 3 back buffers, if there is just reset, I don't want to add extra history level
396 void EglImplementation::SetFullSwapNextFrame()
398 mFullSwapNextFrame = true;
401 void mergeRects(Rect<int>& mergingRect, const std::vector<Rect<int>>& rects)
404 if (mergingRect.IsEmpty())
406 for (;i < rects.size(); i++)
408 if (!rects[i].IsEmpty())
410 mergingRect = rects[i];
416 for (;i < rects.size(); i++)
418 mergingRect.Merge(rects[i]);
422 void insertRects(std::list<std::vector<Rect<int>>>& damagedRectsList, const std::vector<Rect<int>>& damagedRects)
424 damagedRectsList.push_front(damagedRects);
425 if (damagedRectsList.size() > 4) // past triple buffers + current
427 damagedRectsList.pop_back();
431 void EglImplementation::SetDamage( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect )
433 if (!mPartialUpdateRequired)
438 if (eglSurface != EGL_NO_SURFACE) // skip if using surfaceless context
442 eglQuerySurface(mEglDisplay, eglSurface, EGL_WIDTH, &width);
443 eglQuerySurface(mEglDisplay, eglSurface, EGL_HEIGHT, &height);
444 Rect<int> surfaceRect(0, 0, width, height);
446 mSurfaceRect = surfaceRect;
448 if (mFullSwapNextFrame)
450 insertRects(mBufferDamagedRects, std::vector<Rect<int>>(1, surfaceRect));
451 clippingRect = Rect<int>();
455 EGLint bufferAge = GetBufferAge(eglSurface);
457 // Buffer age 0 means the back buffer in invalid and requires full swap
458 if (!damagedRects.size() || bufferAge == 0)
460 // No damage or buffer is out of order or buffer age is reset
461 insertRects(mBufferDamagedRects, std::vector<Rect<int>>(1, surfaceRect));
462 clippingRect = Rect<int>();
466 // We push current frame damaged rects here, zero index for current frame
467 insertRects(mBufferDamagedRects, damagedRects);
469 // Merge damaged rects into clipping rect
470 auto bufferDamagedRects = mBufferDamagedRects.begin();
471 while (bufferAge-- >= 0 && bufferDamagedRects != mBufferDamagedRects.end())
473 const std::vector<Rect<int>>& rects = *bufferDamagedRects++;
474 mergeRects(clippingRect, rects);
477 if (!clippingRect.Intersect(surfaceRect) || clippingRect.Area() > surfaceRect.Area() * 0.8)
479 // clipping area too big or doesn't intersect surface rect
480 clippingRect = Rect<int>();
484 // DALI_LOG_ERROR("eglSetDamageRegionKHR(%d, %d, %d, %d)\n", clippingRect.x, clippingRect.y, clippingRect.width, clippingRect.height);
485 EGLBoolean result = mEglSetDamageRegionKHR(mEglDisplay, eglSurface, reinterpret_cast<int*>(&clippingRect), 1);
486 if (result == EGL_FALSE)
488 DALI_LOG_ERROR("eglSetDamageRegionKHR(%d)\n", eglGetError());
493 void EglImplementation::SwapBuffers(EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects)
495 if (eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
497 if (!mPartialUpdateRequired || mFullSwapNextFrame || !damagedRects.size() || (damagedRects[0].Area() > mSurfaceRect.Area() * 0.8) )
499 SwapBuffers(eglSurface);
503 #ifndef DALI_PROFILE_UBUNTU
504 if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
506 DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers started.\n" );
508 #endif //DALI_PROFILE_UBUNTU
510 std::vector< Rect< int > > mergedRects = damagedRects;
512 // Merge intersecting rects, form an array of non intersecting rects to help driver a bit
513 // Could be optional and can be removed, needs to be checked with and without on platform
514 const int n = mergedRects.size();
515 for(int i = 0; i < n-1; i++)
517 if (mergedRects[i].IsEmpty())
522 for (int j = i+1; j < n; j++)
524 if (mergedRects[j].IsEmpty())
529 if (mergedRects[i].Intersects(mergedRects[j]))
531 mergedRects[i].Merge(mergedRects[j]);
532 mergedRects[j].width = 0;
533 mergedRects[j].height = 0;
539 for (int i = 0; i < n; i++)
541 if (!mergedRects[i].IsEmpty())
543 mergedRects[j++] = mergedRects[i];
549 mergedRects.resize(j);
552 if (!mergedRects.size() || (mergedRects[0].Area() > mSurfaceRect.Area() * 0.8))
554 SwapBuffers(eglSurface);
558 EGLBoolean result = mEglSwapBuffersWithDamageKHR(mEglDisplay, eglSurface, reinterpret_cast<int*>(mergedRects.data()), mergedRects.size());
559 if (result == EGL_FALSE)
561 DALI_LOG_ERROR("eglSwapBuffersWithDamageKHR(%d)\n", eglGetError());
564 #ifndef DALI_PROFILE_UBUNTU
565 if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
567 DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers finished.\n" );
568 mSwapBufferCountAfterResume++;
570 #endif //DALI_PROFILE_UBUNTU
574 void EglImplementation::CopyBuffers( EGLSurface& eglSurface )
576 eglCopyBuffers( mEglDisplay, eglSurface, mCurrentEglNativePixmap );
579 void EglImplementation::WaitGL()
584 bool EglImplementation::ChooseConfig( bool isWindowType, ColorDepth depth )
586 if(mEglConfig && isWindowType == mIsWindow && mColorDepth == depth)
592 mIsWindow = isWindowType;
595 Vector<EGLint> configAttribs;
596 configAttribs.Reserve(31);
600 configAttribs.PushBack( EGL_SURFACE_TYPE );
601 configAttribs.PushBack( EGL_WINDOW_BIT );
605 configAttribs.PushBack( EGL_SURFACE_TYPE );
606 configAttribs.PushBack( EGL_PIXMAP_BIT );
609 configAttribs.PushBack( EGL_RENDERABLE_TYPE );
611 if( mGlesVersion >= 30 )
613 configAttribs.PushBack( EGL_OPENGL_ES3_BIT_KHR );
617 configAttribs.PushBack( EGL_OPENGL_ES2_BIT );
620 // TODO: enable this flag when it becomes supported
621 // configAttribs.PushBack( EGL_CONTEXT_FLAGS_KHR );
622 // configAttribs.PushBack( EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR );
624 configAttribs.PushBack( EGL_RED_SIZE );
625 configAttribs.PushBack( 8 );
626 configAttribs.PushBack( EGL_GREEN_SIZE );
627 configAttribs.PushBack( 8 );
628 configAttribs.PushBack( EGL_BLUE_SIZE );
629 configAttribs.PushBack( 8 );
631 // For underlay video playback, we also need to set the alpha value of the 24/32bit window.
632 configAttribs.PushBack( EGL_ALPHA_SIZE );
633 configAttribs.PushBack( 8 );
635 configAttribs.PushBack( EGL_DEPTH_SIZE );
636 configAttribs.PushBack( mDepthBufferRequired ? 24 : 0 );
637 configAttribs.PushBack( EGL_STENCIL_SIZE );
638 configAttribs.PushBack( mStencilBufferRequired ? 8 : 0 );
640 #ifndef DALI_PROFILE_UBUNTU
641 if( mMultiSamplingLevel != EGL_DONT_CARE )
643 configAttribs.PushBack( EGL_SAMPLES );
644 configAttribs.PushBack( mMultiSamplingLevel );
645 configAttribs.PushBack( EGL_SAMPLE_BUFFERS );
646 configAttribs.PushBack( 1 );
648 #endif // DALI_PROFILE_UBUNTU
649 configAttribs.PushBack( EGL_NONE );
651 // Ensure number of configs is set to 1 as on some drivers,
652 // eglChooseConfig succeeds but does not actually create a proper configuration.
653 if ( ( eglChooseConfig( mEglDisplay, &(configAttribs[0]), &mEglConfig, 1, &numConfigs ) != EGL_TRUE ) ||
654 ( numConfigs != 1 ) )
656 if( mGlesVersion >= 30 )
659 DALI_LOG_ERROR("Fail to use OpenGL es 3.0. Retrying to use OpenGL es 2.0.");
663 if ( numConfigs != 1 )
665 DALI_LOG_ERROR("No configurations found.\n");
667 TEST_EGL_ERROR("eglChooseConfig");
670 EGLint error = eglGetError();
673 case EGL_BAD_DISPLAY:
675 DALI_LOG_ERROR("Display is not an EGL display connection\n");
678 case EGL_BAD_ATTRIBUTE:
680 DALI_LOG_ERROR("The parameter configAttribs contains an invalid frame buffer configuration attribute or an attribute value that is unrecognized or out of range\n");
683 case EGL_NOT_INITIALIZED:
685 DALI_LOG_ERROR("Display has not been initialized\n");
688 case EGL_BAD_PARAMETER:
690 DALI_LOG_ERROR("The parameter numConfig is NULL\n");
695 DALI_LOG_ERROR("Unknown error.\n");
698 DALI_ASSERT_ALWAYS(false && "eglChooseConfig failed!");
701 Integration::Log::LogMessage(Integration::Log::DebugInfo, "Using OpenGL es %d.%d.\n", mGlesVersion / 10, mGlesVersion % 10 );
703 mContextAttribs.Clear();
704 if( mIsKhrCreateContextSupported )
706 mContextAttribs.Reserve(5);
707 mContextAttribs.PushBack( EGL_CONTEXT_MAJOR_VERSION_KHR );
708 mContextAttribs.PushBack( mGlesVersion / 10 );
709 mContextAttribs.PushBack( EGL_CONTEXT_MINOR_VERSION_KHR );
710 mContextAttribs.PushBack( mGlesVersion % 10 );
714 mContextAttribs.Reserve(3);
715 mContextAttribs.PushBack( EGL_CONTEXT_CLIENT_VERSION );
716 mContextAttribs.PushBack( mGlesVersion / 10 );
718 mContextAttribs.PushBack( EGL_NONE );
723 EGLSurface EglImplementation::CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth )
725 mEglNativeWindow = window;
730 ChooseConfig(mIsWindow, mColorDepth);
732 mCurrentEglSurface = eglCreateWindowSurface( mEglDisplay, mEglConfig, mEglNativeWindow, NULL );
733 TEST_EGL_ERROR("eglCreateWindowSurface");
735 DALI_ASSERT_ALWAYS( mCurrentEglSurface && "Create window surface failed" );
737 return mCurrentEglSurface;
740 EGLSurface EglImplementation::CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth )
742 mCurrentEglNativePixmap = pixmap;
747 ChooseConfig(mIsWindow, mColorDepth);
749 mCurrentEglSurface = eglCreatePixmapSurface( mEglDisplay, mEglConfig, mCurrentEglNativePixmap, NULL );
750 TEST_EGL_ERROR("eglCreatePixmapSurface");
752 DALI_ASSERT_ALWAYS( mCurrentEglSurface && "Create pixmap surface failed" );
754 return mCurrentEglSurface;
757 bool EglImplementation::ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext )
759 bool contextLost = false;
761 // display connection has not changed, then we can just create a new surface
762 // the surface is bound to the context, so set the context to null
767 // destroy the surface
768 DestroySurface( eglSurface );
771 // create the EGL surface
772 EGLSurface newEglSurface = CreateSurfaceWindow( window, mColorDepth );
774 // set the context to be current with the new surface
775 MakeContextCurrent( newEglSurface, eglContext );
780 bool EglImplementation::ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface )
782 bool contextLost = false;
784 // display connection has not changed, then we can just create a new surface
785 // create the EGL surface
786 eglSurface = CreateSurfacePixmap( pixmap, mColorDepth );
788 // set the eglSurface to be current
789 MakeCurrent( pixmap, eglSurface );
794 void EglImplementation::SetGlesVersion( const int32_t glesVersion )
796 mGlesVersion = glesVersion;
799 void EglImplementation::SetFirstFrameAfterResume()
801 mSwapBufferCountAfterResume = 0;
804 EGLDisplay EglImplementation::GetDisplay() const
809 EGLContext EglImplementation::GetContext() const
814 int32_t EglImplementation::GetGlesVersion() const
819 bool EglImplementation::IsSurfacelessContextSupported() const
821 return mIsSurfacelessContextSupported;
824 void EglImplementation::WaitClient()
826 // Wait for EGL to finish executing all rendering calls for the current context
827 if ( eglWaitClient() != EGL_TRUE )
829 TEST_EGL_ERROR("eglWaitClient");
833 } // namespace Adaptor
835 } // namespace Internal
839 #pragma GCC diagnostic pop