[Tizen] Implement partial update
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-implementation.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18
19 // CLASS HEADER
20 #include <dali/internal/graphics/gles/egl-implementation.h>
21
22 // EXTERNAL INCLUDES
23 #include <sstream>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/common/dali-vector.h>
26
27 // INTERNAL INCLUDES
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>
31
32 // EGL constants use C style casts
33 #pragma GCC diagnostic push
34 #pragma GCC diagnostic ignored "-Wold-style-cast"
35
36 namespace
37 {
38   const uint32_t THRESHOLD_SWAPBUFFER_COUNT = 5;
39   const uint32_t CHECK_EXTENSION_NUMBER = 3;
40   const std::string EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context";
41   const std::string EGL_KHR_CREATE_CONTEXT = "EGL_KHR_create_context";
42   const std::string EGL_KHR_PARTIAL_UPDATE = "EGL_KHR_partial_update";
43 }
44
45 namespace Dali
46 {
47
48 namespace Internal
49 {
50
51 namespace Adaptor
52 {
53
54 #define TEST_EGL_ERROR(lastCommand) \
55 { \
56   EGLint err = eglGetError(); \
57   if (err != EGL_SUCCESS) \
58   { \
59     DALI_LOG_ERROR("EGL error after %s\n", lastCommand); \
60     Egl::PrintError(err); \
61     DALI_ASSERT_ALWAYS(0 && "EGL error"); \
62   } \
63 }
64
65 EglImplementation::EglImplementation( int multiSamplingLevel,
66                                       Integration::DepthBufferAvailable depthBufferRequired,
67                                       Integration::StencilBufferAvailable stencilBufferRequired,
68                                       Integration::PartialUpdateAvailable partialUpdateAvailable )
69 : mContextAttribs(),
70   mEglNativeDisplay( 0 ),
71   mEglNativeWindow( 0 ),
72   mCurrentEglNativePixmap( 0 ),
73   mEglDisplay( 0 ),
74   mEglConfig( 0 ),
75   mEglContext( 0 ),
76   mCurrentEglSurface( 0 ),
77   mCurrentEglContext( EGL_NO_CONTEXT ),
78   mMultiSamplingLevel( multiSamplingLevel ),
79   mGlesVersion( 30 ),
80   mDamagedRectArray( 0 ),
81   mColorDepth( COLOR_DEPTH_24 ),
82   mGlesInitialized( false ),
83   mIsOwnSurface( true ),
84   mIsWindow( true ),
85   mDepthBufferRequired( depthBufferRequired == Integration::DepthBufferAvailable::TRUE ),
86   mStencilBufferRequired( stencilBufferRequired == Integration::StencilBufferAvailable::TRUE ),
87   mIsSurfacelessContextSupported( false ),
88   mIsKhrCreateContextSupported( false ),
89   mSwapBufferCountAfterResume( 0 ),
90   mIsKhrPartialUpdateSupported( false ),
91   mPartialUpdateAvailable( partialUpdateAvailable == Integration::PartialUpdateAvailable::TRUE ),
92   mEglSetDamageRegionKHR( nullptr ),
93   mSwapBuffersWithDamage( nullptr )
94 {
95   if( mPartialUpdateAvailable )
96   {
97     mEglSetDamageRegionKHR =  reinterpret_cast< PFNEGLSETDAMAGEREGIONKHRPROC >( eglGetProcAddress( "eglSetDamageRegionKHR" ) );
98     mSwapBuffersWithDamage = reinterpret_cast< PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC >( eglGetProcAddress( "eglSwapBuffersWithDamageEXT" ) );
99     if( !mEglSetDamageRegionKHR || !mSwapBuffersWithDamage )
100     {
101       mPartialUpdateAvailable = false;
102       DALI_LOG_ERROR("Initialization of partial update failed.\n");
103     }
104     else
105     {
106       DALI_LOG_RELEASE_INFO("Initialization of partial update success!\n");
107     }
108   }
109 }
110
111 EglImplementation::~EglImplementation()
112 {
113   TerminateGles();
114 }
115
116 bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwnSurface )
117 {
118   if ( !mGlesInitialized )
119   {
120     mEglNativeDisplay = display;
121
122     //@todo see if we can just EGL_DEFAULT_DISPLAY instead
123     mEglDisplay = eglGetDisplay(mEglNativeDisplay);
124     EGLint error = eglGetError();
125
126     if( mEglDisplay == NULL && error != EGL_SUCCESS )
127     {
128       throw Dali::DaliException( "", "OpenGL ES is not supported");
129     }
130
131     EGLint majorVersion = 0;
132     EGLint minorVersion = 0;
133     if ( !eglInitialize( mEglDisplay, &majorVersion, &minorVersion ) )
134     {
135       return false;
136     }
137     eglBindAPI(EGL_OPENGL_ES_API);
138
139     mGlesInitialized = true;
140     mIsOwnSurface = isOwnSurface;
141   }
142
143   // Query EGL extensions to check whether surfaceless context is supported
144   const char* const extensionStr = eglQueryString( mEglDisplay, EGL_EXTENSIONS );
145   std::istringstream stream( extensionStr );
146   std::string currentExtension;
147   uint32_t extensionCheckCount = 0;
148   while( std::getline( stream, currentExtension, ' ' ) && extensionCheckCount < CHECK_EXTENSION_NUMBER )
149   {
150     if( currentExtension == EGL_KHR_SURFACELESS_CONTEXT )
151     {
152       mIsSurfacelessContextSupported = true;
153       extensionCheckCount++;
154     }
155     if( currentExtension == EGL_KHR_CREATE_CONTEXT )
156     {
157       mIsKhrCreateContextSupported = true;
158       extensionCheckCount++;
159     }
160     if( currentExtension == EGL_KHR_PARTIAL_UPDATE )
161     {
162       mIsKhrPartialUpdateSupported = true;
163       extensionCheckCount++;
164     }
165   }
166
167   if( !mIsKhrPartialUpdateSupported )
168   {
169     mPartialUpdateAvailable = false;
170   }
171
172   // We want to display this information all the time, so use the LogMessage directly
173   Integration::Log::LogMessage(Integration::Log::DebugInfo, "EGL Information\n"
174       "            Vendor:        %s\n"
175       "            Version:       %s\n"
176       "            Client APIs:   %s\n"
177       "            Extensions:    %s\n",
178       eglQueryString( mEglDisplay, EGL_VENDOR ),
179       eglQueryString( mEglDisplay, EGL_VERSION ),
180       eglQueryString( mEglDisplay, EGL_CLIENT_APIS ),
181       extensionStr);
182
183   return mGlesInitialized;
184 }
185
186 bool EglImplementation::CreateContext()
187 {
188   // make sure a context isn't created twice
189   DALI_ASSERT_ALWAYS( (mEglContext == 0) && "EGL context recreated" );
190
191   mEglContext = eglCreateContext(mEglDisplay, mEglConfig, NULL, &(mContextAttribs[0]));
192   TEST_EGL_ERROR("eglCreateContext render thread");
193
194   DALI_ASSERT_ALWAYS( EGL_NO_CONTEXT != mEglContext && "EGL context not created" );
195
196   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VENDOR : %s ***\n", glGetString(GL_VENDOR));
197   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_RENDERER : %s ***\n", glGetString(GL_RENDERER));
198   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VERSION : %s ***\n", glGetString(GL_VERSION));
199   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_SHADING_LANGUAGE_VERSION : %s***\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
200   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** Supported Extensions ***\n%s\n\n", glGetString(GL_EXTENSIONS));
201
202   return true;
203 }
204
205 bool EglImplementation::CreateWindowContext( EGLContext& eglContext )
206 {
207   // make sure a context isn't created twice
208   DALI_ASSERT_ALWAYS( (eglContext == 0) && "EGL context recreated" );
209
210   eglContext = eglCreateContext(mEglDisplay, mEglConfig, mEglContext, &(mContextAttribs[0]));
211   TEST_EGL_ERROR("eglCreateContext render thread");
212
213   DALI_ASSERT_ALWAYS( EGL_NO_CONTEXT != eglContext && "EGL context not created" );
214
215   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VENDOR : %s ***\n", glGetString(GL_VENDOR));
216   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_RENDERER : %s ***\n", glGetString(GL_RENDERER));
217   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_VERSION : %s ***\n", glGetString(GL_VERSION));
218   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** GL_SHADING_LANGUAGE_VERSION : %s***\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
219   DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "*** Supported Extensions ***\n%s\n\n", glGetString(GL_EXTENSIONS));
220
221   mEglWindowContexts.push_back( eglContext );
222
223   return true;
224 }
225
226 void EglImplementation::DestroyContext( EGLContext& eglContext )
227 {
228   DALI_ASSERT_ALWAYS( mEglContext && "no EGL context" );
229
230   eglDestroyContext( mEglDisplay, eglContext );
231   eglContext = 0;
232 }
233
234 void EglImplementation::DestroySurface( EGLSurface& eglSurface )
235 {
236   if(mIsOwnSurface && eglSurface)
237   {
238     // Make context null to prevent crash in driver side
239     MakeContextNull();
240     eglDestroySurface( mEglDisplay, eglSurface );
241     eglSurface = 0;
242   }
243 }
244
245 void EglImplementation::MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext )
246 {
247   if (mCurrentEglContext == eglContext)
248   {
249     return;
250   }
251
252   mCurrentEglSurface = eglSurface;
253
254   if(mIsOwnSurface)
255   {
256     eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, eglContext );
257
258     mCurrentEglContext = eglContext;
259   }
260
261   EGLint error = eglGetError();
262
263   if ( error != EGL_SUCCESS )
264   {
265     Egl::PrintError(error);
266
267     DALI_ASSERT_ALWAYS(false && "MakeContextCurrent failed!");
268   }
269 }
270
271 void EglImplementation::MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface )
272 {
273   if (mCurrentEglContext == mEglContext)
274   {
275     return;
276   }
277
278   mCurrentEglNativePixmap = pixmap;
279   mCurrentEglSurface = eglSurface;
280
281   if(mIsOwnSurface)
282   {
283     eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, mEglContext );
284
285     mCurrentEglContext = mEglContext;
286   }
287
288   EGLint error = eglGetError();
289
290   if ( error != EGL_SUCCESS )
291   {
292     Egl::PrintError(error);
293
294     DALI_ASSERT_ALWAYS(false && "MakeCurrent failed!");
295   }
296 }
297
298 void EglImplementation::MakeContextNull()
299 {
300   // clear the current context
301   eglMakeCurrent( mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
302   mCurrentEglContext = EGL_NO_CONTEXT;
303 }
304
305 void EglImplementation::TerminateGles()
306 {
307   if ( mGlesInitialized )
308   {
309     // Make context null to prevent crash in driver side
310     MakeContextNull();
311
312     for ( auto eglSurface : mEglWindowSurfaces )
313     {
314       if(mIsOwnSurface && eglSurface)
315       {
316         eglDestroySurface(mEglDisplay, eglSurface);
317       }
318     }
319     eglDestroyContext(mEglDisplay, mEglContext);
320     for ( auto eglContext : mEglWindowContexts )
321     {
322       eglDestroyContext(mEglDisplay, eglContext);
323     }
324
325     eglTerminate(mEglDisplay);
326
327     mEglDisplay = NULL;
328     mEglConfig  = NULL;
329     mEglContext = NULL;
330     mCurrentEglSurface = NULL;
331     mCurrentEglContext = EGL_NO_CONTEXT;
332
333     mGlesInitialized = false;
334   }
335 }
336
337 bool EglImplementation::IsGlesInitialized() const
338 {
339   return mGlesInitialized;
340 }
341
342
343 const char* GetEglErrorString(EGLint error)
344 {
345     switch(error)
346     {
347     case EGL_SUCCESS: return "No error";
348     case EGL_NOT_INITIALIZED: return "EGL not initialized or failed to initialize";
349     case EGL_BAD_ACCESS: return "Resource inaccessible";
350     case EGL_BAD_ALLOC: return "Cannot allocate resources";
351     case EGL_BAD_ATTRIBUTE: return "Unrecognized attribute or attribute value";
352     case EGL_BAD_CONTEXT: return "Invalid EGL context";
353     case EGL_BAD_CONFIG: return "Invalid EGL frame buffer configuration";
354     case EGL_BAD_CURRENT_SURFACE: return "Current surface is no longer valid";
355     case EGL_BAD_DISPLAY: return "Invalid EGL display";
356     case EGL_BAD_SURFACE: return "Invalid surface";
357     case EGL_BAD_MATCH: return "Inconsistent arguments";
358     case EGL_BAD_PARAMETER: return "Invalid argument";
359     case EGL_BAD_NATIVE_PIXMAP: return "Invalid native pixmap";
360     case EGL_BAD_NATIVE_WINDOW: return "Invalid native window";
361     case EGL_CONTEXT_LOST: return "Context lost";
362     }
363     return "Unknown error ";
364 }
365
366
367 void EglImplementation::SwapBuffers( EGLSurface& eglSurface )
368 {
369   if ( eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
370   {
371 #ifndef DALI_PROFILE_UBUNTU
372     if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
373     {
374       DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers started.\n" );
375     }
376 #endif //DALI_PROFILE_UBUNTU
377
378     if( mPartialUpdateAvailable && mSwapBuffersWithDamage )
379     {
380       mSwapBuffersWithDamage( mEglDisplay, eglSurface, &mDamagedRectArray[0], mDamagedRectArray.size()/4 );
381     }
382     else
383     {
384       eglSwapBuffers( mEglDisplay, eglSurface );
385     }
386
387 #ifndef DALI_PROFILE_UBUNTU
388     if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
389     {
390       DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers finished.\n" );
391       mSwapBufferCountAfterResume++;
392     }
393 #endif //DALI_PROFILE_UBUNTU
394
395   }
396 }
397
398
399 int EglImplementation::GetBufferAge( EGLSurface& eglSurface )
400 {
401   int bufferAge = 0;
402   if ( eglSurface != EGL_NO_SURFACE && mIsKhrPartialUpdateSupported )
403   {
404     if( !eglQuerySurface(mEglDisplay, eglSurface, EGL_BUFFER_AGE_KHR, &bufferAge) )
405     {
406       DALI_LOG_ERROR("EglImplementation::GetBufferAge() eglQuerySurface %s ",  GetEglErrorString(eglGetError()) );
407     }
408   }
409   return bufferAge;
410 }
411
412 void EglImplementation::SetDamagedRect( std::vector<int> damagedRectArray, EGLSurface& eglSurface )
413 {
414   mDamagedRectArray = damagedRectArray;
415   if ( eglSurface != EGL_NO_SURFACE && mPartialUpdateAvailable && mEglSetDamageRegionKHR )
416   {
417     if( !mEglSetDamageRegionKHR( mEglDisplay, eglSurface, &damagedRectArray[0], damagedRectArray.size() / 4 ) )
418     {
419       DALI_LOG_ERROR("EglImplementation::mEglSetDamageRegionKHR() error %s ",  GetEglErrorString(eglGetError()) );
420     }
421   }
422 }
423
424 void EglImplementation::CopyBuffers( EGLSurface& eglSurface )
425 {
426   eglCopyBuffers( mEglDisplay, eglSurface, mCurrentEglNativePixmap );
427 }
428
429 void EglImplementation::WaitGL()
430 {
431   eglWaitGL();
432 }
433
434 bool EglImplementation::ChooseConfig( bool isWindowType, ColorDepth depth )
435 {
436   if(mEglConfig && isWindowType == mIsWindow && mColorDepth == depth)
437   {
438     return true;
439   }
440
441   mColorDepth = depth;
442   mIsWindow = isWindowType;
443
444   EGLint numConfigs;
445   Vector<EGLint> configAttribs;
446   configAttribs.Reserve(31);
447
448   if(isWindowType)
449   {
450     configAttribs.PushBack( EGL_SURFACE_TYPE );
451     configAttribs.PushBack( EGL_WINDOW_BIT );
452   }
453   else
454   {
455     configAttribs.PushBack( EGL_SURFACE_TYPE );
456     configAttribs.PushBack( EGL_PIXMAP_BIT );
457   }
458
459   configAttribs.PushBack( EGL_RENDERABLE_TYPE );
460
461   if( mGlesVersion >= 30 )
462   {
463     configAttribs.PushBack( EGL_OPENGL_ES3_BIT_KHR );
464   }
465   else
466   {
467     configAttribs.PushBack( EGL_OPENGL_ES2_BIT );
468   }
469
470 // TODO: enable this flag when it becomes supported
471 //  configAttribs.PushBack( EGL_CONTEXT_FLAGS_KHR );
472 //  configAttribs.PushBack( EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR );
473
474   configAttribs.PushBack( EGL_RED_SIZE );
475   configAttribs.PushBack( 8 );
476   configAttribs.PushBack( EGL_GREEN_SIZE );
477   configAttribs.PushBack( 8 );
478   configAttribs.PushBack( EGL_BLUE_SIZE );
479   configAttribs.PushBack( 8 );
480
481 //  For underlay video playback, we also need to set the alpha value of the 24/32bit window.
482   configAttribs.PushBack( EGL_ALPHA_SIZE );
483   configAttribs.PushBack( 8 );
484
485   configAttribs.PushBack( EGL_DEPTH_SIZE );
486   configAttribs.PushBack( mDepthBufferRequired ? 24 : 0 );
487   configAttribs.PushBack( EGL_STENCIL_SIZE );
488   configAttribs.PushBack( mStencilBufferRequired ? 8 : 0 );
489
490 #ifndef DALI_PROFILE_UBUNTU
491   if( mMultiSamplingLevel != EGL_DONT_CARE )
492   {
493     configAttribs.PushBack( EGL_SAMPLES );
494     configAttribs.PushBack( mMultiSamplingLevel );
495     configAttribs.PushBack( EGL_SAMPLE_BUFFERS );
496     configAttribs.PushBack( 1 );
497   }
498 #endif // DALI_PROFILE_UBUNTU
499   configAttribs.PushBack( EGL_NONE );
500
501   // Ensure number of configs is set to 1 as on some drivers,
502   // eglChooseConfig succeeds but does not actually create a proper configuration.
503   if ( ( eglChooseConfig( mEglDisplay, &(configAttribs[0]), &mEglConfig, 1, &numConfigs ) != EGL_TRUE ) ||
504        ( numConfigs != 1 ) )
505   {
506     if( mGlesVersion >= 30 )
507     {
508       mEglConfig = NULL;
509       DALI_LOG_ERROR("Fail to use OpenGL es 3.0. Retrying to use OpenGL es 2.0.");
510       return false;
511     }
512
513     if ( numConfigs != 1 )
514     {
515       DALI_LOG_ERROR("No configurations found.\n");
516
517       TEST_EGL_ERROR("eglChooseConfig");
518     }
519
520     EGLint error = eglGetError();
521     switch (error)
522     {
523       case EGL_BAD_DISPLAY:
524       {
525         DALI_LOG_ERROR("Display is not an EGL display connection\n");
526         break;
527       }
528       case EGL_BAD_ATTRIBUTE:
529       {
530         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");
531         break;
532       }
533       case EGL_NOT_INITIALIZED:
534       {
535         DALI_LOG_ERROR("Display has not been initialized\n");
536         break;
537       }
538       case EGL_BAD_PARAMETER:
539       {
540         DALI_LOG_ERROR("The parameter numConfig is NULL\n");
541         break;
542       }
543       default:
544       {
545         DALI_LOG_ERROR("Unknown error.\n");
546       }
547     }
548     DALI_ASSERT_ALWAYS(false && "eglChooseConfig failed!");
549     return false;
550   }
551   Integration::Log::LogMessage(Integration::Log::DebugInfo, "Using OpenGL es %d.%d.\n", mGlesVersion / 10, mGlesVersion % 10 );
552
553   mContextAttribs.Clear();
554   if( mIsKhrCreateContextSupported )
555   {
556     mContextAttribs.Reserve(5);
557     mContextAttribs.PushBack( EGL_CONTEXT_MAJOR_VERSION_KHR );
558     mContextAttribs.PushBack( mGlesVersion / 10 );
559     mContextAttribs.PushBack( EGL_CONTEXT_MINOR_VERSION_KHR );
560     mContextAttribs.PushBack( mGlesVersion % 10 );
561   }
562   else
563   {
564     mContextAttribs.Reserve(3);
565     mContextAttribs.PushBack( EGL_CONTEXT_CLIENT_VERSION );
566     mContextAttribs.PushBack( mGlesVersion / 10 );
567   }
568   mContextAttribs.PushBack( EGL_NONE );
569
570   return true;
571 }
572
573 EGLSurface EglImplementation::CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth )
574 {
575   mEglNativeWindow = window;
576   mColorDepth = depth;
577   mIsWindow = true;
578
579   // egl choose config
580   ChooseConfig(mIsWindow, mColorDepth);
581
582   mCurrentEglSurface = eglCreateWindowSurface( mEglDisplay, mEglConfig, mEglNativeWindow, NULL );
583   TEST_EGL_ERROR("eglCreateWindowSurface");
584
585   DALI_ASSERT_ALWAYS( mCurrentEglSurface && "Create window surface failed" );
586
587   return mCurrentEglSurface;
588 }
589
590 EGLSurface EglImplementation::CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth )
591 {
592   mCurrentEglNativePixmap = pixmap;
593   mColorDepth = depth;
594   mIsWindow = false;
595
596   // egl choose config
597   ChooseConfig(mIsWindow, mColorDepth);
598
599   mCurrentEglSurface = eglCreatePixmapSurface( mEglDisplay, mEglConfig, mCurrentEglNativePixmap, NULL );
600   TEST_EGL_ERROR("eglCreatePixmapSurface");
601
602   DALI_ASSERT_ALWAYS( mCurrentEglSurface && "Create pixmap surface failed" );
603
604   return mCurrentEglSurface;
605 }
606
607 bool EglImplementation::ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext )
608 {
609   bool contextLost = false;
610
611   // display connection has not changed, then we can just create a new surface
612   //  the surface is bound to the context, so set the context to null
613   MakeContextNull();
614
615   // destroy the surface
616   DestroySurface( eglSurface );
617
618   // create the EGL surface
619   EGLSurface newEglSurface = CreateSurfaceWindow( window, mColorDepth );
620
621   // set the context to be current with the new surface
622   MakeContextCurrent( newEglSurface, eglContext );
623
624   return contextLost;
625 }
626
627 bool EglImplementation::ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface )
628 {
629   bool contextLost = false;
630
631   // display connection has not changed, then we can just create a new surface
632   // create the EGL surface
633   eglSurface = CreateSurfacePixmap( pixmap, mColorDepth );
634
635   // set the eglSurface to be current
636   MakeCurrent( pixmap, eglSurface );
637
638   return contextLost;
639 }
640
641 void EglImplementation::SetGlesVersion( const int32_t glesVersion )
642 {
643   mGlesVersion = glesVersion;
644 }
645
646 void EglImplementation::SetFirstFrameAfterResume()
647 {
648   mSwapBufferCountAfterResume = 0;
649 }
650
651 EGLDisplay EglImplementation::GetDisplay() const
652 {
653   return mEglDisplay;
654 }
655
656 EGLContext EglImplementation::GetContext() const
657 {
658   return mEglContext;
659 }
660
661 int32_t EglImplementation::GetGlesVersion() const
662 {
663   return mGlesVersion;
664 }
665
666 bool EglImplementation::IsSurfacelessContextSupported() const
667 {
668   return mIsSurfacelessContextSupported;
669 }
670
671 void EglImplementation::WaitClient()
672 {
673   // Wait for EGL to finish executing all rendering calls for the current context
674   if ( eglWaitClient() != EGL_TRUE )
675   {
676     TEST_EGL_ERROR("eglWaitClient");
677   }
678 }
679
680 } // namespace Adaptor
681
682 } // namespace Internal
683
684 } // namespace Dali
685
686 #pragma GCC diagnostic pop