[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 void EglImplementation::SwapBuffers( EGLSurface& eglSurface )
367 {
368   if ( eglSurface != EGL_NO_SURFACE ) // skip if using surfaceless context
369   {
370 #ifndef DALI_PROFILE_UBUNTU
371     if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
372     {
373       DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers started.\n" );
374     }
375 #endif //DALI_PROFILE_UBUNTU+
376
377     if( mPartialUpdateAvailable && mSwapBuffersWithDamage )
378     {
379       mSwapBuffersWithDamage( mEglDisplay, eglSurface, &mDamagedRectArray[0], mDamagedRectArray.size()/4 );
380     }
381     else
382     {
383       eglSwapBuffers( mEglDisplay, eglSurface );
384     }
385
386 #ifndef DALI_PROFILE_UBUNTU
387     if( mSwapBufferCountAfterResume < THRESHOLD_SWAPBUFFER_COUNT )
388     {
389       DALI_LOG_RELEASE_INFO( "EglImplementation::SwapBuffers finished.\n" );
390       mSwapBufferCountAfterResume++;
391     }
392 #endif //DALI_PROFILE_UBUNTU
393   }
394 }
395
396
397 int EglImplementation::GetBufferAge( EGLSurface& eglSurface )
398 {
399   int bufferAge = 0;
400   if ( eglSurface != EGL_NO_SURFACE && mIsKhrPartialUpdateSupported )
401   {
402     if( !eglQuerySurface(mEglDisplay, eglSurface, EGL_BUFFER_AGE_KHR, &bufferAge) )
403     {
404       DALI_LOG_ERROR("EglImplementation::GetBufferAge() eglQuerySurface %s ",  GetEglErrorString(eglGetError()) );
405     }
406   }
407   return bufferAge;
408 }
409
410 void EglImplementation::SetDamagedRect( std::vector<int> damagedRectArray, EGLSurface& eglSurface )
411 {
412   mDamagedRectArray = damagedRectArray;
413   if ( eglSurface != EGL_NO_SURFACE && mPartialUpdateAvailable && mEglSetDamageRegionKHR )
414   {
415     if( !mEglSetDamageRegionKHR( mEglDisplay, eglSurface, &damagedRectArray[0], damagedRectArray.size() / 4 ) )
416     {
417       DALI_LOG_ERROR("EglImplementation::mEglSetDamageRegionKHR() error %s ",  GetEglErrorString(eglGetError()) );
418     }
419   }
420 }
421
422 void EglImplementation::CopyBuffers( EGLSurface& eglSurface )
423 {
424   eglCopyBuffers( mEglDisplay, eglSurface, mCurrentEglNativePixmap );
425 }
426
427 void EglImplementation::WaitGL()
428 {
429   eglWaitGL();
430 }
431
432 bool EglImplementation::ChooseConfig( bool isWindowType, ColorDepth depth )
433 {
434   if(mEglConfig && isWindowType == mIsWindow && mColorDepth == depth)
435   {
436     return true;
437   }
438
439   mColorDepth = depth;
440   mIsWindow = isWindowType;
441
442   EGLint numConfigs;
443   Vector<EGLint> configAttribs;
444   configAttribs.Reserve(31);
445
446   if(isWindowType)
447   {
448     configAttribs.PushBack( EGL_SURFACE_TYPE );
449     configAttribs.PushBack( EGL_WINDOW_BIT );
450   }
451   else
452   {
453     configAttribs.PushBack( EGL_SURFACE_TYPE );
454     configAttribs.PushBack( EGL_PIXMAP_BIT );
455   }
456
457   configAttribs.PushBack( EGL_RENDERABLE_TYPE );
458
459   if( mGlesVersion >= 30 )
460   {
461     configAttribs.PushBack( EGL_OPENGL_ES3_BIT_KHR );
462   }
463   else
464   {
465     configAttribs.PushBack( EGL_OPENGL_ES2_BIT );
466   }
467
468 // TODO: enable this flag when it becomes supported
469 //  configAttribs.PushBack( EGL_CONTEXT_FLAGS_KHR );
470 //  configAttribs.PushBack( EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR );
471
472   configAttribs.PushBack( EGL_RED_SIZE );
473   configAttribs.PushBack( 8 );
474   configAttribs.PushBack( EGL_GREEN_SIZE );
475   configAttribs.PushBack( 8 );
476   configAttribs.PushBack( EGL_BLUE_SIZE );
477   configAttribs.PushBack( 8 );
478
479 //  For underlay video playback, we also need to set the alpha value of the 24/32bit window.
480   configAttribs.PushBack( EGL_ALPHA_SIZE );
481   configAttribs.PushBack( 8 );
482
483   configAttribs.PushBack( EGL_DEPTH_SIZE );
484   configAttribs.PushBack( mDepthBufferRequired ? 24 : 0 );
485   configAttribs.PushBack( EGL_STENCIL_SIZE );
486   configAttribs.PushBack( mStencilBufferRequired ? 8 : 0 );
487
488 #ifndef DALI_PROFILE_UBUNTU
489   if( mMultiSamplingLevel != EGL_DONT_CARE )
490   {
491     configAttribs.PushBack( EGL_SAMPLES );
492     configAttribs.PushBack( mMultiSamplingLevel );
493     configAttribs.PushBack( EGL_SAMPLE_BUFFERS );
494     configAttribs.PushBack( 1 );
495   }
496 #endif // DALI_PROFILE_UBUNTU
497   configAttribs.PushBack( EGL_NONE );
498
499   // Ensure number of configs is set to 1 as on some drivers,
500   // eglChooseConfig succeeds but does not actually create a proper configuration.
501   if ( ( eglChooseConfig( mEglDisplay, &(configAttribs[0]), &mEglConfig, 1, &numConfigs ) != EGL_TRUE ) ||
502        ( numConfigs != 1 ) )
503   {
504     if( mGlesVersion >= 30 )
505     {
506       mEglConfig = NULL;
507       DALI_LOG_ERROR("Fail to use OpenGL es 3.0. Retrying to use OpenGL es 2.0.");
508       return false;
509     }
510
511     if ( numConfigs != 1 )
512     {
513       DALI_LOG_ERROR("No configurations found.\n");
514
515       TEST_EGL_ERROR("eglChooseConfig");
516     }
517
518     EGLint error = eglGetError();
519     switch (error)
520     {
521       case EGL_BAD_DISPLAY:
522       {
523         DALI_LOG_ERROR("Display is not an EGL display connection\n");
524         break;
525       }
526       case EGL_BAD_ATTRIBUTE:
527       {
528         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");
529         break;
530       }
531       case EGL_NOT_INITIALIZED:
532       {
533         DALI_LOG_ERROR("Display has not been initialized\n");
534         break;
535       }
536       case EGL_BAD_PARAMETER:
537       {
538         DALI_LOG_ERROR("The parameter numConfig is NULL\n");
539         break;
540       }
541       default:
542       {
543         DALI_LOG_ERROR("Unknown error.\n");
544       }
545     }
546     DALI_ASSERT_ALWAYS(false && "eglChooseConfig failed!");
547     return false;
548   }
549   Integration::Log::LogMessage(Integration::Log::DebugInfo, "Using OpenGL es %d.%d.\n", mGlesVersion / 10, mGlesVersion % 10 );
550
551   mContextAttribs.Clear();
552   if( mIsKhrCreateContextSupported )
553   {
554     mContextAttribs.Reserve(5);
555     mContextAttribs.PushBack( EGL_CONTEXT_MAJOR_VERSION_KHR );
556     mContextAttribs.PushBack( mGlesVersion / 10 );
557     mContextAttribs.PushBack( EGL_CONTEXT_MINOR_VERSION_KHR );
558     mContextAttribs.PushBack( mGlesVersion % 10 );
559   }
560   else
561   {
562     mContextAttribs.Reserve(3);
563     mContextAttribs.PushBack( EGL_CONTEXT_CLIENT_VERSION );
564     mContextAttribs.PushBack( mGlesVersion / 10 );
565   }
566   mContextAttribs.PushBack( EGL_NONE );
567
568   return true;
569 }
570
571 EGLSurface EglImplementation::CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth )
572 {
573   mEglNativeWindow = window;
574   mColorDepth = depth;
575   mIsWindow = true;
576
577   // egl choose config
578   ChooseConfig(mIsWindow, mColorDepth);
579
580   mCurrentEglSurface = eglCreateWindowSurface( mEglDisplay, mEglConfig, mEglNativeWindow, NULL );
581   TEST_EGL_ERROR("eglCreateWindowSurface");
582
583   DALI_ASSERT_ALWAYS( mCurrentEglSurface && "Create window surface failed" );
584
585   return mCurrentEglSurface;
586 }
587
588 EGLSurface EglImplementation::CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth )
589 {
590   mCurrentEglNativePixmap = pixmap;
591   mColorDepth = depth;
592   mIsWindow = false;
593
594   // egl choose config
595   ChooseConfig(mIsWindow, mColorDepth);
596
597   mCurrentEglSurface = eglCreatePixmapSurface( mEglDisplay, mEglConfig, mCurrentEglNativePixmap, NULL );
598   TEST_EGL_ERROR("eglCreatePixmapSurface");
599
600   DALI_ASSERT_ALWAYS( mCurrentEglSurface && "Create pixmap surface failed" );
601
602   return mCurrentEglSurface;
603 }
604
605 bool EglImplementation::ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext )
606 {
607   bool contextLost = false;
608
609   // display connection has not changed, then we can just create a new surface
610   //  the surface is bound to the context, so set the context to null
611   MakeContextNull();
612
613   // destroy the surface
614   DestroySurface( eglSurface );
615
616   // create the EGL surface
617   EGLSurface newEglSurface = CreateSurfaceWindow( window, mColorDepth );
618
619   // set the context to be current with the new surface
620   MakeContextCurrent( newEglSurface, eglContext );
621
622   return contextLost;
623 }
624
625 bool EglImplementation::ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface )
626 {
627   bool contextLost = false;
628
629   // display connection has not changed, then we can just create a new surface
630   // create the EGL surface
631   eglSurface = CreateSurfacePixmap( pixmap, mColorDepth );
632
633   // set the eglSurface to be current
634   MakeCurrent( pixmap, eglSurface );
635
636   return contextLost;
637 }
638
639 void EglImplementation::SetGlesVersion( const int32_t glesVersion )
640 {
641   mGlesVersion = glesVersion;
642 }
643
644 void EglImplementation::SetFirstFrameAfterResume()
645 {
646   mSwapBufferCountAfterResume = 0;
647 }
648
649 EGLDisplay EglImplementation::GetDisplay() const
650 {
651   return mEglDisplay;
652 }
653
654 EGLContext EglImplementation::GetContext() const
655 {
656   return mEglContext;
657 }
658
659 int32_t EglImplementation::GetGlesVersion() const
660 {
661   return mGlesVersion;
662 }
663
664 bool EglImplementation::IsSurfacelessContextSupported() const
665 {
666   return mIsSurfacelessContextSupported;
667 }
668
669 void EglImplementation::WaitClient()
670 {
671   // Wait for EGL to finish executing all rendering calls for the current context
672   if ( eglWaitClient() != EGL_TRUE )
673   {
674     TEST_EGL_ERROR("eglWaitClient");
675   }
676 }
677
678 } // namespace Adaptor
679
680 } // namespace Internal
681
682 } // namespace Dali
683
684 #pragma GCC diagnostic pop