1 /* 2 * Copyright (C) 2011 The Android Open Source Project 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 #include <stdio.h> 17 #include <stdlib.h> 18 #include <string.h> 19 #include "egl_dispatch.h" 20 #include "egl_ftable.h" 21 #include <pthread.h> 22 23 #define EGL_LIB "ANDROID_EGL_LIB" 24 25 static struct egl_dispatch *s_dispatch = NULL; 26 static pthread_once_t eglDispatchInitialized = PTHREAD_ONCE_INIT; 27 28 void initEglDispatch() 29 { 30 // 31 // Load back-end EGL implementation library 32 // 33 char *eglLib = (char *) "libEGL.so"; 34 if (getenv(EGL_LIB) != NULL) { 35 eglLib = getenv(EGL_LIB); 36 } 37 38 s_dispatch = loadEGL(eglLib); 39 if (!s_dispatch) { 40 fprintf(stderr,"FATAL ERROR: Could not load EGL lib [%s]\n", eglLib); 41 exit(-1); 42 } 43 } 44 45 static struct egl_dispatch *getDispatch() 46 { 47 pthread_once(&eglDispatchInitialized, initEglDispatch); 48 return s_dispatch; 49 } 50 51 __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) 52 { 53 for (int i=0; i<egl_num_funcs; i++) { 54 if (!strcmp(egl_funcs_by_name[i].name, procname)) { 55 return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; 56 } 57 } 58 59 return getDispatch()->eglGetProcAddress(procname); 60 } 61 62 //////////////// Path through functions ////////// 63 64 EGLint eglGetError() 65 { 66 return getDispatch()->eglGetError(); 67 } 68 69 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) 70 { 71 return getDispatch()->eglGetDisplay(display_id); 72 } 73 74 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) 75 { 76 return getDispatch()->eglInitialize(dpy, major, minor); 77 } 78 79 EGLBoolean eglTerminate(EGLDisplay dpy) 80 { 81 return getDispatch()->eglTerminate(dpy); 82 } 83 84 const char* eglQueryString(EGLDisplay dpy, EGLint name) 85 { 86 return getDispatch()->eglQueryString(dpy, name); 87 } 88 89 EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) 90 { 91 return getDispatch()->eglGetConfigs(dpy, configs, config_size, num_config); 92 } 93 94 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) 95 { 96 return getDispatch()->eglChooseConfig(dpy, attrib_list, configs, config_size, num_config); 97 } 98 99 EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) 100 { 101 return getDispatch()->eglGetConfigAttrib(dpy, config, attribute, value); 102 } 103 104 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) 105 { 106 return getDispatch()->eglCreateWindowSurface(dpy, config, win, attrib_list); 107 } 108 109 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) 110 { 111 return getDispatch()->eglCreatePbufferSurface(dpy, config, attrib_list); 112 } 113 114 EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) 115 { 116 return getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); 117 } 118 119 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) 120 { 121 return getDispatch()->eglDestroySurface(dpy, surface); 122 } 123 124 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) 125 { 126 return getDispatch()->eglQuerySurface(dpy, surface, attribute, value); 127 } 128 129 EGLBoolean eglBindAPI(EGLenum api) 130 { 131 return getDispatch()->eglBindAPI(api); 132 } 133 134 EGLenum eglQueryAPI() 135 { 136 return getDispatch()->eglQueryAPI(); 137 } 138 139 EGLBoolean eglWaitClient() 140 { 141 return getDispatch()->eglWaitClient(); 142 } 143 144 EGLBoolean eglReleaseThread() 145 { 146 return getDispatch()->eglReleaseThread(); 147 } 148 149 EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) 150 { 151 return getDispatch()->eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list); 152 } 153 154 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) 155 { 156 return getDispatch()->eglSurfaceAttrib(dpy, surface, attribute, value); 157 } 158 159 EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) 160 { 161 return getDispatch()->eglBindTexImage(dpy, surface, buffer); 162 } 163 164 EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) 165 { 166 return getDispatch()->eglReleaseTexImage(dpy, surface, buffer); 167 } 168 169 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) 170 { 171 return getDispatch()->eglSwapInterval(dpy, interval); 172 } 173 174 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) 175 { 176 return getDispatch()->eglCreateContext(dpy, config, share_context, attrib_list); 177 } 178 179 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) 180 { 181 return getDispatch()->eglDestroyContext(dpy, ctx); 182 } 183 184 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) 185 { 186 return getDispatch()->eglMakeCurrent(dpy, draw, read, ctx); 187 } 188 189 EGLContext eglGetCurrentContext() 190 { 191 return getDispatch()->eglGetCurrentContext(); 192 } 193 194 EGLSurface eglGetCurrentSurface(EGLint readdraw) 195 { 196 return getDispatch()->eglGetCurrentSurface(readdraw); 197 } 198 199 EGLDisplay eglGetCurrentDisplay() 200 { 201 return getDispatch()->eglGetCurrentDisplay(); 202 } 203 204 EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) 205 { 206 return getDispatch()->eglQueryContext(dpy, ctx, attribute, value); 207 } 208 209 EGLBoolean eglWaitGL() 210 { 211 return getDispatch()->eglWaitGL(); 212 } 213 214 EGLBoolean eglWaitNative(EGLint engine) 215 { 216 return getDispatch()->eglWaitNative(engine); 217 } 218 219 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) 220 { 221 return getDispatch()->eglSwapBuffers(dpy, surface); 222 } 223 224 EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) 225 { 226 return getDispatch()->eglCopyBuffers(dpy, surface, target); 227 } 228 229 EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) 230 { 231 return getDispatch()->eglLockSurfaceKHR(display, surface, attrib_list); 232 } 233 234 EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) 235 { 236 return getDispatch()->eglUnlockSurfaceKHR(display, surface); 237 } 238 239 EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) 240 { 241 return getDispatch()->eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list); 242 } 243 244 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) 245 { 246 return getDispatch()->eglDestroyImageKHR(dpy, image); 247 } 248 249 EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) 250 { 251 return getDispatch()->eglCreateSyncKHR(dpy, type, attrib_list); 252 } 253 254 EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) 255 { 256 return getDispatch()->eglDestroySyncKHR(dpy, sync); 257 } 258 259 EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) 260 { 261 return getDispatch()->eglClientWaitSyncKHR(dpy, sync, flags, timeout); 262 } 263 264 EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) 265 { 266 return getDispatch()->eglSignalSyncKHR(dpy, sync, mode); 267 } 268 269 EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) 270 { 271 return getDispatch()->eglGetSyncAttribKHR(dpy, sync, attribute, value); 272 } 273 274 EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height) 275 { 276 return getDispatch()->eglSetSwapRectangleANDROID(dpy, draw, left, top, width, height); 277 } 278