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>
25 #include <GLES3/gl3ext.h>
28 #include <GLES2/gl2.h>
29 #endif // DALI_GLES_VERSION >= 30
31 #include <GLES2/gl2ext.h>
33 #include <EGL/eglext.h>
35 #include <dali/integration-api/debug.h>
38 #include <gl/egl-implementation.h>
43 // function pointers assigned in InitializeEglImageKHR
44 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = 0;
45 PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = 0;
46 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = 0;
47 } // unnamed namespace
59 EglImageExtensions::EglImageExtensions(EglImplementation* eglImpl)
60 : mEglImplementation(eglImpl),
61 mImageKHRInitialized(false),
62 mImageKHRInitializeFailed(false)
64 DALI_ASSERT_ALWAYS( eglImpl && "EGL Implementation not instantiated" );
67 EglImageExtensions::~EglImageExtensions()
71 void* EglImageExtensions::CreateImageKHR(EGLClientBuffer clientBuffer)
73 if (mImageKHRInitialized == false)
75 InitializeEglImageKHR();
78 if (mImageKHRInitialized == false)
83 // Use the EGL image extension
84 const EGLint attribs[] =
86 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
90 EGLImageKHR eglImage = eglCreateImageKHR( mEglImplementation->GetDisplay(),
92 EGL_NATIVE_PIXMAP_KHR,
96 DALI_ASSERT_DEBUG( EGL_NO_IMAGE_KHR != eglImage && "X11Image::GlExtensionCreate eglCreateImageKHR failed!\n");
97 if( EGL_NO_IMAGE_KHR == eglImage )
99 switch( eglGetError() )
105 case EGL_BAD_DISPLAY:
107 DALI_LOG_ERROR( "EGL_BAD_DISPLAY: Invalid EGLDisplay object" );
110 case EGL_BAD_CONTEXT:
112 DALI_LOG_ERROR( "EGL_BAD_CONTEXT: Invalid EGLContext object" );
115 case EGL_BAD_PARAMETER:
117 DALI_LOG_ERROR( "EGL_BAD_PARAMETER: Invalid target parameter or attribute in attrib_list" );
122 DALI_LOG_ERROR( "EGL_BAD_MATCH: attrib_list does not match target" );
127 DALI_LOG_ERROR( "EGL_BAD_ACCESS: Previously bound off-screen, or EGLImage sibling error" );
132 DALI_LOG_ERROR( "EGL_BAD_ALLOC: Insufficient memory is available" );
142 return (void*)eglImage;
145 void EglImageExtensions::DestroyImageKHR(void* eglImageKHR)
147 DALI_ASSERT_DEBUG( mImageKHRInitialized );
149 if( ! mImageKHRInitialized )
154 if( eglImageKHR == NULL )
159 EGLImageKHR eglImage = static_cast<EGLImageKHR>(eglImageKHR);
161 EGLBoolean result = eglDestroyImageKHR(mEglImplementation->GetDisplay(), eglImage);
163 if( EGL_FALSE == result )
165 switch( eglGetError() )
167 case EGL_BAD_DISPLAY:
169 DALI_LOG_ERROR( "EGL_BAD_DISPLAY: Invalid EGLDisplay object" );
172 case EGL_BAD_PARAMETER:
174 DALI_LOG_ERROR( "EGL_BAD_PARAMETER: eglImage is not a valid EGLImageKHR object created with respect to EGLDisplay" );
179 DALI_LOG_ERROR( "EGL_BAD_ACCESS: EGLImage sibling error" );
190 void EglImageExtensions::TargetTextureKHR(void* eglImageKHR)
192 DALI_ASSERT_DEBUG( mImageKHRInitialized );
194 if( eglImageKHR != NULL )
196 EGLImageKHR eglImage = static_cast<EGLImageKHR>(eglImageKHR);
198 #ifdef EGL_ERROR_CHECKING
199 GLint glError = glGetError();
202 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)eglImage);
204 #ifdef EGL_ERROR_CHECKING
205 glError = glGetError();
206 if( GL_NO_ERROR != glError )
208 DALI_LOG_ERROR(" glEGLImageTargetTexture2DOES returned error %0x04x\n", glError );
214 void EglImageExtensions::InitializeEglImageKHR()
216 // avoid trying to reload extended KHR functions, if it fails the first time
217 if( ! mImageKHRInitializeFailed )
219 eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); /* parasoft-suppress MISRA2004-11_1_DMC "Using EGL defined functions." */
220 eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); /* parasoft-suppress MISRA2004-11_1_DMC "Using EGL defined functions." */
221 glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress("glEGLImageTargetTexture2DOES"); /* parasoft-suppress MISRA2004-11_1_DMC "Using EGL defined functions." */
224 if (eglCreateImageKHR && eglDestroyImageKHR && glEGLImageTargetTexture2DOES)
226 mImageKHRInitialized = true;
230 mImageKHRInitializeFailed = true;
234 } // namespace Adaptor
236 } // namespace Internal