/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "HostConnection.h" #include "ThreadInfo.h" #include "eglDisplay.h" #include "egl_ftable.h" #include // The one and only supported display object. static eglDisplay s_display; static EGLClient_eglInterface s_eglIface = { getThreadInfo: getEGLThreadInfo }; #define RETURN_ERROR(ret,err) \ getEGLThreadInfo()->eglError = err; \ return ret; #define VALIDATE_CONFIG(cfg,ret) \ if(((int)cfg<0)||((int)cfg>s_display.getNumConfigs())) { \ RETURN_ERROR(ret,EGL_BAD_CONFIG); \ } #define VALIDATE_DISPLAY(dpy,ret) \ if ((dpy) != (EGLDisplay)&s_display) { \ getEGLThreadInfo()->eglError = EGL_BAD_DISPLAY; \ return ret; \ } #define VALIDATE_DISPLAY_INIT(dpy,ret) \ VALIDATE_DISPLAY(dpy, ret) \ if (!s_display.initialized()) { \ getEGLThreadInfo()->eglError = EGL_NOT_INITIALIZED; \ return ret; \ } EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) { // // we support only EGL_DEFAULT_DISPLAY. // if (display_id != EGL_DEFAULT_DISPLAY) { return EGL_NO_DISPLAY; } return (EGLDisplay)&s_display; } EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { VALIDATE_DISPLAY(dpy,EGL_FALSE); if (!s_display.initialize(&s_eglIface)) { return EGL_FALSE; } *major = s_display.getVersionMajor(); *minor = s_display.getVersionMinor(); return EGL_TRUE; } EGLBoolean eglTerminate(EGLDisplay dpy) { VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); s_display.terminate(); return EGL_TRUE; } EGLint eglGetError() { return getEGLThreadInfo()->eglError; } __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) { // search in EGL function table for (int i=0; igetProcAddress( procname ); if (proc != NULL) { return (__eglMustCastToProperFunctionPointerType)proc; } // look in gles2 if (s_display.gles2_iface() != NULL) { proc = s_display.gles2_iface()->getProcAddress( procname ); if (proc != NULL) { return (__eglMustCastToProperFunctionPointerType)proc; } } // Fail - function not found. return NULL; } const char* eglQueryString(EGLDisplay dpy, EGLint name) { VALIDATE_DISPLAY_INIT(dpy, NULL); return s_display.queryString(name); } EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) { VALIDATE_DISPLAY_INIT(dpy, NULL); if(!num_config) { RETURN_ERROR(EGL_FALSE,EGL_BAD_PARAMETER); } GLint numConfigs = s_display.getNumConfigs(); if (!configs) { *num_config = numConfigs; return EGL_TRUE; } int i=0; for (i=0 ; i