Home | History | Annotate | Download | only in libOpenglRender
      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 "EGLDispatch.h"
     17 #include <stdio.h>
     18 #include <stdlib.h>
     19 #include "osDynLibrary.h"
     20 
     21 EGLDispatch s_egl;
     22 
     23 #define DEFAULT_EGL_LIB EMUGL_LIBNAME("EGL_translator")
     24 
     25 bool init_egl_dispatch()
     26 {
     27 
     28     const char *libName = getenv("ANDROID_EGL_LIB");
     29     if (!libName) libName = DEFAULT_EGL_LIB;
     30 
     31     osUtils::dynLibrary *lib = osUtils::dynLibrary::open(libName);
     32     if (!lib) {
     33         printf("Failed to open %s\n", libName);
     34         return NULL;
     35     }
     36     s_egl.eglGetError = (eglGetError_t) lib->findSymbol("eglGetError");
     37     s_egl.eglGetDisplay = (eglGetDisplay_t) lib->findSymbol("eglGetDisplay");
     38     s_egl.eglInitialize = (eglInitialize_t) lib->findSymbol("eglInitialize");
     39     s_egl.eglTerminate = (eglTerminate_t) lib->findSymbol("eglTerminate");
     40     s_egl.eglQueryString = (eglQueryString_t) lib->findSymbol("eglQueryString");
     41     s_egl.eglGetConfigs = (eglGetConfigs_t) lib->findSymbol("eglGetConfigs");
     42     s_egl.eglChooseConfig = (eglChooseConfig_t) lib->findSymbol("eglChooseConfig");
     43     s_egl.eglGetConfigAttrib = (eglGetConfigAttrib_t) lib->findSymbol("eglGetConfigAttrib");
     44     s_egl.eglCreateWindowSurface = (eglCreateWindowSurface_t) lib->findSymbol("eglCreateWindowSurface");
     45     s_egl.eglCreatePbufferSurface = (eglCreatePbufferSurface_t) lib->findSymbol("eglCreatePbufferSurface");
     46     s_egl.eglCreatePixmapSurface = (eglCreatePixmapSurface_t) lib->findSymbol("eglCreatePixmapSurface");
     47     s_egl.eglDestroySurface = (eglDestroySurface_t) lib->findSymbol("eglDestroySurface");
     48     s_egl.eglQuerySurface = (eglQuerySurface_t) lib->findSymbol("eglQuerySurface");
     49     s_egl.eglBindAPI = (eglBindAPI_t) lib->findSymbol("eglBindAPI");
     50     s_egl.eglQueryAPI = (eglQueryAPI_t) lib->findSymbol("eglQueryAPI");
     51     s_egl.eglWaitClient = (eglWaitClient_t) lib->findSymbol("eglWaitClient");
     52     s_egl.eglReleaseThread = (eglReleaseThread_t) lib->findSymbol("eglReleaseThread");
     53     s_egl.eglCreatePbufferFromClientBuffer = (eglCreatePbufferFromClientBuffer_t) lib->findSymbol("eglCreatePbufferFromClientBuffer");
     54     s_egl.eglSurfaceAttrib = (eglSurfaceAttrib_t) lib->findSymbol("eglSurfaceAttrib");
     55     s_egl.eglBindTexImage = (eglBindTexImage_t) lib->findSymbol("eglBindTexImage");
     56     s_egl.eglReleaseTexImage = (eglReleaseTexImage_t) lib->findSymbol("eglReleaseTexImage");
     57     s_egl.eglSwapInterval = (eglSwapInterval_t) lib->findSymbol("eglSwapInterval");
     58     s_egl.eglCreateContext = (eglCreateContext_t) lib->findSymbol("eglCreateContext");
     59     s_egl.eglDestroyContext = (eglDestroyContext_t) lib->findSymbol("eglDestroyContext");
     60     s_egl.eglMakeCurrent = (eglMakeCurrent_t) lib->findSymbol("eglMakeCurrent");
     61     s_egl.eglGetCurrentContext = (eglGetCurrentContext_t) lib->findSymbol("eglGetCurrentContext");
     62     s_egl.eglGetCurrentSurface = (eglGetCurrentSurface_t) lib->findSymbol("eglGetCurrentSurface");
     63     s_egl.eglGetCurrentDisplay = (eglGetCurrentDisplay_t) lib->findSymbol("eglGetCurrentDisplay");
     64     s_egl.eglQueryContext = (eglQueryContext_t) lib->findSymbol("eglQueryContext");
     65     s_egl.eglWaitGL = (eglWaitGL_t) lib->findSymbol("eglWaitGL");
     66     s_egl.eglWaitNative = (eglWaitNative_t) lib->findSymbol("eglWaitNative");
     67     s_egl.eglSwapBuffers = (eglSwapBuffers_t) lib->findSymbol("eglSwapBuffers");
     68     s_egl.eglCopyBuffers = (eglCopyBuffers_t) lib->findSymbol("eglCopyBuffers");
     69     s_egl.eglGetProcAddress = (eglGetProcAddress_t) lib->findSymbol("eglGetProcAddress");
     70 
     71 #define INIT_EGL_EXT_FUNC(name) \
     72     if (s_egl.eglGetProcAddress) s_egl.name = (name ## _t) s_egl.eglGetProcAddress(#name); \
     73     if (!s_egl.name || !s_egl.eglGetProcAddress) s_egl.name = (name ## _t) lib->findSymbol(#name)
     74 
     75     INIT_EGL_EXT_FUNC(eglLockSurfaceKHR);
     76     INIT_EGL_EXT_FUNC(eglUnlockSurfaceKHR);
     77     INIT_EGL_EXT_FUNC(eglCreateImageKHR);
     78     INIT_EGL_EXT_FUNC(eglDestroyImageKHR);
     79     INIT_EGL_EXT_FUNC(eglCreateSyncKHR);
     80     INIT_EGL_EXT_FUNC(eglDestroySyncKHR);
     81     INIT_EGL_EXT_FUNC(eglClientWaitSyncKHR);
     82     INIT_EGL_EXT_FUNC(eglSignalSyncKHR);
     83     INIT_EGL_EXT_FUNC(eglGetSyncAttribKHR);
     84     INIT_EGL_EXT_FUNC(eglSetSwapRectangleANDROID);
     85 
     86     return true;
     87 }
     88