2 * Copyright (c) 2014 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 "egl-image-extensions.h"
23 #if DALI_GLES_VERSION >= 30
24 #include <GLES3/gl3.h>
26 #include <GLES2/gl2.h>
27 #endif // DALI_GLES_VERSION >= 30
29 #include <GLES2/gl2ext.h>
31 #include <EGL/eglext.h>
33 #include <dali/integration-api/debug.h>
36 #include <gl/egl-implementation.h>
41 // function pointers assigned in InitializeEglImageKHR
42 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHRProc = 0;
43 PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHRProc = 0;
44 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOESProc = 0;
45 } // unnamed namespace
57 EglImageExtensions::EglImageExtensions(EglImplementation* eglImpl)
58 : mEglImplementation(eglImpl),
59 mImageKHRInitialized(false),
60 mImageKHRInitializeFailed(false)
62 DALI_ASSERT_ALWAYS( eglImpl && "EGL Implementation not instantiated" );
65 EglImageExtensions::~EglImageExtensions()
69 void* EglImageExtensions::CreateImageKHR(EGLClientBuffer clientBuffer)
71 if (mImageKHRInitialized == false)
73 InitializeEglImageKHR();
76 if (mImageKHRInitialized == false)
81 // Use the EGL image extension
82 const EGLint attribs[] =
84 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
88 EGLImageKHR eglImage = eglCreateImageKHRProc( mEglImplementation->GetDisplay(),
90 EGL_NATIVE_PIXMAP_KHR,
94 DALI_ASSERT_DEBUG( EGL_NO_IMAGE_KHR != eglImage && "X11Image::GlExtensionCreate eglCreateImageKHR failed!\n");
95 if( EGL_NO_IMAGE_KHR == eglImage )
97 switch( eglGetError() )
103 case EGL_BAD_DISPLAY:
105 DALI_LOG_ERROR( "EGL_BAD_DISPLAY: Invalid EGLDisplay object\n" );
108 case EGL_BAD_CONTEXT:
110 DALI_LOG_ERROR( "EGL_BAD_CONTEXT: Invalid EGLContext object\n" );
113 case EGL_BAD_PARAMETER:
115 DALI_LOG_ERROR( "EGL_BAD_PARAMETER: Invalid target parameter or attribute in attrib_list\n" );
120 DALI_LOG_ERROR( "EGL_BAD_MATCH: attrib_list does not match target\n" );
125 DALI_LOG_ERROR( "EGL_BAD_ACCESS: Previously bound off-screen, or EGLImage sibling error\n" );
130 DALI_LOG_ERROR( "EGL_BAD_ALLOC: Insufficient memory is available\n" );
140 return (void*)eglImage;
143 void EglImageExtensions::DestroyImageKHR(void* eglImageKHR)
145 DALI_ASSERT_DEBUG( mImageKHRInitialized );
147 if( ! mImageKHRInitialized )
152 if( eglImageKHR == NULL )
157 EGLImageKHR eglImage = static_cast<EGLImageKHR>(eglImageKHR);
159 EGLBoolean result = eglDestroyImageKHRProc(mEglImplementation->GetDisplay(), eglImage);
161 if( EGL_FALSE == result )
163 switch( eglGetError() )
165 case EGL_BAD_DISPLAY:
167 DALI_LOG_ERROR( "EGL_BAD_DISPLAY: Invalid EGLDisplay object\n" );
170 case EGL_BAD_PARAMETER:
172 DALI_LOG_ERROR( "EGL_BAD_PARAMETER: eglImage is not a valid EGLImageKHR object created with respect to EGLDisplay\n" );
177 DALI_LOG_ERROR( "EGL_BAD_ACCESS: EGLImage sibling error\n" );
188 void EglImageExtensions::TargetTextureKHR(void* eglImageKHR)
190 DALI_ASSERT_DEBUG( mImageKHRInitialized );
192 if( eglImageKHR != NULL )
194 EGLImageKHR eglImage = static_cast<EGLImageKHR>(eglImageKHR);
196 #ifdef EGL_ERROR_CHECKING
197 GLint glError = glGetError();
200 glEGLImageTargetTexture2DOESProc(GL_TEXTURE_2D, (GLeglImageOES)eglImage);
202 #ifdef EGL_ERROR_CHECKING
203 glError = glGetError();
204 if( GL_NO_ERROR != glError )
206 DALI_LOG_ERROR(" glEGLImageTargetTexture2DOES returned error %0x04x\n", glError );
212 void EglImageExtensions::InitializeEglImageKHR()
214 // avoid trying to reload extended KHR functions, if it fails the first time
215 if( ! mImageKHRInitializeFailed )
217 eglCreateImageKHRProc = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); /* parasoft-suppress MISRA2004-11_1_DMC "Using EGL defined functions." */
218 eglDestroyImageKHRProc = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); /* parasoft-suppress MISRA2004-11_1_DMC "Using EGL defined functions." */
219 glEGLImageTargetTexture2DOESProc = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress("glEGLImageTargetTexture2DOES"); /* parasoft-suppress MISRA2004-11_1_DMC "Using EGL defined functions." */
222 if (eglCreateImageKHRProc && eglDestroyImageKHRProc && glEGLImageTargetTexture2DOESProc)
224 mImageKHRInitialized = true;
228 mImageKHRInitializeFailed = true;
232 } // namespace Adaptor
234 } // namespace Internal