diff options
Diffstat (limited to 'emulator/opengl/tests')
68 files changed, 10822 insertions, 0 deletions
diff --git a/emulator/opengl/tests/EGL_host_wrapper/Android.mk b/emulator/opengl/tests/EGL_host_wrapper/Android.mk new file mode 100644 index 0000000..19d8794 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/Android.mk @@ -0,0 +1,16 @@ +ifeq ($(HOST_OS),linux) + +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-host-static-library,libEGL_host_wrapper) + +LOCAL_SRC_FILES := \ + egl.cpp \ + egl_dispatch.cpp + +$(call emugl-export,LDLIBS,-ldl -pthread) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-end-module) + +endif # HOST_OS == linux diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl.cpp b/emulator/opengl/tests/EGL_host_wrapper/egl.cpp new file mode 100644 index 0000000..6fa27ac --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl.cpp @@ -0,0 +1,277 @@ +/* +* 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "egl_dispatch.h" +#include "egl_ftable.h" +#include <pthread.h> + +#define EGL_LIB "ANDROID_EGL_LIB" + +static struct egl_dispatch *s_dispatch = NULL; +static pthread_once_t eglDispatchInitialized = PTHREAD_ONCE_INIT; + +void initEglDispatch() +{ + // + // Load back-end EGL implementation library + // + char *eglLib = (char *) "libEGL.so"; + if (getenv(EGL_LIB) != NULL) { + eglLib = getenv(EGL_LIB); + } + + s_dispatch = loadEGL(eglLib); + if (!s_dispatch) { + fprintf(stderr,"FATAL ERROR: Could not load EGL lib [%s]\n", eglLib); + exit(-1); + } +} + +static struct egl_dispatch *getDispatch() +{ + pthread_once(&eglDispatchInitialized, initEglDispatch); + return s_dispatch; +} + +__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) +{ + for (int i=0; i<egl_num_funcs; i++) { + if (!strcmp(egl_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; + } + } + + return getDispatch()->eglGetProcAddress(procname); +} + +//////////////// Path through functions ////////// + +EGLint eglGetError() +{ + return getDispatch()->eglGetError(); +} + +EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) +{ + return getDispatch()->eglGetDisplay(display_id); +} + +EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + return getDispatch()->eglInitialize(dpy, major, minor); +} + +EGLBoolean eglTerminate(EGLDisplay dpy) +{ + return getDispatch()->eglTerminate(dpy); +} + +const char* eglQueryString(EGLDisplay dpy, EGLint name) +{ + return getDispatch()->eglQueryString(dpy, name); +} + +EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + return getDispatch()->eglGetConfigs(dpy, configs, config_size, num_config); +} + +EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + return getDispatch()->eglChooseConfig(dpy, attrib_list, configs, config_size, num_config); +} + +EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglGetConfigAttrib(dpy, config, attribute, value); +} + +EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateWindowSurface(dpy, config, win, attrib_list); +} + +EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePbufferSurface(dpy, config, attrib_list); +} + +EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); +} + +EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) +{ + return getDispatch()->eglDestroySurface(dpy, surface); +} + +EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglQuerySurface(dpy, surface, attribute, value); +} + +EGLBoolean eglBindAPI(EGLenum api) +{ + return getDispatch()->eglBindAPI(api); +} + +EGLenum eglQueryAPI() +{ + return getDispatch()->eglQueryAPI(); +} + +EGLBoolean eglWaitClient() +{ + return getDispatch()->eglWaitClient(); +} + +EGLBoolean eglReleaseThread() +{ + return getDispatch()->eglReleaseThread(); +} + +EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list); +} + +EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + return getDispatch()->eglSurfaceAttrib(dpy, surface, attribute, value); +} + +EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglBindTexImage(dpy, surface, buffer); +} + +EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglReleaseTexImage(dpy, surface, buffer); +} + +EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + return getDispatch()->eglSwapInterval(dpy, interval); +} + +EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateContext(dpy, config, share_context, attrib_list); +} + +EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + return getDispatch()->eglDestroyContext(dpy, ctx); +} + +EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +{ + return getDispatch()->eglMakeCurrent(dpy, draw, read, ctx); +} + +EGLContext eglGetCurrentContext() +{ + return getDispatch()->eglGetCurrentContext(); +} + +EGLSurface eglGetCurrentSurface(EGLint readdraw) +{ + return getDispatch()->eglGetCurrentSurface(readdraw); +} + +EGLDisplay eglGetCurrentDisplay() +{ + return getDispatch()->eglGetCurrentDisplay(); +} + +EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglQueryContext(dpy, ctx, attribute, value); +} + +EGLBoolean eglWaitGL() +{ + return getDispatch()->eglWaitGL(); +} + +EGLBoolean eglWaitNative(EGLint engine) +{ + return getDispatch()->eglWaitNative(engine); +} + +EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) +{ + return getDispatch()->eglSwapBuffers(dpy, surface); +} + +EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) +{ + return getDispatch()->eglCopyBuffers(dpy, surface, target); +} + +EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) +{ + return getDispatch()->eglLockSurfaceKHR(display, surface, attrib_list); +} + +EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) +{ + return getDispatch()->eglUnlockSurfaceKHR(display, surface); +} + +EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list); +} + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) +{ + return getDispatch()->eglDestroyImageKHR(dpy, image); +} + +EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateSyncKHR(dpy, type, attrib_list); +} + +EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + return getDispatch()->eglDestroySyncKHR(dpy, sync); +} + +EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + return getDispatch()->eglClientWaitSyncKHR(dpy, sync, flags, timeout); +} + +EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) +{ + return getDispatch()->eglSignalSyncKHR(dpy, sync, mode); +} + +EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglGetSyncAttribKHR(dpy, sync, attribute, value); +} + +EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height) +{ + return getDispatch()->eglSetSwapRectangleANDROID(dpy, draw, left, top, width, height); +} diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp new file mode 100644 index 0000000..a9b8214 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp @@ -0,0 +1,77 @@ +/* +* 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 <stdio.h> +#include <dlfcn.h> +#include "egl_dispatch.h" + + +egl_dispatch *loadEGL(const char *p_eglPath) +{ + void *libEGL = dlopen(p_eglPath, RTLD_NOW); + if (!libEGL) { + return NULL; + } + + egl_dispatch *disp = new egl_dispatch; + + void *ptr; + ptr = dlsym(libEGL,"eglGetError"); disp->set_eglGetError((eglGetError_t)ptr); + ptr = dlsym(libEGL,"eglGetDisplay"); disp->set_eglGetDisplay((eglGetDisplay_t)ptr); + ptr = dlsym(libEGL,"eglInitialize"); disp->set_eglInitialize((eglInitialize_t)ptr); + ptr = dlsym(libEGL,"eglTerminate"); disp->set_eglTerminate((eglTerminate_t)ptr); + ptr = dlsym(libEGL,"eglQueryString"); disp->set_eglQueryString((eglQueryString_t)ptr); + ptr = dlsym(libEGL,"eglGetConfigs"); disp->set_eglGetConfigs((eglGetConfigs_t)ptr); + ptr = dlsym(libEGL,"eglChooseConfig"); disp->set_eglChooseConfig((eglChooseConfig_t)ptr); + ptr = dlsym(libEGL,"eglGetConfigAttrib"); disp->set_eglGetConfigAttrib((eglGetConfigAttrib_t)ptr); + ptr = dlsym(libEGL,"eglCreateWindowSurface"); disp->set_eglCreateWindowSurface((eglCreateWindowSurface_t)ptr); + ptr = dlsym(libEGL,"eglCreatePbufferSurface"); disp->set_eglCreatePbufferSurface((eglCreatePbufferSurface_t)ptr); + ptr = dlsym(libEGL,"eglCreatePixmapSurface"); disp->set_eglCreatePixmapSurface((eglCreatePixmapSurface_t)ptr); + ptr = dlsym(libEGL,"eglDestroySurface"); disp->set_eglDestroySurface((eglDestroySurface_t)ptr); + ptr = dlsym(libEGL,"eglQuerySurface"); disp->set_eglQuerySurface((eglQuerySurface_t)ptr); + ptr = dlsym(libEGL,"eglBindAPI"); disp->set_eglBindAPI((eglBindAPI_t)ptr); + ptr = dlsym(libEGL,"eglQueryAPI"); disp->set_eglQueryAPI((eglQueryAPI_t)ptr); + ptr = dlsym(libEGL,"eglWaitClient"); disp->set_eglWaitClient((eglWaitClient_t)ptr); + ptr = dlsym(libEGL,"eglReleaseThread"); disp->set_eglReleaseThread((eglReleaseThread_t)ptr); + ptr = dlsym(libEGL,"eglCreatePbufferFromClientBuffer"); disp->set_eglCreatePbufferFromClientBuffer((eglCreatePbufferFromClientBuffer_t)ptr); + ptr = dlsym(libEGL,"eglSurfaceAttrib"); disp->set_eglSurfaceAttrib((eglSurfaceAttrib_t)ptr); + ptr = dlsym(libEGL,"eglBindTexImage"); disp->set_eglBindTexImage((eglBindTexImage_t)ptr); + ptr = dlsym(libEGL,"eglReleaseTexImage"); disp->set_eglReleaseTexImage((eglReleaseTexImage_t)ptr); + ptr = dlsym(libEGL,"eglSwapInterval"); disp->set_eglSwapInterval((eglSwapInterval_t)ptr); + ptr = dlsym(libEGL,"eglCreateContext"); disp->set_eglCreateContext((eglCreateContext_t)ptr); + ptr = dlsym(libEGL,"eglDestroyContext"); disp->set_eglDestroyContext((eglDestroyContext_t)ptr); + ptr = dlsym(libEGL,"eglMakeCurrent"); disp->set_eglMakeCurrent((eglMakeCurrent_t)ptr); + ptr = dlsym(libEGL,"eglGetCurrentContext"); disp->set_eglGetCurrentContext((eglGetCurrentContext_t)ptr); + ptr = dlsym(libEGL,"eglGetCurrentSurface"); disp->set_eglGetCurrentSurface((eglGetCurrentSurface_t)ptr); + ptr = dlsym(libEGL,"eglGetCurrentDisplay"); disp->set_eglGetCurrentDisplay((eglGetCurrentDisplay_t)ptr); + ptr = dlsym(libEGL,"eglQueryContext"); disp->set_eglQueryContext((eglQueryContext_t)ptr); + ptr = dlsym(libEGL,"eglWaitGL"); disp->set_eglWaitGL((eglWaitGL_t)ptr); + ptr = dlsym(libEGL,"eglWaitNative"); disp->set_eglWaitNative((eglWaitNative_t)ptr); + ptr = dlsym(libEGL,"eglSwapBuffers"); disp->set_eglSwapBuffers((eglSwapBuffers_t)ptr); + ptr = dlsym(libEGL,"eglCopyBuffers"); disp->set_eglCopyBuffers((eglCopyBuffers_t)ptr); + ptr = dlsym(libEGL,"eglGetProcAddress"); disp->set_eglGetProcAddress((eglGetProcAddress_t)ptr); + ptr = dlsym(libEGL,"eglLockSurfaceKHR"); disp->set_eglLockSurfaceKHR((eglLockSurfaceKHR_t)ptr); + ptr = dlsym(libEGL,"eglUnlockSurfaceKHR"); disp->set_eglUnlockSurfaceKHR((eglUnlockSurfaceKHR_t)ptr); + ptr = dlsym(libEGL,"eglCreateImageKHR"); disp->set_eglCreateImageKHR((eglCreateImageKHR_t)ptr); + ptr = dlsym(libEGL,"eglDestroyImageKHR"); disp->set_eglDestroyImageKHR((eglDestroyImageKHR_t)ptr); + ptr = dlsym(libEGL,"eglCreateSyncKHR"); disp->set_eglCreateSyncKHR((eglCreateSyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglDestroySyncKHR"); disp->set_eglDestroySyncKHR((eglDestroySyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglClientWaitSyncKHR"); disp->set_eglClientWaitSyncKHR((eglClientWaitSyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglSignalSyncKHR"); disp->set_eglSignalSyncKHR((eglSignalSyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglGetSyncAttribKHR"); disp->set_eglGetSyncAttribKHR((eglGetSyncAttribKHR_t)ptr); + ptr = dlsym(libEGL,"eglSetSwapRectangleANDROID"); disp->set_eglSetSwapRectangleANDROID((eglSetSwapRectangleANDROID_t)ptr); + + return disp; +} diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h new file mode 100644 index 0000000..e5f67c9 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h @@ -0,0 +1,115 @@ +/* +* 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. +*/ +#ifndef _EGL_DISPATCH_H +#define _EGL_DISPATCH_H + +#include "egl_proc.h" + +struct egl_dispatch { + eglGetError_t eglGetError; + eglGetDisplay_t eglGetDisplay; + eglInitialize_t eglInitialize; + eglTerminate_t eglTerminate; + eglQueryString_t eglQueryString; + eglGetConfigs_t eglGetConfigs; + eglChooseConfig_t eglChooseConfig; + eglGetConfigAttrib_t eglGetConfigAttrib; + eglCreateWindowSurface_t eglCreateWindowSurface; + eglCreatePbufferSurface_t eglCreatePbufferSurface; + eglCreatePixmapSurface_t eglCreatePixmapSurface; + eglDestroySurface_t eglDestroySurface; + eglQuerySurface_t eglQuerySurface; + eglBindAPI_t eglBindAPI; + eglQueryAPI_t eglQueryAPI; + eglWaitClient_t eglWaitClient; + eglReleaseThread_t eglReleaseThread; + eglCreatePbufferFromClientBuffer_t eglCreatePbufferFromClientBuffer; + eglSurfaceAttrib_t eglSurfaceAttrib; + eglBindTexImage_t eglBindTexImage; + eglReleaseTexImage_t eglReleaseTexImage; + eglSwapInterval_t eglSwapInterval; + eglCreateContext_t eglCreateContext; + eglDestroyContext_t eglDestroyContext; + eglMakeCurrent_t eglMakeCurrent; + eglGetCurrentContext_t eglGetCurrentContext; + eglGetCurrentSurface_t eglGetCurrentSurface; + eglGetCurrentDisplay_t eglGetCurrentDisplay; + eglQueryContext_t eglQueryContext; + eglWaitGL_t eglWaitGL; + eglWaitNative_t eglWaitNative; + eglSwapBuffers_t eglSwapBuffers; + eglCopyBuffers_t eglCopyBuffers; + eglGetProcAddress_t eglGetProcAddress; + eglLockSurfaceKHR_t eglLockSurfaceKHR; + eglUnlockSurfaceKHR_t eglUnlockSurfaceKHR; + eglCreateImageKHR_t eglCreateImageKHR; + eglDestroyImageKHR_t eglDestroyImageKHR; + eglCreateSyncKHR_t eglCreateSyncKHR; + eglDestroySyncKHR_t eglDestroySyncKHR; + eglClientWaitSyncKHR_t eglClientWaitSyncKHR; + eglSignalSyncKHR_t eglSignalSyncKHR; + eglGetSyncAttribKHR_t eglGetSyncAttribKHR; + eglSetSwapRectangleANDROID_t eglSetSwapRectangleANDROID; + //Accessors + eglGetError_t set_eglGetError(eglGetError_t f) { eglGetError_t retval = eglGetError; eglGetError = f; return retval;} + eglGetDisplay_t set_eglGetDisplay(eglGetDisplay_t f) { eglGetDisplay_t retval = eglGetDisplay; eglGetDisplay = f; return retval;} + eglInitialize_t set_eglInitialize(eglInitialize_t f) { eglInitialize_t retval = eglInitialize; eglInitialize = f; return retval;} + eglTerminate_t set_eglTerminate(eglTerminate_t f) { eglTerminate_t retval = eglTerminate; eglTerminate = f; return retval;} + eglQueryString_t set_eglQueryString(eglQueryString_t f) { eglQueryString_t retval = eglQueryString; eglQueryString = f; return retval;} + eglGetConfigs_t set_eglGetConfigs(eglGetConfigs_t f) { eglGetConfigs_t retval = eglGetConfigs; eglGetConfigs = f; return retval;} + eglChooseConfig_t set_eglChooseConfig(eglChooseConfig_t f) { eglChooseConfig_t retval = eglChooseConfig; eglChooseConfig = f; return retval;} + eglGetConfigAttrib_t set_eglGetConfigAttrib(eglGetConfigAttrib_t f) { eglGetConfigAttrib_t retval = eglGetConfigAttrib; eglGetConfigAttrib = f; return retval;} + eglCreateWindowSurface_t set_eglCreateWindowSurface(eglCreateWindowSurface_t f) { eglCreateWindowSurface_t retval = eglCreateWindowSurface; eglCreateWindowSurface = f; return retval;} + eglCreatePbufferSurface_t set_eglCreatePbufferSurface(eglCreatePbufferSurface_t f) { eglCreatePbufferSurface_t retval = eglCreatePbufferSurface; eglCreatePbufferSurface = f; return retval;} + eglCreatePixmapSurface_t set_eglCreatePixmapSurface(eglCreatePixmapSurface_t f) { eglCreatePixmapSurface_t retval = eglCreatePixmapSurface; eglCreatePixmapSurface = f; return retval;} + eglDestroySurface_t set_eglDestroySurface(eglDestroySurface_t f) { eglDestroySurface_t retval = eglDestroySurface; eglDestroySurface = f; return retval;} + eglQuerySurface_t set_eglQuerySurface(eglQuerySurface_t f) { eglQuerySurface_t retval = eglQuerySurface; eglQuerySurface = f; return retval;} + eglBindAPI_t set_eglBindAPI(eglBindAPI_t f) { eglBindAPI_t retval = eglBindAPI; eglBindAPI = f; return retval;} + eglQueryAPI_t set_eglQueryAPI(eglQueryAPI_t f) { eglQueryAPI_t retval = eglQueryAPI; eglQueryAPI = f; return retval;} + eglWaitClient_t set_eglWaitClient(eglWaitClient_t f) { eglWaitClient_t retval = eglWaitClient; eglWaitClient = f; return retval;} + eglReleaseThread_t set_eglReleaseThread(eglReleaseThread_t f) { eglReleaseThread_t retval = eglReleaseThread; eglReleaseThread = f; return retval;} + eglCreatePbufferFromClientBuffer_t set_eglCreatePbufferFromClientBuffer(eglCreatePbufferFromClientBuffer_t f) { eglCreatePbufferFromClientBuffer_t retval = eglCreatePbufferFromClientBuffer; eglCreatePbufferFromClientBuffer = f; return retval;} + eglSurfaceAttrib_t set_eglSurfaceAttrib(eglSurfaceAttrib_t f) { eglSurfaceAttrib_t retval = eglSurfaceAttrib; eglSurfaceAttrib = f; return retval;} + eglBindTexImage_t set_eglBindTexImage(eglBindTexImage_t f) { eglBindTexImage_t retval = eglBindTexImage; eglBindTexImage = f; return retval;} + eglReleaseTexImage_t set_eglReleaseTexImage(eglReleaseTexImage_t f) { eglReleaseTexImage_t retval = eglReleaseTexImage; eglReleaseTexImage = f; return retval;} + eglSwapInterval_t set_eglSwapInterval(eglSwapInterval_t f) { eglSwapInterval_t retval = eglSwapInterval; eglSwapInterval = f; return retval;} + eglCreateContext_t set_eglCreateContext(eglCreateContext_t f) { eglCreateContext_t retval = eglCreateContext; eglCreateContext = f; return retval;} + eglDestroyContext_t set_eglDestroyContext(eglDestroyContext_t f) { eglDestroyContext_t retval = eglDestroyContext; eglDestroyContext = f; return retval;} + eglMakeCurrent_t set_eglMakeCurrent(eglMakeCurrent_t f) { eglMakeCurrent_t retval = eglMakeCurrent; eglMakeCurrent = f; return retval;} + eglGetCurrentContext_t set_eglGetCurrentContext(eglGetCurrentContext_t f) { eglGetCurrentContext_t retval = eglGetCurrentContext; eglGetCurrentContext = f; return retval;} + eglGetCurrentSurface_t set_eglGetCurrentSurface(eglGetCurrentSurface_t f) { eglGetCurrentSurface_t retval = eglGetCurrentSurface; eglGetCurrentSurface = f; return retval;} + eglGetCurrentDisplay_t set_eglGetCurrentDisplay(eglGetCurrentDisplay_t f) { eglGetCurrentDisplay_t retval = eglGetCurrentDisplay; eglGetCurrentDisplay = f; return retval;} + eglQueryContext_t set_eglQueryContext(eglQueryContext_t f) { eglQueryContext_t retval = eglQueryContext; eglQueryContext = f; return retval;} + eglWaitGL_t set_eglWaitGL(eglWaitGL_t f) { eglWaitGL_t retval = eglWaitGL; eglWaitGL = f; return retval;} + eglWaitNative_t set_eglWaitNative(eglWaitNative_t f) { eglWaitNative_t retval = eglWaitNative; eglWaitNative = f; return retval;} + eglSwapBuffers_t set_eglSwapBuffers(eglSwapBuffers_t f) { eglSwapBuffers_t retval = eglSwapBuffers; eglSwapBuffers = f; return retval;} + eglCopyBuffers_t set_eglCopyBuffers(eglCopyBuffers_t f) { eglCopyBuffers_t retval = eglCopyBuffers; eglCopyBuffers = f; return retval;} + eglGetProcAddress_t set_eglGetProcAddress(eglGetProcAddress_t f) { eglGetProcAddress_t retval = eglGetProcAddress; eglGetProcAddress = f; return retval;} + eglLockSurfaceKHR_t set_eglLockSurfaceKHR(eglLockSurfaceKHR_t f) { eglLockSurfaceKHR_t retval = eglLockSurfaceKHR; eglLockSurfaceKHR = f; return retval;} + eglUnlockSurfaceKHR_t set_eglUnlockSurfaceKHR(eglUnlockSurfaceKHR_t f) { eglUnlockSurfaceKHR_t retval = eglUnlockSurfaceKHR; eglUnlockSurfaceKHR = f; return retval;} + eglCreateImageKHR_t set_eglCreateImageKHR(eglCreateImageKHR_t f) { eglCreateImageKHR_t retval = eglCreateImageKHR; eglCreateImageKHR = f; return retval;} + eglDestroyImageKHR_t set_eglDestroyImageKHR(eglDestroyImageKHR_t f) { eglDestroyImageKHR_t retval = eglDestroyImageKHR; eglDestroyImageKHR = f; return retval;} + eglCreateSyncKHR_t set_eglCreateSyncKHR(eglCreateSyncKHR_t f) { eglCreateSyncKHR_t retval = eglCreateSyncKHR; eglCreateSyncKHR = f; return retval;} + eglDestroySyncKHR_t set_eglDestroySyncKHR(eglDestroySyncKHR_t f) { eglDestroySyncKHR_t retval = eglDestroySyncKHR; eglDestroySyncKHR = f; return retval;} + eglClientWaitSyncKHR_t set_eglClientWaitSyncKHR(eglClientWaitSyncKHR_t f) { eglClientWaitSyncKHR_t retval = eglClientWaitSyncKHR; eglClientWaitSyncKHR = f; return retval;} + eglSignalSyncKHR_t set_eglSignalSyncKHR(eglSignalSyncKHR_t f) { eglSignalSyncKHR_t retval = eglSignalSyncKHR; eglSignalSyncKHR = f; return retval;} + eglGetSyncAttribKHR_t set_eglGetSyncAttribKHR(eglGetSyncAttribKHR_t f) { eglGetSyncAttribKHR_t retval = eglGetSyncAttribKHR; eglGetSyncAttribKHR = f; return retval;} + eglSetSwapRectangleANDROID_t set_eglSetSwapRectangleANDROID(eglSetSwapRectangleANDROID_t f) { eglSetSwapRectangleANDROID_t retval = eglSetSwapRectangleANDROID; eglSetSwapRectangleANDROID = f; return retval;} +}; + +egl_dispatch *loadEGL(const char *p_eglPath); + +#endif diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h b/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h new file mode 100644 index 0000000..ee40585 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h @@ -0,0 +1,66 @@ +/* +* 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. +*/ +static struct _egl_funcs_by_name { + const char *name; + void *proc; +} egl_funcs_by_name[] = { + {"eglGetError", (void *)eglGetError}, + {"eglGetDisplay", (void *)eglGetDisplay}, + {"eglInitialize", (void *)eglInitialize}, + {"eglTerminate", (void *)eglTerminate}, + {"eglQueryString", (void *)eglQueryString}, + {"eglGetConfigs", (void *)eglGetConfigs}, + {"eglChooseConfig", (void *)eglChooseConfig}, + {"eglGetConfigAttrib", (void *)eglGetConfigAttrib}, + {"eglCreateWindowSurface", (void *)eglCreateWindowSurface}, + {"eglCreatePbufferSurface", (void *)eglCreatePbufferSurface}, + {"eglCreatePixmapSurface", (void *)eglCreatePixmapSurface}, + {"eglDestroySurface", (void *)eglDestroySurface}, + {"eglQuerySurface", (void *)eglQuerySurface}, + {"eglBindAPI", (void *)eglBindAPI}, + {"eglQueryAPI", (void *)eglQueryAPI}, + {"eglWaitClient", (void *)eglWaitClient}, + {"eglReleaseThread", (void *)eglReleaseThread}, + {"eglCreatePbufferFromClientBuffer", (void *)eglCreatePbufferFromClientBuffer}, + {"eglSurfaceAttrib", (void *)eglSurfaceAttrib}, + {"eglBindTexImage", (void *)eglBindTexImage}, + {"eglReleaseTexImage", (void *)eglReleaseTexImage}, + {"eglSwapInterval", (void *)eglSwapInterval}, + {"eglCreateContext", (void *)eglCreateContext}, + {"eglDestroyContext", (void *)eglDestroyContext}, + {"eglMakeCurrent", (void *)eglMakeCurrent}, + {"eglGetCurrentContext", (void *)eglGetCurrentContext}, + {"eglGetCurrentSurface", (void *)eglGetCurrentSurface}, + {"eglGetCurrentDisplay", (void *)eglGetCurrentDisplay}, + {"eglQueryContext", (void *)eglQueryContext}, + {"eglWaitGL", (void *)eglWaitGL}, + {"eglWaitNative", (void *)eglWaitNative}, + {"eglSwapBuffers", (void *)eglSwapBuffers}, + {"eglCopyBuffers", (void *)eglCopyBuffers}, + {"eglGetProcAddress", (void *)eglGetProcAddress}, + {"eglLockSurfaceKHR", (void *)eglLockSurfaceKHR}, + {"eglUnlockSurfaceKHR", (void *)eglUnlockSurfaceKHR}, + {"eglCreateImageKHR", (void *)eglCreateImageKHR}, + {"eglDestroyImageKHR", (void *)eglDestroyImageKHR}, + {"eglCreateSyncKHR", (void *)eglCreateSyncKHR}, + {"eglDestroySyncKHR", (void *)eglDestroySyncKHR}, + {"eglClientWaitSyncKHR", (void *)eglClientWaitSyncKHR}, + {"eglSignalSyncKHR", (void *)eglSignalSyncKHR}, + {"eglGetSyncAttribKHR", (void *)eglGetSyncAttribKHR}, + {"eglSetSwapRectangleANDROID", (void *)eglSetSwapRectangleANDROID} +}; + +static int egl_num_funcs = sizeof(egl_funcs_by_name) / sizeof(struct _egl_funcs_by_name); diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h b/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h new file mode 100644 index 0000000..140c030 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h @@ -0,0 +1,68 @@ +/* +* 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. +*/ +#ifndef _EGL_PROC_H +#define _EGL_PROC_H + +#include <EGL/egl.h> +#define EGL_EGLEXT_PROTOTYPES +#include <EGL/eglext.h> + +typedef EGLint (* eglGetError_t) (); +typedef EGLDisplay (* eglGetDisplay_t) (EGLNativeDisplayType); +typedef EGLBoolean (* eglInitialize_t) (EGLDisplay, EGLint*, EGLint*); +typedef EGLBoolean (* eglTerminate_t) (EGLDisplay); +typedef char* (* eglQueryString_t) (EGLDisplay, EGLint); +typedef EGLBoolean (* eglGetConfigs_t) (EGLDisplay, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglChooseConfig_t) (EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglGetConfigAttrib_t) (EGLDisplay, EGLConfig, EGLint, EGLint*); +typedef EGLSurface (* eglCreateWindowSurface_t) (EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*); +typedef EGLSurface (* eglCreatePbufferSurface_t) (EGLDisplay, EGLConfig, const EGLint*); +typedef EGLSurface (* eglCreatePixmapSurface_t) (EGLDisplay, EGLConfig, EGLNativePixmapType, const EGLint*); +typedef EGLBoolean (* eglDestroySurface_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglQuerySurface_t) (EGLDisplay, EGLSurface, EGLint, EGLint*); +typedef EGLBoolean (* eglBindAPI_t) (EGLenum); +typedef EGLenum (* eglQueryAPI_t) (); +typedef EGLBoolean (* eglWaitClient_t) (); +typedef EGLBoolean (* eglReleaseThread_t) (); +typedef EGLSurface (* eglCreatePbufferFromClientBuffer_t) (EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint*); +typedef EGLBoolean (* eglSurfaceAttrib_t) (EGLDisplay, EGLSurface, EGLint, EGLint); +typedef EGLBoolean (* eglBindTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglReleaseTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglSwapInterval_t) (EGLDisplay, EGLint); +typedef EGLContext (* eglCreateContext_t) (EGLDisplay, EGLConfig, EGLContext, const EGLint*); +typedef EGLBoolean (* eglDestroyContext_t) (EGLDisplay, EGLContext); +typedef EGLBoolean (* eglMakeCurrent_t) (EGLDisplay, EGLSurface, EGLSurface, EGLContext); +typedef EGLContext (* eglGetCurrentContext_t) (); +typedef EGLSurface (* eglGetCurrentSurface_t) (EGLint); +typedef EGLDisplay (* eglGetCurrentDisplay_t) (); +typedef EGLBoolean (* eglQueryContext_t) (EGLDisplay, EGLContext, EGLint, EGLint*); +typedef EGLBoolean (* eglWaitGL_t) (); +typedef EGLBoolean (* eglWaitNative_t) (EGLint); +typedef EGLBoolean (* eglSwapBuffers_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglCopyBuffers_t) (EGLDisplay, EGLSurface, EGLNativePixmapType); +typedef __eglMustCastToProperFunctionPointerType (* eglGetProcAddress_t) (const char*); +typedef EGLBoolean (* eglLockSurfaceKHR_t) (EGLDisplay, EGLSurface, const EGLint*); +typedef EGLBoolean (* eglUnlockSurfaceKHR_t) (EGLDisplay, EGLSurface); +typedef EGLImageKHR (* eglCreateImageKHR_t) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); +typedef EGLBoolean (* eglDestroyImageKHR_t) (EGLDisplay, EGLImageKHR image); +typedef EGLSyncKHR (* eglCreateSyncKHR_t) (EGLDisplay, EGLenum, const EGLint*); +typedef EGLBoolean (* eglDestroySyncKHR_t) (EGLDisplay, EGLSyncKHR sync); +typedef EGLint (* eglClientWaitSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR timeout); +typedef EGLBoolean (* eglSignalSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLenum); +typedef EGLBoolean (* eglGetSyncAttribKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLint*); +typedef EGLBoolean (* eglSetSwapRectangleANDROID_t) (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); + +#endif // of _EGL_PROC_H diff --git a/emulator/opengl/tests/emulator_test_renderer/Android.mk b/emulator/opengl/tests/emulator_test_renderer/Android.mk new file mode 100644 index 0000000..9c4cfdd --- /dev/null +++ b/emulator/opengl/tests/emulator_test_renderer/Android.mk @@ -0,0 +1,22 @@ +LOCAL_PATH:=$(call my-dir) + +$(call emugl-begin-host-executable,emulator_test_renderer) +$(call emugl-import,libOpenglRender event_injector) + +LOCAL_SRC_FILES := main.cpp + +PREBUILT := $(HOST_PREBUILT_TAG) +LOCAL_SDL_CONFIG ?= prebuilts/tools/$(PREBUILT)/sdl/bin/sdl-config +LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags) +LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs)) + +LOCAL_CFLAGS += $(LOCAL_SDL_CFLAGS) -g -O0 +LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS) + +ifeq ($(HOST_OS),windows) +LOCAL_LDLIBS += -lws2_32 +endif + +LOCAL_STATIC_LIBRARIES += libSDL libSDLmain + +$(call emugl-end-module) diff --git a/emulator/opengl/tests/emulator_test_renderer/main.cpp b/emulator/opengl/tests/emulator_test_renderer/main.cpp new file mode 100644 index 0000000..06abce7 --- /dev/null +++ b/emulator/opengl/tests/emulator_test_renderer/main.cpp @@ -0,0 +1,222 @@ +/* +* 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. +*/ +#undef HAVE_MALLOC_H +#include <SDL.h> +#include <SDL_syswm.h> +#include <stdio.h> +#include <string.h> +#include "libOpenglRender/render_api.h" +#include <EventInjector.h> + +static int convert_keysym(int sym); // forward + +#ifdef __linux__ +#include <X11/Xlib.h> +#endif +#ifdef _WIN32 + +#include <winsock2.h> +int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +#else +int main(int argc, char *argv[]) +#endif +{ + int portNum = 22468; + int winWidth = 320; + int winHeight = 480; + int width, height; + int mouseDown = 0; + const char* env = getenv("ANDROID_WINDOW_SIZE"); + FBNativeWindowType windowId = NULL; + EventInjector* injector; + int consolePort = 5554; + + if (env && sscanf(env, "%dx%d", &width, &height) == 2) { + winWidth = width; + winHeight = height; + } + +#ifdef __linux__ + // some OpenGL implementations may call X functions + // it is safer to synchronize all X calls made by all the + // rendering threads. (although the calls we do are locked + // in the FrameBuffer singleton object). + XInitThreads(); +#endif + + // + // Inialize SDL window + // + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { + fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_Surface *surface = SDL_SetVideoMode(winWidth, winHeight, 32, SDL_SWSURFACE); + if (surface == NULL) { + fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); + return -1; + } + + SDL_SysWMinfo wminfo; + memset(&wminfo, 0, sizeof(wminfo)); + SDL_GetWMInfo(&wminfo); +#ifdef _WIN32 + windowId = wminfo.window; + WSADATA wsaData; + int rc = WSAStartup( MAKEWORD(2,2), &wsaData); + if (rc != 0) { + printf( "could not initialize Winsock\n" ); + } +#elif __linux__ + windowId = wminfo.info.x11.window; +#elif __APPLE__ + windowId = wminfo.nsWindowPtr; +#endif + + printf("initializing renderer process\n"); + + // + // initialize OpenGL renderer to render in our window + // + bool inited = initOpenGLRenderer(winWidth, winHeight, portNum); + if (!inited) { + return -1; + } + printf("renderer process started\n"); + + float zRot = 0.0f; + inited = createOpenGLSubwindow(windowId, 0, 0, + winWidth, winHeight, zRot); + if (!inited) { + printf("failed to create OpenGL subwindow\n"); + stopOpenGLRenderer(); + return -1; + } + int subwinWidth = winWidth; + int subwinHeight = winHeight; + + injector = new EventInjector(consolePort); + + // Just wait until the window is closed + SDL_Event ev; + + for (;;) { + injector->wait(1000/15); + injector->poll(); + + while (SDL_PollEvent(&ev)) { + switch (ev.type) { + case SDL_MOUSEBUTTONDOWN: + if (!mouseDown) { + injector->sendMouseDown(ev.button.x, ev.button.y); + mouseDown = 1; + } + break; + case SDL_MOUSEBUTTONUP: + if (mouseDown) { + injector->sendMouseUp(ev.button.x,ev.button.y); + mouseDown = 0; + } + break; + case SDL_MOUSEMOTION: + if (mouseDown) + injector->sendMouseMotion(ev.button.x,ev.button.y); + break; + + case SDL_KEYDOWN: +#ifdef __APPLE__ + /* special code to deal with Command-Q properly */ + if (ev.key.keysym.sym == SDLK_q && + ev.key.keysym.mod & KMOD_META) { + goto EXIT; + } +#endif + injector->sendKeyDown(convert_keysym(ev.key.keysym.sym)); + + if (ev.key.keysym.sym == SDLK_KP_MINUS) { + subwinWidth /= 2; + subwinHeight /= 2; + + bool stat = destroyOpenGLSubwindow(); + printf("destroy subwin returned %d\n", stat); + stat = createOpenGLSubwindow(windowId, + (winWidth - subwinWidth) / 2, + (winHeight - subwinHeight) / 2, + subwinWidth, subwinHeight, + zRot); + printf("create subwin returned %d\n", stat); + } + else if (ev.key.keysym.sym == SDLK_KP_PLUS) { + subwinWidth *= 2; + subwinHeight *= 2; + + bool stat = destroyOpenGLSubwindow(); + printf("destroy subwin returned %d\n", stat); + stat = createOpenGLSubwindow(windowId, + (winWidth - subwinWidth) / 2, + (winHeight - subwinHeight) / 2, + subwinWidth, subwinHeight, + zRot); + printf("create subwin returned %d\n", stat); + } + else if (ev.key.keysym.sym == SDLK_KP_MULTIPLY) { + zRot += 10.0f; + setOpenGLDisplayRotation(zRot); + } + else if (ev.key.keysym.sym == SDLK_KP_ENTER) { + repaintOpenGLDisplay(); + } + break; + case SDL_KEYUP: + injector->sendKeyUp(convert_keysym(ev.key.keysym.sym)); + break; + case SDL_QUIT: + goto EXIT; + } + } + } +EXIT: + // + // stop the renderer + // + printf("stopping the renderer process\n"); + stopOpenGLRenderer(); + + return 0; +} + +static int convert_keysym(int sym) +{ +#define EE(x,y) SDLK_##x, EventInjector::KEY_##y, + static const int keymap[] = { + EE(LEFT,LEFT) + EE(RIGHT,RIGHT) + EE(DOWN,DOWN) + EE(UP,UP) + EE(RETURN,ENTER) + EE(F1,SOFT1) + EE(ESCAPE,BACK) + EE(HOME,HOME) + -1 + }; + int nn; + for (nn = 0; keymap[nn] >= 0; nn += 2) { + if (keymap[nn] == sym) + return keymap[nn+1]; + } + return sym; +} diff --git a/emulator/opengl/tests/event_injector/Android.mk b/emulator/opengl/tests/event_injector/Android.mk new file mode 100644 index 0000000..26eb476 --- /dev/null +++ b/emulator/opengl/tests/event_injector/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-host-static-library,event_injector) + +LOCAL_SRC_FILES := \ + EventInjector.cpp \ + sockets.c \ + emulator-console.c \ + iolooper-select.c + +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-end-module) diff --git a/emulator/opengl/tests/event_injector/EventInjector.cpp b/emulator/opengl/tests/event_injector/EventInjector.cpp new file mode 100644 index 0000000..6dade6e --- /dev/null +++ b/emulator/opengl/tests/event_injector/EventInjector.cpp @@ -0,0 +1,76 @@ +/* +* 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 "EventInjector.h" +#include "emulator-console.h" + +#define PRIVATE EventInjectorPrivate + +class PRIVATE +{ +public: + IoLooper* mLooper; + EmulatorConsole* mConsole; + + EventInjectorPrivate(int port) { + mLooper = iolooper_new(); + mConsole = emulatorConsole_new(port, mLooper); + } +}; + +EventInjector::EventInjector(int consolePort) +{ + mPrivate = new PRIVATE(consolePort); +} + +EventInjector::~EventInjector() +{ + delete mPrivate; +} + +void EventInjector::wait(int timeout_ms) +{ + iolooper_wait(mPrivate->mLooper, timeout_ms); +} + +void EventInjector::poll(void) +{ + emulatorConsole_poll(mPrivate->mConsole); +} + +void EventInjector::sendMouseDown( int x, int y ) +{ + emulatorConsole_sendMouseDown(mPrivate->mConsole, x, y); +} + +void EventInjector::sendMouseUp( int x, int y ) +{ + emulatorConsole_sendMouseUp(mPrivate->mConsole, x, y); +} + +void EventInjector::sendMouseMotion( int x, int y ) +{ + emulatorConsole_sendMouseMotion(mPrivate->mConsole, x, y); +} + +void EventInjector::sendKeyDown( int keycode ) +{ + emulatorConsole_sendKey(mPrivate->mConsole, keycode, 1); +} + +void EventInjector::sendKeyUp( int keycode ) +{ + emulatorConsole_sendKey(mPrivate->mConsole, keycode, 0); +} diff --git a/emulator/opengl/tests/event_injector/EventInjector.h b/emulator/opengl/tests/event_injector/EventInjector.h new file mode 100644 index 0000000..a8fded7 --- /dev/null +++ b/emulator/opengl/tests/event_injector/EventInjector.h @@ -0,0 +1,59 @@ +/* +* 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. +*/ +/* Event redirector is used to inject user events from a GL window + * into the emulated program. + */ +#ifndef EVENT_INJECTOR_H +#define EVENT_INJECTOR_H + +class EventInjectorPrivate; + +class EventInjector +{ +public: + EventInjector(int consolePort); + virtual ~EventInjector(); + + void wait( int timeout_ms ); + void poll( void ); + + void sendMouseDown( int x, int y ); + void sendMouseUp( int x, int y ); + void sendMouseMotion( int x, int y ); + void sendKeyDown( int keycode ); + void sendKeyUp( int keycode ); + + /* Keycode values expected by the Linux kernel, and the emulator */ + enum { + KEY_BACK = 158, + KEY_HOME = 102, + KEY_SOFT1 = 229, + KEY_LEFT = 105, + KEY_UP = 103, + KEY_DOWN = 108, + KEY_RIGHT = 106, + KEY_VOLUMEUP = 115, + KEY_VOLUMEDOWN = 114, + KEY_SEND = 231, + KEY_END = 107, + KEY_ENTER = 28, + }; + +private: + EventInjectorPrivate* mPrivate; +}; + +#endif /* EVENT_INJECTOR_H */ diff --git a/emulator/opengl/tests/event_injector/emulator-console.c b/emulator/opengl/tests/event_injector/emulator-console.c new file mode 100644 index 0000000..a8c49b2 --- /dev/null +++ b/emulator/opengl/tests/event_injector/emulator-console.c @@ -0,0 +1,345 @@ +/* +* 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 "emulator-console.h" +#include "sockets.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define DEBUG 0 +#if DEBUG >= 1 +# define D(...) printf(__VA_ARGS__), printf("\n") +#else +# define D(...) ((void)0) +#endif +#if DEBUG >= 2 +# define DD(...) printf(__VA_ARGS__), printf("\n") +#else +# define DD(...) ((void)0) +#endif + +#define ANEW0(p) (p) = calloc(sizeof(*(p)), 1) + +enum { + STATE_CONNECTING = 0, + STATE_CONNECTED, + STATE_WAITING, + STATE_ERROR = 2 +}; + +typedef struct Msg { + const char* data; // pointer to data + int size; // size of data + int sent; // already sent (so sent..size remain in buffer). + struct Msg* next; // next message in queue. +} Msg; + +static Msg* +msg_alloc( const char* data, int datalen ) +{ + Msg* msg; + + msg = malloc(sizeof(*msg) + datalen); + msg->data = (const char*)(msg + 1); + msg->size = datalen; + msg->sent = 0; + memcpy((char*)msg->data, data, datalen); + msg->next = NULL; + + return msg; +} + +static void +msg_free( Msg* msg ) +{ + free(msg); +} + +struct EmulatorConsole { + int fd; + IoLooper* looper; + int state; + Msg* out_msg; + SockAddress address; + int64_t waitUntil; +}; + +/* Read as much from the input as possible, ignoring it. + */ +static int +emulatorConsole_eatInput( EmulatorConsole* con ) +{ + for (;;) { + char temp[64]; + int ret = socket_recv(con->fd, temp, sizeof temp); + if (ret < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + return 0; + } + return -1; + } + if (ret == 0) { + return -1; + } + DD("Console received: '%.*s'", ret, temp); + } +} + +static int +emulatorConsole_sendOutput( EmulatorConsole* con ) +{ + if (con->state != STATE_CONNECTED) { + errno = EINVAL; + return -1; + } + + while (con->out_msg != NULL) { + Msg* msg = con->out_msg; + int ret; + + ret = socket_send(con->fd, + msg->data + msg->sent, + msg->size - msg->sent); + if (ret > 0) { + DD("Console sent: '%.*s'", ret, msg->data + msg->sent); + + msg->sent += ret; + if (msg->sent == msg->size) { + con->out_msg = msg->next; + msg_free(msg); + } + continue; + } + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + return 0; + } + con->state = STATE_ERROR; + D("Console error when sending: %s", strerror(errno)); + return -1; + } + iolooper_del_write(con->looper, con->fd); + return 0; +} + +static void +emulatorConsole_completeConnect(EmulatorConsole* con) +{ + D("Console connected!"); + iolooper_add_read(con->looper, con->fd); + iolooper_del_write(con->looper, con->fd); + con->state = STATE_CONNECTED; + if (con->out_msg != NULL) { + iolooper_add_write(con->looper, con->fd); + emulatorConsole_sendOutput(con); + } +} + +static void +emulatorConsole_retry(EmulatorConsole* con) +{ + /* Not possible yet, wait one second */ + D("Could not connect to emulator, waiting 1 second: %s", errno_str); + con->state = STATE_WAITING; + con->waitUntil = iolooper_now() + 5000; +} + +static void +emulatorConsole_connect(EmulatorConsole* con) +{ + D("Trying to connect!"); + if (con->fd < 0) { + con->fd = socket_create_inet( SOCKET_STREAM ); + if (con->fd < 0) { + D("ERROR: Could not create socket: %s", errno_str); + con->state = STATE_ERROR; + return; + } + socket_set_nonblock(con->fd); + } + con->state = STATE_CONNECTING; + if (socket_connect(con->fd, &con->address) < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) { + iolooper_add_write(con->looper, con->fd); + } else { + emulatorConsole_retry(con); + } + return; + } + + emulatorConsole_completeConnect(con); +} + +static void +emulatorConsole_reset( EmulatorConsole* con ) +{ + D("Resetting console connection"); + while (con->out_msg) { + Msg* msg = con->out_msg; + con->out_msg = msg->next; + msg_free(msg); + } + iolooper_del_read(con->looper, con->fd); + iolooper_del_write(con->looper, con->fd); + socket_close(con->fd); + con->fd = -1; + emulatorConsole_connect(con); +} + +/* Create a new EmulatorConsole object to connect asynchronously to + * a given emulator port. Note that this should always succeeds since + * the connection is asynchronous. + */ +EmulatorConsole* +emulatorConsole_new(int port, IoLooper* looper) +{ + EmulatorConsole* con; + SockAddress addr; + + ANEW0(con); + con->looper = looper; + con->fd = -1; + sock_address_init_inet(&con->address, SOCK_ADDRESS_INET_LOOPBACK, port); + + emulatorConsole_connect(con); + return con; +} + +int +emulatorConsole_poll( EmulatorConsole* con ) +{ + int ret; + + if (con->state == STATE_WAITING) { + if (iolooper_now() >= con->waitUntil) + emulatorConsole_connect(con); + return 0; + } + + if (!iolooper_is_read(con->looper, con->fd) && + !iolooper_is_write(con->looper, con->fd)) + { + return 0; + } + +LOOP: + switch (con->state) { + case STATE_ERROR: + return -1; + + case STATE_CONNECTING: + // read socket error to determine success / error. + if (socket_get_error(con->fd) != 0) { + emulatorConsole_retry(con); + } else { + emulatorConsole_completeConnect(con); + } + return 0; + + case STATE_CONNECTED: + /* ignore input, if any */ + if (iolooper_is_read(con->looper, con->fd)) { + if (emulatorConsole_eatInput(con) < 0) { + goto SET_ERROR; + } + } + /* send outgoing data, if any */ + if (iolooper_is_write(con->looper, con->fd)) { + if (emulatorConsole_sendOutput(con) < 0) { + goto SET_ERROR; + } + } + return 0; + + default: + D("UNSUPPORTED STATE!"); + break; + } + +SET_ERROR: + D("Console ERROR!: %s\n", errno_str); + con->state = STATE_ERROR; + emulatorConsole_reset(con); + return -1; +} + +/* Send a message to the console asynchronously. Any answer will be + * ignored. */ +void +emulatorConsole_send( EmulatorConsole* con, const char* command ) +{ + int cmdlen = strlen(command); + Msg* msg; + Msg** plast; + + if (cmdlen == 0) + return; + + /* Append new message at end of outgoing list */ + msg = msg_alloc(command, cmdlen); + plast = &con->out_msg; + while (*plast) { + plast = &(*plast)->next; + } + *plast = msg; + if (con->out_msg == msg) { + iolooper_add_write(con->looper, con->fd); + } + emulatorConsole_sendOutput(con); +} + + +void +emulatorConsole_sendMouseDown( EmulatorConsole* con, int x, int y ) +{ + char temp[128]; + + D("sendMouseDown(%d,%d)", x, y); + snprintf(temp, sizeof temp, + "event send 3:0:%d 3:1:%d 1:330:1 0:0:0\r\n", + x, y); + emulatorConsole_send(con, temp); +} + +void +emulatorConsole_sendMouseMotion( EmulatorConsole* con, int x, int y ) +{ + /* Same as mouse down */ + emulatorConsole_sendMouseDown(con, x, y); +} + +void +emulatorConsole_sendMouseUp( EmulatorConsole* con, int x, int y ) +{ + char temp[128]; + + D("sendMouseUp(%d,%d)", x, y); + snprintf(temp, sizeof temp, + "event send 3:0:%d 3:1:%d 1:330:0 0:0:0\r\n", + x, y); + emulatorConsole_send(con, temp); +} + +#define EE(x,y) if (keycode == x) return y; + +void +emulatorConsole_sendKey( EmulatorConsole* con, int keycode, int down ) +{ + char temp[128]; + + snprintf(temp, sizeof temp, + "event send EV_KEY:%d:%d 0:0:0\r\n", keycode, down); + emulatorConsole_send(con, temp); +} diff --git a/emulator/opengl/tests/event_injector/emulator-console.h b/emulator/opengl/tests/event_injector/emulator-console.h new file mode 100644 index 0000000..19e9687 --- /dev/null +++ b/emulator/opengl/tests/event_injector/emulator-console.h @@ -0,0 +1,55 @@ +/* +* 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. +*/ +#ifndef ANDROID_EMULATOR_CONSOLE_H +#define ANDROID_EMULATOR_CONSOLE_H + +#include "iolooper.h" +#include "sockets.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct EmulatorConsole EmulatorConsole; + +/* Create a new EmulatorConsole object to connect asynchronously to + * a given emulator port. Note that this always succeeds since the + * connection is asynchronous. + */ +EmulatorConsole* emulatorConsole_new(int port, IoLooper* looper); + +/* Call this after an iolooper_poll() or iolooper_wait() to check + * the status of the console's socket and act upon it. + * + * Returns 0 on success, or -1 on error (which indicates disconnection!) + */ +int emulatorConsole_poll( EmulatorConsole* console ); + +/* Send a message to the console asynchronously. Any answer will be + * ignored. */ +void emulatorConsole_send( EmulatorConsole* console, const char* command ); + +void emulatorConsole_sendMouseDown( EmulatorConsole* con, int x, int y ); +void emulatorConsole_sendMouseMotion( EmulatorConsole* con, int x, int y ); +void emulatorConsole_sendMouseUp( EmulatorConsole* con, int x, int y ); + +void emulatorConsole_sendKey( EmulatorConsole* con, int keycode, int down ); + +#ifdef __cplusplus +} +#endif + +#endif /* ANDROID_EMULATOR_CONSOLE_H */ diff --git a/emulator/opengl/tests/event_injector/iolooper-select.c b/emulator/opengl/tests/event_injector/iolooper-select.c new file mode 100644 index 0000000..c5fc7c2 --- /dev/null +++ b/emulator/opengl/tests/event_injector/iolooper-select.c @@ -0,0 +1,274 @@ +/* +* 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 <errno.h> +#include <stdlib.h> +#include "iolooper.h" +#include "sockets.h" + +/* An implementation of iolooper.h based on Unix select() */ +#ifdef _WIN32 +# include <winsock2.h> +# include <time.h> +#else +# include <sys/types.h> +# include <sys/select.h> +# include <sys/time.h> +#endif + +struct IoLooper { + fd_set reads[1]; + fd_set writes[1]; + fd_set reads_result[1]; + fd_set writes_result[1]; + int max_fd; + int max_fd_valid; +}; + +IoLooper* +iolooper_new(void) +{ + IoLooper* iol = malloc(sizeof(*iol)); + iolooper_reset(iol); + return iol; +} + +void +iolooper_free( IoLooper* iol ) +{ + free(iol); +} + +void +iolooper_reset( IoLooper* iol ) +{ + FD_ZERO(iol->reads); + FD_ZERO(iol->writes); + iol->max_fd = -1; + iol->max_fd_valid = 1; +} + +static void +iolooper_add_fd( IoLooper* iol, int fd ) +{ + if (iol->max_fd_valid && fd > iol->max_fd) { + iol->max_fd = fd; + } +} + +static void +iolooper_del_fd( IoLooper* iol, int fd ) +{ + if (iol->max_fd_valid && fd == iol->max_fd) + iol->max_fd_valid = 0; +} + +void +iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags ) +{ + if (fd < 0) + return; + + int changed = oldflags ^ newflags; + + if ((changed & IOLOOPER_READ) != 0) { + if ((newflags & IOLOOPER_READ) != 0) + iolooper_add_read(iol, fd); + else + iolooper_del_read(iol, fd); + } + if ((changed & IOLOOPER_WRITE) != 0) { + if ((newflags & IOLOOPER_WRITE) != 0) + iolooper_add_write(iol, fd); + else + iolooper_del_write(iol, fd); + } +} + + +static int +iolooper_fd_count( IoLooper* iol ) +{ + int max_fd = iol->max_fd; + int fd; + + if (iol->max_fd_valid) + return max_fd + 1; + + /* recompute max fd */ + for (fd = 0; fd < FD_SETSIZE; fd++) { + if (!FD_ISSET(fd, iol->reads) && !FD_ISSET(fd, iol->writes)) + continue; + + max_fd = fd; + } + iol->max_fd = max_fd; + iol->max_fd_valid = 1; + + return max_fd + 1; +} + +void +iolooper_add_read( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_add_fd(iol, fd); + FD_SET(fd, iol->reads); + } +} + +void +iolooper_add_write( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_add_fd(iol, fd); + FD_SET(fd, iol->writes); + } +} + +void +iolooper_del_read( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_del_fd(iol, fd); + FD_CLR(fd, iol->reads); + } +} + +void +iolooper_del_write( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_del_fd(iol, fd); + FD_CLR(fd, iol->writes); + } +} + +int +iolooper_poll( IoLooper* iol ) +{ + int count = iolooper_fd_count(iol); + int ret; + fd_set errs; + + if (count == 0) + return 0; + + FD_ZERO(&errs); + + do { + struct timeval tv; + + tv.tv_sec = tv.tv_usec = 0; + + iol->reads_result[0] = iol->reads[0]; + iol->writes_result[0] = iol->writes[0]; + + ret = select( count, iol->reads_result, iol->writes_result, &errs, &tv); + } while (ret < 0 && errno == EINTR); + + return ret; +} + +int +iolooper_wait( IoLooper* iol, int64_t duration ) +{ + int count = iolooper_fd_count(iol); + int ret; + fd_set errs; + struct timeval tm0, *tm = NULL; + + if (count == 0) + return 0; + + if (duration < 0) + tm = NULL; + else { + tm = &tm0; + tm->tv_sec = duration / 1000; + tm->tv_usec = (duration - 1000*tm->tv_sec) * 1000; + } + + FD_ZERO(&errs); + + do { + iol->reads_result[0] = iol->reads[0]; + iol->writes_result[0] = iol->writes[0]; + + ret = select( count, iol->reads_result, iol->writes_result, &errs, tm); + if (ret == 0) { + // Indicates timeout + errno = ETIMEDOUT; + } + } while (ret < 0 && errno == EINTR); + + return ret; +} + + +int +iolooper_is_read( IoLooper* iol, int fd ) +{ + return FD_ISSET(fd, iol->reads_result); +} + +int +iolooper_is_write( IoLooper* iol, int fd ) +{ + return FD_ISSET(fd, iol->writes_result); +} + +int +iolooper_has_operations( IoLooper* iol ) +{ + return iolooper_fd_count(iol) > 0; +} + +int64_t +iolooper_now(void) +{ +#ifdef _WIN32 + FILETIME now; + int64_t now_100ns; + + GetSystemTimeAsFileTime(&now); + + /* Get the time as hundreds of nanosecond intervals since + 12:00 AM January 1t 1601 UTC. We don't really need + to compute the value relative to the Posix epoch */ + now_100ns = ((int64_t)now.dwHighDateTime << 32) | now.dwLowDateTime; + + /* 100 ns == 0.1 us == 0.0001 ms */ + return now_100ns / 10000LL; + +#else /* !_WIN32 */ + struct timeval time_now; + return gettimeofday(&time_now, NULL) ? -1 : (int64_t)time_now.tv_sec * 1000LL + + time_now.tv_usec / 1000; +#endif /* !_WIN32 */ +} + +int +iolooper_wait_absolute(IoLooper* iol, int64_t deadline) +{ + int64_t timeout = deadline - iolooper_now(); + + /* If the deadline has passed, set the timeout to 0, this allows us + * to poll the file descriptor nonetheless */ + if (timeout < 0) + timeout = 0; + + return iolooper_wait(iol, timeout); +} diff --git a/emulator/opengl/tests/event_injector/iolooper.h b/emulator/opengl/tests/event_injector/iolooper.h new file mode 100644 index 0000000..4aa3db7 --- /dev/null +++ b/emulator/opengl/tests/event_injector/iolooper.h @@ -0,0 +1,91 @@ +/* +* 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. +*/ +#ifndef IOLOOPER_H +#define IOLOOPER_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* An IOLooper is an abstraction for select() */ + +typedef struct IoLooper IoLooper; + +IoLooper* iolooper_new(void); +void iolooper_free( IoLooper* iol ); +void iolooper_reset( IoLooper* iol ); + +void iolooper_add_read( IoLooper* iol, int fd ); +void iolooper_add_write( IoLooper* iol, int fd ); +void iolooper_del_read( IoLooper* iol, int fd ); +void iolooper_del_write( IoLooper* iol, int fd ); + +enum { + IOLOOPER_READ = (1<<0), + IOLOOPER_WRITE = (1<<1), +}; +void iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags); + +int iolooper_poll( IoLooper* iol ); +/* Wrapper around select() + * Return: + * > 0 in case an I/O has occurred, or < 0 on error, or 0 on timeout with + * errno set to ETIMEDOUT. + */ +int iolooper_wait( IoLooper* iol, int64_t duration ); + +int iolooper_is_read( IoLooper* iol, int fd ); +int iolooper_is_write( IoLooper* iol, int fd ); +/* Returns 1 if this IoLooper has one or more file descriptor to interact with */ +int iolooper_has_operations( IoLooper* iol ); +/* Gets current time in milliseconds. + * Return: + * Number of milliseconds corresponded to the current time on success, or -1 + * on failure. + */ +int64_t iolooper_now(void); +/* Waits for an I/O to occur before specific absolute time. + * This routine should be used (instead of iolooper_wait) in cases when multiple + * sequential I/O should be completed within given time interval. For instance, + * consider the scenario, when "server" does two sequential writes, and "client" + * now has to read data transferred with these two distinct writes. It might be + * wasteful to do two reads, each with the same (large) timeout. Instead, it + * would be better to assign a deadline for both reads before the first read, + * and call iolooper_wait_absoulte with the same deadline value: + * int64_t deadline = iolooper_now() + TIMEOUT; + * if (iolooper_wait_absoulte(iol, deadline)) { + * // Process first buffer. + * (iolooper_wait_absoulte(iol, deadline)) { + * // Process second read + * } + * } + * Param: + * iol IoLooper instance for an I/O. + * deadline Deadline (absoulte time in milliseconds) before which an I/O should + * occur. + * Return: + * Number of I/O descriptors set in iol, if an I/O has occurred, 0 if no I/O + * occurred before the deadline, or -1 on error. + */ +int iolooper_wait_absolute(IoLooper* iol, int64_t deadline); + +#ifdef __cplusplus +} +#endif + +#endif /* IOLOOPER_H */ diff --git a/emulator/opengl/tests/event_injector/sockets.c b/emulator/opengl/tests/event_injector/sockets.c new file mode 100644 index 0000000..a2cc334 --- /dev/null +++ b/emulator/opengl/tests/event_injector/sockets.c @@ -0,0 +1,1554 @@ +/* +* 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. +*/ +#ifdef __linux__ /* Recent versions of glibc only define EAI_NODATA, which is an + extension to the POSIX standard, if _GNU_SOURCE is defined. */ +# define _GNU_SOURCE 1 +#endif + +#include "sockets.h" +#include <fcntl.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +//#include "android/utils/path.h" +//#include "android/utils/debug.h" +//#include "android/utils/misc.h" +//#include "android/utils/system.h" + +#define D(...) ((void)0) + +#ifdef _WIN32 +# define xxWIN32_LEAN_AND_MEAN +# define _WIN32_WINNT 0x501 +# include <windows.h> +# include <winsock2.h> +# include <ws2tcpip.h> +#else /* !_WIN32 */ +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <netinet/in.h> +# include <netinet/tcp.h> +# include <netdb.h> +# if HAVE_UNIX_SOCKETS +# include <sys/un.h> +# ifndef UNIX_PATH_MAX +# define UNIX_PATH_MAX (sizeof(((struct sockaddr_un*)0)->sun_path)-1) +# endif +# endif +#endif /* !_WIN32 */ + +#define MIN(x,y) ({ typeof(x) _x = (x); typeof(y) _y = (y); _x <= _y ? _x : _y; }) +#define AFREE(p) free(p) +#define AARRAY_NEW(p,count) (p) = malloc(sizeof(*(p))*(count)) +#define AARRAY_NEW0(p,count) (p) = calloc(sizeof(*(p)),(count)) + +/* QSOCKET_CALL is used to deal with the fact that EINTR happens pretty + * easily in QEMU since we use SIGALRM to implement periodic timers + */ +#ifdef _WIN32 +# define QSOCKET_CALL(_ret,_cmd) \ + do { _ret = (_cmd); } while ( _ret < 0 && WSAGetLastError() == WSAEINTR ) +#else +# define QSOCKET_CALL(_ret,_cmd) \ + do { \ + errno = 0; \ + do { _ret = (_cmd); } while ( _ret < 0 && errno == EINTR ); \ + } while (0); +#endif + +#ifdef _WIN32 + +#include <errno.h> + +static int winsock_error; + +#define WINSOCK_ERRORS_LIST \ + EE(WSA_INVALID_HANDLE,EINVAL,"invalid handle") \ + EE(WSA_NOT_ENOUGH_MEMORY,ENOMEM,"not enough memory") \ + EE(WSA_INVALID_PARAMETER,EINVAL,"invalid parameter") \ + EE(WSAEINTR,EINTR,"interrupted function call") \ + EE(WSAEALREADY,EALREADY,"operation already in progress") \ + EE(WSAEBADF,EBADF,"bad file descriptor") \ + EE(WSAEACCES,EACCES,"permission denied") \ + EE(WSAEFAULT,EFAULT,"bad address") \ + EE(WSAEINVAL,EINVAL,"invalid argument") \ + EE(WSAEMFILE,EMFILE,"too many opened files") \ + EE(WSAEWOULDBLOCK,EWOULDBLOCK,"resource temporarily unavailable") \ + EE(WSAEINPROGRESS,EINPROGRESS,"operation now in progress") \ + EE(WSAEALREADY,EAGAIN,"operation already in progress") \ + EE(WSAENOTSOCK,EBADF,"socket operation not on socket") \ + EE(WSAEDESTADDRREQ,EDESTADDRREQ,"destination address required") \ + EE(WSAEMSGSIZE,EMSGSIZE,"message too long") \ + EE(WSAEPROTOTYPE,EPROTOTYPE,"wrong protocol type for socket") \ + EE(WSAENOPROTOOPT,ENOPROTOOPT,"bad protocol option") \ + EE(WSAEADDRINUSE,EADDRINUSE,"address already in use") \ + EE(WSAEADDRNOTAVAIL,EADDRNOTAVAIL,"cannot assign requested address") \ + EE(WSAENETDOWN,ENETDOWN,"network is down") \ + EE(WSAENETUNREACH,ENETUNREACH,"network unreachable") \ + EE(WSAENETRESET,ENETRESET,"network dropped connection on reset") \ + EE(WSAECONNABORTED,ECONNABORTED,"software caused connection abort") \ + EE(WSAECONNRESET,ECONNRESET,"connection reset by peer") \ + EE(WSAENOBUFS,ENOBUFS,"no buffer space available") \ + EE(WSAEISCONN,EISCONN,"socket is already connected") \ + EE(WSAENOTCONN,ENOTCONN,"socket is not connected") \ + EE(WSAESHUTDOWN,ESHUTDOWN,"cannot send after socket shutdown") \ + EE(WSAETOOMANYREFS,ETOOMANYREFS,"too many references") \ + EE(WSAETIMEDOUT,ETIMEDOUT,"connection timed out") \ + EE(WSAECONNREFUSED,ECONNREFUSED,"connection refused") \ + EE(WSAELOOP,ELOOP,"cannot translate name") \ + EE(WSAENAMETOOLONG,ENAMETOOLONG,"name too long") \ + EE(WSAEHOSTDOWN,EHOSTDOWN,"host is down") \ + EE(WSAEHOSTUNREACH,EHOSTUNREACH,"no route to host") \ + +typedef struct { + int winsock; + int unix; + const char* string; +} WinsockError; + +static const WinsockError _winsock_errors[] = { +#define EE(w,u,s) { w, u, s }, + WINSOCK_ERRORS_LIST +#undef EE + { -1, -1, NULL } +}; + +/* this function reads the latest winsock error code and updates + * errno to a matching value. It also returns the new value of + * errno. + */ +static int +_fix_errno( void ) +{ + const WinsockError* werr = _winsock_errors; + int unix = EINVAL; /* generic error code */ + + winsock_error = WSAGetLastError(); + + for ( ; werr->string != NULL; werr++ ) { + if (werr->winsock == winsock_error) { + unix = werr->unix; + break; + } + } + errno = unix; + return -1; +} + +static int +_set_errno( int code ) +{ + winsock_error = -1; + errno = code; + return -1; +} + +/* this function returns a string describing the latest Winsock error */ +const char* +_errno_str(void) +{ + const WinsockError* werr = _winsock_errors; + const char* result = NULL; + + for ( ; werr->string; werr++ ) { + if (werr->winsock == winsock_error) { + result = werr->string; + break; + } + } + + if (result == NULL) { + result = "Unknown socket error"; + } + return result; +} +#else +static int +_fix_errno( void ) +{ + return -1; +} + +static int +_set_errno( int code ) +{ + errno = code; + return -1; +} +#endif + +/* socket types */ + +static int +socket_family_to_bsd( SocketFamily family ) +{ + switch (family) { + case SOCKET_INET: return AF_INET; + case SOCKET_IN6: return AF_INET6; +#if HAVE_UNIX_SOCKETS + case SOCKET_UNIX: return AF_LOCAL; +#endif + default: return -1; + } +} + +static int +socket_type_to_bsd( SocketType type ) +{ + switch (type) { + case SOCKET_DGRAM: return SOCK_DGRAM; + case SOCKET_STREAM: return SOCK_STREAM; + default: return 0; + } +} + +static SocketType +socket_type_from_bsd( int type ) +{ + switch (type) { + case SOCK_DGRAM: return SOCKET_DGRAM; + case SOCK_STREAM: return SOCKET_STREAM; + default: return (SocketType) SOCKET_UNSPEC; + } +} + +#if 0 +static int +socket_type_check( SocketType type ) +{ + return (type == SOCKET_DGRAM || type == SOCKET_STREAM); +} +#endif + +typedef union { + struct sockaddr sa[1]; + struct sockaddr_in in[1]; +#if HAVE_IN6_SOCKETS + struct sockaddr_in6 in6[1]; +#endif +#if HAVE_UNIX_SOCKETS + struct sockaddr_un un[1]; +#endif +} sockaddr_storage; + +/* socket addresses */ + +void +sock_address_init_inet( SockAddress* a, uint32_t ip, uint16_t port ) +{ + a->family = SOCKET_INET; + a->u.inet.port = port; + a->u.inet.address = ip; +} + +void +sock_address_init_in6 ( SockAddress* a, const uint8_t* ip6[16], uint16_t port ) +{ + a->family = SOCKET_IN6; + a->u.in6.port = port; + memcpy( a->u.in6.address, ip6, sizeof(a->u.in6.address) ); +} + +void +sock_address_init_unix( SockAddress* a, const char* path ) +{ + a->family = SOCKET_UNIX; + a->u._unix.path = strdup(path ? path : ""); + a->u._unix.owner = 1; +} + +void sock_address_done( SockAddress* a ) +{ + if (a->family == SOCKET_UNIX && a->u._unix.owner) { + a->u._unix.owner = 0; + free((char*)a->u._unix.path); + } +} + +static char* +format_char( char* buf, char* end, int c ) +{ + if (buf < end) { + if (buf+1 == end) { + *buf++ = 0; + } else { + *buf++ = (char) c; + *buf = 0; + } + } + return buf; +} + +static char* +format_str( char* buf, char* end, const char* str ) +{ + int len = strlen(str); + int avail = end - buf; + + if (len > avail) + len = avail; + + memcpy( buf, str, len ); + buf += len; + + if (buf == end) + buf[-1] = 0; + else + buf[0] = 0; + + return buf; +} + +static char* +format_unsigned( char* buf, char* end, unsigned val ) +{ + char temp[16]; + int nn; + + for ( nn = 0; val != 0; nn++ ) { + int rem = val % 10; + temp[nn] = '0'+rem; + val /= 10; + } + + if (nn == 0) + temp[nn++] = '0'; + + while (nn > 0) + buf = format_char(buf, end, temp[--nn]); + + return buf; +} + +static char* +format_hex( char* buf, char* end, unsigned val, int ndigits ) +{ + int shift = 4*ndigits; + static const char hex[16] = "0123456789abcdef"; + + while (shift >= 0) { + buf = format_char(buf, end, hex[(val >> shift) & 15]); + shift -= 4; + } + return buf; +} + +static char* +format_ip4( char* buf, char* end, uint32_t ip ) +{ + buf = format_unsigned( buf, end, (unsigned)(ip >> 24) ); + buf = format_char( buf, end, '.'); + buf = format_unsigned( buf, end, (unsigned)((ip >> 16) & 255)); + buf = format_char( buf, end, '.'); + buf = format_unsigned( buf, end, (unsigned)((ip >> 8) & 255)); + buf = format_char( buf, end, '.'); + buf = format_unsigned( buf, end, (unsigned)(ip & 255)); + return buf; +} + +static char* +format_ip6( char* buf, char* end, const uint8_t* ip6 ) +{ + int nn; + for (nn = 0; nn < 8; nn++) { + int val = (ip6[0] << 16) | ip6[1]; + ip6 += 2; + if (nn > 0) + buf = format_char(buf, end, ':'); + if (val == 0) + continue; + buf = format_hex(buf, end, val, 4); + } + return buf; +} + +const char* +sock_address_to_string( const SockAddress* a ) +{ + static char buf0[PATH_MAX]; + char *buf = buf0, *end = buf + sizeof(buf0); + + switch (a->family) { + case SOCKET_INET: + buf = format_ip4( buf, end, a->u.inet.address ); + buf = format_char( buf, end, ':' ); + buf = format_unsigned( buf, end, (unsigned) a->u.inet.port ); + break; + + case SOCKET_IN6: + buf = format_ip6( buf, end, a->u.in6.address ); + buf = format_char( buf, end, ':' ); + buf = format_unsigned( buf, end, (unsigned) a->u.in6.port ); + break; + + case SOCKET_UNIX: + buf = format_str( buf, end, a->u._unix.path ); + break; + + default: + return NULL; + } + + return buf0; +} + +int +sock_address_equal( const SockAddress* a, const SockAddress* b ) +{ + if (a->family != b->family) + return 0; + + switch (a->family) { + case SOCKET_INET: + return (a->u.inet.address == b->u.inet.address && + a->u.inet.port == b->u.inet.port); + + case SOCKET_IN6: + return (!memcmp(a->u.in6.address, b->u.in6.address, 16) && + a->u.in6.port == b->u.in6.port); + + case SOCKET_UNIX: + return (!strcmp(a->u._unix.path, b->u._unix.path)); + + default: + return 0; + } +} + +int +sock_address_get_port( const SockAddress* a ) +{ + switch (a->family) { + case SOCKET_INET: + return a->u.inet.port; + case SOCKET_IN6: + return a->u.in6.port; + default: + return -1; + } +} + +void +sock_address_set_port( SockAddress* a, uint16_t port ) +{ + switch (a->family) { + case SOCKET_INET: + a->u.inet.port = port; + break; + case SOCKET_IN6: + a->u.in6.port = port; + break; + default: + ; + } +} + +const char* +sock_address_get_path( const SockAddress* a ) +{ + if (a->family == SOCKET_UNIX) + return a->u._unix.path; + else + return NULL; +} + +int +sock_address_get_ip( const SockAddress* a ) +{ + if (a->family == SOCKET_INET) + return a->u.inet.address; + + return -1; +} + +#if 0 +char* +bufprint_sock_address( char* p, char* end, const SockAddress* a ) +{ + switch (a->family) { + case SOCKET_INET: + { + uint32_t ip = a->u.inet.address; + + return bufprint( p, end, "%d.%d.%d.%d:%d", + (ip >> 24) & 255, (ip >> 16) & 255, + (ip >> 8) & 255, ip & 255, + a->u.inet.port ); + } + case SOCKET_IN6: + { + int nn = 0; + const char* column = ""; + const uint8_t* tab = a->u.in6.address; + for (nn = 0; nn < 16; nn += 2) { + p = bufprint(p, end, "%s%04x", column, (tab[n] << 8) | tab[n+1]); + column = ":"; + } + return bufprint(p, end, ":%d", a->u.in6.port); + } + case SOCKET_UNIX: + { + return bufprint(p, end, "%s", a->u._unix.path); + } + default: + return p; + } +} +#endif + +static int +sock_address_to_bsd( const SockAddress* a, sockaddr_storage* paddress, socklen_t *psize ) +{ + switch (a->family) { + case SOCKET_INET: + { + struct sockaddr_in* dst = paddress->in; + + *psize = sizeof(*dst); + + memset( paddress, 0, *psize ); + + dst->sin_family = AF_INET; + dst->sin_port = htons(a->u.inet.port); + dst->sin_addr.s_addr = htonl(a->u.inet.address); + } + break; + +#if HAVE_IN6_SOCKETS + case SOCKET_IN6: + { + struct sockaddr_in6* dst = paddress->in6; + + *psize = sizeof(*dst); + + memset( paddress, 0, *psize ); + + dst->sin6_family = AF_INET6; + dst->sin6_port = htons(a->u.in6.port); + memcpy( dst->sin6_addr.s6_addr, a->u.in6.address, 16 ); + } + break; +#endif /* HAVE_IN6_SOCKETS */ + +#if HAVE_UNIX_SOCKETS + case SOCKET_UNIX: + { + int slen = strlen(a->u._unix.path); + struct sockaddr_un* dst = paddress->un; + + if (slen >= (int)UNIX_PATH_MAX) + return -1; + + memset( dst, 0, sizeof(*dst) ); + + dst->sun_family = AF_LOCAL; + memcpy( dst->sun_path, a->u._unix.path, slen ); + dst->sun_path[slen] = 0; + + *psize = (char*)&dst->sun_path[slen+1] - (char*)dst; + } + break; +#endif /* HAVE_UNIX_SOCKETS */ + + default: + return _set_errno(EINVAL); + } + + return 0; +} + +static int +sock_address_from_bsd( SockAddress* a, const void* from, size_t fromlen ) +{ + switch (((struct sockaddr *)from)->sa_family) { + case AF_INET: + { + const struct sockaddr_in* src = from; + + if (fromlen < sizeof(*src)) + return _set_errno(EINVAL); + + a->family = SOCKET_INET; + a->u.inet.port = ntohs(src->sin_port); + a->u.inet.address = ntohl(src->sin_addr.s_addr); + } + break; + +#ifdef HAVE_IN6_SOCKETS + case AF_INET6: + { + const struct sockaddr_in6* src = from; + + if (fromlen < sizeof(*src)) + return _set_errno(EINVAL); + + a->family = SOCKET_IN6; + a->u.in6.port = ntohs(src->sin6_port); + memcpy(a->u.in6.address, src->sin6_addr.s6_addr, 16); + } + break; +#endif + +#ifdef HAVE_UNIX_SOCKETS + case AF_LOCAL: + { + const struct sockaddr_un* src = from; + char* end; + + if (fromlen < sizeof(*src)) + return _set_errno(EINVAL); + + /* check that the path is zero-terminated */ + end = memchr(src->sun_path, 0, UNIX_PATH_MAX); + if (end == NULL) + return _set_errno(EINVAL); + + a->family = SOCKET_UNIX; + a->u._unix.owner = 1; + a->u._unix.path = strdup(src->sun_path); + } + break; +#endif + + default: + return _set_errno(EINVAL); + } + return 0; +} + + +int +sock_address_init_resolve( SockAddress* a, const char* hostname, uint16_t port, int preferIn6 ) +{ + struct addrinfo hints[1]; + struct addrinfo* res; + int ret; + + memset(hints, 0, sizeof(hints)); + hints->ai_family = preferIn6 ? AF_INET6 : AF_UNSPEC; + + ret = getaddrinfo(hostname, NULL, hints, &res); + if (ret != 0) { + int err; + + switch (ret) { + case EAI_AGAIN: /* server is down */ + case EAI_FAIL: /* server is sick */ + err = EHOSTDOWN; + break; + +#ifdef EAI_NODATA + case EAI_NODATA: +#endif + case EAI_NONAME: + err = ENOENT; + break; + + case EAI_MEMORY: + err = ENOMEM; + break; + + default: + err = EINVAL; + } + return _set_errno(err); + } + + /* Parse the returned list of addresses. */ + { + struct addrinfo* res_ipv4 = NULL; + struct addrinfo* res_ipv6 = NULL; + struct addrinfo* r; + + /* If preferIn6 is false, we stop on the first IPv4 address, + * otherwise, we stop on the first IPv6 one + */ + for (r = res; r != NULL; r = r->ai_next) { + if (r->ai_family == AF_INET && res_ipv4 == NULL) { + res_ipv4 = r; + if (!preferIn6) + break; + } + else if (r->ai_family == AF_INET6 && res_ipv6 == NULL) { + res_ipv6 = r; + if (preferIn6) + break; + } + } + + /* Select the best address in 'r', which will be NULL + * if there is no corresponding address. + */ + if (preferIn6) { + r = res_ipv6; + if (r == NULL) + r = res_ipv4; + } else { + r = res_ipv4; + if (r == NULL) + r = res_ipv6; + } + + if (r == NULL) { + ret = _set_errno(ENOENT); + goto Exit; + } + + /* Convert to a SockAddress */ + ret = sock_address_from_bsd( a, r->ai_addr, r->ai_addrlen ); + if (ret < 0) + goto Exit; + } + + /* need to set the port */ + switch (a->family) { + case SOCKET_INET: a->u.inet.port = port; break; + case SOCKET_IN6: a->u.in6.port = port; break; + default: ; + } + +Exit: + freeaddrinfo(res); + return ret; +} + +/* The Winsock headers for mingw lack some definitions */ +#ifndef AI_ADDRCONFIG +# define AI_ADDRCONFIG 0 +#endif + +SockAddress** +sock_address_list_create( const char* hostname, + const char* port, + unsigned flags ) +{ + SockAddress** list = NULL; + SockAddress* addr; + int nn, count, ret; + struct addrinfo ai, *res, *e; + + memset(&ai, 0, sizeof(ai)); + ai.ai_flags |= AI_ADDRCONFIG; + ai.ai_family = PF_UNSPEC; + + if (flags & SOCKET_LIST_FORCE_INET) + ai.ai_family = PF_INET; + else if (flags & SOCKET_LIST_FORCE_IN6) + ai.ai_family = PF_INET6; + + if (flags & SOCKET_LIST_PASSIVE) + ai.ai_flags |= AI_PASSIVE; + else + ai.ai_flags |= AI_CANONNAME; + + if (flags & SOCKET_LIST_DGRAM) + ai.ai_socktype = SOCK_DGRAM; + + while (1) { + struct addrinfo hints = ai; + + ret = getaddrinfo(hostname, port, &hints, &res); + if (ret == 0) + break; + + switch (ret) { +#ifdef EAI_ADDRFAMILY + case EAI_ADDRFAMILY: +#endif + case EAI_NODATA: + _set_errno(ENOENT); + break; + case EAI_FAMILY: + _set_errno(EAFNOSUPPORT); + break; + case EAI_AGAIN: + _set_errno(EAGAIN); + break; +#ifdef EAI_SYSTEM + case EAI_SYSTEM: + if (errno == EINTR) + continue; + break; +#endif + default: + _set_errno(EINVAL); + } + return NULL; + } + + /* allocate result list */ + for (count = 0, e = res; e != NULL; e = e->ai_next) + count += 1; + + AARRAY_NEW(list, count+1); + AARRAY_NEW(addr, count); + + for (nn = 0, e = res; e != NULL; e = e->ai_next) { + + ret = sock_address_from_bsd(addr, e->ai_addr, e->ai_addrlen); + if (ret < 0) + continue; + + list[nn++] = addr++; + } + list[nn] = NULL; + freeaddrinfo(res); + return list; +} + +SockAddress** +sock_address_list_create2(const char* host_and_port, unsigned flags ) +{ + char host_name[512]; + const char* actual_host_name = "localhost"; + // Parse host and port name. + const char* port_name = strchr(host_and_port, ':'); + if (port_name != NULL) { + int to_copy = MIN((int)sizeof(host_name)-1, port_name - host_and_port); + if (to_copy != 0) { + memcpy(host_name, host_and_port, to_copy); + host_name[to_copy] = '\0'; + actual_host_name = host_name; + port_name++; + } else { + return NULL; + } + } else { + port_name = host_and_port; + } + // Make sure that port_name is not empty. + if (port_name[0] == '\0') { + return NULL; + } + return sock_address_list_create(actual_host_name, port_name, flags); +} + +void +sock_address_list_free( SockAddress** list ) +{ + int nn; + SockAddress* addr; + + if (list == NULL) + return; + + addr = list[0]; + for (nn = 0; list[nn] != NULL; nn++) { + sock_address_done(list[nn]); + list[nn] = NULL; + } + AFREE(addr); + AFREE(list); +} + +int +sock_address_get_numeric_info( SockAddress* a, + char* host, + size_t hostlen, + char* serv, + size_t servlen ) +{ + struct sockaddr* saddr; + socklen_t slen; + int ret; + + switch (a->family) { + case SOCKET_INET: + saddr = (struct sockaddr*) &a->u.inet.address; + slen = sizeof(a->u.inet.address); + break; + +#if HAVE_IN6_SOCKET + case SOCKET_IN6: + saddr = (struct sockaddr*) &a->u.in6.address; + slen = sizeof(a->u.in6.address); + break; +#endif + default: + return _set_errno(EINVAL); + } + + ret = getnameinfo( saddr, slen, host, hostlen, serv, servlen, + NI_NUMERICHOST | NI_NUMERICSERV ); + + switch (ret) { + case 0: + break; + case EAI_AGAIN: + ret = EAGAIN; + break; + default: + ret = EINVAL; + } + return ret; +} + +int +socket_create( SocketFamily family, SocketType type ) +{ + int ret; + int sfamily = socket_family_to_bsd(family); + int stype = socket_type_to_bsd(type); + + if (sfamily < 0 || stype < 0) { + return _set_errno(EINVAL); + } + + QSOCKET_CALL(ret, socket(sfamily, stype, 0)); + if (ret < 0) + return _fix_errno(); + + return ret; +} + + +int +socket_create_inet( SocketType type ) +{ + return socket_create( SOCKET_INET, type ); +} + +#if HAVE_IN6_SOCKETS +int +socket_create_in6 ( SocketType type ) +{ + return socket_create( SOCKET_IN6, type ); +} +#endif + +#if HAVE_UNIX_SOCKETS +int +socket_create_unix( SocketType type ) +{ + return socket_create( SOCKET_UNIX, type ); +} +#endif + +int socket_can_read(int fd) +{ +#ifdef _WIN32 + unsigned long opt; + + if (ioctlsocket(fd, FIONREAD, &opt) < 0) + return 0; + + return opt; +#else + int opt; + + if (ioctl(fd, FIONREAD, &opt) < 0) + return 0; + + return opt; +#endif +} + +#define SOCKET_CALL(cmd) \ + int ret; \ + QSOCKET_CALL(ret, (cmd)); \ + if (ret < 0) \ + return _fix_errno(); \ + return ret; \ + +int +socket_send(int fd, const void* buf, int buflen) +{ + SOCKET_CALL(send(fd, buf, buflen, 0)) +} + +int +socket_send_oob( int fd, const void* buf, int buflen ) +{ + SOCKET_CALL(send(fd, buf, buflen, MSG_OOB)); +} + +int +socket_sendto(int fd, const void* buf, int buflen, const SockAddress* to) +{ + sockaddr_storage sa; + socklen_t salen; + + if (sock_address_to_bsd(to, &sa, &salen) < 0) + return -1; + + SOCKET_CALL(sendto(fd, buf, buflen, 0, sa.sa, salen)); +} + +int +socket_recv(int fd, void* buf, int len) +{ + SOCKET_CALL(recv(fd, buf, len, 0)); +} + +int +socket_recvfrom(int fd, void* buf, int len, SockAddress* from) +{ + sockaddr_storage sa; + socklen_t salen = sizeof(sa); + int ret; + + QSOCKET_CALL(ret,recvfrom(fd,buf,len,0,sa.sa,&salen)); + if (ret < 0) + return _fix_errno(); + + if (sock_address_from_bsd(from, &sa, salen) < 0) + return -1; + + return ret; +} + +int +socket_connect( int fd, const SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen; + + if (sock_address_to_bsd(address, &addr, &addrlen) < 0) + return -1; + + SOCKET_CALL(connect(fd,addr.sa,addrlen)); +} + +int +socket_bind( int fd, const SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen; + + if (sock_address_to_bsd(address, &addr, &addrlen) < 0) + return -1; + + SOCKET_CALL(bind(fd, addr.sa, addrlen)); +} + +int +socket_get_address( int fd, SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen = sizeof(addr); + int ret; + + QSOCKET_CALL(ret, getsockname(fd, addr.sa, &addrlen)); + if (ret < 0) + return _fix_errno(); + + return sock_address_from_bsd(address, &addr, addrlen); +} + +int +socket_get_peer_address( int fd, SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen = sizeof(addr); + int ret; + + QSOCKET_CALL(ret, getpeername(fd, addr.sa, &addrlen)); + if (ret < 0) + return _fix_errno(); + + return sock_address_from_bsd(address, &addr, addrlen); +} + +int +socket_listen( int fd, int backlog ) +{ + SOCKET_CALL(listen(fd, backlog)); +} + +int +socket_accept( int fd, SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen = sizeof(addr); + int ret; + + QSOCKET_CALL(ret, accept(fd, addr.sa, &addrlen)); + if (ret < 0) + return _fix_errno(); + + if (address) { + if (sock_address_from_bsd(address, &addr, addrlen) < 0) { + socket_close(ret); + return -1; + } + } + return ret; +} + +static int +socket_getoption(int fd, int domain, int option, int defaut) +{ + int ret; + while (1) { +#ifdef _WIN32 + DWORD opt = (DWORD)-1; +#else + int opt = -1; +#endif + socklen_t optlen = sizeof(opt); + ret = getsockopt(fd, domain, option, (char*)&opt, &optlen); + if (ret == 0) + return (int)opt; + if (errno != EINTR) + return defaut; + } +#undef OPT_CAST +} + + +SocketType socket_get_type(int fd) +{ + int so_type = socket_getoption(fd, SOL_SOCKET, SO_TYPE, -1); + return socket_type_from_bsd(so_type); +} + +int socket_set_nonblock(int fd) +{ +#ifdef _WIN32 + unsigned long opt = 1; + return ioctlsocket(fd, FIONBIO, &opt); +#else + int flags = fcntl(fd, F_GETFL); + return fcntl(fd, F_SETFL, flags | O_NONBLOCK); +#endif +} + +int socket_set_blocking(int fd) +{ +#ifdef _WIN32 + unsigned long opt = 0; + return ioctlsocket(fd, FIONBIO, &opt); +#else + int flags = fcntl(fd, F_GETFL); + return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); +#endif +} + +static int +socket_setoption(int fd, int domain, int option, int _flag) +{ +#ifdef _WIN32 + DWORD flag = (DWORD) _flag; +#else + int flag = _flag; +#endif + return setsockopt( fd, domain, option, (const char*)&flag, sizeof(flag) ); +} + +int socket_set_xreuseaddr(int fd) +{ +#ifdef _WIN32 + /* on Windows, SO_REUSEADDR is used to indicate that several programs can + * bind to the same port. this is completely different from the Unix + * semantics. instead of SO_EXCLUSIVEADDR to ensure that explicitely prevent + * this. + */ + return socket_setoption(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, 1); +#else + return socket_setoption(fd, SOL_SOCKET, SO_REUSEADDR, 1); +#endif +} + + +int socket_set_oobinline(int fd) +{ + return socket_setoption(fd, SOL_SOCKET, SO_OOBINLINE, 1); +} + + +int socket_set_nodelay(int fd) +{ + return socket_setoption(fd, IPPROTO_TCP, TCP_NODELAY, 1); +} + +int socket_set_ipv6only(int fd) +{ +/* IPV6_ONLY is only supported since Vista on Windows, + * and the Mingw headers lack its definition anyway. + */ +#if defined(_WIN32) && !defined(IPV6_V6ONLY) + return 0; +#else + return socket_setoption(fd, IPPROTO_IPV6, IPV6_V6ONLY, 1); +#endif +} + + +int socket_get_error(int fd) +{ + return socket_getoption(fd, SOL_SOCKET, SO_ERROR, -1); +} + +#ifdef _WIN32 +#include <stdlib.h> + +static void socket_cleanup(void) +{ + WSACleanup(); +} + +int socket_init(void) +{ + WSADATA Data; + int ret, err; + + ret = WSAStartup(MAKEWORD(2,2), &Data); + if (ret != 0) { + err = WSAGetLastError(); + return -1; + } + atexit(socket_cleanup); + return 0; +} + +#else /* !_WIN32 */ + +int socket_init(void) +{ + return 0; /* nothing to do on Unix */ +} + +#endif /* !_WIN32 */ + +#ifdef _WIN32 + +void +socket_close( int fd ) +{ + int old_errno = errno; + + shutdown( fd, SD_BOTH ); + /* we want to drain the socket before closing it */ + //qemu_set_fd_handler( fd, socket_close_handler, NULL, (void*)fd ); + closesocket(fd); + + errno = old_errno; +} + +#else /* !_WIN32 */ + +#include <unistd.h> + +void +socket_close( int fd ) +{ + int old_errno = errno; + + shutdown( fd, SHUT_RDWR ); + close( fd ); + + errno = old_errno; +} + +#endif /* !_WIN32 */ + + +static int +socket_bind_server( int s, const SockAddress* to, SocketType type ) +{ + socket_set_xreuseaddr(s); + + if (socket_bind(s, to) < 0) { + D("could not bind server socket address %s: %s", + sock_address_to_string(to), errno_str); + goto FAIL; + } + + if (type == SOCKET_STREAM) { + if (socket_listen(s, 4) < 0) { + D("could not listen server socket %s: %s", + sock_address_to_string(to), errno_str); + goto FAIL; + } + } + return s; + +FAIL: + socket_close(s); + return -1; +} + + +static int +socket_connect_client( int s, const SockAddress* to ) +{ + if (socket_connect(s, to) < 0) { + D( "could not connect client socket to %s: %s\n", + sock_address_to_string(to), errno_str ); + socket_close(s); + return -1; + } + + socket_set_nonblock( s ); + return s; +} + + +static int +socket_in_server( int address, int port, SocketType type ) +{ + SockAddress addr; + int s; + + sock_address_init_inet( &addr, address, port ); + s = socket_create_inet( type ); + if (s < 0) + return -1; + + return socket_bind_server( s, &addr, type ); +} + + +static int +socket_in_client( SockAddress* to, SocketType type ) +{ + int s; + + s = socket_create_inet( type ); + if (s < 0) return -1; + + return socket_connect_client( s, to ); +} + + +int +socket_loopback_server( int port, SocketType type ) +{ + return socket_in_server( SOCK_ADDRESS_INET_LOOPBACK, port, type ); +} + +int +socket_loopback_client( int port, SocketType type ) +{ + SockAddress addr; + + sock_address_init_inet( &addr, SOCK_ADDRESS_INET_LOOPBACK, port ); + return socket_in_client( &addr, type ); +} + + +int +socket_network_client( const char* host, int port, SocketType type ) +{ + SockAddress addr; + + if (sock_address_init_resolve( &addr, host, port, 0) < 0) + return -1; + + return socket_in_client( &addr, type ); +} + + +int +socket_anyaddr_server( int port, SocketType type ) +{ + return socket_in_server( SOCK_ADDRESS_INET_ANY, port, type ); +} + +int +socket_accept_any( int server_fd ) +{ + int fd; + + QSOCKET_CALL(fd, accept( server_fd, NULL, 0 )); + if (fd < 0) { + D( "could not accept client connection from fd %d: %s", + server_fd, errno_str ); + return -1; + } + + /* set to non-blocking */ + socket_set_nonblock( fd ); + return fd; +} + + +#if HAVE_UNIX_SOCKETS + +int +socket_unix_server( const char* name, SocketType type ) +{ + SockAddress addr; + int s, ret; + + s = socket_create_unix( type ); + if (s < 0) + return -1; + + sock_address_init_unix( &addr, name ); + + do { + ret = unlink( name ); + } while (ret < 0 && errno == EINTR); + + ret = socket_bind_server( s, &addr, type ); + + sock_address_done( &addr ); + return ret; +} + +int +socket_unix_client( const char* name, SocketType type ) +{ + SockAddress addr; + int s, ret; + + s = socket_create_unix(type); + if (s < 0) + return -1; + + sock_address_init_unix( &addr, name ); + + ret = socket_connect_client( s, &addr ); + + sock_address_done( &addr ); + return ret; +} + +#endif /* HAVE_UNIX_SOCKETS */ + + + +int +socket_pair(int *fd1, int *fd2) +{ +#ifndef _WIN32 + int fds[2]; + int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); + + if (!ret) { + socket_set_nonblock(fds[0]); + socket_set_nonblock(fds[1]); + *fd1 = fds[0]; + *fd2 = fds[1]; + } + return ret; +#else /* _WIN32 */ + /* on Windows, select() only works with network sockets, which + * means we absolutely cannot use Win32 PIPEs to implement + * socket pairs with the current event loop implementation. + * We're going to do like Cygwin: create a random pair + * of localhost TCP sockets and connect them together + */ + int s0, s1, s2, port; + struct sockaddr_in sockin; + socklen_t len; + + /* first, create the 'server' socket. + * a port number of 0 means 'any port between 1024 and 5000. + * see Winsock bind() documentation for details */ + s0 = socket_loopback_server( 0, SOCK_STREAM ); + if (s0 < 0) + return -1; + + /* now connect a client socket to it, we first need to + * extract the server socket's port number */ + len = sizeof sockin; + if (getsockname(s0, (struct sockaddr*) &sockin, &len) < 0) { + closesocket (s0); + return -1; + } + + port = ntohs(sockin.sin_port); + s2 = socket_loopback_client( port, SOCK_STREAM ); + if (s2 < 0) { + closesocket(s0); + return -1; + } + + /* we need to accept the connection on the server socket + * this will create the second socket for the pair + */ + len = sizeof sockin; + s1 = accept(s0, (struct sockaddr*) &sockin, &len); + if (s1 == INVALID_SOCKET) { + closesocket (s0); + closesocket (s2); + return -1; + } + socket_set_nonblock(s1); + + /* close server socket */ + closesocket(s0); + *fd1 = s1; + *fd2 = s2; + return 0; +#endif /* _WIN32 */ +} + + + +int +socket_mcast_inet_add_membership( int s, uint32_t ip ) +{ + struct ip_mreq imr; + + imr.imr_multiaddr.s_addr = htonl(ip); + imr.imr_interface.s_addr = htonl(INADDR_ANY); + + if ( setsockopt( s, IPPROTO_IP, IP_ADD_MEMBERSHIP, + (const char *)&imr, + sizeof(struct ip_mreq)) < 0 ) + { + return _fix_errno(); + } + return 0; +} + +int +socket_mcast_inet_drop_membership( int s, uint32_t ip ) +{ + struct ip_mreq imr; + + imr.imr_multiaddr.s_addr = htonl(ip); + imr.imr_interface.s_addr = htonl(INADDR_ANY); + + if ( setsockopt( s, IPPROTO_IP, IP_DROP_MEMBERSHIP, + (const char *)&imr, + sizeof(struct ip_mreq)) < 0 ) + { + return _fix_errno(); + } + return 0; +} + +int +socket_mcast_inet_set_loop( int s, int enabled ) +{ + return socket_setoption( s, IPPROTO_IP, IP_MULTICAST_LOOP, !!enabled ); +} + +int +socket_mcast_inet_set_ttl( int s, int ttl ) +{ + return socket_setoption( s, IPPROTO_IP, IP_MULTICAST_TTL, ttl ); +} + + +char* +host_name( void ) +{ + static char buf[256]; /* 255 is the max host name length supported by DNS */ + int ret; + + QSOCKET_CALL(ret, gethostname(buf, sizeof(buf))); + + if (ret < 0) + return "localhost"; + else + return buf; +} diff --git a/emulator/opengl/tests/event_injector/sockets.h b/emulator/opengl/tests/event_injector/sockets.h new file mode 100644 index 0000000..ea48c5f --- /dev/null +++ b/emulator/opengl/tests/event_injector/sockets.h @@ -0,0 +1,432 @@ +/* +* 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. +*/ +/* headers to use the BSD sockets */ +#ifndef ANDROID_SOCKET_H +#define ANDROID_SOCKET_H + +#include <stddef.h> +#include <stdint.h> +#include <errno.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* we're going to hide the implementation details of sockets behind + * a simple wrapper interface declared here. + * + * all socket operations set the global 'errno' variable on error. + * this is unlike Winsock which instead modifies another internal + * variable accessed through WSAGetLastError() and WSASetLastError() + */ + +/* the wrapper will convert any Winsock error message into an errno + * code for you. There are however a few standard Unix error codes + * that are not defined by the MS C library headers, so we add them + * here. We use the official Winsock error codes, which are documented + * even though we don't want to include the Winsock headers + */ +#ifdef _WIN32 +# ifndef EINTR +# define EINTR 10004 +# endif +# ifndef EAGAIN +# define EAGAIN 10035 +# endif +# ifndef EWOULDBLOCK +# define EWOULDBLOCK EAGAIN +# endif +# ifndef EINPROGRESS +# define EINPROGRESS 10036 +# endif +# ifndef EALREADY +# define EALREADY 10037 +# endif +# ifndef EDESTADDRREQ +# define EDESTADDRREQ 10039 +# endif +# ifndef EMSGSIZE +# define EMSGSIZE 10040 +# endif +# ifndef EPROTOTYPE +# define EPROTOTYPE 10041 +# endif +# ifndef ENOPROTOOPT +# define ENOPROTOOPT 10042 +# endif +# ifndef EAFNOSUPPORT +# define EAFNOSUPPORT 10047 +# endif +# ifndef EADDRINUSE +# define EADDRINUSE 10048 +# endif +# ifndef EADDRNOTAVAIL +# define EADDRNOTAVAIL 10049 +# endif +# ifndef ENETDOWN +# define ENETDOWN 10050 +# endif +# ifndef ENETUNREACH +# define ENETUNREACH 10051 +# endif +# ifndef ENETRESET +# define ENETRESET 10052 +# endif +# ifndef ECONNABORTED +# define ECONNABORTED 10053 +# endif +# ifndef ECONNRESET +# define ECONNRESET 10054 +# endif +# ifndef ENOBUFS +# define ENOBUFS 10055 +# endif +# ifndef EISCONN +# define EISCONN 10056 +# endif +# ifndef ENOTCONN +# define ENOTCONN 10057 +# endif +# ifndef ESHUTDOWN +# define ESHUTDOWN 10058 +# endif +# ifndef ETOOMANYREFS +# define ETOOMANYREFS 10059 +# endif +# ifndef ETIMEDOUT +# define ETIMEDOUT 10060 +# endif +# ifndef ECONNREFUSED +# define ECONNREFUSED 10061 +# endif +# ifndef ELOOP +# define ELOOP 10062 +# endif +# ifndef EHOSTDOWN +# define EHOSTDOWN 10064 +# endif +# ifndef EHOSTUNREACH +# define EHOSTUNREACH 10065 +# endif +#endif /* _WIN32 */ + +/* Define 'errno_str' as a handy macro to return the string + * corresponding to a given errno code. On Unix, this is + * equivalent to strerror(errno), but on Windows, this will + * take care of Winsock-originated errors as well. + */ +#ifdef _WIN32 + extern const char* _errno_str(void); +# define errno_str _errno_str() +#else +# define errno_str strerror(errno) +#endif + +/* always enable IPv6 sockets for now. + * the QEMU internal router is not capable of + * supporting them, but we plan to replace it + * with something better in the future. + */ +#define HAVE_IN6_SOCKETS 1 + +/* Unix sockets are not available on Win32 */ +#ifndef _WIN32 +# define HAVE_UNIX_SOCKETS 1 +#endif + +/* initialize the socket sub-system. this must be called before + * using any of the declarations below. + */ +int socket_init( void ); + +/* return the name of the current host */ +char* host_name( void ); + +/* supported socket types */ +typedef enum { + SOCKET_DGRAM = 0, + SOCKET_STREAM +} SocketType; + +/* supported socket families */ +typedef enum { + SOCKET_UNSPEC, + SOCKET_INET, + SOCKET_IN6, + SOCKET_UNIX +} SocketFamily; + +/* Generic socket address structure. Note that for Unix + * sockets, the path is stored in a heap-allocated block, + * unless the 'owner' field is cleared. If this is the case, + */ +typedef struct { + SocketFamily family; + union { + struct { + uint16_t port; + uint32_t address; + } inet; + struct { + uint16_t port; + uint8_t address[16]; + } in6; + struct { + int owner; + const char* path; + } _unix; + } u; +} SockAddress; + +#define SOCK_ADDRESS_INET_ANY 0x00000000 +#define SOCK_ADDRESS_INET_LOOPBACK 0x7f000001 + +/* initialize a new IPv4 socket address, the IP address and port are + * in host endianess. + */ +void sock_address_init_inet( SockAddress* a, uint32_t ip, uint16_t port ); + +/* Initialize an IPv6 socket address, the address is in network order + * and the port in host endianess. + */ +#if HAVE_IN6_SOCKETS +void sock_address_init_in6 ( SockAddress* a, const uint8_t* ip6[16], uint16_t port ); +#endif + +/* Intialize a Unix socket address, this will copy the 'path' string into the + * heap. You need to call sock_address_done() to release the copy + */ +#if HAVE_UNIX_SOCKETS +void sock_address_init_unix( SockAddress* a, const char* path ); +#endif + +/* Finalize a socket address, only needed for now for Unix addresses */ +void sock_address_done( SockAddress* a ); + +int sock_address_equal( const SockAddress* a, const SockAddress* b ); + +/* return a static string describing the address */ +const char* sock_address_to_string( const SockAddress* a ); + +static __inline__ +SocketFamily sock_address_get_family( const SockAddress* a ) +{ + return a->family; +} + +/* return the port number of a given socket address, or -1 if it's a Unix one */ +int sock_address_get_port( const SockAddress* a ); + +/* set the port number of a given socket address, don't do anything for Unix ones */ +void sock_address_set_port( SockAddress* a, uint16_t port ); + +/* return the path of a given Unix socket, returns NULL for non-Unix ones */ +const char* sock_address_get_path( const SockAddress* a ); + +/* return the inet address, or -1 if it's not SOCKET_INET */ +int sock_address_get_ip( const SockAddress* a ); + +/* bufprint a socket address into a human-readable string */ +char* bufprint_sock_address( char* p, char* end, const SockAddress* a ); + +/* resolve a hostname or decimal IPv4/IPv6 address into a socket address. + * returns 0 on success, or -1 on failure. Note that the values or errno + * set by this function are the following: + * + * EINVAL : invalid argument + * EHOSTDOWN : could not reach DNS server + * ENOENT : no host with this name, or host doesn't have any IP address + * ENOMEM : not enough memory to perform request + */ +int sock_address_init_resolve( SockAddress* a, + const char* hostname, + uint16_t port, + int preferIn6 ); + +int sock_address_get_numeric_info( SockAddress* a, + char* host, + size_t hostlen, + char* serv, + size_t servlen ); + +/* Support for listing all socket addresses of a given host */ +enum { + SOCKET_LIST_PASSIVE = (1 << 0), + SOCKET_LIST_FORCE_INET = (1 << 1), + SOCKET_LIST_FORCE_IN6 = (1 << 2), + SOCKET_LIST_DGRAM = (1 << 3), +}; + +/* resolve a host and service/port name into a list of SockAddress objects. + * returns a NULL-terminated array of SockAddress pointers on success, + * or NULL in case of failure, with the value of errno set to one of the + * following: + * + * EINVAL : invalid argument + * EHOSTDOWN : could not reach DNS server + * ENOENT : no host with this name, or host doesn't have IP address + * ENOMEM : not enough memory to perform request + * + * other system-level errors can also be set depending on the host sockets + * implementation. + * + * This function loops on EINTR so the caller shouldn't have to check for it. + */ +SockAddress** sock_address_list_create( const char* hostname, + const char* port, + unsigned flags ); + +/* resolve a string containing host and port name into a list of SockAddress + * objects. Parameter host_and_port should be in format [host:]port, where + * 'host' addresses the machine and must be resolvable into an IP address, and + * 'port' is a decimal numeric value for the port. 'host' is optional, and if + * ommited, localhost will be used. + * returns a NULL-terminated array of SockAddress pointers on success, + * or NULL in case of failure, with the value of errno set to one of the + * following: + * + * EINVAL : invalid argument + * EHOSTDOWN : could not reach DNS server + * ENOENT : no host with this name, or host doesn't have IP address + * ENOMEM : not enough memory to perform request + * + * other system-level errors can also be set depending on the host sockets + * implementation. + * + * This function loops on EINTR so the caller shouldn't have to check for it. + */ +SockAddress** sock_address_list_create2(const char* host_and_port, + unsigned flags ); + +void sock_address_list_free( SockAddress** list ); + +/* create a new socket, return the socket number of -1 on failure */ +int socket_create( SocketFamily family, SocketType type ); + +/* create a new socket intended for IPv4 communication. returns the socket number, + * or -1 on failure. + */ +int socket_create_inet( SocketType type ); + +/* create a new socket intended for IPv6 communication. returns the socket number, + * or -1 on failure. + */ +#if HAVE_IN6_SOCKETS +int socket_create_in6 ( SocketType type ); +#endif + +/* create a unix/local domain socket. returns the socket number, + * or -1 on failure. + */ +#if HAVE_UNIX_SOCKETS +int socket_create_unix( SocketType type ); +#endif + +/* return the type of a given socket */ +SocketType socket_get_type(int fd); + +/* set SO_REUSEADDR on Unix, SO_EXCLUSIVEADDR on Windows */ +int socket_set_xreuseaddr(int fd); + +/* set socket in non-blocking mode */ +int socket_set_nonblock(int fd); + +/* set socket in blocking mode */ +int socket_set_blocking(int fd); + +/* disable the TCP Nagle algorithm for lower latency */ +int socket_set_nodelay(int fd); + +/* send OOB data inline for this socket */ +int socket_set_oobinline(int fd); + +/* force listening to IPv6 interfaces only */ +int socket_set_ipv6only(int fd); + +/* retrieve last socket error code */ +int socket_get_error(int fd); + +/* close an opened socket. Note that this is unlike the Unix 'close' because: + * - it will properly shutdown the socket in the background + * - it does not modify errno + */ +void socket_close( int fd ); + +/* the following functions are equivalent to the BSD sockets ones + */ +int socket_recv ( int fd, void* buf, int buflen ); +int socket_recvfrom( int fd, void* buf, int buflen, SockAddress* from ); + +int socket_send ( int fd, const void* buf, int buflen ); +int socket_send_oob( int fd, const void* buf, int buflen ); +int socket_sendto( int fd, const void* buf, int buflen, const SockAddress* to ); + +int socket_connect( int fd, const SockAddress* address ); +int socket_bind( int fd, const SockAddress* address ); +int socket_get_address( int fd, SockAddress* address ); +int socket_get_peer_address( int fd, SockAddress* address ); +int socket_listen( int fd, int backlog ); +int socket_accept( int fd, SockAddress* address ); + +/* returns the number of bytes that can be read from a socket */ +int socket_can_read( int fd ); + +/* this call creates a pair of non-blocking sockets connected + * to each other. this is equivalent to calling the Unix function: + * socketpair(AF_LOCAL,SOCK_STREAM,0,&fds) + * + * on Windows, this will use a pair of TCP loopback sockets instead + * returns 0 on success, -1 on error. + */ +int socket_pair(int *fd1, int *fd2); + +/* create a server socket listening on the host's loopback interface */ +int socket_loopback_server( int port, SocketType type ); + +/* connect to a port on the host's loopback interface */ +int socket_loopback_client( int port, SocketType type ); + +/* create a server socket listening to a Unix domain path */ +#if HAVE_UNIX_SOCKETS +int socket_unix_server( const char* name, SocketType type ); +#endif + +/* create a Unix sockets and connects it to a Unix server */ +#if HAVE_UNIX_SOCKETS +int socket_unix_client( const char* name, SocketType type ); +#endif + +/* create an IPv4 client socket and connect it to a given host */ +int socket_network_client( const char* host, int port, SocketType type ); + +/* create an IPv4 socket and binds it to a given port of the host's interface */ +int socket_anyaddr_server( int port, SocketType type ); + +/* accept a connection from the host's any interface, return the new socket + * descriptor or -1 */ +int socket_accept_any( int server_fd ); + + +int socket_mcast_inet_add_membership( int s, uint32_t ip ); +int socket_mcast_inet_drop_membership( int s, uint32_t ip ); +int socket_mcast_inet_set_loop( int s, int enabled ); +int socket_mcast_inet_set_ttl( int s, int ttl ); + +#ifdef __cplusplus +} +#endif + +#endif /* ANDROID_SOCKET_H */ diff --git a/emulator/opengl/tests/gles_android_wrapper/Android.mk b/emulator/opengl/tests/gles_android_wrapper/Android.mk new file mode 100644 index 0000000..f7c8fed --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/Android.mk @@ -0,0 +1,80 @@ +LOCAL_PATH := $(call my-dir) + +#### libGLESv1_CM_emul.so +$(call emugl-begin-shared-library,libGLESv1_CM_emul) +$(call emugl-import,libGLESv1_enc) +$(call emugl-gen-wrapper,$(EMUGL_PATH)/system/GLESv1_enc,gl) +$(call emugl-set-shared-library-subpath,egl) + +LOCAL_SRC_FILES += glesv1_emul_ifc.cpp + +$(call emugl-end-module) + +emulatorOpengl := $(LOCAL_PATH)/../.. +logTag := -DLOG_TAG=\"eglWrapper\" +EMUGEN = $(BUILD_OUT_EXECUTABLES)/emugen +## comment for no debug +#debugFlags = -g -O0 + +#### libGLESv2_CM_emul.so +$(call emugl-begin-shared-library, libGLESv2_emul) +$(call emugl-import,libGLESv2_enc) +$(call emugl-gen-wrapper,$(EMUGL_PATH)/system/GLESv2_enc,gl2) +LOCAL_SRC_FILES += glesv2_emul_ifc.cpp +$(call emugl-set-shared-library-subpath,egl) +$(call emugl-end-module) + +##### libEGL_emul.so ########### + +# THE FOLLOWING DOESN'T WORK YET +# +$(call emugl-begin-shared-library,libEGL_emul) +$(call emugl-import,libut_rendercontrol_enc libGLESv1_CM_emul libGLESv2_emul libOpenglSystemCommon) + +$(call emugl-set-shared-library-subpath,egl) +LOCAL_CFLAGS += $(logTag) + +LOCAL_SRC_FILES := \ + egl.cpp \ + egl_dispatch.cpp \ + ServerConnection.cpp \ + ThreadInfo.cpp + +$(call emugl-end-module) + +#### egl.cfg #### + +# Ensure that this file is only copied to emulator-specific builds. +# Other builds are device-specific and will provide their own +# version of this file to point to the appropriate HW EGL libraries. +# +ifneq (,$(filter full full_x86 sdk sdk_x86,$(TARGET_PRODUCT))) +ifeq (,$(BUILD_EMULATOR_OPENGL_DRIVER)) +include $(CLEAR_VARS) + +LOCAL_MODULE := egl.cfg +LOCAL_SRC_FILES := $(LOCAL_MODULE) + +LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/egl +LOCAL_MODULE_TAGS := debug +LOCAL_MODULE_CLASS := ETC + +include $(BUILD_PREBUILT) +endif # building 'real' driver BUILD_EMULATOR_OPENGL_DRIVER +endif # TARGET_PRODUCT in 'full sdk full_x86 sdk_x86' + +#### gles_emul.cfg #### +include $(CLEAR_VARS) + +LOCAL_MODULE := gles_emul.cfg +LOCAL_SRC_FILES := $(LOCAL_MODULE) + +LOCAL_MODULE_PATH := $(TARGET_OUT)/etc +LOCAL_MODULE_TAGS := debug +LOCAL_MODULE_CLASS := ETC + +include $(BUILD_PREBUILT) + + + + diff --git a/emulator/opengl/tests/gles_android_wrapper/ApiInitializer.h b/emulator/opengl/tests/gles_android_wrapper/ApiInitializer.h new file mode 100644 index 0000000..793c735 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ApiInitializer.h @@ -0,0 +1,42 @@ +/* +* Copyright 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. +*/ + +#ifndef _API_INITIALIZER_H_ +#define _API_INITIALIZER_H_ +#include <stdlib.h> +#include <dlfcn.h> + +class ApiInitializer { +public: + ApiInitializer(void *dso) : + m_dso(dso) { + } + static void *s_getProc(const char *name, void *userData) { + ApiInitializer *self = (ApiInitializer *)userData; + return self->getProc(name); + } +private: + void *m_dso; + void *getProc(const char *name) { + void *symbol = NULL; + if (m_dso) { + symbol = dlsym(m_dso, name); + } + return symbol; + } +}; + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/CleanSpec.mk b/emulator/opengl/tests/gles_android_wrapper/CleanSpec.mk new file mode 100644 index 0000000..f56383a --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/CleanSpec.mk @@ -0,0 +1,50 @@ +# Copyright (C) 2007 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. +# + +# If you don't need to do a full clean build but would like to touch +# a file or delete some intermediate files, add a clean step to the end +# of the list. These steps will only be run once, if they haven't been +# run before. +# +# E.g.: +# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) +# +# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with +# files that are missing or have been moved. +# +# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. +# Use $(OUT_DIR) to refer to the "out" directory. +# +# If you need to re-do something that's already mentioned, just copy +# the command and add it to the bottom of the list. E.g., if a change +# that you made last week required touching a file and a change you +# made today requires touching the same file, just copy the old +# touch step and add it to the end of the list. +# +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ + +# For example: +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) +#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) +#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) + +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ +$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/SHARED_LIBRARIES/libGLES_emul_intermediates) diff --git a/emulator/opengl/tests/gles_android_wrapper/ServerConnection.cpp b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.cpp new file mode 100644 index 0000000..ff4e390 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.cpp @@ -0,0 +1,125 @@ +/* +* 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 <stdio.h> +#include <stdlib.h> +#include "ServerConnection.h" +#include "TcpStream.h" +#include "QemuPipeStream.h" +#include <cutils/log.h> +#include "ThreadInfo.h" + +gl_client_context_t *ServerConnection::s_getGlContext() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (ti->serverConn) { + return ti->serverConn->m_glEnc; + } + return NULL; +} + +gl2_client_context_t *ServerConnection::s_getGl2Context() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (ti->serverConn) { + return ti->serverConn->m_gl2Enc; + } + return NULL; +} + +ServerConnection *ServerConnection::s_getServerConnection() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (!ti->serverConn) + { + ti->serverConn = new ServerConnection(); + if (ti->serverConn->create() < 0) { + delete ti->serverConn; + ti->serverConn = NULL; + } + } + + return ti->serverConn; +} + + +ServerConnection::ServerConnection() : + m_stream(NULL), + m_glEnc(NULL), + m_ut_enc(NULL) +{ +} + +ServerConnection::~ServerConnection() +{ + delete m_ut_enc; + delete m_glEnc; + delete m_stream; +} + + + +int ServerConnection::create(size_t bufsize, + const char *defaultServer) +{ + /* XXX: Make configurable through system property */ + int useQemuPipe = 1; + + if (m_stream != NULL) delete(m_stream); + + if (useQemuPipe) { + QemuPipeStream* pipeStream = new QemuPipeStream(bufsize); + + if (pipeStream->connect() < 0) { + ALOGE("couldn't connect to host server\n"); + delete pipeStream; + return -1; + } + m_stream = pipeStream; + } + else /* !useQemuPipe */ + { + TcpStream* tcpStream = new TcpStream(bufsize); + + char *s = getenv(ENV_RGL_SERVER); + char *hostname; + if (s == NULL) { + hostname = strdup(defaultServer); + } else { + hostname = strdup(s); + } + + if (tcpStream->connect(hostname, CODEC_SERVER_PORT) < 0) { + ALOGE("couldn't connect to %s\n", hostname); + free(hostname); + delete tcpStream; + return -1; + } + LOGI("connecting to server %s\n", hostname); + free(hostname); + + m_stream = tcpStream; + } + + m_glEnc = new GLEncoder(m_stream); + m_glEnc->setContextAccessor(s_getGlContext); + + m_gl2Enc = new GL2Encoder(m_stream); + m_gl2Enc->setContextAccessor(s_getGl2Context); + + m_ut_enc = new ut_rendercontrol_encoder_context_t(m_stream); + return 0; +} + diff --git a/emulator/opengl/tests/gles_android_wrapper/ServerConnection.h b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.h new file mode 100644 index 0000000..84f40d8 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.h @@ -0,0 +1,55 @@ +/* +* 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. +*/ +#ifndef _SERVER_CONNECTION_H +#define _SERVER_CONNECTION_H + +#include "GLEncoder.h" +#include "GL2Encoder.h" +#include "IOStream.h" +#include "codec_defs.h" +#include "ut_rendercontrol_enc.h" +#include <pthread.h> + +#define ENV_RGL_SERVER "RGL_SERVER" +#define RGL_DEFAULT_SERVER "10.0.2.2" + +class ServerConnection { +public: + ~ServerConnection(); + int create(size_t buf_size = 4 * 1024 * 1024, const char *defaultServer = RGL_DEFAULT_SERVER); + static gl_client_context_t *s_getGlContext(); + static ServerConnection *s_getServerConnection(); + static gl2_client_context_t *s_getGl2Context(); + GLEncoder *glEncoder() { return m_glEnc; } + GL2Encoder *gl2Encoder() { return m_gl2Enc; } + ut_rendercontrol_encoder_context_t * utEnc() { return m_ut_enc; } + +private: + ServerConnection(); + +private: + static pthread_key_t s_glKey; + static pthread_key_t s_connectionKey; + static void s_initKeys(); + IOStream *m_stream; + GLEncoder *m_glEnc; + GL2Encoder *m_gl2Enc; + ut_rendercontrol_encoder_context_t *m_ut_enc; + +}; + + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.cpp b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.cpp new file mode 100644 index 0000000..5bf6a7d --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.cpp @@ -0,0 +1,39 @@ +/* +* 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 "ThreadInfo.h" +#include "cutils/threads.h" + +thread_store_t s_tls = THREAD_STORE_INITIALIZER; + +static void tlsDestruct(void *ptr) +{ + if (ptr) { + EGLThreadInfo *ti = (EGLThreadInfo *)ptr; + delete ti->serverConn; + delete ti; + } +} + +EGLThreadInfo *getEGLThreadInfo() +{ + EGLThreadInfo *ti = (EGLThreadInfo *)thread_store_get(&s_tls); + if (ti) return ti; + + ti = new EGLThreadInfo(); + thread_store_set(&s_tls, ti, tlsDestruct); + + return ti; +} diff --git a/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.h b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.h new file mode 100644 index 0000000..f748a39 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.h @@ -0,0 +1,49 @@ +/* +* 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. +*/ +#ifndef _THREAD_INFO_H +#define _THREAD_INFO_H + +#include "ServerConnection.h" +#include <EGL/egl.h> + +struct EGLWrapperContext +{ + EGLWrapperContext(EGLContext p_aglContext, int _version) { + aglContext = p_aglContext; + clientState = NULL; + version = _version; + } + + ~EGLWrapperContext() { + delete clientState; + } + + EGLContext aglContext; + GLClientState *clientState; + int version; +}; + +struct EGLThreadInfo +{ + EGLThreadInfo() : currentContext(NULL), serverConn(NULL) {} + + EGLWrapperContext *currentContext; + ServerConnection *serverConn; +}; + + +EGLThreadInfo *getEGLThreadInfo(); +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/egl.cfg b/emulator/opengl/tests/gles_android_wrapper/egl.cfg new file mode 100644 index 0000000..891b07d --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl.cfg @@ -0,0 +1 @@ +0 0 emul
\ No newline at end of file diff --git a/emulator/opengl/tests/gles_android_wrapper/egl.cpp b/emulator/opengl/tests/gles_android_wrapper/egl.cpp new file mode 100644 index 0000000..1e2e456 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl.cpp @@ -0,0 +1,663 @@ +/* +* 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. +*/ + +// +// WARNING -------------------------- WARNING +// This code meant to be used for testing purposes only. It is not production +// level quality. +// Use on your own risk !! +// + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include "egl_dispatch.h" +#include "egl_ftable.h" +#include <cutils/process_name.h> +#include <cutils/log.h> +#include "ServerConnection.h" +#include "ThreadInfo.h" +#include <pthread.h> +#include "gl_wrapper_context.h" +#include "gl2_wrapper_context.h" + +#define GLES_EMUL_TARGETS_FILE "/system/etc/gles_emul.cfg" +// implementation libraries; +#define GLESv1_enc_LIB "/system/lib/libGLESv1_enc.so" +#define GLESv2_enc_LIB "/system/lib/libGLESv2_enc.so" +#define GLES_android_LIB "/system/lib/egl/libGLES_android.so" +// driver libraries; +#define GLESv1_DRIVER "/system/lib/egl/libGLESv1_CM_emul.so" +#define GLESv2_DRIVER "/system/lib/egl/libGLESv2_emul.so" + + +static struct egl_dispatch *s_dispatch = NULL; +pthread_once_t dispatchTablesInitialized = PTHREAD_ONCE_INIT; + +static bool s_needEncode = false; + +static gl_wrapper_context_t *g_gl_dispatch = NULL; +static gl2_wrapper_context_t *g_gl2_dispatch = NULL; + +template <class T> +int initApi(const char *driverLibName, const char *implLibName, T **dispatchTable, T *(*accessor)()) +{ + void *driverLib = dlopen(driverLibName, RTLD_NOW | RTLD_LOCAL); + if (driverLib == NULL) { + ALOGE("failed to load %s : %s\n", driverLibName, dlerror()); + return -1; + } + + typedef T *(*createFcn_t)(void *, T *(*accessor)()); + createFcn_t createFcn; + createFcn = (createFcn_t) dlsym(driverLib, "createFromLib"); + if (createFcn == NULL) { + ALOGE("failed to load createFromLib constructor function\n"); + return -1; + } + + void *implLib = dlopen(implLibName, RTLD_NOW | RTLD_LOCAL); + if (implLib == NULL) { + ALOGE("couldn't open %s", implLibName); + return -2; + } + *dispatchTable = createFcn(implLib, accessor); + if (*dispatchTable == NULL) { + return -3; + } + + // XXX - we do close the impl library since it doesn't have data, as far as we concern. + dlclose(implLib); + + // XXX - we do not dlclose the driver library, so its not initialized when + // later loaded by android - is this required? + ALOGD("loading %s into %s complete\n", implLibName, driverLibName); + return 0; + +} + +static gl_wrapper_context_t *getGLContext() +{ + return g_gl_dispatch; +} + +static gl2_wrapper_context_t *getGL2Context() +{ + return g_gl2_dispatch; +} + +const char *getProcName() +{ + static const char *procname = NULL; + + if (procname == NULL) { + const char *str = get_process_name(); + if (strcmp(str, "unknown") != 0) { + procname = str; + } else { + // we need to obtain our process name from the command line; + FILE *fp = fopen("/proc/self/cmdline", "rt"); + if (fp == NULL) { + ALOGE("couldn't open /proc/self/cmdline\n"); + return NULL; + } + + char line[1000]; + if (fgets(line, sizeof(line), fp) == NULL) { + ALOGE("couldn't read the self cmdline from \n"); + fclose(fp); + return NULL; + } + fclose(fp); + + if (line[0] == '\0') { + ALOGE("cmdline is empty\n"); + return NULL; + } + + //obtain the basename; + line[sizeof(line) - 1] = '\0'; + char *p = line; + while (*p != '\0' && + *p != '\t' && + *p != ' ' && + *p != '\n') { + p++; + } + + *p = '\0'; p--; + while (p > line && *p != '/') p--; + if (*p == '/') p++; + procname = strdup(p); + } + } + + return procname; +} + + + +bool isNeedEncode() +{ + const char *procname = getProcName(); + if (procname == NULL) return false; + ALOGD("isNeedEncode? for %s\n", procname); + // check on our whitelist + FILE *fp = fopen(GLES_EMUL_TARGETS_FILE, "rt"); + if (fp == NULL) { + ALOGE("couldn't open %s\n", GLES_EMUL_TARGETS_FILE); + return false; + } + + char line[100]; + bool found = false; + size_t procnameLen = strlen(procname); + + while (fgets(line, sizeof(line), fp) != NULL) { + if (strlen(line) >= procnameLen && + !strncmp(procname, line, procnameLen)) { + char c = line[procnameLen]; + if (c == '\0' || c == ' ' || c == '\t' || c == '\n') { + found = true; + ALOGD("should use encoder for %s\n", procname); + break; + } + } + } + fclose(fp); + return found; +} + +void initDispatchTables() +{ + // + // Load our back-end implementation of EGL/GLES + // + ALOGD("Loading egl dispatch for %s\n", getProcName()); + + void *gles_android = dlopen("/system/lib/egl/libGLES_android.so", RTLD_NOW | RTLD_LOCAL); + if (!gles_android) { + fprintf(stderr,"FATAL ERROR: Could not load libGLES_android lib\n"); + exit(-1); + } + + // + // Load back-end EGL implementation library + // + s_dispatch = create_egl_dispatch( gles_android ); + if (!s_dispatch) { + fprintf(stderr,"FATAL ERROR: Could not create egl dispatch\n"); + exit(-1); + } + + // + // initialize gles + // + s_needEncode = isNeedEncode(); + void *gles_encoder = NULL; + if (s_needEncode) { + // initialize a connection to the server, and the GLESv1/v2 encoders; + ServerConnection * connection = ServerConnection::s_getServerConnection(); + if (connection == NULL) { + ALOGE("couldn't create server connection\n"); + s_needEncode = false; + } + } + + // init dispatch tabels for GLESv1 & GLESv2 + if (s_needEncode) { + // XXX - we do not check the retrun value because there isn't much we can do here on failure. + + if (initApi<gl_wrapper_context_t>(GLESv1_DRIVER, GLESv1_enc_LIB, &g_gl_dispatch, getGLContext) < 0) { + // fallback to android on faluire + s_needEncode = false; + } else { + initApi<gl2_wrapper_context_t>(GLESv2_DRIVER, GLESv2_enc_LIB, &g_gl2_dispatch, getGL2Context); + } + } + + if (!s_needEncode) { + ALOGD("Initializing native opengl for %s\n", getProcName()); + initApi<gl_wrapper_context_t>(GLESv1_DRIVER, GLES_android_LIB, &g_gl_dispatch, getGLContext); + // try to initialize gl2 from GLES, though its probably going to fail + initApi<gl2_wrapper_context_t>(GLESv2_DRIVER, GLES_android_LIB, &g_gl2_dispatch, getGL2Context); + } +} + +static struct egl_dispatch *getDispatch() +{ + pthread_once(&dispatchTablesInitialized, initDispatchTables); + return s_dispatch; +} + +__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) +{ + + // search in EGL function table + for (int i=0; i<egl_num_funcs; i++) { + if (!strcmp(egl_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; + } + } + + // we do not support eglGetProcAddress for GLESv1 & GLESv2. The loader + // should be able to find this function through dynamic loading. + return NULL; +} + +//////////////// Path through functions ////////// + +EGLint eglGetError() +{ + return getDispatch()->eglGetError(); +} + +EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) +{ + return getDispatch()->eglGetDisplay(display_id); +} + +EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + return getDispatch()->eglInitialize(dpy, major, minor); +} + +EGLBoolean eglTerminate(EGLDisplay dpy) +{ + return getDispatch()->eglTerminate(dpy); +} + +const char* eglQueryString(EGLDisplay dpy, EGLint name) +{ + return getDispatch()->eglQueryString(dpy, name); +} + +EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + return getDispatch()->eglGetConfigs(dpy, configs, config_size, num_config); +} + +static EGLint * filter_es2_bit(const EGLint *attrib_list, bool *isES2) +{ + if (attrib_list == NULL) { + if (isES2 != NULL) *isES2 = false; + return NULL; + } + + EGLint *attribs = NULL; + int nAttribs = 0; + while(attrib_list[nAttribs] != EGL_NONE) nAttribs++; + nAttribs++; + + attribs = new EGLint[nAttribs]; + memcpy(attribs, attrib_list, nAttribs * sizeof(EGLint)); + if (isES2 != NULL) *isES2 = false; + + // scan the attribute list for ES2 request and replace with ES1. + for (int i = 0; i < nAttribs; i++) { + if (attribs[i] == EGL_RENDERABLE_TYPE) { + if (attribs[i + 1] & EGL_OPENGL_ES2_BIT) { + attribs[i + 1] &= ~EGL_OPENGL_ES2_BIT; + attribs[i + 1] |= EGL_OPENGL_ES_BIT; + ALOGD("removing ES2 bit 0x%x\n", attribs[i + 1]); + if (isES2 != NULL) *isES2 = true; + } + } + } + return attribs; +} + +EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + EGLBoolean res; + if (s_needEncode) { + EGLint *attribs = filter_es2_bit(attrib_list, NULL); + res = getDispatch()->eglChooseConfig(dpy, + attribs, + configs, + config_size, + num_config); + ALOGD("eglChooseConfig: %d configs found\n", *num_config); + if (*num_config == 0 && attribs != NULL) { + ALOGD("requested attributes:\n"); + for (int i = 0; attribs[i] != EGL_NONE; i++) { + ALOGD("%d: 0x%x\n", i, attribs[i]); + } + } + + delete attribs; + } else { + res = getDispatch()->eglChooseConfig(dpy, attrib_list, configs, config_size, num_config); + } + return res; +} + +EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +{ + if (s_needEncode && attribute == EGL_RENDERABLE_TYPE) { + *value = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT; + return EGL_TRUE; + } else { + return getDispatch()->eglGetConfigAttrib(dpy, config, attribute, value); + } +} + +EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) +{ + EGLSurface surface = getDispatch()->eglCreateWindowSurface(dpy, config, win, attrib_list); + if (surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return surface; +} + +EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + EGLSurface surface = getDispatch()->eglCreatePbufferSurface(dpy, config, attrib_list); + if (surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return surface; +} + +EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) +{ + EGLSurface surface = getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); + if (surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return surface; +} + +EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) +{ + EGLBoolean res = getDispatch()->eglDestroySurface(dpy, surface); + if (res && surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->destroySurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return res; +} + +EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) +{ + EGLBoolean res = getDispatch()->eglQuerySurface(dpy, surface, attribute, value); + if (res && attribute == EGL_RENDERABLE_TYPE) { + *value |= EGL_OPENGL_ES2_BIT; + } + return res; +} + +EGLBoolean eglBindAPI(EGLenum api) +{ + return getDispatch()->eglBindAPI(api); +} + +EGLenum eglQueryAPI() +{ + return getDispatch()->eglQueryAPI(); +} + +EGLBoolean eglWaitClient() +{ + return getDispatch()->eglWaitClient(); +} + +EGLBoolean eglReleaseThread() +{ + return getDispatch()->eglReleaseThread(); +} + +EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list); +} + +EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + return getDispatch()->eglSurfaceAttrib(dpy, surface, attribute, value); +} + +EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglBindTexImage(dpy, surface, buffer); +} + +EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglReleaseTexImage(dpy, surface, buffer); +} + +EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + return getDispatch()->eglSwapInterval(dpy, interval); +} + +EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) +{ + + EGLContext share = share_context; + if (share) share = ((EGLWrapperContext *)share_context)->aglContext; + + // check if are ES2, and convert it to ES1. + int nAttribs = 0; + if (attrib_list != NULL) { + while(attrib_list[nAttribs] != EGL_NONE) { + nAttribs++; + } + nAttribs++; + } + + EGLint *attrib = NULL; + if (nAttribs > 0) { + attrib = new EGLint[nAttribs]; + memcpy(attrib, attrib_list, nAttribs * sizeof(EGLint)); + } + + int version = 1; + for (int i = 0; i < nAttribs; i++) { + if (attrib[i] == EGL_CONTEXT_CLIENT_VERSION && + attrib[i + 1] == 2) { + version = 2; + attrib[i + 1] = 1; // replace to version 1 + } + } + + EGLContext ctx = getDispatch()->eglCreateContext(dpy, config, share, attrib); + delete attrib; + EGLWrapperContext *wctx = new EGLWrapperContext(ctx, version); + if (ctx != EGL_NO_CONTEXT) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + wctx->clientState = new GLClientState(); + server->utEnc()->createContext(server->utEnc(), getpid(), + (uint32_t)wctx, + (uint32_t)(share_context == EGL_NO_CONTEXT ? 0 : share_context), wctx->version); + } + } + return (EGLContext)wctx; +} + +EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + EGLBoolean res = EGL_FALSE; + + if (ctx && ctx != EGL_NO_CONTEXT) { + res = getDispatch()->eglDestroyContext(dpy, wctx->aglContext); + if (res) { + EGLThreadInfo *ti = getEGLThreadInfo(); + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection())) { + server->utEnc()->destroyContext(ti->serverConn->utEnc(), getpid(), (uint32_t)ctx); + } + if (ti->currentContext == wctx) ti->currentContext = NULL; + delete wctx; + } + } + + return res; +} + +EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + EGLContext aglContext = (ctx == EGL_NO_CONTEXT ? EGL_NO_CONTEXT : wctx->aglContext); + EGLThreadInfo *ti = getEGLThreadInfo(); + EGLBoolean res = getDispatch()->eglMakeCurrent(dpy, draw, read, aglContext); + if (res ) { + // NOTE - we do get a pointer to the server connection, (rather then using ti->serverConn) + // for cases that this is the first egl call of the current thread. + + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection())) { + server->utEnc()->makeCurrentContext(server->utEnc(), getpid(), + (uint32_t) (draw == EGL_NO_SURFACE ? 0 : draw), + (uint32_t) (read == EGL_NO_SURFACE ? 0 : read), + (uint32_t) (ctx == EGL_NO_CONTEXT ? 0 : ctx)); + server->glEncoder()->setClientState( wctx ? wctx->clientState : NULL ); + server->gl2Encoder()->setClientState( wctx ? wctx->clientState : NULL ); + } + + // set current context in our thread info + ti->currentContext = wctx; + } + return res; + +} + +EGLContext eglGetCurrentContext() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + return (ti->currentContext ? ti->currentContext : EGL_NO_CONTEXT); +} + +EGLSurface eglGetCurrentSurface(EGLint readdraw) +{ + return getDispatch()->eglGetCurrentSurface(readdraw); +} + +EGLDisplay eglGetCurrentDisplay() +{ + return getDispatch()->eglGetCurrentDisplay(); +} + +EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + if (wctx) { + if (attribute == EGL_CONTEXT_CLIENT_VERSION) { + *value = wctx->version; + return EGL_TRUE; + } else { + return getDispatch()->eglQueryContext(dpy, wctx->aglContext, attribute, value); + } + } + else { + return EGL_BAD_CONTEXT; + } +} + +EGLBoolean eglWaitGL() +{ + return getDispatch()->eglWaitGL(); +} + +EGLBoolean eglWaitNative(EGLint engine) +{ + return getDispatch()->eglWaitNative(engine); +} + +EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) +{ + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->swapBuffers(server->utEnc(), getpid(), (uint32_t)surface); + server->glEncoder()->flush(); + server->gl2Encoder()->flush(); + return 1; + } + return getDispatch()->eglSwapBuffers(dpy, surface); +} + +EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) +{ + return getDispatch()->eglCopyBuffers(dpy, surface, target); +} + +EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) +{ + return getDispatch()->eglLockSurfaceKHR(display, surface, attrib_list); +} + +EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) +{ + return getDispatch()->eglUnlockSurfaceKHR(display, surface); +} + +EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + EGLContext aglContext = (wctx ? wctx->aglContext : EGL_NO_CONTEXT); + return getDispatch()->eglCreateImageKHR(dpy, aglContext, target, buffer, attrib_list); +} + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) +{ + return getDispatch()->eglDestroyImageKHR(dpy, image); +} + +EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateSyncKHR(dpy, type, attrib_list); +} + +EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + return getDispatch()->eglDestroySyncKHR(dpy, sync); +} + +EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + return getDispatch()->eglClientWaitSyncKHR(dpy, sync, flags, timeout); +} + +EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) +{ + return getDispatch()->eglSignalSyncKHR(dpy, sync, mode); +} + +EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglGetSyncAttribKHR(dpy, sync, attribute, value); +} + +EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height) +{ + return getDispatch()->eglSetSwapRectangleANDROID(dpy, draw, left, top, width, height); +} diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.cpp b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.cpp new file mode 100644 index 0000000..f69ca61 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.cpp @@ -0,0 +1,71 @@ +/* +* 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 <stdio.h> +#include "egl_dispatch.h" +#include <dlfcn.h> + +egl_dispatch *create_egl_dispatch(void *gles_android) +{ + egl_dispatch *disp = new egl_dispatch; + + void *ptr; + ptr = dlsym(gles_android,"eglGetError"); disp->set_eglGetError((eglGetError_t)ptr); + ptr = dlsym(gles_android,"eglGetDisplay"); disp->set_eglGetDisplay((eglGetDisplay_t)ptr); + ptr = dlsym(gles_android,"eglInitialize"); disp->set_eglInitialize((eglInitialize_t)ptr); + ptr = dlsym(gles_android,"eglTerminate"); disp->set_eglTerminate((eglTerminate_t)ptr); + ptr = dlsym(gles_android,"eglQueryString"); disp->set_eglQueryString((eglQueryString_t)ptr); + ptr = dlsym(gles_android,"eglGetConfigs"); disp->set_eglGetConfigs((eglGetConfigs_t)ptr); + ptr = dlsym(gles_android,"eglChooseConfig"); disp->set_eglChooseConfig((eglChooseConfig_t)ptr); + ptr = dlsym(gles_android,"eglGetConfigAttrib"); disp->set_eglGetConfigAttrib((eglGetConfigAttrib_t)ptr); + ptr = dlsym(gles_android,"eglCreateWindowSurface"); disp->set_eglCreateWindowSurface((eglCreateWindowSurface_t)ptr); + ptr = dlsym(gles_android,"eglCreatePbufferSurface"); disp->set_eglCreatePbufferSurface((eglCreatePbufferSurface_t)ptr); + ptr = dlsym(gles_android,"eglCreatePixmapSurface"); disp->set_eglCreatePixmapSurface((eglCreatePixmapSurface_t)ptr); + ptr = dlsym(gles_android,"eglDestroySurface"); disp->set_eglDestroySurface((eglDestroySurface_t)ptr); + ptr = dlsym(gles_android,"eglQuerySurface"); disp->set_eglQuerySurface((eglQuerySurface_t)ptr); + ptr = dlsym(gles_android,"eglBindAPI"); disp->set_eglBindAPI((eglBindAPI_t)ptr); + ptr = dlsym(gles_android,"eglQueryAPI"); disp->set_eglQueryAPI((eglQueryAPI_t)ptr); + ptr = dlsym(gles_android,"eglWaitClient"); disp->set_eglWaitClient((eglWaitClient_t)ptr); + ptr = dlsym(gles_android,"eglReleaseThread"); disp->set_eglReleaseThread((eglReleaseThread_t)ptr); + ptr = dlsym(gles_android,"eglCreatePbufferFromClientBuffer"); disp->set_eglCreatePbufferFromClientBuffer((eglCreatePbufferFromClientBuffer_t)ptr); + ptr = dlsym(gles_android,"eglSurfaceAttrib"); disp->set_eglSurfaceAttrib((eglSurfaceAttrib_t)ptr); + ptr = dlsym(gles_android,"eglBindTexImage"); disp->set_eglBindTexImage((eglBindTexImage_t)ptr); + ptr = dlsym(gles_android,"eglReleaseTexImage"); disp->set_eglReleaseTexImage((eglReleaseTexImage_t)ptr); + ptr = dlsym(gles_android,"eglSwapInterval"); disp->set_eglSwapInterval((eglSwapInterval_t)ptr); + ptr = dlsym(gles_android,"eglCreateContext"); disp->set_eglCreateContext((eglCreateContext_t)ptr); + ptr = dlsym(gles_android,"eglDestroyContext"); disp->set_eglDestroyContext((eglDestroyContext_t)ptr); + ptr = dlsym(gles_android,"eglMakeCurrent"); disp->set_eglMakeCurrent((eglMakeCurrent_t)ptr); + ptr = dlsym(gles_android,"eglGetCurrentContext"); disp->set_eglGetCurrentContext((eglGetCurrentContext_t)ptr); + ptr = dlsym(gles_android,"eglGetCurrentSurface"); disp->set_eglGetCurrentSurface((eglGetCurrentSurface_t)ptr); + ptr = dlsym(gles_android,"eglGetCurrentDisplay"); disp->set_eglGetCurrentDisplay((eglGetCurrentDisplay_t)ptr); + ptr = dlsym(gles_android,"eglQueryContext"); disp->set_eglQueryContext((eglQueryContext_t)ptr); + ptr = dlsym(gles_android,"eglWaitGL"); disp->set_eglWaitGL((eglWaitGL_t)ptr); + ptr = dlsym(gles_android,"eglWaitNative"); disp->set_eglWaitNative((eglWaitNative_t)ptr); + ptr = dlsym(gles_android,"eglSwapBuffers"); disp->set_eglSwapBuffers((eglSwapBuffers_t)ptr); + ptr = dlsym(gles_android,"eglCopyBuffers"); disp->set_eglCopyBuffers((eglCopyBuffers_t)ptr); + ptr = dlsym(gles_android,"eglGetProcAddress"); disp->set_eglGetProcAddress((eglGetProcAddress_t)ptr); + ptr = dlsym(gles_android,"eglLockSurfaceKHR"); disp->set_eglLockSurfaceKHR((eglLockSurfaceKHR_t)ptr); + ptr = dlsym(gles_android,"eglUnlockSurfaceKHR"); disp->set_eglUnlockSurfaceKHR((eglUnlockSurfaceKHR_t)ptr); + ptr = dlsym(gles_android,"eglCreateImageKHR"); disp->set_eglCreateImageKHR((eglCreateImageKHR_t)ptr); + ptr = dlsym(gles_android,"eglDestroyImageKHR"); disp->set_eglDestroyImageKHR((eglDestroyImageKHR_t)ptr); + ptr = dlsym(gles_android,"eglCreateSyncKHR"); disp->set_eglCreateSyncKHR((eglCreateSyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglDestroySyncKHR"); disp->set_eglDestroySyncKHR((eglDestroySyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglClientWaitSyncKHR"); disp->set_eglClientWaitSyncKHR((eglClientWaitSyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglSignalSyncKHR"); disp->set_eglSignalSyncKHR((eglSignalSyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglGetSyncAttribKHR"); disp->set_eglGetSyncAttribKHR((eglGetSyncAttribKHR_t)ptr); + ptr = dlsym(gles_android,"eglSetSwapRectangleANDROID"); disp->set_eglSetSwapRectangleANDROID((eglSetSwapRectangleANDROID_t)ptr); + + return disp; +} diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.h b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.h new file mode 100644 index 0000000..1b8de0d --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.h @@ -0,0 +1,115 @@ +/* +* 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. +*/ +#ifndef _EGL_DISPATCH_H +#define _EGL_DISPATCH_H + +#include "egl_proc.h" + +struct egl_dispatch { + eglGetError_t eglGetError; + eglGetDisplay_t eglGetDisplay; + eglInitialize_t eglInitialize; + eglTerminate_t eglTerminate; + eglQueryString_t eglQueryString; + eglGetConfigs_t eglGetConfigs; + eglChooseConfig_t eglChooseConfig; + eglGetConfigAttrib_t eglGetConfigAttrib; + eglCreateWindowSurface_t eglCreateWindowSurface; + eglCreatePbufferSurface_t eglCreatePbufferSurface; + eglCreatePixmapSurface_t eglCreatePixmapSurface; + eglDestroySurface_t eglDestroySurface; + eglQuerySurface_t eglQuerySurface; + eglBindAPI_t eglBindAPI; + eglQueryAPI_t eglQueryAPI; + eglWaitClient_t eglWaitClient; + eglReleaseThread_t eglReleaseThread; + eglCreatePbufferFromClientBuffer_t eglCreatePbufferFromClientBuffer; + eglSurfaceAttrib_t eglSurfaceAttrib; + eglBindTexImage_t eglBindTexImage; + eglReleaseTexImage_t eglReleaseTexImage; + eglSwapInterval_t eglSwapInterval; + eglCreateContext_t eglCreateContext; + eglDestroyContext_t eglDestroyContext; + eglMakeCurrent_t eglMakeCurrent; + eglGetCurrentContext_t eglGetCurrentContext; + eglGetCurrentSurface_t eglGetCurrentSurface; + eglGetCurrentDisplay_t eglGetCurrentDisplay; + eglQueryContext_t eglQueryContext; + eglWaitGL_t eglWaitGL; + eglWaitNative_t eglWaitNative; + eglSwapBuffers_t eglSwapBuffers; + eglCopyBuffers_t eglCopyBuffers; + eglGetProcAddress_t eglGetProcAddress; + eglLockSurfaceKHR_t eglLockSurfaceKHR; + eglUnlockSurfaceKHR_t eglUnlockSurfaceKHR; + eglCreateImageKHR_t eglCreateImageKHR; + eglDestroyImageKHR_t eglDestroyImageKHR; + eglCreateSyncKHR_t eglCreateSyncKHR; + eglDestroySyncKHR_t eglDestroySyncKHR; + eglClientWaitSyncKHR_t eglClientWaitSyncKHR; + eglSignalSyncKHR_t eglSignalSyncKHR; + eglGetSyncAttribKHR_t eglGetSyncAttribKHR; + eglSetSwapRectangleANDROID_t eglSetSwapRectangleANDROID; + //Accessors + eglGetError_t set_eglGetError(eglGetError_t f) { eglGetError_t retval = eglGetError; eglGetError = f; return retval;} + eglGetDisplay_t set_eglGetDisplay(eglGetDisplay_t f) { eglGetDisplay_t retval = eglGetDisplay; eglGetDisplay = f; return retval;} + eglInitialize_t set_eglInitialize(eglInitialize_t f) { eglInitialize_t retval = eglInitialize; eglInitialize = f; return retval;} + eglTerminate_t set_eglTerminate(eglTerminate_t f) { eglTerminate_t retval = eglTerminate; eglTerminate = f; return retval;} + eglQueryString_t set_eglQueryString(eglQueryString_t f) { eglQueryString_t retval = eglQueryString; eglQueryString = f; return retval;} + eglGetConfigs_t set_eglGetConfigs(eglGetConfigs_t f) { eglGetConfigs_t retval = eglGetConfigs; eglGetConfigs = f; return retval;} + eglChooseConfig_t set_eglChooseConfig(eglChooseConfig_t f) { eglChooseConfig_t retval = eglChooseConfig; eglChooseConfig = f; return retval;} + eglGetConfigAttrib_t set_eglGetConfigAttrib(eglGetConfigAttrib_t f) { eglGetConfigAttrib_t retval = eglGetConfigAttrib; eglGetConfigAttrib = f; return retval;} + eglCreateWindowSurface_t set_eglCreateWindowSurface(eglCreateWindowSurface_t f) { eglCreateWindowSurface_t retval = eglCreateWindowSurface; eglCreateWindowSurface = f; return retval;} + eglCreatePbufferSurface_t set_eglCreatePbufferSurface(eglCreatePbufferSurface_t f) { eglCreatePbufferSurface_t retval = eglCreatePbufferSurface; eglCreatePbufferSurface = f; return retval;} + eglCreatePixmapSurface_t set_eglCreatePixmapSurface(eglCreatePixmapSurface_t f) { eglCreatePixmapSurface_t retval = eglCreatePixmapSurface; eglCreatePixmapSurface = f; return retval;} + eglDestroySurface_t set_eglDestroySurface(eglDestroySurface_t f) { eglDestroySurface_t retval = eglDestroySurface; eglDestroySurface = f; return retval;} + eglQuerySurface_t set_eglQuerySurface(eglQuerySurface_t f) { eglQuerySurface_t retval = eglQuerySurface; eglQuerySurface = f; return retval;} + eglBindAPI_t set_eglBindAPI(eglBindAPI_t f) { eglBindAPI_t retval = eglBindAPI; eglBindAPI = f; return retval;} + eglQueryAPI_t set_eglQueryAPI(eglQueryAPI_t f) { eglQueryAPI_t retval = eglQueryAPI; eglQueryAPI = f; return retval;} + eglWaitClient_t set_eglWaitClient(eglWaitClient_t f) { eglWaitClient_t retval = eglWaitClient; eglWaitClient = f; return retval;} + eglReleaseThread_t set_eglReleaseThread(eglReleaseThread_t f) { eglReleaseThread_t retval = eglReleaseThread; eglReleaseThread = f; return retval;} + eglCreatePbufferFromClientBuffer_t set_eglCreatePbufferFromClientBuffer(eglCreatePbufferFromClientBuffer_t f) { eglCreatePbufferFromClientBuffer_t retval = eglCreatePbufferFromClientBuffer; eglCreatePbufferFromClientBuffer = f; return retval;} + eglSurfaceAttrib_t set_eglSurfaceAttrib(eglSurfaceAttrib_t f) { eglSurfaceAttrib_t retval = eglSurfaceAttrib; eglSurfaceAttrib = f; return retval;} + eglBindTexImage_t set_eglBindTexImage(eglBindTexImage_t f) { eglBindTexImage_t retval = eglBindTexImage; eglBindTexImage = f; return retval;} + eglReleaseTexImage_t set_eglReleaseTexImage(eglReleaseTexImage_t f) { eglReleaseTexImage_t retval = eglReleaseTexImage; eglReleaseTexImage = f; return retval;} + eglSwapInterval_t set_eglSwapInterval(eglSwapInterval_t f) { eglSwapInterval_t retval = eglSwapInterval; eglSwapInterval = f; return retval;} + eglCreateContext_t set_eglCreateContext(eglCreateContext_t f) { eglCreateContext_t retval = eglCreateContext; eglCreateContext = f; return retval;} + eglDestroyContext_t set_eglDestroyContext(eglDestroyContext_t f) { eglDestroyContext_t retval = eglDestroyContext; eglDestroyContext = f; return retval;} + eglMakeCurrent_t set_eglMakeCurrent(eglMakeCurrent_t f) { eglMakeCurrent_t retval = eglMakeCurrent; eglMakeCurrent = f; return retval;} + eglGetCurrentContext_t set_eglGetCurrentContext(eglGetCurrentContext_t f) { eglGetCurrentContext_t retval = eglGetCurrentContext; eglGetCurrentContext = f; return retval;} + eglGetCurrentSurface_t set_eglGetCurrentSurface(eglGetCurrentSurface_t f) { eglGetCurrentSurface_t retval = eglGetCurrentSurface; eglGetCurrentSurface = f; return retval;} + eglGetCurrentDisplay_t set_eglGetCurrentDisplay(eglGetCurrentDisplay_t f) { eglGetCurrentDisplay_t retval = eglGetCurrentDisplay; eglGetCurrentDisplay = f; return retval;} + eglQueryContext_t set_eglQueryContext(eglQueryContext_t f) { eglQueryContext_t retval = eglQueryContext; eglQueryContext = f; return retval;} + eglWaitGL_t set_eglWaitGL(eglWaitGL_t f) { eglWaitGL_t retval = eglWaitGL; eglWaitGL = f; return retval;} + eglWaitNative_t set_eglWaitNative(eglWaitNative_t f) { eglWaitNative_t retval = eglWaitNative; eglWaitNative = f; return retval;} + eglSwapBuffers_t set_eglSwapBuffers(eglSwapBuffers_t f) { eglSwapBuffers_t retval = eglSwapBuffers; eglSwapBuffers = f; return retval;} + eglCopyBuffers_t set_eglCopyBuffers(eglCopyBuffers_t f) { eglCopyBuffers_t retval = eglCopyBuffers; eglCopyBuffers = f; return retval;} + eglGetProcAddress_t set_eglGetProcAddress(eglGetProcAddress_t f) { eglGetProcAddress_t retval = eglGetProcAddress; eglGetProcAddress = f; return retval;} + eglLockSurfaceKHR_t set_eglLockSurfaceKHR(eglLockSurfaceKHR_t f) { eglLockSurfaceKHR_t retval = eglLockSurfaceKHR; eglLockSurfaceKHR = f; return retval;} + eglUnlockSurfaceKHR_t set_eglUnlockSurfaceKHR(eglUnlockSurfaceKHR_t f) { eglUnlockSurfaceKHR_t retval = eglUnlockSurfaceKHR; eglUnlockSurfaceKHR = f; return retval;} + eglCreateImageKHR_t set_eglCreateImageKHR(eglCreateImageKHR_t f) { eglCreateImageKHR_t retval = eglCreateImageKHR; eglCreateImageKHR = f; return retval;} + eglDestroyImageKHR_t set_eglDestroyImageKHR(eglDestroyImageKHR_t f) { eglDestroyImageKHR_t retval = eglDestroyImageKHR; eglDestroyImageKHR = f; return retval;} + eglCreateSyncKHR_t set_eglCreateSyncKHR(eglCreateSyncKHR_t f) { eglCreateSyncKHR_t retval = eglCreateSyncKHR; eglCreateSyncKHR = f; return retval;} + eglDestroySyncKHR_t set_eglDestroySyncKHR(eglDestroySyncKHR_t f) { eglDestroySyncKHR_t retval = eglDestroySyncKHR; eglDestroySyncKHR = f; return retval;} + eglClientWaitSyncKHR_t set_eglClientWaitSyncKHR(eglClientWaitSyncKHR_t f) { eglClientWaitSyncKHR_t retval = eglClientWaitSyncKHR; eglClientWaitSyncKHR = f; return retval;} + eglSignalSyncKHR_t set_eglSignalSyncKHR(eglSignalSyncKHR_t f) { eglSignalSyncKHR_t retval = eglSignalSyncKHR; eglSignalSyncKHR = f; return retval;} + eglGetSyncAttribKHR_t set_eglGetSyncAttribKHR(eglGetSyncAttribKHR_t f) { eglGetSyncAttribKHR_t retval = eglGetSyncAttribKHR; eglGetSyncAttribKHR = f; return retval;} + eglSetSwapRectangleANDROID_t set_eglSetSwapRectangleANDROID(eglSetSwapRectangleANDROID_t f) { eglSetSwapRectangleANDROID_t retval = eglSetSwapRectangleANDROID; eglSetSwapRectangleANDROID = f; return retval;} +}; + +egl_dispatch *create_egl_dispatch(void *gles_andorid); + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_ftable.h b/emulator/opengl/tests/gles_android_wrapper/egl_ftable.h new file mode 100644 index 0000000..ee40585 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_ftable.h @@ -0,0 +1,66 @@ +/* +* 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. +*/ +static struct _egl_funcs_by_name { + const char *name; + void *proc; +} egl_funcs_by_name[] = { + {"eglGetError", (void *)eglGetError}, + {"eglGetDisplay", (void *)eglGetDisplay}, + {"eglInitialize", (void *)eglInitialize}, + {"eglTerminate", (void *)eglTerminate}, + {"eglQueryString", (void *)eglQueryString}, + {"eglGetConfigs", (void *)eglGetConfigs}, + {"eglChooseConfig", (void *)eglChooseConfig}, + {"eglGetConfigAttrib", (void *)eglGetConfigAttrib}, + {"eglCreateWindowSurface", (void *)eglCreateWindowSurface}, + {"eglCreatePbufferSurface", (void *)eglCreatePbufferSurface}, + {"eglCreatePixmapSurface", (void *)eglCreatePixmapSurface}, + {"eglDestroySurface", (void *)eglDestroySurface}, + {"eglQuerySurface", (void *)eglQuerySurface}, + {"eglBindAPI", (void *)eglBindAPI}, + {"eglQueryAPI", (void *)eglQueryAPI}, + {"eglWaitClient", (void *)eglWaitClient}, + {"eglReleaseThread", (void *)eglReleaseThread}, + {"eglCreatePbufferFromClientBuffer", (void *)eglCreatePbufferFromClientBuffer}, + {"eglSurfaceAttrib", (void *)eglSurfaceAttrib}, + {"eglBindTexImage", (void *)eglBindTexImage}, + {"eglReleaseTexImage", (void *)eglReleaseTexImage}, + {"eglSwapInterval", (void *)eglSwapInterval}, + {"eglCreateContext", (void *)eglCreateContext}, + {"eglDestroyContext", (void *)eglDestroyContext}, + {"eglMakeCurrent", (void *)eglMakeCurrent}, + {"eglGetCurrentContext", (void *)eglGetCurrentContext}, + {"eglGetCurrentSurface", (void *)eglGetCurrentSurface}, + {"eglGetCurrentDisplay", (void *)eglGetCurrentDisplay}, + {"eglQueryContext", (void *)eglQueryContext}, + {"eglWaitGL", (void *)eglWaitGL}, + {"eglWaitNative", (void *)eglWaitNative}, + {"eglSwapBuffers", (void *)eglSwapBuffers}, + {"eglCopyBuffers", (void *)eglCopyBuffers}, + {"eglGetProcAddress", (void *)eglGetProcAddress}, + {"eglLockSurfaceKHR", (void *)eglLockSurfaceKHR}, + {"eglUnlockSurfaceKHR", (void *)eglUnlockSurfaceKHR}, + {"eglCreateImageKHR", (void *)eglCreateImageKHR}, + {"eglDestroyImageKHR", (void *)eglDestroyImageKHR}, + {"eglCreateSyncKHR", (void *)eglCreateSyncKHR}, + {"eglDestroySyncKHR", (void *)eglDestroySyncKHR}, + {"eglClientWaitSyncKHR", (void *)eglClientWaitSyncKHR}, + {"eglSignalSyncKHR", (void *)eglSignalSyncKHR}, + {"eglGetSyncAttribKHR", (void *)eglGetSyncAttribKHR}, + {"eglSetSwapRectangleANDROID", (void *)eglSetSwapRectangleANDROID} +}; + +static int egl_num_funcs = sizeof(egl_funcs_by_name) / sizeof(struct _egl_funcs_by_name); diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_proc.h b/emulator/opengl/tests/gles_android_wrapper/egl_proc.h new file mode 100644 index 0000000..140c030 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_proc.h @@ -0,0 +1,68 @@ +/* +* 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. +*/ +#ifndef _EGL_PROC_H +#define _EGL_PROC_H + +#include <EGL/egl.h> +#define EGL_EGLEXT_PROTOTYPES +#include <EGL/eglext.h> + +typedef EGLint (* eglGetError_t) (); +typedef EGLDisplay (* eglGetDisplay_t) (EGLNativeDisplayType); +typedef EGLBoolean (* eglInitialize_t) (EGLDisplay, EGLint*, EGLint*); +typedef EGLBoolean (* eglTerminate_t) (EGLDisplay); +typedef char* (* eglQueryString_t) (EGLDisplay, EGLint); +typedef EGLBoolean (* eglGetConfigs_t) (EGLDisplay, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglChooseConfig_t) (EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglGetConfigAttrib_t) (EGLDisplay, EGLConfig, EGLint, EGLint*); +typedef EGLSurface (* eglCreateWindowSurface_t) (EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*); +typedef EGLSurface (* eglCreatePbufferSurface_t) (EGLDisplay, EGLConfig, const EGLint*); +typedef EGLSurface (* eglCreatePixmapSurface_t) (EGLDisplay, EGLConfig, EGLNativePixmapType, const EGLint*); +typedef EGLBoolean (* eglDestroySurface_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglQuerySurface_t) (EGLDisplay, EGLSurface, EGLint, EGLint*); +typedef EGLBoolean (* eglBindAPI_t) (EGLenum); +typedef EGLenum (* eglQueryAPI_t) (); +typedef EGLBoolean (* eglWaitClient_t) (); +typedef EGLBoolean (* eglReleaseThread_t) (); +typedef EGLSurface (* eglCreatePbufferFromClientBuffer_t) (EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint*); +typedef EGLBoolean (* eglSurfaceAttrib_t) (EGLDisplay, EGLSurface, EGLint, EGLint); +typedef EGLBoolean (* eglBindTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglReleaseTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglSwapInterval_t) (EGLDisplay, EGLint); +typedef EGLContext (* eglCreateContext_t) (EGLDisplay, EGLConfig, EGLContext, const EGLint*); +typedef EGLBoolean (* eglDestroyContext_t) (EGLDisplay, EGLContext); +typedef EGLBoolean (* eglMakeCurrent_t) (EGLDisplay, EGLSurface, EGLSurface, EGLContext); +typedef EGLContext (* eglGetCurrentContext_t) (); +typedef EGLSurface (* eglGetCurrentSurface_t) (EGLint); +typedef EGLDisplay (* eglGetCurrentDisplay_t) (); +typedef EGLBoolean (* eglQueryContext_t) (EGLDisplay, EGLContext, EGLint, EGLint*); +typedef EGLBoolean (* eglWaitGL_t) (); +typedef EGLBoolean (* eglWaitNative_t) (EGLint); +typedef EGLBoolean (* eglSwapBuffers_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglCopyBuffers_t) (EGLDisplay, EGLSurface, EGLNativePixmapType); +typedef __eglMustCastToProperFunctionPointerType (* eglGetProcAddress_t) (const char*); +typedef EGLBoolean (* eglLockSurfaceKHR_t) (EGLDisplay, EGLSurface, const EGLint*); +typedef EGLBoolean (* eglUnlockSurfaceKHR_t) (EGLDisplay, EGLSurface); +typedef EGLImageKHR (* eglCreateImageKHR_t) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); +typedef EGLBoolean (* eglDestroyImageKHR_t) (EGLDisplay, EGLImageKHR image); +typedef EGLSyncKHR (* eglCreateSyncKHR_t) (EGLDisplay, EGLenum, const EGLint*); +typedef EGLBoolean (* eglDestroySyncKHR_t) (EGLDisplay, EGLSyncKHR sync); +typedef EGLint (* eglClientWaitSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR timeout); +typedef EGLBoolean (* eglSignalSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLenum); +typedef EGLBoolean (* eglGetSyncAttribKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLint*); +typedef EGLBoolean (* eglSetSwapRectangleANDROID_t) (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); + +#endif // of _EGL_PROC_H diff --git a/emulator/opengl/tests/gles_android_wrapper/gles.cpp b/emulator/opengl/tests/gles_android_wrapper/gles.cpp new file mode 100644 index 0000000..c0949c8 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles.cpp @@ -0,0 +1,1410 @@ +/* +* 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "gles_dispatch.h" +#include "gles_ftable.h" +#include <EGL/egl.h> +#include <cutils/log.h> + +static struct gles_dispatch *s_dispatch = NULL; + +void init_gles(void *gles_android) +{ + s_dispatch = create_gles_dispatch(gles_android); + if (s_dispatch == NULL) { + ALOGE("failed to create gles dispatch\n"); + } +} + +static struct gles_dispatch *getDispatch() +{ + if (!s_dispatch) { + fprintf(stderr,"FATAL ERROR: GLES has not been initialized\n"); + exit(-1); + } + + return s_dispatch; +} + +__eglMustCastToProperFunctionPointerType gles_getProcAddress(const char *procname) +{ + for (int i=0; i<gles_num_funcs; i++) { + if (!strcmp(gles_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)gles_funcs_by_name[i].proc; + } + } + + return NULL; +} + +///////////// Path-through functions /////////////// +void glAlphaFunc(GLenum func, GLclampf ref) +{ + getDispatch()->glAlphaFunc(func, ref); +} + +void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +{ + getDispatch()->glClearColor(red, green, blue, alpha); +} + +void glClearDepthf(GLclampf depth) +{ + getDispatch()->glClearDepthf(depth); +} + +void glClipPlanef(GLenum plane, const GLfloat *equation) +{ + getDispatch()->glClipPlanef(plane, equation); +} + +void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +{ + getDispatch()->glColor4f(red, green, blue, alpha); +} + +void glDepthRangef(GLclampf zNear, GLclampf zFar) +{ + getDispatch()->glDepthRangef(zNear, zFar); +} + +void glFogf(GLenum pname, GLfloat param) +{ + getDispatch()->glFogf(pname, param); +} + +void glFogfv(GLenum pname, const GLfloat *params) +{ + getDispatch()->glFogfv(pname, params); +} + +void glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glFrustumf(left, right, bottom, top, zNear, zFar); +} + +void glGetClipPlanef(GLenum pname, GLfloat eqn[4]) +{ + getDispatch()->glGetClipPlanef(pname, eqn); +} + +void glGetFloatv(GLenum pname, GLfloat *params) +{ + getDispatch()->glGetFloatv(pname, params); +} + +void glGetLightfv(GLenum light, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetLightfv(light, pname, params); +} + +void glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetMaterialfv(face, pname, params); +} + +void glGetTexEnvfv(GLenum env, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetTexEnvfv(env, pname, params); +} + +void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetTexParameterfv(target, pname, params); +} + +void glLightModelf(GLenum pname, GLfloat param) +{ + getDispatch()->glLightModelf(pname, param); +} + +void glLightModelfv(GLenum pname, const GLfloat *params) +{ + getDispatch()->glLightModelfv(pname, params); +} + +void glLightf(GLenum light, GLenum pname, GLfloat param) +{ + getDispatch()->glLightf(light, pname, param); +} + +void glLightfv(GLenum light, GLenum pname, const GLfloat *params) +{ + getDispatch()->glLightfv(light, pname, params); +} + +void glLineWidth(GLfloat width) +{ + getDispatch()->glLineWidth(width); +} + +void glLoadMatrixf(const GLfloat *m) +{ + getDispatch()->glLoadMatrixf(m); +} + +void glMaterialf(GLenum face, GLenum pname, GLfloat param) +{ + getDispatch()->glMaterialf(face, pname, param); +} + +void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) +{ + getDispatch()->glMaterialfv(face, pname, params); +} + +void glMultMatrixf(const GLfloat *m) +{ + getDispatch()->glMultMatrixf(m); +} + +void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) +{ + getDispatch()->glMultiTexCoord4f(target, s, t, r, q); +} + +void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) +{ + getDispatch()->glNormal3f(nx, ny, nz); +} + +void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glOrthof(left, right, bottom, top, zNear, zFar); +} + +void glPointParameterf(GLenum pname, GLfloat param) +{ + getDispatch()->glPointParameterf(pname, param); +} + +void glPointParameterfv(GLenum pname, const GLfloat *params) +{ + getDispatch()->glPointParameterfv(pname, params); +} + +void glPointSize(GLfloat size) +{ + getDispatch()->glPointSize(size); +} + +void glPolygonOffset(GLfloat factor, GLfloat units) +{ + getDispatch()->glPolygonOffset(factor, units); +} + +void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +{ + getDispatch()->glRotatef(angle, x, y, z); +} + +void glScalef(GLfloat x, GLfloat y, GLfloat z) +{ + getDispatch()->glScalef(x, y, z); +} + +void glTexEnvf(GLenum target, GLenum pname, GLfloat param) +{ + getDispatch()->glTexEnvf(target, pname, param); +} + +void glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params) +{ + getDispatch()->glTexEnvfv(target, pname, params); +} + +void glTexParameterf(GLenum target, GLenum pname, GLfloat param) +{ + getDispatch()->glTexParameterf(target, pname, param); +} + +void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params) +{ + getDispatch()->glTexParameterfv(target, pname, params); +} + +void glTranslatef(GLfloat x, GLfloat y, GLfloat z) +{ + getDispatch()->glTranslatef(x, y, z); +} + +void glActiveTexture(GLenum texture) +{ + getDispatch()->glActiveTexture(texture); +} + +void glAlphaFuncx(GLenum func, GLclampx ref) +{ + getDispatch()->glAlphaFuncx(func, ref); +} + +void glBindBuffer(GLenum target, GLuint buffer) +{ + getDispatch()->glBindBuffer(target, buffer); +} + +void glBindTexture(GLenum target, GLuint texture) +{ + getDispatch()->glBindTexture(target, texture); +} + +void glBlendFunc(GLenum sfactor, GLenum dfactor) +{ + getDispatch()->glBlendFunc(sfactor, dfactor); +} + +void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) +{ + getDispatch()->glBufferData(target, size, data, usage); +} + +void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) +{ + getDispatch()->glBufferSubData(target, offset, size, data); +} + +void glClear(GLbitfield mask) +{ + getDispatch()->glClear(mask); +} + +void glClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) +{ + getDispatch()->glClearColorx(red, green, blue, alpha); +} + +void glClearDepthx(GLclampx depth) +{ + getDispatch()->glClearDepthx(depth); +} + +void glClearStencil(GLint s) +{ + getDispatch()->glClearStencil(s); +} + +void glClientActiveTexture(GLenum texture) +{ + getDispatch()->glClientActiveTexture(texture); +} + +void glClipPlanex(GLenum plane, const GLfixed *equation) +{ + getDispatch()->glClipPlanex(plane, equation); +} + +void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) +{ + getDispatch()->glColor4ub(red, green, blue, alpha); +} + +void glColor4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) +{ + getDispatch()->glColor4x(red, green, blue, alpha); +} + +void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) +{ + getDispatch()->glColorMask(red, green, blue, alpha); +} + +void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glColorPointer(size, type, stride, pointer); +} + +void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) +{ + getDispatch()->glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); +} + +void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) +{ + getDispatch()->glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); +} + +void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) +{ + getDispatch()->glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); +} + +void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) +{ + getDispatch()->glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); +} + +void glCullFace(GLenum mode) +{ + getDispatch()->glCullFace(mode); +} + +void glDeleteBuffers(GLsizei n, const GLuint *buffers) +{ + getDispatch()->glDeleteBuffers(n, buffers); +} + +void glDeleteTextures(GLsizei n, const GLuint *textures) +{ + getDispatch()->glDeleteTextures(n, textures); +} + +void glDepthFunc(GLenum func) +{ + getDispatch()->glDepthFunc(func); +} + +void glDepthMask(GLboolean flag) +{ + getDispatch()->glDepthMask(flag); +} + +void glDepthRangex(GLclampx zNear, GLclampx zFar) +{ + getDispatch()->glDepthRangex(zNear, zFar); +} + +void glDisable(GLenum cap) +{ + getDispatch()->glDisable(cap); +} + +void glDisableClientState(GLenum array) +{ + getDispatch()->glDisableClientState(array); +} + +void glDrawArrays(GLenum mode, GLint first, GLsizei count) +{ + getDispatch()->glDrawArrays(mode, first, count); +} + +void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) +{ + getDispatch()->glDrawElements(mode, count, type, indices); +} + +void glEnable(GLenum cap) +{ + getDispatch()->glEnable(cap); +} + +void glEnableClientState(GLenum array) +{ + getDispatch()->glEnableClientState(array); +} + +void glFinish() +{ + getDispatch()->glFinish(); +} + +void glFlush() +{ + getDispatch()->glFlush(); +} + +void glFogx(GLenum pname, GLfixed param) +{ + getDispatch()->glFogx(pname, param); +} + +void glFogxv(GLenum pname, const GLfixed *params) +{ + getDispatch()->glFogxv(pname, params); +} + +void glFrontFace(GLenum mode) +{ + getDispatch()->glFrontFace(mode); +} + +void glFrustumx(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glFrustumx(left, right, bottom, top, zNear, zFar); +} + +void glGetBooleanv(GLenum pname, GLboolean *params) +{ + getDispatch()->glGetBooleanv(pname, params); +} + +void glGetBufferParameteriv(GLenum target, GLenum pname, GLint *params) +{ + getDispatch()->glGetBufferParameteriv(target, pname, params); +} + +void glGetClipPlanex(GLenum pname, GLfixed eqn[4]) +{ + getDispatch()->glGetClipPlanex(pname, eqn); +} + +void glGenBuffers(GLsizei n, GLuint *buffers) +{ + getDispatch()->glGenBuffers(n, buffers); +} + +void glGenTextures(GLsizei n, GLuint *textures) +{ + getDispatch()->glGenTextures(n, textures); +} + +GLenum glGetError() +{ + return getDispatch()->glGetError(); +} + +void glGetFixedv(GLenum pname, GLfixed *params) +{ + getDispatch()->glGetFixedv(pname, params); +} + +void glGetIntegerv(GLenum pname, GLint *params) +{ + getDispatch()->glGetIntegerv(pname, params); +} + +void glGetLightxv(GLenum light, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetLightxv(light, pname, params); +} + +void glGetMaterialxv(GLenum face, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetMaterialxv(face, pname, params); +} + +void glGetPointerv(GLenum pname, GLvoid **params) +{ + getDispatch()->glGetPointerv(pname, params); +} + +const GLubyte* glGetString(GLenum name) +{ + return getDispatch()->glGetString(name); +} + +void glGetTexEnviv(GLenum env, GLenum pname, GLint *params) +{ + getDispatch()->glGetTexEnviv(env, pname, params); +} + +void glGetTexEnvxv(GLenum env, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexEnvxv(env, pname, params); +} + +void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) +{ + getDispatch()->glGetTexParameteriv(target, pname, params); +} + +void glGetTexParameterxv(GLenum target, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexParameterxv(target, pname, params); +} + +void glHint(GLenum target, GLenum mode) +{ + getDispatch()->glHint(target, mode); +} + +GLboolean glIsBuffer(GLuint buffer) +{ + return getDispatch()->glIsBuffer(buffer); +} + +GLboolean glIsEnabled(GLenum cap) +{ + return getDispatch()->glIsEnabled(cap); +} + +GLboolean glIsTexture(GLuint texture) +{ + return getDispatch()->glIsTexture(texture); +} + +void glLightModelx(GLenum pname, GLfixed param) +{ + getDispatch()->glLightModelx(pname, param); +} + +void glLightModelxv(GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightModelxv(pname, params); +} + +void glLightx(GLenum light, GLenum pname, GLfixed param) +{ + getDispatch()->glLightx(light, pname, param); +} + +void glLightxv(GLenum light, GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightxv(light, pname, params); +} + +void glLineWidthx(GLfixed width) +{ + getDispatch()->glLineWidthx(width); +} + +void glLoadIdentity() +{ + getDispatch()->glLoadIdentity(); +} + +void glLoadMatrixx(const GLfixed *m) +{ + getDispatch()->glLoadMatrixx(m); +} + +void glLogicOp(GLenum opcode) +{ + getDispatch()->glLogicOp(opcode); +} + +void glMaterialx(GLenum face, GLenum pname, GLfixed param) +{ + getDispatch()->glMaterialx(face, pname, param); +} + +void glMaterialxv(GLenum face, GLenum pname, const GLfixed *params) +{ + getDispatch()->glMaterialxv(face, pname, params); +} + +void glMatrixMode(GLenum mode) +{ + getDispatch()->glMatrixMode(mode); +} + +void glMultMatrixx(const GLfixed *m) +{ + getDispatch()->glMultMatrixx(m); +} + +void glMultiTexCoord4x(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) +{ + getDispatch()->glMultiTexCoord4x(target, s, t, r, q); +} + +void glNormal3x(GLfixed nx, GLfixed ny, GLfixed nz) +{ + getDispatch()->glNormal3x(nx, ny, nz); +} + +void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glNormalPointer(type, stride, pointer); +} + +void glOrthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glOrthox(left, right, bottom, top, zNear, zFar); +} + +void glPixelStorei(GLenum pname, GLint param) +{ + getDispatch()->glPixelStorei(pname, param); +} + +void glPointParameterx(GLenum pname, GLfixed param) +{ + getDispatch()->glPointParameterx(pname, param); +} + +void glPointParameterxv(GLenum pname, const GLfixed *params) +{ + getDispatch()->glPointParameterxv(pname, params); +} + +void glPointSizex(GLfixed size) +{ + getDispatch()->glPointSizex(size); +} + +void glPolygonOffsetx(GLfixed factor, GLfixed units) +{ + getDispatch()->glPolygonOffsetx(factor, units); +} + +void glPopMatrix() +{ + getDispatch()->glPopMatrix(); +} + +void glPushMatrix() +{ + getDispatch()->glPushMatrix(); +} + +void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +{ + getDispatch()->glReadPixels(x, y, width, height, format, type, pixels); +} + +void glRotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glRotatex(angle, x, y, z); +} + +void glSampleCoverage(GLclampf value, GLboolean invert) +{ + getDispatch()->glSampleCoverage(value, invert); +} + +void glSampleCoveragex(GLclampx value, GLboolean invert) +{ + getDispatch()->glSampleCoveragex(value, invert); +} + +void glScalex(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glScalex(x, y, z); +} + +void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) +{ + getDispatch()->glScissor(x, y, width, height); +} + +void glShadeModel(GLenum mode) +{ + getDispatch()->glShadeModel(mode); +} + +void glStencilFunc(GLenum func, GLint ref, GLuint mask) +{ + getDispatch()->glStencilFunc(func, ref, mask); +} + +void glStencilMask(GLuint mask) +{ + getDispatch()->glStencilMask(mask); +} + +void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) +{ + getDispatch()->glStencilOp(fail, zfail, zpass); +} + +void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glTexCoordPointer(size, type, stride, pointer); +} + +void glTexEnvi(GLenum target, GLenum pname, GLint param) +{ + getDispatch()->glTexEnvi(target, pname, param); +} + +void glTexEnvx(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexEnvx(target, pname, param); +} + +void glTexEnviv(GLenum target, GLenum pname, const GLint *params) +{ + getDispatch()->glTexEnviv(target, pname, params); +} + +void glTexEnvxv(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexEnvxv(target, pname, params); +} + +void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) +{ + getDispatch()->glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); +} + +void glTexParameteri(GLenum target, GLenum pname, GLint param) +{ + getDispatch()->glTexParameteri(target, pname, param); +} + +void glTexParameterx(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexParameterx(target, pname, param); +} + +void glTexParameteriv(GLenum target, GLenum pname, const GLint *params) +{ + getDispatch()->glTexParameteriv(target, pname, params); +} + +void glTexParameterxv(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexParameterxv(target, pname, params); +} + +void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) +{ + getDispatch()->glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); +} + +void glTranslatex(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glTranslatex(x, y, z); +} + +void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glVertexPointer(size, type, stride, pointer); +} + +void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) +{ + getDispatch()->glViewport(x, y, width, height); +} + +void glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glPointSizePointerOES(type, stride, pointer); +} + +void glBlendEquationSeparateOES(GLenum modeRGB, GLenum modeAlpha) +{ + getDispatch()->glBlendEquationSeparateOES(modeRGB, modeAlpha); +} + +void glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +{ + getDispatch()->glBlendFuncSeparateOES(srcRGB, dstRGB, srcAlpha, dstAlpha); +} + +void glBlendEquationOES(GLenum mode) +{ + getDispatch()->glBlendEquationOES(mode); +} + +void glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) +{ + getDispatch()->glDrawTexsOES(x, y, z, width, height); +} + +void glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) +{ + getDispatch()->glDrawTexiOES(x, y, z, width, height); +} + +void glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) +{ + getDispatch()->glDrawTexxOES(x, y, z, width, height); +} + +void glDrawTexsvOES(const GLshort *coords) +{ + getDispatch()->glDrawTexsvOES(coords); +} + +void glDrawTexivOES(const GLint *coords) +{ + getDispatch()->glDrawTexivOES(coords); +} + +void glDrawTexxvOES(const GLfixed *coords) +{ + getDispatch()->glDrawTexxvOES(coords); +} + +void glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) +{ + getDispatch()->glDrawTexfOES(x, y, z, width, height); +} + +void glDrawTexfvOES(const GLfloat *coords) +{ + getDispatch()->glDrawTexfvOES(coords); +} + +void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) +{ + getDispatch()->glEGLImageTargetTexture2DOES(target, image); +} + +void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) +{ + getDispatch()->glEGLImageTargetRenderbufferStorageOES(target, image); +} + +void glAlphaFuncxOES(GLenum func, GLclampx ref) +{ + getDispatch()->glAlphaFuncxOES(func, ref); +} + +void glClearColorxOES(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) +{ + getDispatch()->glClearColorxOES(red, green, blue, alpha); +} + +void glClearDepthxOES(GLclampx depth) +{ + getDispatch()->glClearDepthxOES(depth); +} + +void glClipPlanexOES(GLenum plane, const GLfixed *equation) +{ + getDispatch()->glClipPlanexOES(plane, equation); +} + +void glColor4xOES(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) +{ + getDispatch()->glColor4xOES(red, green, blue, alpha); +} + +void glDepthRangexOES(GLclampx zNear, GLclampx zFar) +{ + getDispatch()->glDepthRangexOES(zNear, zFar); +} + +void glFogxOES(GLenum pname, GLfixed param) +{ + getDispatch()->glFogxOES(pname, param); +} + +void glFogxvOES(GLenum pname, const GLfixed *params) +{ + getDispatch()->glFogxvOES(pname, params); +} + +void glFrustumxOES(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glFrustumxOES(left, right, bottom, top, zNear, zFar); +} + +void glGetClipPlanexOES(GLenum pname, GLfixed eqn[4]) +{ + getDispatch()->glGetClipPlanexOES(pname, eqn); +} + +void glGetFixedvOES(GLenum pname, GLfixed *params) +{ + getDispatch()->glGetFixedvOES(pname, params); +} + +void glGetLightxvOES(GLenum light, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetLightxvOES(light, pname, params); +} + +void glGetMaterialxvOES(GLenum face, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetMaterialxvOES(face, pname, params); +} + +void glGetTexEnvxvOES(GLenum env, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexEnvxvOES(env, pname, params); +} + +void glGetTexParameterxvOES(GLenum target, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexParameterxvOES(target, pname, params); +} + +void glLightModelxOES(GLenum pname, GLfixed param) +{ + getDispatch()->glLightModelxOES(pname, param); +} + +void glLightModelxvOES(GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightModelxvOES(pname, params); +} + +void glLightxOES(GLenum light, GLenum pname, GLfixed param) +{ + getDispatch()->glLightxOES(light, pname, param); +} + +void glLightxvOES(GLenum light, GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightxvOES(light, pname, params); +} + +void glLineWidthxOES(GLfixed width) +{ + getDispatch()->glLineWidthxOES(width); +} + +void glLoadMatrixxOES(const GLfixed *m) +{ + getDispatch()->glLoadMatrixxOES(m); +} + +void glMaterialxOES(GLenum face, GLenum pname, GLfixed param) +{ + getDispatch()->glMaterialxOES(face, pname, param); +} + +void glMaterialxvOES(GLenum face, GLenum pname, const GLfixed *params) +{ + getDispatch()->glMaterialxvOES(face, pname, params); +} + +void glMultMatrixxOES(const GLfixed *m) +{ + getDispatch()->glMultMatrixxOES(m); +} + +void glMultiTexCoord4xOES(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) +{ + getDispatch()->glMultiTexCoord4xOES(target, s, t, r, q); +} + +void glNormal3xOES(GLfixed nx, GLfixed ny, GLfixed nz) +{ + getDispatch()->glNormal3xOES(nx, ny, nz); +} + +void glOrthoxOES(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glOrthoxOES(left, right, bottom, top, zNear, zFar); +} + +void glPointParameterxOES(GLenum pname, GLfixed param) +{ + getDispatch()->glPointParameterxOES(pname, param); +} + +void glPointParameterxvOES(GLenum pname, const GLfixed *params) +{ + getDispatch()->glPointParameterxvOES(pname, params); +} + +void glPointSizexOES(GLfixed size) +{ + getDispatch()->glPointSizexOES(size); +} + +void glPolygonOffsetxOES(GLfixed factor, GLfixed units) +{ + getDispatch()->glPolygonOffsetxOES(factor, units); +} + +void glRotatexOES(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glRotatexOES(angle, x, y, z); +} + +void glSampleCoveragexOES(GLclampx value, GLboolean invert) +{ + getDispatch()->glSampleCoveragexOES(value, invert); +} + +void glScalexOES(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glScalexOES(x, y, z); +} + +void glTexEnvxOES(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexEnvxOES(target, pname, param); +} + +void glTexEnvxvOES(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexEnvxvOES(target, pname, params); +} + +void glTexParameterxOES(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexParameterxOES(target, pname, param); +} + +void glTexParameterxvOES(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexParameterxvOES(target, pname, params); +} + +void glTranslatexOES(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glTranslatexOES(x, y, z); +} + +GLboolean glIsRenderbufferOES(GLuint renderbuffer) +{ + return getDispatch()->glIsRenderbufferOES(renderbuffer); +} + +void glBindRenderbufferOES(GLenum target, GLuint renderbuffer) +{ + getDispatch()->glBindRenderbufferOES(target, renderbuffer); +} + +void glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) +{ + getDispatch()->glDeleteRenderbuffersOES(n, renderbuffers); +} + +void glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) +{ + getDispatch()->glGenRenderbuffersOES(n, renderbuffers); +} + +void glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +{ + getDispatch()->glRenderbufferStorageOES(target, internalformat, width, height); +} + +void glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint *params) +{ + getDispatch()->glGetRenderbufferParameterivOES(target, pname, params); +} + +GLboolean glIsFramebufferOES(GLuint framebuffer) +{ + return getDispatch()->glIsFramebufferOES(framebuffer); +} + +void glBindFramebufferOES(GLenum target, GLuint framebuffer) +{ + getDispatch()->glBindFramebufferOES(target, framebuffer); +} + +void glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) +{ + getDispatch()->glDeleteFramebuffersOES(n, framebuffers); +} + +void glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) +{ + getDispatch()->glGenFramebuffersOES(n, framebuffers); +} + +GLenum glCheckFramebufferStatusOES(GLenum target) +{ + return getDispatch()->glCheckFramebufferStatusOES(target); +} + +void glFramebufferRenderbufferOES(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + getDispatch()->glFramebufferRenderbufferOES(target, attachment, renderbuffertarget, renderbuffer); +} + +void glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + getDispatch()->glFramebufferTexture2DOES(target, attachment, textarget, texture, level); +} + +void glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) +{ + getDispatch()->glGetFramebufferAttachmentParameterivOES(target, attachment, pname, params); +} + +void glGenerateMipmapOES(GLenum target) +{ + getDispatch()->glGenerateMipmapOES(target); +} + +void* glMapBufferOES(GLenum target, GLenum access) +{ + return getDispatch()->glMapBufferOES(target, access); +} + +GLboolean glUnmapBufferOES(GLenum target) +{ + return getDispatch()->glUnmapBufferOES(target); +} + +void glGetBufferPointervOES(GLenum target, GLenum pname, GLvoid **ptr) +{ + getDispatch()->glGetBufferPointervOES(target, pname, ptr); +} + +void glCurrentPaletteMatrixOES(GLuint matrixpaletteindex) +{ + getDispatch()->glCurrentPaletteMatrixOES(matrixpaletteindex); +} + +void glLoadPaletteFromModelViewMatrixOES() +{ + getDispatch()->glLoadPaletteFromModelViewMatrixOES(); +} + +void glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glMatrixIndexPointerOES(size, type, stride, pointer); +} + +void glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glWeightPointerOES(size, type, stride, pointer); +} + +GLbitfield glQueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]) +{ + return getDispatch()->glQueryMatrixxOES(mantissa, exponent); +} + +void glDepthRangefOES(GLclampf zNear, GLclampf zFar) +{ + getDispatch()->glDepthRangefOES(zNear, zFar); +} + +void glFrustumfOES(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glFrustumfOES(left, right, bottom, top, zNear, zFar); +} + +void glOrthofOES(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glOrthofOES(left, right, bottom, top, zNear, zFar); +} + +void glClipPlanefOES(GLenum plane, const GLfloat *equation) +{ + getDispatch()->glClipPlanefOES(plane, equation); +} + +void glGetClipPlanefOES(GLenum pname, GLfloat eqn[4]) +{ + getDispatch()->glGetClipPlanefOES(pname, eqn); +} + +void glClearDepthfOES(GLclampf depth) +{ + getDispatch()->glClearDepthfOES(depth); +} + +void glTexGenfOES(GLenum coord, GLenum pname, GLfloat param) +{ + getDispatch()->glTexGenfOES(coord, pname, param); +} + +void glTexGenfvOES(GLenum coord, GLenum pname, const GLfloat *params) +{ + getDispatch()->glTexGenfvOES(coord, pname, params); +} + +void glTexGeniOES(GLenum coord, GLenum pname, GLint param) +{ + getDispatch()->glTexGeniOES(coord, pname, param); +} + +void glTexGenivOES(GLenum coord, GLenum pname, const GLint *params) +{ + getDispatch()->glTexGenivOES(coord, pname, params); +} + +void glTexGenxOES(GLenum coord, GLenum pname, GLfixed param) +{ + getDispatch()->glTexGenxOES(coord, pname, param); +} + +void glTexGenxvOES(GLenum coord, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexGenxvOES(coord, pname, params); +} + +void glGetTexGenfvOES(GLenum coord, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetTexGenfvOES(coord, pname, params); +} + +void glGetTexGenivOES(GLenum coord, GLenum pname, GLint *params) +{ + getDispatch()->glGetTexGenivOES(coord, pname, params); +} + +void glGetTexGenxvOES(GLenum coord, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexGenxvOES(coord, pname, params); +} + +void glBindVertexArrayOES(GLuint array) +{ + getDispatch()->glBindVertexArrayOES(array); +} + +void glDeleteVertexArraysOES(GLsizei n, const GLuint *arrays) +{ + getDispatch()->glDeleteVertexArraysOES(n, arrays); +} + +void glGenVertexArraysOES(GLsizei n, GLuint *arrays) +{ + getDispatch()->glGenVertexArraysOES(n, arrays); +} + +GLboolean glIsVertexArrayOES(GLuint array) +{ + return getDispatch()->glIsVertexArrayOES(array); +} + +void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments) +{ + getDispatch()->glDiscardFramebufferEXT(target, numAttachments, attachments); +} + +void glMultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +{ + getDispatch()->glMultiDrawArraysEXT(mode, first, count, primcount); +} + +void glMultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount) +{ + getDispatch()->glMultiDrawElementsEXT(mode, count, type, indices, primcount); +} + +void glClipPlanefIMG(GLenum p, const GLfloat *eqn) +{ + getDispatch()->glClipPlanefIMG(p, eqn); +} + +void glClipPlanexIMG(GLenum p, const GLfixed *eqn) +{ + getDispatch()->glClipPlanexIMG(p, eqn); +} + +void glRenderbufferStorageMultisampleIMG(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +{ + getDispatch()->glRenderbufferStorageMultisampleIMG(target, samples, internalformat, width, height); +} + +void glFramebufferTexture2DMultisampleIMG(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) +{ + getDispatch()->glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, texture, level, samples); +} + +void glDeleteFencesNV(GLsizei n, const GLuint *fences) +{ + getDispatch()->glDeleteFencesNV(n, fences); +} + +void glGenFencesNV(GLsizei n, GLuint *fences) +{ + getDispatch()->glGenFencesNV(n, fences); +} + +GLboolean glIsFenceNV(GLuint fence) +{ + return getDispatch()->glIsFenceNV(fence); +} + +GLboolean glTestFenceNV(GLuint fence) +{ + return getDispatch()->glTestFenceNV(fence); +} + +void glGetFenceivNV(GLuint fence, GLenum pname, GLint *params) +{ + getDispatch()->glGetFenceivNV(fence, pname, params); +} + +void glFinishFenceNV(GLuint fence) +{ + getDispatch()->glFinishFenceNV(fence); +} + +void glSetFenceNV(GLuint fence, GLenum condition) +{ + getDispatch()->glSetFenceNV(fence, condition); +} + +void glGetDriverControlsQCOM(GLint *num, GLsizei size, GLuint *driverControls) +{ + getDispatch()->glGetDriverControlsQCOM(num, size, driverControls); +} + +void glGetDriverControlStringQCOM(GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString) +{ + getDispatch()->glGetDriverControlStringQCOM(driverControl, bufSize, length, driverControlString); +} + +void glEnableDriverControlQCOM(GLuint driverControl) +{ + getDispatch()->glEnableDriverControlQCOM(driverControl); +} + +void glDisableDriverControlQCOM(GLuint driverControl) +{ + getDispatch()->glDisableDriverControlQCOM(driverControl); +} + +void glExtGetTexturesQCOM(GLuint *textures, GLint maxTextures, GLint *numTextures) +{ + getDispatch()->glExtGetTexturesQCOM(textures, maxTextures, numTextures); +} + +void glExtGetBuffersQCOM(GLuint *buffers, GLint maxBuffers, GLint *numBuffers) +{ + getDispatch()->glExtGetBuffersQCOM(buffers, maxBuffers, numBuffers); +} + +void glExtGetRenderbuffersQCOM(GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers) +{ + getDispatch()->glExtGetRenderbuffersQCOM(renderbuffers, maxRenderbuffers, numRenderbuffers); +} + +void glExtGetFramebuffersQCOM(GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers) +{ + getDispatch()->glExtGetFramebuffersQCOM(framebuffers, maxFramebuffers, numFramebuffers); +} + +void glExtGetTexLevelParameterivQCOM(GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params) +{ + getDispatch()->glExtGetTexLevelParameterivQCOM(texture, face, level, pname, params); +} + +void glExtTexObjectStateOverrideiQCOM(GLenum target, GLenum pname, GLint param) +{ + getDispatch()->glExtTexObjectStateOverrideiQCOM(target, pname, param); +} + +void glExtGetTexSubImageQCOM(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels) +{ + getDispatch()->glExtGetTexSubImageQCOM(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, texels); +} + +void glExtGetBufferPointervQCOM(GLenum target, GLvoid **params) +{ + getDispatch()->glExtGetBufferPointervQCOM(target, params); +} + +void glExtGetShadersQCOM(GLuint *shaders, GLint maxShaders, GLint *numShaders) +{ + getDispatch()->glExtGetShadersQCOM(shaders, maxShaders, numShaders); +} + +void glExtGetProgramsQCOM(GLuint *programs, GLint maxPrograms, GLint *numPrograms) +{ + getDispatch()->glExtGetProgramsQCOM(programs, maxPrograms, numPrograms); +} + +GLboolean glExtIsProgramBinaryQCOM(GLuint program) +{ + return getDispatch()->glExtIsProgramBinaryQCOM(program); +} + +void glExtGetProgramBinarySourceQCOM(GLuint program, GLenum shadertype, GLchar *source, GLint *length) +{ + getDispatch()->glExtGetProgramBinarySourceQCOM(program, shadertype, source, length); +} + +void glStartTilingQCOM(GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask) +{ + getDispatch()->glStartTilingQCOM(x, y, width, height, preserveMask); +} + +void glEndTilingQCOM(GLbitfield preserveMask) +{ + getDispatch()->glEndTilingQCOM(preserveMask); +} + diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.cpp b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.cpp new file mode 100644 index 0000000..0a17624 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.cpp @@ -0,0 +1,298 @@ +/* +* 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 "gles_dispatch.h" +#include <stdio.h> +#include <dlfcn.h> + +gles_dispatch *create_gles_dispatch(void *gles_android) +{ + gles_dispatch *disp = new gles_dispatch; + + void *ptr; + ptr = dlsym(gles_android,"glAlphaFunc"); disp->set_glAlphaFunc((glAlphaFunc_t)ptr); + ptr = dlsym(gles_android,"glClearColor"); disp->set_glClearColor((glClearColor_t)ptr); + ptr = dlsym(gles_android,"glClearDepthf"); disp->set_glClearDepthf((glClearDepthf_t)ptr); + ptr = dlsym(gles_android,"glClipPlanef"); disp->set_glClipPlanef((glClipPlanef_t)ptr); + ptr = dlsym(gles_android,"glColor4f"); disp->set_glColor4f((glColor4f_t)ptr); + ptr = dlsym(gles_android,"glDepthRangef"); disp->set_glDepthRangef((glDepthRangef_t)ptr); + ptr = dlsym(gles_android,"glFogf"); disp->set_glFogf((glFogf_t)ptr); + ptr = dlsym(gles_android,"glFogfv"); disp->set_glFogfv((glFogfv_t)ptr); + ptr = dlsym(gles_android,"glFrustumf"); disp->set_glFrustumf((glFrustumf_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanef"); disp->set_glGetClipPlanef((glGetClipPlanef_t)ptr); + ptr = dlsym(gles_android,"glGetFloatv"); disp->set_glGetFloatv((glGetFloatv_t)ptr); + ptr = dlsym(gles_android,"glGetLightfv"); disp->set_glGetLightfv((glGetLightfv_t)ptr); + ptr = dlsym(gles_android,"glGetMaterialfv"); disp->set_glGetMaterialfv((glGetMaterialfv_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnvfv"); disp->set_glGetTexEnvfv((glGetTexEnvfv_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameterfv"); disp->set_glGetTexParameterfv((glGetTexParameterfv_t)ptr); + ptr = dlsym(gles_android,"glLightModelf"); disp->set_glLightModelf((glLightModelf_t)ptr); + ptr = dlsym(gles_android,"glLightModelfv"); disp->set_glLightModelfv((glLightModelfv_t)ptr); + ptr = dlsym(gles_android,"glLightf"); disp->set_glLightf((glLightf_t)ptr); + ptr = dlsym(gles_android,"glLightfv"); disp->set_glLightfv((glLightfv_t)ptr); + ptr = dlsym(gles_android,"glLineWidth"); disp->set_glLineWidth((glLineWidth_t)ptr); + ptr = dlsym(gles_android,"glLoadMatrixf"); disp->set_glLoadMatrixf((glLoadMatrixf_t)ptr); + ptr = dlsym(gles_android,"glMaterialf"); disp->set_glMaterialf((glMaterialf_t)ptr); + ptr = dlsym(gles_android,"glMaterialfv"); disp->set_glMaterialfv((glMaterialfv_t)ptr); + ptr = dlsym(gles_android,"glMultMatrixf"); disp->set_glMultMatrixf((glMultMatrixf_t)ptr); + ptr = dlsym(gles_android,"glMultiTexCoord4f"); disp->set_glMultiTexCoord4f((glMultiTexCoord4f_t)ptr); + ptr = dlsym(gles_android,"glNormal3f"); disp->set_glNormal3f((glNormal3f_t)ptr); + ptr = dlsym(gles_android,"glOrthof"); disp->set_glOrthof((glOrthof_t)ptr); + ptr = dlsym(gles_android,"glPointParameterf"); disp->set_glPointParameterf((glPointParameterf_t)ptr); + ptr = dlsym(gles_android,"glPointParameterfv"); disp->set_glPointParameterfv((glPointParameterfv_t)ptr); + ptr = dlsym(gles_android,"glPointSize"); disp->set_glPointSize((glPointSize_t)ptr); + ptr = dlsym(gles_android,"glPolygonOffset"); disp->set_glPolygonOffset((glPolygonOffset_t)ptr); + ptr = dlsym(gles_android,"glRotatef"); disp->set_glRotatef((glRotatef_t)ptr); + ptr = dlsym(gles_android,"glScalef"); disp->set_glScalef((glScalef_t)ptr); + ptr = dlsym(gles_android,"glTexEnvf"); disp->set_glTexEnvf((glTexEnvf_t)ptr); + ptr = dlsym(gles_android,"glTexEnvfv"); disp->set_glTexEnvfv((glTexEnvfv_t)ptr); + ptr = dlsym(gles_android,"glTexParameterf"); disp->set_glTexParameterf((glTexParameterf_t)ptr); + ptr = dlsym(gles_android,"glTexParameterfv"); disp->set_glTexParameterfv((glTexParameterfv_t)ptr); + ptr = dlsym(gles_android,"glTranslatef"); disp->set_glTranslatef((glTranslatef_t)ptr); + ptr = dlsym(gles_android,"glActiveTexture"); disp->set_glActiveTexture((glActiveTexture_t)ptr); + ptr = dlsym(gles_android,"glAlphaFuncx"); disp->set_glAlphaFuncx((glAlphaFuncx_t)ptr); + ptr = dlsym(gles_android,"glBindBuffer"); disp->set_glBindBuffer((glBindBuffer_t)ptr); + ptr = dlsym(gles_android,"glBindTexture"); disp->set_glBindTexture((glBindTexture_t)ptr); + ptr = dlsym(gles_android,"glBlendFunc"); disp->set_glBlendFunc((glBlendFunc_t)ptr); + ptr = dlsym(gles_android,"glBufferData"); disp->set_glBufferData((glBufferData_t)ptr); + ptr = dlsym(gles_android,"glBufferSubData"); disp->set_glBufferSubData((glBufferSubData_t)ptr); + ptr = dlsym(gles_android,"glClear"); disp->set_glClear((glClear_t)ptr); + ptr = dlsym(gles_android,"glClearColorx"); disp->set_glClearColorx((glClearColorx_t)ptr); + ptr = dlsym(gles_android,"glClearDepthx"); disp->set_glClearDepthx((glClearDepthx_t)ptr); + ptr = dlsym(gles_android,"glClearStencil"); disp->set_glClearStencil((glClearStencil_t)ptr); + ptr = dlsym(gles_android,"glClientActiveTexture"); disp->set_glClientActiveTexture((glClientActiveTexture_t)ptr); + ptr = dlsym(gles_android,"glClipPlanex"); disp->set_glClipPlanex((glClipPlanex_t)ptr); + ptr = dlsym(gles_android,"glColor4ub"); disp->set_glColor4ub((glColor4ub_t)ptr); + ptr = dlsym(gles_android,"glColor4x"); disp->set_glColor4x((glColor4x_t)ptr); + ptr = dlsym(gles_android,"glColorMask"); disp->set_glColorMask((glColorMask_t)ptr); + ptr = dlsym(gles_android,"glColorPointer"); disp->set_glColorPointer((glColorPointer_t)ptr); + ptr = dlsym(gles_android,"glCompressedTexImage2D"); disp->set_glCompressedTexImage2D((glCompressedTexImage2D_t)ptr); + ptr = dlsym(gles_android,"glCompressedTexSubImage2D"); disp->set_glCompressedTexSubImage2D((glCompressedTexSubImage2D_t)ptr); + ptr = dlsym(gles_android,"glCopyTexImage2D"); disp->set_glCopyTexImage2D((glCopyTexImage2D_t)ptr); + ptr = dlsym(gles_android,"glCopyTexSubImage2D"); disp->set_glCopyTexSubImage2D((glCopyTexSubImage2D_t)ptr); + ptr = dlsym(gles_android,"glCullFace"); disp->set_glCullFace((glCullFace_t)ptr); + ptr = dlsym(gles_android,"glDeleteBuffers"); disp->set_glDeleteBuffers((glDeleteBuffers_t)ptr); + ptr = dlsym(gles_android,"glDeleteTextures"); disp->set_glDeleteTextures((glDeleteTextures_t)ptr); + ptr = dlsym(gles_android,"glDepthFunc"); disp->set_glDepthFunc((glDepthFunc_t)ptr); + ptr = dlsym(gles_android,"glDepthMask"); disp->set_glDepthMask((glDepthMask_t)ptr); + ptr = dlsym(gles_android,"glDepthRangex"); disp->set_glDepthRangex((glDepthRangex_t)ptr); + ptr = dlsym(gles_android,"glDisable"); disp->set_glDisable((glDisable_t)ptr); + ptr = dlsym(gles_android,"glDisableClientState"); disp->set_glDisableClientState((glDisableClientState_t)ptr); + ptr = dlsym(gles_android,"glDrawArrays"); disp->set_glDrawArrays((glDrawArrays_t)ptr); + ptr = dlsym(gles_android,"glDrawElements"); disp->set_glDrawElements((glDrawElements_t)ptr); + ptr = dlsym(gles_android,"glEnable"); disp->set_glEnable((glEnable_t)ptr); + ptr = dlsym(gles_android,"glEnableClientState"); disp->set_glEnableClientState((glEnableClientState_t)ptr); + ptr = dlsym(gles_android,"glFinish"); disp->set_glFinish((glFinish_t)ptr); + ptr = dlsym(gles_android,"glFlush"); disp->set_glFlush((glFlush_t)ptr); + ptr = dlsym(gles_android,"glFogx"); disp->set_glFogx((glFogx_t)ptr); + ptr = dlsym(gles_android,"glFogxv"); disp->set_glFogxv((glFogxv_t)ptr); + ptr = dlsym(gles_android,"glFrontFace"); disp->set_glFrontFace((glFrontFace_t)ptr); + ptr = dlsym(gles_android,"glFrustumx"); disp->set_glFrustumx((glFrustumx_t)ptr); + ptr = dlsym(gles_android,"glGetBooleanv"); disp->set_glGetBooleanv((glGetBooleanv_t)ptr); + ptr = dlsym(gles_android,"glGetBufferParameteriv"); disp->set_glGetBufferParameteriv((glGetBufferParameteriv_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanex"); disp->set_glGetClipPlanex((glGetClipPlanex_t)ptr); + ptr = dlsym(gles_android,"glGenBuffers"); disp->set_glGenBuffers((glGenBuffers_t)ptr); + ptr = dlsym(gles_android,"glGenTextures"); disp->set_glGenTextures((glGenTextures_t)ptr); + ptr = dlsym(gles_android,"glGetError"); disp->set_glGetError((glGetError_t)ptr); + ptr = dlsym(gles_android,"glGetFixedv"); disp->set_glGetFixedv((glGetFixedv_t)ptr); + ptr = dlsym(gles_android,"glGetIntegerv"); disp->set_glGetIntegerv((glGetIntegerv_t)ptr); + ptr = dlsym(gles_android,"glGetLightxv"); disp->set_glGetLightxv((glGetLightxv_t)ptr); + ptr = dlsym(gles_android,"glGetMaterialxv"); disp->set_glGetMaterialxv((glGetMaterialxv_t)ptr); + ptr = dlsym(gles_android,"glGetPointerv"); disp->set_glGetPointerv((glGetPointerv_t)ptr); + ptr = dlsym(gles_android,"glGetString"); disp->set_glGetString((glGetString_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnviv"); disp->set_glGetTexEnviv((glGetTexEnviv_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnvxv"); disp->set_glGetTexEnvxv((glGetTexEnvxv_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameteriv"); disp->set_glGetTexParameteriv((glGetTexParameteriv_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameterxv"); disp->set_glGetTexParameterxv((glGetTexParameterxv_t)ptr); + ptr = dlsym(gles_android,"glHint"); disp->set_glHint((glHint_t)ptr); + ptr = dlsym(gles_android,"glIsBuffer"); disp->set_glIsBuffer((glIsBuffer_t)ptr); + ptr = dlsym(gles_android,"glIsEnabled"); disp->set_glIsEnabled((glIsEnabled_t)ptr); + ptr = dlsym(gles_android,"glIsTexture"); disp->set_glIsTexture((glIsTexture_t)ptr); + ptr = dlsym(gles_android,"glLightModelx"); disp->set_glLightModelx((glLightModelx_t)ptr); + ptr = dlsym(gles_android,"glLightModelxv"); disp->set_glLightModelxv((glLightModelxv_t)ptr); + ptr = dlsym(gles_android,"glLightx"); disp->set_glLightx((glLightx_t)ptr); + ptr = dlsym(gles_android,"glLightxv"); disp->set_glLightxv((glLightxv_t)ptr); + ptr = dlsym(gles_android,"glLineWidthx"); disp->set_glLineWidthx((glLineWidthx_t)ptr); + ptr = dlsym(gles_android,"glLoadIdentity"); disp->set_glLoadIdentity((glLoadIdentity_t)ptr); + ptr = dlsym(gles_android,"glLoadMatrixx"); disp->set_glLoadMatrixx((glLoadMatrixx_t)ptr); + ptr = dlsym(gles_android,"glLogicOp"); disp->set_glLogicOp((glLogicOp_t)ptr); + ptr = dlsym(gles_android,"glMaterialx"); disp->set_glMaterialx((glMaterialx_t)ptr); + ptr = dlsym(gles_android,"glMaterialxv"); disp->set_glMaterialxv((glMaterialxv_t)ptr); + ptr = dlsym(gles_android,"glMatrixMode"); disp->set_glMatrixMode((glMatrixMode_t)ptr); + ptr = dlsym(gles_android,"glMultMatrixx"); disp->set_glMultMatrixx((glMultMatrixx_t)ptr); + ptr = dlsym(gles_android,"glMultiTexCoord4x"); disp->set_glMultiTexCoord4x((glMultiTexCoord4x_t)ptr); + ptr = dlsym(gles_android,"glNormal3x"); disp->set_glNormal3x((glNormal3x_t)ptr); + ptr = dlsym(gles_android,"glNormalPointer"); disp->set_glNormalPointer((glNormalPointer_t)ptr); + ptr = dlsym(gles_android,"glOrthox"); disp->set_glOrthox((glOrthox_t)ptr); + ptr = dlsym(gles_android,"glPixelStorei"); disp->set_glPixelStorei((glPixelStorei_t)ptr); + ptr = dlsym(gles_android,"glPointParameterx"); disp->set_glPointParameterx((glPointParameterx_t)ptr); + ptr = dlsym(gles_android,"glPointParameterxv"); disp->set_glPointParameterxv((glPointParameterxv_t)ptr); + ptr = dlsym(gles_android,"glPointSizex"); disp->set_glPointSizex((glPointSizex_t)ptr); + ptr = dlsym(gles_android,"glPolygonOffsetx"); disp->set_glPolygonOffsetx((glPolygonOffsetx_t)ptr); + ptr = dlsym(gles_android,"glPopMatrix"); disp->set_glPopMatrix((glPopMatrix_t)ptr); + ptr = dlsym(gles_android,"glPushMatrix"); disp->set_glPushMatrix((glPushMatrix_t)ptr); + ptr = dlsym(gles_android,"glReadPixels"); disp->set_glReadPixels((glReadPixels_t)ptr); + ptr = dlsym(gles_android,"glRotatex"); disp->set_glRotatex((glRotatex_t)ptr); + ptr = dlsym(gles_android,"glSampleCoverage"); disp->set_glSampleCoverage((glSampleCoverage_t)ptr); + ptr = dlsym(gles_android,"glSampleCoveragex"); disp->set_glSampleCoveragex((glSampleCoveragex_t)ptr); + ptr = dlsym(gles_android,"glScalex"); disp->set_glScalex((glScalex_t)ptr); + ptr = dlsym(gles_android,"glScissor"); disp->set_glScissor((glScissor_t)ptr); + ptr = dlsym(gles_android,"glShadeModel"); disp->set_glShadeModel((glShadeModel_t)ptr); + ptr = dlsym(gles_android,"glStencilFunc"); disp->set_glStencilFunc((glStencilFunc_t)ptr); + ptr = dlsym(gles_android,"glStencilMask"); disp->set_glStencilMask((glStencilMask_t)ptr); + ptr = dlsym(gles_android,"glStencilOp"); disp->set_glStencilOp((glStencilOp_t)ptr); + ptr = dlsym(gles_android,"glTexCoordPointer"); disp->set_glTexCoordPointer((glTexCoordPointer_t)ptr); + ptr = dlsym(gles_android,"glTexEnvi"); disp->set_glTexEnvi((glTexEnvi_t)ptr); + ptr = dlsym(gles_android,"glTexEnvx"); disp->set_glTexEnvx((glTexEnvx_t)ptr); + ptr = dlsym(gles_android,"glTexEnviv"); disp->set_glTexEnviv((glTexEnviv_t)ptr); + ptr = dlsym(gles_android,"glTexEnvxv"); disp->set_glTexEnvxv((glTexEnvxv_t)ptr); + ptr = dlsym(gles_android,"glTexImage2D"); disp->set_glTexImage2D((glTexImage2D_t)ptr); + ptr = dlsym(gles_android,"glTexParameteri"); disp->set_glTexParameteri((glTexParameteri_t)ptr); + ptr = dlsym(gles_android,"glTexParameterx"); disp->set_glTexParameterx((glTexParameterx_t)ptr); + ptr = dlsym(gles_android,"glTexParameteriv"); disp->set_glTexParameteriv((glTexParameteriv_t)ptr); + ptr = dlsym(gles_android,"glTexParameterxv"); disp->set_glTexParameterxv((glTexParameterxv_t)ptr); + ptr = dlsym(gles_android,"glTexSubImage2D"); disp->set_glTexSubImage2D((glTexSubImage2D_t)ptr); + ptr = dlsym(gles_android,"glTranslatex"); disp->set_glTranslatex((glTranslatex_t)ptr); + ptr = dlsym(gles_android,"glVertexPointer"); disp->set_glVertexPointer((glVertexPointer_t)ptr); + ptr = dlsym(gles_android,"glViewport"); disp->set_glViewport((glViewport_t)ptr); + ptr = dlsym(gles_android,"glPointSizePointerOES"); disp->set_glPointSizePointerOES((glPointSizePointerOES_t)ptr); + ptr = dlsym(gles_android,"glBlendEquationSeparateOES"); disp->set_glBlendEquationSeparateOES((glBlendEquationSeparateOES_t)ptr); + ptr = dlsym(gles_android,"glBlendFuncSeparateOES"); disp->set_glBlendFuncSeparateOES((glBlendFuncSeparateOES_t)ptr); + ptr = dlsym(gles_android,"glBlendEquationOES"); disp->set_glBlendEquationOES((glBlendEquationOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexsOES"); disp->set_glDrawTexsOES((glDrawTexsOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexiOES"); disp->set_glDrawTexiOES((glDrawTexiOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexxOES"); disp->set_glDrawTexxOES((glDrawTexxOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexsvOES"); disp->set_glDrawTexsvOES((glDrawTexsvOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexivOES"); disp->set_glDrawTexivOES((glDrawTexivOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexxvOES"); disp->set_glDrawTexxvOES((glDrawTexxvOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexfOES"); disp->set_glDrawTexfOES((glDrawTexfOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexfvOES"); disp->set_glDrawTexfvOES((glDrawTexfvOES_t)ptr); + ptr = dlsym(gles_android,"glEGLImageTargetTexture2DOES"); disp->set_glEGLImageTargetTexture2DOES((glEGLImageTargetTexture2DOES_t)ptr); + ptr = dlsym(gles_android,"glEGLImageTargetRenderbufferStorageOES"); disp->set_glEGLImageTargetRenderbufferStorageOES((glEGLImageTargetRenderbufferStorageOES_t)ptr); + ptr = dlsym(gles_android,"glAlphaFuncxOES"); disp->set_glAlphaFuncxOES((glAlphaFuncxOES_t)ptr); + ptr = dlsym(gles_android,"glClearColorxOES"); disp->set_glClearColorxOES((glClearColorxOES_t)ptr); + ptr = dlsym(gles_android,"glClearDepthxOES"); disp->set_glClearDepthxOES((glClearDepthxOES_t)ptr); + ptr = dlsym(gles_android,"glClipPlanexOES"); disp->set_glClipPlanexOES((glClipPlanexOES_t)ptr); + ptr = dlsym(gles_android,"glColor4xOES"); disp->set_glColor4xOES((glColor4xOES_t)ptr); + ptr = dlsym(gles_android,"glDepthRangexOES"); disp->set_glDepthRangexOES((glDepthRangexOES_t)ptr); + ptr = dlsym(gles_android,"glFogxOES"); disp->set_glFogxOES((glFogxOES_t)ptr); + ptr = dlsym(gles_android,"glFogxvOES"); disp->set_glFogxvOES((glFogxvOES_t)ptr); + ptr = dlsym(gles_android,"glFrustumxOES"); disp->set_glFrustumxOES((glFrustumxOES_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanexOES"); disp->set_glGetClipPlanexOES((glGetClipPlanexOES_t)ptr); + ptr = dlsym(gles_android,"glGetFixedvOES"); disp->set_glGetFixedvOES((glGetFixedvOES_t)ptr); + ptr = dlsym(gles_android,"glGetLightxvOES"); disp->set_glGetLightxvOES((glGetLightxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetMaterialxvOES"); disp->set_glGetMaterialxvOES((glGetMaterialxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnvxvOES"); disp->set_glGetTexEnvxvOES((glGetTexEnvxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameterxvOES"); disp->set_glGetTexParameterxvOES((glGetTexParameterxvOES_t)ptr); + ptr = dlsym(gles_android,"glLightModelxOES"); disp->set_glLightModelxOES((glLightModelxOES_t)ptr); + ptr = dlsym(gles_android,"glLightModelxvOES"); disp->set_glLightModelxvOES((glLightModelxvOES_t)ptr); + ptr = dlsym(gles_android,"glLightxOES"); disp->set_glLightxOES((glLightxOES_t)ptr); + ptr = dlsym(gles_android,"glLightxvOES"); disp->set_glLightxvOES((glLightxvOES_t)ptr); + ptr = dlsym(gles_android,"glLineWidthxOES"); disp->set_glLineWidthxOES((glLineWidthxOES_t)ptr); + ptr = dlsym(gles_android,"glLoadMatrixxOES"); disp->set_glLoadMatrixxOES((glLoadMatrixxOES_t)ptr); + ptr = dlsym(gles_android,"glMaterialxOES"); disp->set_glMaterialxOES((glMaterialxOES_t)ptr); + ptr = dlsym(gles_android,"glMaterialxvOES"); disp->set_glMaterialxvOES((glMaterialxvOES_t)ptr); + ptr = dlsym(gles_android,"glMultMatrixxOES"); disp->set_glMultMatrixxOES((glMultMatrixxOES_t)ptr); + ptr = dlsym(gles_android,"glMultiTexCoord4xOES"); disp->set_glMultiTexCoord4xOES((glMultiTexCoord4xOES_t)ptr); + ptr = dlsym(gles_android,"glNormal3xOES"); disp->set_glNormal3xOES((glNormal3xOES_t)ptr); + ptr = dlsym(gles_android,"glOrthoxOES"); disp->set_glOrthoxOES((glOrthoxOES_t)ptr); + ptr = dlsym(gles_android,"glPointParameterxOES"); disp->set_glPointParameterxOES((glPointParameterxOES_t)ptr); + ptr = dlsym(gles_android,"glPointParameterxvOES"); disp->set_glPointParameterxvOES((glPointParameterxvOES_t)ptr); + ptr = dlsym(gles_android,"glPointSizexOES"); disp->set_glPointSizexOES((glPointSizexOES_t)ptr); + ptr = dlsym(gles_android,"glPolygonOffsetxOES"); disp->set_glPolygonOffsetxOES((glPolygonOffsetxOES_t)ptr); + ptr = dlsym(gles_android,"glRotatexOES"); disp->set_glRotatexOES((glRotatexOES_t)ptr); + ptr = dlsym(gles_android,"glSampleCoveragexOES"); disp->set_glSampleCoveragexOES((glSampleCoveragexOES_t)ptr); + ptr = dlsym(gles_android,"glScalexOES"); disp->set_glScalexOES((glScalexOES_t)ptr); + ptr = dlsym(gles_android,"glTexEnvxOES"); disp->set_glTexEnvxOES((glTexEnvxOES_t)ptr); + ptr = dlsym(gles_android,"glTexEnvxvOES"); disp->set_glTexEnvxvOES((glTexEnvxvOES_t)ptr); + ptr = dlsym(gles_android,"glTexParameterxOES"); disp->set_glTexParameterxOES((glTexParameterxOES_t)ptr); + ptr = dlsym(gles_android,"glTexParameterxvOES"); disp->set_glTexParameterxvOES((glTexParameterxvOES_t)ptr); + ptr = dlsym(gles_android,"glTranslatexOES"); disp->set_glTranslatexOES((glTranslatexOES_t)ptr); + ptr = dlsym(gles_android,"glIsRenderbufferOES"); disp->set_glIsRenderbufferOES((glIsRenderbufferOES_t)ptr); + ptr = dlsym(gles_android,"glBindRenderbufferOES"); disp->set_glBindRenderbufferOES((glBindRenderbufferOES_t)ptr); + ptr = dlsym(gles_android,"glDeleteRenderbuffersOES"); disp->set_glDeleteRenderbuffersOES((glDeleteRenderbuffersOES_t)ptr); + ptr = dlsym(gles_android,"glGenRenderbuffersOES"); disp->set_glGenRenderbuffersOES((glGenRenderbuffersOES_t)ptr); + ptr = dlsym(gles_android,"glRenderbufferStorageOES"); disp->set_glRenderbufferStorageOES((glRenderbufferStorageOES_t)ptr); + ptr = dlsym(gles_android,"glGetRenderbufferParameterivOES"); disp->set_glGetRenderbufferParameterivOES((glGetRenderbufferParameterivOES_t)ptr); + ptr = dlsym(gles_android,"glIsFramebufferOES"); disp->set_glIsFramebufferOES((glIsFramebufferOES_t)ptr); + ptr = dlsym(gles_android,"glBindFramebufferOES"); disp->set_glBindFramebufferOES((glBindFramebufferOES_t)ptr); + ptr = dlsym(gles_android,"glDeleteFramebuffersOES"); disp->set_glDeleteFramebuffersOES((glDeleteFramebuffersOES_t)ptr); + ptr = dlsym(gles_android,"glGenFramebuffersOES"); disp->set_glGenFramebuffersOES((glGenFramebuffersOES_t)ptr); + ptr = dlsym(gles_android,"glCheckFramebufferStatusOES"); disp->set_glCheckFramebufferStatusOES((glCheckFramebufferStatusOES_t)ptr); + ptr = dlsym(gles_android,"glFramebufferRenderbufferOES"); disp->set_glFramebufferRenderbufferOES((glFramebufferRenderbufferOES_t)ptr); + ptr = dlsym(gles_android,"glFramebufferTexture2DOES"); disp->set_glFramebufferTexture2DOES((glFramebufferTexture2DOES_t)ptr); + ptr = dlsym(gles_android,"glGetFramebufferAttachmentParameterivOES"); disp->set_glGetFramebufferAttachmentParameterivOES((glGetFramebufferAttachmentParameterivOES_t)ptr); + ptr = dlsym(gles_android,"glGenerateMipmapOES"); disp->set_glGenerateMipmapOES((glGenerateMipmapOES_t)ptr); + ptr = dlsym(gles_android,"glMapBufferOES"); disp->set_glMapBufferOES((glMapBufferOES_t)ptr); + ptr = dlsym(gles_android,"glUnmapBufferOES"); disp->set_glUnmapBufferOES((glUnmapBufferOES_t)ptr); + ptr = dlsym(gles_android,"glGetBufferPointervOES"); disp->set_glGetBufferPointervOES((glGetBufferPointervOES_t)ptr); + ptr = dlsym(gles_android,"glCurrentPaletteMatrixOES"); disp->set_glCurrentPaletteMatrixOES((glCurrentPaletteMatrixOES_t)ptr); + ptr = dlsym(gles_android,"glLoadPaletteFromModelViewMatrixOES"); disp->set_glLoadPaletteFromModelViewMatrixOES((glLoadPaletteFromModelViewMatrixOES_t)ptr); + ptr = dlsym(gles_android,"glMatrixIndexPointerOES"); disp->set_glMatrixIndexPointerOES((glMatrixIndexPointerOES_t)ptr); + ptr = dlsym(gles_android,"glWeightPointerOES"); disp->set_glWeightPointerOES((glWeightPointerOES_t)ptr); + ptr = dlsym(gles_android,"glQueryMatrixxOES"); disp->set_glQueryMatrixxOES((glQueryMatrixxOES_t)ptr); + ptr = dlsym(gles_android,"glDepthRangefOES"); disp->set_glDepthRangefOES((glDepthRangefOES_t)ptr); + ptr = dlsym(gles_android,"glFrustumfOES"); disp->set_glFrustumfOES((glFrustumfOES_t)ptr); + ptr = dlsym(gles_android,"glOrthofOES"); disp->set_glOrthofOES((glOrthofOES_t)ptr); + ptr = dlsym(gles_android,"glClipPlanefOES"); disp->set_glClipPlanefOES((glClipPlanefOES_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanefOES"); disp->set_glGetClipPlanefOES((glGetClipPlanefOES_t)ptr); + ptr = dlsym(gles_android,"glClearDepthfOES"); disp->set_glClearDepthfOES((glClearDepthfOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenfOES"); disp->set_glTexGenfOES((glTexGenfOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenfvOES"); disp->set_glTexGenfvOES((glTexGenfvOES_t)ptr); + ptr = dlsym(gles_android,"glTexGeniOES"); disp->set_glTexGeniOES((glTexGeniOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenivOES"); disp->set_glTexGenivOES((glTexGenivOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenxOES"); disp->set_glTexGenxOES((glTexGenxOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenxvOES"); disp->set_glTexGenxvOES((glTexGenxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexGenfvOES"); disp->set_glGetTexGenfvOES((glGetTexGenfvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexGenivOES"); disp->set_glGetTexGenivOES((glGetTexGenivOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexGenxvOES"); disp->set_glGetTexGenxvOES((glGetTexGenxvOES_t)ptr); + ptr = dlsym(gles_android,"glBindVertexArrayOES"); disp->set_glBindVertexArrayOES((glBindVertexArrayOES_t)ptr); + ptr = dlsym(gles_android,"glDeleteVertexArraysOES"); disp->set_glDeleteVertexArraysOES((glDeleteVertexArraysOES_t)ptr); + ptr = dlsym(gles_android,"glGenVertexArraysOES"); disp->set_glGenVertexArraysOES((glGenVertexArraysOES_t)ptr); + ptr = dlsym(gles_android,"glIsVertexArrayOES"); disp->set_glIsVertexArrayOES((glIsVertexArrayOES_t)ptr); + ptr = dlsym(gles_android,"glDiscardFramebufferEXT"); disp->set_glDiscardFramebufferEXT((glDiscardFramebufferEXT_t)ptr); + ptr = dlsym(gles_android,"glMultiDrawArraysEXT"); disp->set_glMultiDrawArraysEXT((glMultiDrawArraysEXT_t)ptr); + ptr = dlsym(gles_android,"glMultiDrawElementsEXT"); disp->set_glMultiDrawElementsEXT((glMultiDrawElementsEXT_t)ptr); + ptr = dlsym(gles_android,"glClipPlanefIMG"); disp->set_glClipPlanefIMG((glClipPlanefIMG_t)ptr); + ptr = dlsym(gles_android,"glClipPlanexIMG"); disp->set_glClipPlanexIMG((glClipPlanexIMG_t)ptr); + ptr = dlsym(gles_android,"glRenderbufferStorageMultisampleIMG"); disp->set_glRenderbufferStorageMultisampleIMG((glRenderbufferStorageMultisampleIMG_t)ptr); + ptr = dlsym(gles_android,"glFramebufferTexture2DMultisampleIMG"); disp->set_glFramebufferTexture2DMultisampleIMG((glFramebufferTexture2DMultisampleIMG_t)ptr); + ptr = dlsym(gles_android,"glDeleteFencesNV"); disp->set_glDeleteFencesNV((glDeleteFencesNV_t)ptr); + ptr = dlsym(gles_android,"glGenFencesNV"); disp->set_glGenFencesNV((glGenFencesNV_t)ptr); + ptr = dlsym(gles_android,"glIsFenceNV"); disp->set_glIsFenceNV((glIsFenceNV_t)ptr); + ptr = dlsym(gles_android,"glTestFenceNV"); disp->set_glTestFenceNV((glTestFenceNV_t)ptr); + ptr = dlsym(gles_android,"glGetFenceivNV"); disp->set_glGetFenceivNV((glGetFenceivNV_t)ptr); + ptr = dlsym(gles_android,"glFinishFenceNV"); disp->set_glFinishFenceNV((glFinishFenceNV_t)ptr); + ptr = dlsym(gles_android,"glSetFenceNV"); disp->set_glSetFenceNV((glSetFenceNV_t)ptr); + ptr = dlsym(gles_android,"glGetDriverControlsQCOM"); disp->set_glGetDriverControlsQCOM((glGetDriverControlsQCOM_t)ptr); + ptr = dlsym(gles_android,"glGetDriverControlStringQCOM"); disp->set_glGetDriverControlStringQCOM((glGetDriverControlStringQCOM_t)ptr); + ptr = dlsym(gles_android,"glEnableDriverControlQCOM"); disp->set_glEnableDriverControlQCOM((glEnableDriverControlQCOM_t)ptr); + ptr = dlsym(gles_android,"glDisableDriverControlQCOM"); disp->set_glDisableDriverControlQCOM((glDisableDriverControlQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetTexturesQCOM"); disp->set_glExtGetTexturesQCOM((glExtGetTexturesQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetBuffersQCOM"); disp->set_glExtGetBuffersQCOM((glExtGetBuffersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetRenderbuffersQCOM"); disp->set_glExtGetRenderbuffersQCOM((glExtGetRenderbuffersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetFramebuffersQCOM"); disp->set_glExtGetFramebuffersQCOM((glExtGetFramebuffersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetTexLevelParameterivQCOM"); disp->set_glExtGetTexLevelParameterivQCOM((glExtGetTexLevelParameterivQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtTexObjectStateOverrideiQCOM"); disp->set_glExtTexObjectStateOverrideiQCOM((glExtTexObjectStateOverrideiQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetTexSubImageQCOM"); disp->set_glExtGetTexSubImageQCOM((glExtGetTexSubImageQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetBufferPointervQCOM"); disp->set_glExtGetBufferPointervQCOM((glExtGetBufferPointervQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetShadersQCOM"); disp->set_glExtGetShadersQCOM((glExtGetShadersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetProgramsQCOM"); disp->set_glExtGetProgramsQCOM((glExtGetProgramsQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtIsProgramBinaryQCOM"); disp->set_glExtIsProgramBinaryQCOM((glExtIsProgramBinaryQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetProgramBinarySourceQCOM"); disp->set_glExtGetProgramBinarySourceQCOM((glExtGetProgramBinarySourceQCOM_t)ptr); + ptr = dlsym(gles_android,"glStartTilingQCOM"); disp->set_glStartTilingQCOM((glStartTilingQCOM_t)ptr); + ptr = dlsym(gles_android,"glEndTilingQCOM"); disp->set_glEndTilingQCOM((glEndTilingQCOM_t)ptr); + + return disp; +} diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.h b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.h new file mode 100644 index 0000000..98a4fca --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.h @@ -0,0 +1,570 @@ +/* +* 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. +*/ +#ifndef _GLES_DISPATCH_H +#define _GLES_DISPATCH_H + +#include "gles_proc.h" + + +struct gles_dispatch { + glAlphaFunc_t glAlphaFunc; + glClearColor_t glClearColor; + glClearDepthf_t glClearDepthf; + glClipPlanef_t glClipPlanef; + glColor4f_t glColor4f; + glDepthRangef_t glDepthRangef; + glFogf_t glFogf; + glFogfv_t glFogfv; + glFrustumf_t glFrustumf; + glGetClipPlanef_t glGetClipPlanef; + glGetFloatv_t glGetFloatv; + glGetLightfv_t glGetLightfv; + glGetMaterialfv_t glGetMaterialfv; + glGetTexEnvfv_t glGetTexEnvfv; + glGetTexParameterfv_t glGetTexParameterfv; + glLightModelf_t glLightModelf; + glLightModelfv_t glLightModelfv; + glLightf_t glLightf; + glLightfv_t glLightfv; + glLineWidth_t glLineWidth; + glLoadMatrixf_t glLoadMatrixf; + glMaterialf_t glMaterialf; + glMaterialfv_t glMaterialfv; + glMultMatrixf_t glMultMatrixf; + glMultiTexCoord4f_t glMultiTexCoord4f; + glNormal3f_t glNormal3f; + glOrthof_t glOrthof; + glPointParameterf_t glPointParameterf; + glPointParameterfv_t glPointParameterfv; + glPointSize_t glPointSize; + glPolygonOffset_t glPolygonOffset; + glRotatef_t glRotatef; + glScalef_t glScalef; + glTexEnvf_t glTexEnvf; + glTexEnvfv_t glTexEnvfv; + glTexParameterf_t glTexParameterf; + glTexParameterfv_t glTexParameterfv; + glTranslatef_t glTranslatef; + glActiveTexture_t glActiveTexture; + glAlphaFuncx_t glAlphaFuncx; + glBindBuffer_t glBindBuffer; + glBindTexture_t glBindTexture; + glBlendFunc_t glBlendFunc; + glBufferData_t glBufferData; + glBufferSubData_t glBufferSubData; + glClear_t glClear; + glClearColorx_t glClearColorx; + glClearDepthx_t glClearDepthx; + glClearStencil_t glClearStencil; + glClientActiveTexture_t glClientActiveTexture; + glClipPlanex_t glClipPlanex; + glColor4ub_t glColor4ub; + glColor4x_t glColor4x; + glColorMask_t glColorMask; + glColorPointer_t glColorPointer; + glCompressedTexImage2D_t glCompressedTexImage2D; + glCompressedTexSubImage2D_t glCompressedTexSubImage2D; + glCopyTexImage2D_t glCopyTexImage2D; + glCopyTexSubImage2D_t glCopyTexSubImage2D; + glCullFace_t glCullFace; + glDeleteBuffers_t glDeleteBuffers; + glDeleteTextures_t glDeleteTextures; + glDepthFunc_t glDepthFunc; + glDepthMask_t glDepthMask; + glDepthRangex_t glDepthRangex; + glDisable_t glDisable; + glDisableClientState_t glDisableClientState; + glDrawArrays_t glDrawArrays; + glDrawElements_t glDrawElements; + glEnable_t glEnable; + glEnableClientState_t glEnableClientState; + glFinish_t glFinish; + glFlush_t glFlush; + glFogx_t glFogx; + glFogxv_t glFogxv; + glFrontFace_t glFrontFace; + glFrustumx_t glFrustumx; + glGetBooleanv_t glGetBooleanv; + glGetBufferParameteriv_t glGetBufferParameteriv; + glGetClipPlanex_t glGetClipPlanex; + glGenBuffers_t glGenBuffers; + glGenTextures_t glGenTextures; + glGetError_t glGetError; + glGetFixedv_t glGetFixedv; + glGetIntegerv_t glGetIntegerv; + glGetLightxv_t glGetLightxv; + glGetMaterialxv_t glGetMaterialxv; + glGetPointerv_t glGetPointerv; + glGetString_t glGetString; + glGetTexEnviv_t glGetTexEnviv; + glGetTexEnvxv_t glGetTexEnvxv; + glGetTexParameteriv_t glGetTexParameteriv; + glGetTexParameterxv_t glGetTexParameterxv; + glHint_t glHint; + glIsBuffer_t glIsBuffer; + glIsEnabled_t glIsEnabled; + glIsTexture_t glIsTexture; + glLightModelx_t glLightModelx; + glLightModelxv_t glLightModelxv; + glLightx_t glLightx; + glLightxv_t glLightxv; + glLineWidthx_t glLineWidthx; + glLoadIdentity_t glLoadIdentity; + glLoadMatrixx_t glLoadMatrixx; + glLogicOp_t glLogicOp; + glMaterialx_t glMaterialx; + glMaterialxv_t glMaterialxv; + glMatrixMode_t glMatrixMode; + glMultMatrixx_t glMultMatrixx; + glMultiTexCoord4x_t glMultiTexCoord4x; + glNormal3x_t glNormal3x; + glNormalPointer_t glNormalPointer; + glOrthox_t glOrthox; + glPixelStorei_t glPixelStorei; + glPointParameterx_t glPointParameterx; + glPointParameterxv_t glPointParameterxv; + glPointSizex_t glPointSizex; + glPolygonOffsetx_t glPolygonOffsetx; + glPopMatrix_t glPopMatrix; + glPushMatrix_t glPushMatrix; + glReadPixels_t glReadPixels; + glRotatex_t glRotatex; + glSampleCoverage_t glSampleCoverage; + glSampleCoveragex_t glSampleCoveragex; + glScalex_t glScalex; + glScissor_t glScissor; + glShadeModel_t glShadeModel; + glStencilFunc_t glStencilFunc; + glStencilMask_t glStencilMask; + glStencilOp_t glStencilOp; + glTexCoordPointer_t glTexCoordPointer; + glTexEnvi_t glTexEnvi; + glTexEnvx_t glTexEnvx; + glTexEnviv_t glTexEnviv; + glTexEnvxv_t glTexEnvxv; + glTexImage2D_t glTexImage2D; + glTexParameteri_t glTexParameteri; + glTexParameterx_t glTexParameterx; + glTexParameteriv_t glTexParameteriv; + glTexParameterxv_t glTexParameterxv; + glTexSubImage2D_t glTexSubImage2D; + glTranslatex_t glTranslatex; + glVertexPointer_t glVertexPointer; + glViewport_t glViewport; + glPointSizePointerOES_t glPointSizePointerOES; + glBlendEquationSeparateOES_t glBlendEquationSeparateOES; + glBlendFuncSeparateOES_t glBlendFuncSeparateOES; + glBlendEquationOES_t glBlendEquationOES; + glDrawTexsOES_t glDrawTexsOES; + glDrawTexiOES_t glDrawTexiOES; + glDrawTexxOES_t glDrawTexxOES; + glDrawTexsvOES_t glDrawTexsvOES; + glDrawTexivOES_t glDrawTexivOES; + glDrawTexxvOES_t glDrawTexxvOES; + glDrawTexfOES_t glDrawTexfOES; + glDrawTexfvOES_t glDrawTexfvOES; + glEGLImageTargetTexture2DOES_t glEGLImageTargetTexture2DOES; + glEGLImageTargetRenderbufferStorageOES_t glEGLImageTargetRenderbufferStorageOES; + glAlphaFuncxOES_t glAlphaFuncxOES; + glClearColorxOES_t glClearColorxOES; + glClearDepthxOES_t glClearDepthxOES; + glClipPlanexOES_t glClipPlanexOES; + glColor4xOES_t glColor4xOES; + glDepthRangexOES_t glDepthRangexOES; + glFogxOES_t glFogxOES; + glFogxvOES_t glFogxvOES; + glFrustumxOES_t glFrustumxOES; + glGetClipPlanexOES_t glGetClipPlanexOES; + glGetFixedvOES_t glGetFixedvOES; + glGetLightxvOES_t glGetLightxvOES; + glGetMaterialxvOES_t glGetMaterialxvOES; + glGetTexEnvxvOES_t glGetTexEnvxvOES; + glGetTexParameterxvOES_t glGetTexParameterxvOES; + glLightModelxOES_t glLightModelxOES; + glLightModelxvOES_t glLightModelxvOES; + glLightxOES_t glLightxOES; + glLightxvOES_t glLightxvOES; + glLineWidthxOES_t glLineWidthxOES; + glLoadMatrixxOES_t glLoadMatrixxOES; + glMaterialxOES_t glMaterialxOES; + glMaterialxvOES_t glMaterialxvOES; + glMultMatrixxOES_t glMultMatrixxOES; + glMultiTexCoord4xOES_t glMultiTexCoord4xOES; + glNormal3xOES_t glNormal3xOES; + glOrthoxOES_t glOrthoxOES; + glPointParameterxOES_t glPointParameterxOES; + glPointParameterxvOES_t glPointParameterxvOES; + glPointSizexOES_t glPointSizexOES; + glPolygonOffsetxOES_t glPolygonOffsetxOES; + glRotatexOES_t glRotatexOES; + glSampleCoveragexOES_t glSampleCoveragexOES; + glScalexOES_t glScalexOES; + glTexEnvxOES_t glTexEnvxOES; + glTexEnvxvOES_t glTexEnvxvOES; + glTexParameterxOES_t glTexParameterxOES; + glTexParameterxvOES_t glTexParameterxvOES; + glTranslatexOES_t glTranslatexOES; + glIsRenderbufferOES_t glIsRenderbufferOES; + glBindRenderbufferOES_t glBindRenderbufferOES; + glDeleteRenderbuffersOES_t glDeleteRenderbuffersOES; + glGenRenderbuffersOES_t glGenRenderbuffersOES; + glRenderbufferStorageOES_t glRenderbufferStorageOES; + glGetRenderbufferParameterivOES_t glGetRenderbufferParameterivOES; + glIsFramebufferOES_t glIsFramebufferOES; + glBindFramebufferOES_t glBindFramebufferOES; + glDeleteFramebuffersOES_t glDeleteFramebuffersOES; + glGenFramebuffersOES_t glGenFramebuffersOES; + glCheckFramebufferStatusOES_t glCheckFramebufferStatusOES; + glFramebufferRenderbufferOES_t glFramebufferRenderbufferOES; + glFramebufferTexture2DOES_t glFramebufferTexture2DOES; + glGetFramebufferAttachmentParameterivOES_t glGetFramebufferAttachmentParameterivOES; + glGenerateMipmapOES_t glGenerateMipmapOES; + glMapBufferOES_t glMapBufferOES; + glUnmapBufferOES_t glUnmapBufferOES; + glGetBufferPointervOES_t glGetBufferPointervOES; + glCurrentPaletteMatrixOES_t glCurrentPaletteMatrixOES; + glLoadPaletteFromModelViewMatrixOES_t glLoadPaletteFromModelViewMatrixOES; + glMatrixIndexPointerOES_t glMatrixIndexPointerOES; + glWeightPointerOES_t glWeightPointerOES; + glQueryMatrixxOES_t glQueryMatrixxOES; + glDepthRangefOES_t glDepthRangefOES; + glFrustumfOES_t glFrustumfOES; + glOrthofOES_t glOrthofOES; + glClipPlanefOES_t glClipPlanefOES; + glGetClipPlanefOES_t glGetClipPlanefOES; + glClearDepthfOES_t glClearDepthfOES; + glTexGenfOES_t glTexGenfOES; + glTexGenfvOES_t glTexGenfvOES; + glTexGeniOES_t glTexGeniOES; + glTexGenivOES_t glTexGenivOES; + glTexGenxOES_t glTexGenxOES; + glTexGenxvOES_t glTexGenxvOES; + glGetTexGenfvOES_t glGetTexGenfvOES; + glGetTexGenivOES_t glGetTexGenivOES; + glGetTexGenxvOES_t glGetTexGenxvOES; + glBindVertexArrayOES_t glBindVertexArrayOES; + glDeleteVertexArraysOES_t glDeleteVertexArraysOES; + glGenVertexArraysOES_t glGenVertexArraysOES; + glIsVertexArrayOES_t glIsVertexArrayOES; + glDiscardFramebufferEXT_t glDiscardFramebufferEXT; + glMultiDrawArraysEXT_t glMultiDrawArraysEXT; + glMultiDrawElementsEXT_t glMultiDrawElementsEXT; + glClipPlanefIMG_t glClipPlanefIMG; + glClipPlanexIMG_t glClipPlanexIMG; + glRenderbufferStorageMultisampleIMG_t glRenderbufferStorageMultisampleIMG; + glFramebufferTexture2DMultisampleIMG_t glFramebufferTexture2DMultisampleIMG; + glDeleteFencesNV_t glDeleteFencesNV; + glGenFencesNV_t glGenFencesNV; + glIsFenceNV_t glIsFenceNV; + glTestFenceNV_t glTestFenceNV; + glGetFenceivNV_t glGetFenceivNV; + glFinishFenceNV_t glFinishFenceNV; + glSetFenceNV_t glSetFenceNV; + glGetDriverControlsQCOM_t glGetDriverControlsQCOM; + glGetDriverControlStringQCOM_t glGetDriverControlStringQCOM; + glEnableDriverControlQCOM_t glEnableDriverControlQCOM; + glDisableDriverControlQCOM_t glDisableDriverControlQCOM; + glExtGetTexturesQCOM_t glExtGetTexturesQCOM; + glExtGetBuffersQCOM_t glExtGetBuffersQCOM; + glExtGetRenderbuffersQCOM_t glExtGetRenderbuffersQCOM; + glExtGetFramebuffersQCOM_t glExtGetFramebuffersQCOM; + glExtGetTexLevelParameterivQCOM_t glExtGetTexLevelParameterivQCOM; + glExtTexObjectStateOverrideiQCOM_t glExtTexObjectStateOverrideiQCOM; + glExtGetTexSubImageQCOM_t glExtGetTexSubImageQCOM; + glExtGetBufferPointervQCOM_t glExtGetBufferPointervQCOM; + glExtGetShadersQCOM_t glExtGetShadersQCOM; + glExtGetProgramsQCOM_t glExtGetProgramsQCOM; + glExtIsProgramBinaryQCOM_t glExtIsProgramBinaryQCOM; + glExtGetProgramBinarySourceQCOM_t glExtGetProgramBinarySourceQCOM; + glStartTilingQCOM_t glStartTilingQCOM; + glEndTilingQCOM_t glEndTilingQCOM; + //Accessors + glAlphaFunc_t set_glAlphaFunc(glAlphaFunc_t f) { glAlphaFunc_t retval = glAlphaFunc; glAlphaFunc = f; return retval;} + glClearColor_t set_glClearColor(glClearColor_t f) { glClearColor_t retval = glClearColor; glClearColor = f; return retval;} + glClearDepthf_t set_glClearDepthf(glClearDepthf_t f) { glClearDepthf_t retval = glClearDepthf; glClearDepthf = f; return retval;} + glClipPlanef_t set_glClipPlanef(glClipPlanef_t f) { glClipPlanef_t retval = glClipPlanef; glClipPlanef = f; return retval;} + glColor4f_t set_glColor4f(glColor4f_t f) { glColor4f_t retval = glColor4f; glColor4f = f; return retval;} + glDepthRangef_t set_glDepthRangef(glDepthRangef_t f) { glDepthRangef_t retval = glDepthRangef; glDepthRangef = f; return retval;} + glFogf_t set_glFogf(glFogf_t f) { glFogf_t retval = glFogf; glFogf = f; return retval;} + glFogfv_t set_glFogfv(glFogfv_t f) { glFogfv_t retval = glFogfv; glFogfv = f; return retval;} + glFrustumf_t set_glFrustumf(glFrustumf_t f) { glFrustumf_t retval = glFrustumf; glFrustumf = f; return retval;} + glGetClipPlanef_t set_glGetClipPlanef(glGetClipPlanef_t f) { glGetClipPlanef_t retval = glGetClipPlanef; glGetClipPlanef = f; return retval;} + glGetFloatv_t set_glGetFloatv(glGetFloatv_t f) { glGetFloatv_t retval = glGetFloatv; glGetFloatv = f; return retval;} + glGetLightfv_t set_glGetLightfv(glGetLightfv_t f) { glGetLightfv_t retval = glGetLightfv; glGetLightfv = f; return retval;} + glGetMaterialfv_t set_glGetMaterialfv(glGetMaterialfv_t f) { glGetMaterialfv_t retval = glGetMaterialfv; glGetMaterialfv = f; return retval;} + glGetTexEnvfv_t set_glGetTexEnvfv(glGetTexEnvfv_t f) { glGetTexEnvfv_t retval = glGetTexEnvfv; glGetTexEnvfv = f; return retval;} + glGetTexParameterfv_t set_glGetTexParameterfv(glGetTexParameterfv_t f) { glGetTexParameterfv_t retval = glGetTexParameterfv; glGetTexParameterfv = f; return retval;} + glLightModelf_t set_glLightModelf(glLightModelf_t f) { glLightModelf_t retval = glLightModelf; glLightModelf = f; return retval;} + glLightModelfv_t set_glLightModelfv(glLightModelfv_t f) { glLightModelfv_t retval = glLightModelfv; glLightModelfv = f; return retval;} + glLightf_t set_glLightf(glLightf_t f) { glLightf_t retval = glLightf; glLightf = f; return retval;} + glLightfv_t set_glLightfv(glLightfv_t f) { glLightfv_t retval = glLightfv; glLightfv = f; return retval;} + glLineWidth_t set_glLineWidth(glLineWidth_t f) { glLineWidth_t retval = glLineWidth; glLineWidth = f; return retval;} + glLoadMatrixf_t set_glLoadMatrixf(glLoadMatrixf_t f) { glLoadMatrixf_t retval = glLoadMatrixf; glLoadMatrixf = f; return retval;} + glMaterialf_t set_glMaterialf(glMaterialf_t f) { glMaterialf_t retval = glMaterialf; glMaterialf = f; return retval;} + glMaterialfv_t set_glMaterialfv(glMaterialfv_t f) { glMaterialfv_t retval = glMaterialfv; glMaterialfv = f; return retval;} + glMultMatrixf_t set_glMultMatrixf(glMultMatrixf_t f) { glMultMatrixf_t retval = glMultMatrixf; glMultMatrixf = f; return retval;} + glMultiTexCoord4f_t set_glMultiTexCoord4f(glMultiTexCoord4f_t f) { glMultiTexCoord4f_t retval = glMultiTexCoord4f; glMultiTexCoord4f = f; return retval;} + glNormal3f_t set_glNormal3f(glNormal3f_t f) { glNormal3f_t retval = glNormal3f; glNormal3f = f; return retval;} + glOrthof_t set_glOrthof(glOrthof_t f) { glOrthof_t retval = glOrthof; glOrthof = f; return retval;} + glPointParameterf_t set_glPointParameterf(glPointParameterf_t f) { glPointParameterf_t retval = glPointParameterf; glPointParameterf = f; return retval;} + glPointParameterfv_t set_glPointParameterfv(glPointParameterfv_t f) { glPointParameterfv_t retval = glPointParameterfv; glPointParameterfv = f; return retval;} + glPointSize_t set_glPointSize(glPointSize_t f) { glPointSize_t retval = glPointSize; glPointSize = f; return retval;} + glPolygonOffset_t set_glPolygonOffset(glPolygonOffset_t f) { glPolygonOffset_t retval = glPolygonOffset; glPolygonOffset = f; return retval;} + glRotatef_t set_glRotatef(glRotatef_t f) { glRotatef_t retval = glRotatef; glRotatef = f; return retval;} + glScalef_t set_glScalef(glScalef_t f) { glScalef_t retval = glScalef; glScalef = f; return retval;} + glTexEnvf_t set_glTexEnvf(glTexEnvf_t f) { glTexEnvf_t retval = glTexEnvf; glTexEnvf = f; return retval;} + glTexEnvfv_t set_glTexEnvfv(glTexEnvfv_t f) { glTexEnvfv_t retval = glTexEnvfv; glTexEnvfv = f; return retval;} + glTexParameterf_t set_glTexParameterf(glTexParameterf_t f) { glTexParameterf_t retval = glTexParameterf; glTexParameterf = f; return retval;} + glTexParameterfv_t set_glTexParameterfv(glTexParameterfv_t f) { glTexParameterfv_t retval = glTexParameterfv; glTexParameterfv = f; return retval;} + glTranslatef_t set_glTranslatef(glTranslatef_t f) { glTranslatef_t retval = glTranslatef; glTranslatef = f; return retval;} + glActiveTexture_t set_glActiveTexture(glActiveTexture_t f) { glActiveTexture_t retval = glActiveTexture; glActiveTexture = f; return retval;} + glAlphaFuncx_t set_glAlphaFuncx(glAlphaFuncx_t f) { glAlphaFuncx_t retval = glAlphaFuncx; glAlphaFuncx = f; return retval;} + glBindBuffer_t set_glBindBuffer(glBindBuffer_t f) { glBindBuffer_t retval = glBindBuffer; glBindBuffer = f; return retval;} + glBindTexture_t set_glBindTexture(glBindTexture_t f) { glBindTexture_t retval = glBindTexture; glBindTexture = f; return retval;} + glBlendFunc_t set_glBlendFunc(glBlendFunc_t f) { glBlendFunc_t retval = glBlendFunc; glBlendFunc = f; return retval;} + glBufferData_t set_glBufferData(glBufferData_t f) { glBufferData_t retval = glBufferData; glBufferData = f; return retval;} + glBufferSubData_t set_glBufferSubData(glBufferSubData_t f) { glBufferSubData_t retval = glBufferSubData; glBufferSubData = f; return retval;} + glClear_t set_glClear(glClear_t f) { glClear_t retval = glClear; glClear = f; return retval;} + glClearColorx_t set_glClearColorx(glClearColorx_t f) { glClearColorx_t retval = glClearColorx; glClearColorx = f; return retval;} + glClearDepthx_t set_glClearDepthx(glClearDepthx_t f) { glClearDepthx_t retval = glClearDepthx; glClearDepthx = f; return retval;} + glClearStencil_t set_glClearStencil(glClearStencil_t f) { glClearStencil_t retval = glClearStencil; glClearStencil = f; return retval;} + glClientActiveTexture_t set_glClientActiveTexture(glClientActiveTexture_t f) { glClientActiveTexture_t retval = glClientActiveTexture; glClientActiveTexture = f; return retval;} + glClipPlanex_t set_glClipPlanex(glClipPlanex_t f) { glClipPlanex_t retval = glClipPlanex; glClipPlanex = f; return retval;} + glColor4ub_t set_glColor4ub(glColor4ub_t f) { glColor4ub_t retval = glColor4ub; glColor4ub = f; return retval;} + glColor4x_t set_glColor4x(glColor4x_t f) { glColor4x_t retval = glColor4x; glColor4x = f; return retval;} + glColorMask_t set_glColorMask(glColorMask_t f) { glColorMask_t retval = glColorMask; glColorMask = f; return retval;} + glColorPointer_t set_glColorPointer(glColorPointer_t f) { glColorPointer_t retval = glColorPointer; glColorPointer = f; return retval;} + glCompressedTexImage2D_t set_glCompressedTexImage2D(glCompressedTexImage2D_t f) { glCompressedTexImage2D_t retval = glCompressedTexImage2D; glCompressedTexImage2D = f; return retval;} + glCompressedTexSubImage2D_t set_glCompressedTexSubImage2D(glCompressedTexSubImage2D_t f) { glCompressedTexSubImage2D_t retval = glCompressedTexSubImage2D; glCompressedTexSubImage2D = f; return retval;} + glCopyTexImage2D_t set_glCopyTexImage2D(glCopyTexImage2D_t f) { glCopyTexImage2D_t retval = glCopyTexImage2D; glCopyTexImage2D = f; return retval;} + glCopyTexSubImage2D_t set_glCopyTexSubImage2D(glCopyTexSubImage2D_t f) { glCopyTexSubImage2D_t retval = glCopyTexSubImage2D; glCopyTexSubImage2D = f; return retval;} + glCullFace_t set_glCullFace(glCullFace_t f) { glCullFace_t retval = glCullFace; glCullFace = f; return retval;} + glDeleteBuffers_t set_glDeleteBuffers(glDeleteBuffers_t f) { glDeleteBuffers_t retval = glDeleteBuffers; glDeleteBuffers = f; return retval;} + glDeleteTextures_t set_glDeleteTextures(glDeleteTextures_t f) { glDeleteTextures_t retval = glDeleteTextures; glDeleteTextures = f; return retval;} + glDepthFunc_t set_glDepthFunc(glDepthFunc_t f) { glDepthFunc_t retval = glDepthFunc; glDepthFunc = f; return retval;} + glDepthMask_t set_glDepthMask(glDepthMask_t f) { glDepthMask_t retval = glDepthMask; glDepthMask = f; return retval;} + glDepthRangex_t set_glDepthRangex(glDepthRangex_t f) { glDepthRangex_t retval = glDepthRangex; glDepthRangex = f; return retval;} + glDisable_t set_glDisable(glDisable_t f) { glDisable_t retval = glDisable; glDisable = f; return retval;} + glDisableClientState_t set_glDisableClientState(glDisableClientState_t f) { glDisableClientState_t retval = glDisableClientState; glDisableClientState = f; return retval;} + glDrawArrays_t set_glDrawArrays(glDrawArrays_t f) { glDrawArrays_t retval = glDrawArrays; glDrawArrays = f; return retval;} + glDrawElements_t set_glDrawElements(glDrawElements_t f) { glDrawElements_t retval = glDrawElements; glDrawElements = f; return retval;} + glEnable_t set_glEnable(glEnable_t f) { glEnable_t retval = glEnable; glEnable = f; return retval;} + glEnableClientState_t set_glEnableClientState(glEnableClientState_t f) { glEnableClientState_t retval = glEnableClientState; glEnableClientState = f; return retval;} + glFinish_t set_glFinish(glFinish_t f) { glFinish_t retval = glFinish; glFinish = f; return retval;} + glFlush_t set_glFlush(glFlush_t f) { glFlush_t retval = glFlush; glFlush = f; return retval;} + glFogx_t set_glFogx(glFogx_t f) { glFogx_t retval = glFogx; glFogx = f; return retval;} + glFogxv_t set_glFogxv(glFogxv_t f) { glFogxv_t retval = glFogxv; glFogxv = f; return retval;} + glFrontFace_t set_glFrontFace(glFrontFace_t f) { glFrontFace_t retval = glFrontFace; glFrontFace = f; return retval;} + glFrustumx_t set_glFrustumx(glFrustumx_t f) { glFrustumx_t retval = glFrustumx; glFrustumx = f; return retval;} + glGetBooleanv_t set_glGetBooleanv(glGetBooleanv_t f) { glGetBooleanv_t retval = glGetBooleanv; glGetBooleanv = f; return retval;} + glGetBufferParameteriv_t set_glGetBufferParameteriv(glGetBufferParameteriv_t f) { glGetBufferParameteriv_t retval = glGetBufferParameteriv; glGetBufferParameteriv = f; return retval;} + glGetClipPlanex_t set_glGetClipPlanex(glGetClipPlanex_t f) { glGetClipPlanex_t retval = glGetClipPlanex; glGetClipPlanex = f; return retval;} + glGenBuffers_t set_glGenBuffers(glGenBuffers_t f) { glGenBuffers_t retval = glGenBuffers; glGenBuffers = f; return retval;} + glGenTextures_t set_glGenTextures(glGenTextures_t f) { glGenTextures_t retval = glGenTextures; glGenTextures = f; return retval;} + glGetError_t set_glGetError(glGetError_t f) { glGetError_t retval = glGetError; glGetError = f; return retval;} + glGetFixedv_t set_glGetFixedv(glGetFixedv_t f) { glGetFixedv_t retval = glGetFixedv; glGetFixedv = f; return retval;} + glGetIntegerv_t set_glGetIntegerv(glGetIntegerv_t f) { glGetIntegerv_t retval = glGetIntegerv; glGetIntegerv = f; return retval;} + glGetLightxv_t set_glGetLightxv(glGetLightxv_t f) { glGetLightxv_t retval = glGetLightxv; glGetLightxv = f; return retval;} + glGetMaterialxv_t set_glGetMaterialxv(glGetMaterialxv_t f) { glGetMaterialxv_t retval = glGetMaterialxv; glGetMaterialxv = f; return retval;} + glGetPointerv_t set_glGetPointerv(glGetPointerv_t f) { glGetPointerv_t retval = glGetPointerv; glGetPointerv = f; return retval;} + glGetString_t set_glGetString(glGetString_t f) { glGetString_t retval = glGetString; glGetString = f; return retval;} + glGetTexEnviv_t set_glGetTexEnviv(glGetTexEnviv_t f) { glGetTexEnviv_t retval = glGetTexEnviv; glGetTexEnviv = f; return retval;} + glGetTexEnvxv_t set_glGetTexEnvxv(glGetTexEnvxv_t f) { glGetTexEnvxv_t retval = glGetTexEnvxv; glGetTexEnvxv = f; return retval;} + glGetTexParameteriv_t set_glGetTexParameteriv(glGetTexParameteriv_t f) { glGetTexParameteriv_t retval = glGetTexParameteriv; glGetTexParameteriv = f; return retval;} + glGetTexParameterxv_t set_glGetTexParameterxv(glGetTexParameterxv_t f) { glGetTexParameterxv_t retval = glGetTexParameterxv; glGetTexParameterxv = f; return retval;} + glHint_t set_glHint(glHint_t f) { glHint_t retval = glHint; glHint = f; return retval;} + glIsBuffer_t set_glIsBuffer(glIsBuffer_t f) { glIsBuffer_t retval = glIsBuffer; glIsBuffer = f; return retval;} + glIsEnabled_t set_glIsEnabled(glIsEnabled_t f) { glIsEnabled_t retval = glIsEnabled; glIsEnabled = f; return retval;} + glIsTexture_t set_glIsTexture(glIsTexture_t f) { glIsTexture_t retval = glIsTexture; glIsTexture = f; return retval;} + glLightModelx_t set_glLightModelx(glLightModelx_t f) { glLightModelx_t retval = glLightModelx; glLightModelx = f; return retval;} + glLightModelxv_t set_glLightModelxv(glLightModelxv_t f) { glLightModelxv_t retval = glLightModelxv; glLightModelxv = f; return retval;} + glLightx_t set_glLightx(glLightx_t f) { glLightx_t retval = glLightx; glLightx = f; return retval;} + glLightxv_t set_glLightxv(glLightxv_t f) { glLightxv_t retval = glLightxv; glLightxv = f; return retval;} + glLineWidthx_t set_glLineWidthx(glLineWidthx_t f) { glLineWidthx_t retval = glLineWidthx; glLineWidthx = f; return retval;} + glLoadIdentity_t set_glLoadIdentity(glLoadIdentity_t f) { glLoadIdentity_t retval = glLoadIdentity; glLoadIdentity = f; return retval;} + glLoadMatrixx_t set_glLoadMatrixx(glLoadMatrixx_t f) { glLoadMatrixx_t retval = glLoadMatrixx; glLoadMatrixx = f; return retval;} + glLogicOp_t set_glLogicOp(glLogicOp_t f) { glLogicOp_t retval = glLogicOp; glLogicOp = f; return retval;} + glMaterialx_t set_glMaterialx(glMaterialx_t f) { glMaterialx_t retval = glMaterialx; glMaterialx = f; return retval;} + glMaterialxv_t set_glMaterialxv(glMaterialxv_t f) { glMaterialxv_t retval = glMaterialxv; glMaterialxv = f; return retval;} + glMatrixMode_t set_glMatrixMode(glMatrixMode_t f) { glMatrixMode_t retval = glMatrixMode; glMatrixMode = f; return retval;} + glMultMatrixx_t set_glMultMatrixx(glMultMatrixx_t f) { glMultMatrixx_t retval = glMultMatrixx; glMultMatrixx = f; return retval;} + glMultiTexCoord4x_t set_glMultiTexCoord4x(glMultiTexCoord4x_t f) { glMultiTexCoord4x_t retval = glMultiTexCoord4x; glMultiTexCoord4x = f; return retval;} + glNormal3x_t set_glNormal3x(glNormal3x_t f) { glNormal3x_t retval = glNormal3x; glNormal3x = f; return retval;} + glNormalPointer_t set_glNormalPointer(glNormalPointer_t f) { glNormalPointer_t retval = glNormalPointer; glNormalPointer = f; return retval;} + glOrthox_t set_glOrthox(glOrthox_t f) { glOrthox_t retval = glOrthox; glOrthox = f; return retval;} + glPixelStorei_t set_glPixelStorei(glPixelStorei_t f) { glPixelStorei_t retval = glPixelStorei; glPixelStorei = f; return retval;} + glPointParameterx_t set_glPointParameterx(glPointParameterx_t f) { glPointParameterx_t retval = glPointParameterx; glPointParameterx = f; return retval;} + glPointParameterxv_t set_glPointParameterxv(glPointParameterxv_t f) { glPointParameterxv_t retval = glPointParameterxv; glPointParameterxv = f; return retval;} + glPointSizex_t set_glPointSizex(glPointSizex_t f) { glPointSizex_t retval = glPointSizex; glPointSizex = f; return retval;} + glPolygonOffsetx_t set_glPolygonOffsetx(glPolygonOffsetx_t f) { glPolygonOffsetx_t retval = glPolygonOffsetx; glPolygonOffsetx = f; return retval;} + glPopMatrix_t set_glPopMatrix(glPopMatrix_t f) { glPopMatrix_t retval = glPopMatrix; glPopMatrix = f; return retval;} + glPushMatrix_t set_glPushMatrix(glPushMatrix_t f) { glPushMatrix_t retval = glPushMatrix; glPushMatrix = f; return retval;} + glReadPixels_t set_glReadPixels(glReadPixels_t f) { glReadPixels_t retval = glReadPixels; glReadPixels = f; return retval;} + glRotatex_t set_glRotatex(glRotatex_t f) { glRotatex_t retval = glRotatex; glRotatex = f; return retval;} + glSampleCoverage_t set_glSampleCoverage(glSampleCoverage_t f) { glSampleCoverage_t retval = glSampleCoverage; glSampleCoverage = f; return retval;} + glSampleCoveragex_t set_glSampleCoveragex(glSampleCoveragex_t f) { glSampleCoveragex_t retval = glSampleCoveragex; glSampleCoveragex = f; return retval;} + glScalex_t set_glScalex(glScalex_t f) { glScalex_t retval = glScalex; glScalex = f; return retval;} + glScissor_t set_glScissor(glScissor_t f) { glScissor_t retval = glScissor; glScissor = f; return retval;} + glShadeModel_t set_glShadeModel(glShadeModel_t f) { glShadeModel_t retval = glShadeModel; glShadeModel = f; return retval;} + glStencilFunc_t set_glStencilFunc(glStencilFunc_t f) { glStencilFunc_t retval = glStencilFunc; glStencilFunc = f; return retval;} + glStencilMask_t set_glStencilMask(glStencilMask_t f) { glStencilMask_t retval = glStencilMask; glStencilMask = f; return retval;} + glStencilOp_t set_glStencilOp(glStencilOp_t f) { glStencilOp_t retval = glStencilOp; glStencilOp = f; return retval;} + glTexCoordPointer_t set_glTexCoordPointer(glTexCoordPointer_t f) { glTexCoordPointer_t retval = glTexCoordPointer; glTexCoordPointer = f; return retval;} + glTexEnvi_t set_glTexEnvi(glTexEnvi_t f) { glTexEnvi_t retval = glTexEnvi; glTexEnvi = f; return retval;} + glTexEnvx_t set_glTexEnvx(glTexEnvx_t f) { glTexEnvx_t retval = glTexEnvx; glTexEnvx = f; return retval;} + glTexEnviv_t set_glTexEnviv(glTexEnviv_t f) { glTexEnviv_t retval = glTexEnviv; glTexEnviv = f; return retval;} + glTexEnvxv_t set_glTexEnvxv(glTexEnvxv_t f) { glTexEnvxv_t retval = glTexEnvxv; glTexEnvxv = f; return retval;} + glTexImage2D_t set_glTexImage2D(glTexImage2D_t f) { glTexImage2D_t retval = glTexImage2D; glTexImage2D = f; return retval;} + glTexParameteri_t set_glTexParameteri(glTexParameteri_t f) { glTexParameteri_t retval = glTexParameteri; glTexParameteri = f; return retval;} + glTexParameterx_t set_glTexParameterx(glTexParameterx_t f) { glTexParameterx_t retval = glTexParameterx; glTexParameterx = f; return retval;} + glTexParameteriv_t set_glTexParameteriv(glTexParameteriv_t f) { glTexParameteriv_t retval = glTexParameteriv; glTexParameteriv = f; return retval;} + glTexParameterxv_t set_glTexParameterxv(glTexParameterxv_t f) { glTexParameterxv_t retval = glTexParameterxv; glTexParameterxv = f; return retval;} + glTexSubImage2D_t set_glTexSubImage2D(glTexSubImage2D_t f) { glTexSubImage2D_t retval = glTexSubImage2D; glTexSubImage2D = f; return retval;} + glTranslatex_t set_glTranslatex(glTranslatex_t f) { glTranslatex_t retval = glTranslatex; glTranslatex = f; return retval;} + glVertexPointer_t set_glVertexPointer(glVertexPointer_t f) { glVertexPointer_t retval = glVertexPointer; glVertexPointer = f; return retval;} + glViewport_t set_glViewport(glViewport_t f) { glViewport_t retval = glViewport; glViewport = f; return retval;} + glPointSizePointerOES_t set_glPointSizePointerOES(glPointSizePointerOES_t f) { glPointSizePointerOES_t retval = glPointSizePointerOES; glPointSizePointerOES = f; return retval;} + glBlendEquationSeparateOES_t set_glBlendEquationSeparateOES(glBlendEquationSeparateOES_t f) { glBlendEquationSeparateOES_t retval = glBlendEquationSeparateOES; glBlendEquationSeparateOES = f; return retval;} + glBlendFuncSeparateOES_t set_glBlendFuncSeparateOES(glBlendFuncSeparateOES_t f) { glBlendFuncSeparateOES_t retval = glBlendFuncSeparateOES; glBlendFuncSeparateOES = f; return retval;} + glBlendEquationOES_t set_glBlendEquationOES(glBlendEquationOES_t f) { glBlendEquationOES_t retval = glBlendEquationOES; glBlendEquationOES = f; return retval;} + glDrawTexsOES_t set_glDrawTexsOES(glDrawTexsOES_t f) { glDrawTexsOES_t retval = glDrawTexsOES; glDrawTexsOES = f; return retval;} + glDrawTexiOES_t set_glDrawTexiOES(glDrawTexiOES_t f) { glDrawTexiOES_t retval = glDrawTexiOES; glDrawTexiOES = f; return retval;} + glDrawTexxOES_t set_glDrawTexxOES(glDrawTexxOES_t f) { glDrawTexxOES_t retval = glDrawTexxOES; glDrawTexxOES = f; return retval;} + glDrawTexsvOES_t set_glDrawTexsvOES(glDrawTexsvOES_t f) { glDrawTexsvOES_t retval = glDrawTexsvOES; glDrawTexsvOES = f; return retval;} + glDrawTexivOES_t set_glDrawTexivOES(glDrawTexivOES_t f) { glDrawTexivOES_t retval = glDrawTexivOES; glDrawTexivOES = f; return retval;} + glDrawTexxvOES_t set_glDrawTexxvOES(glDrawTexxvOES_t f) { glDrawTexxvOES_t retval = glDrawTexxvOES; glDrawTexxvOES = f; return retval;} + glDrawTexfOES_t set_glDrawTexfOES(glDrawTexfOES_t f) { glDrawTexfOES_t retval = glDrawTexfOES; glDrawTexfOES = f; return retval;} + glDrawTexfvOES_t set_glDrawTexfvOES(glDrawTexfvOES_t f) { glDrawTexfvOES_t retval = glDrawTexfvOES; glDrawTexfvOES = f; return retval;} + glEGLImageTargetTexture2DOES_t set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES_t f) { glEGLImageTargetTexture2DOES_t retval = glEGLImageTargetTexture2DOES; glEGLImageTargetTexture2DOES = f; return retval;} + glEGLImageTargetRenderbufferStorageOES_t set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES_t f) { glEGLImageTargetRenderbufferStorageOES_t retval = glEGLImageTargetRenderbufferStorageOES; glEGLImageTargetRenderbufferStorageOES = f; return retval;} + glAlphaFuncxOES_t set_glAlphaFuncxOES(glAlphaFuncxOES_t f) { glAlphaFuncxOES_t retval = glAlphaFuncxOES; glAlphaFuncxOES = f; return retval;} + glClearColorxOES_t set_glClearColorxOES(glClearColorxOES_t f) { glClearColorxOES_t retval = glClearColorxOES; glClearColorxOES = f; return retval;} + glClearDepthxOES_t set_glClearDepthxOES(glClearDepthxOES_t f) { glClearDepthxOES_t retval = glClearDepthxOES; glClearDepthxOES = f; return retval;} + glClipPlanexOES_t set_glClipPlanexOES(glClipPlanexOES_t f) { glClipPlanexOES_t retval = glClipPlanexOES; glClipPlanexOES = f; return retval;} + glColor4xOES_t set_glColor4xOES(glColor4xOES_t f) { glColor4xOES_t retval = glColor4xOES; glColor4xOES = f; return retval;} + glDepthRangexOES_t set_glDepthRangexOES(glDepthRangexOES_t f) { glDepthRangexOES_t retval = glDepthRangexOES; glDepthRangexOES = f; return retval;} + glFogxOES_t set_glFogxOES(glFogxOES_t f) { glFogxOES_t retval = glFogxOES; glFogxOES = f; return retval;} + glFogxvOES_t set_glFogxvOES(glFogxvOES_t f) { glFogxvOES_t retval = glFogxvOES; glFogxvOES = f; return retval;} + glFrustumxOES_t set_glFrustumxOES(glFrustumxOES_t f) { glFrustumxOES_t retval = glFrustumxOES; glFrustumxOES = f; return retval;} + glGetClipPlanexOES_t set_glGetClipPlanexOES(glGetClipPlanexOES_t f) { glGetClipPlanexOES_t retval = glGetClipPlanexOES; glGetClipPlanexOES = f; return retval;} + glGetFixedvOES_t set_glGetFixedvOES(glGetFixedvOES_t f) { glGetFixedvOES_t retval = glGetFixedvOES; glGetFixedvOES = f; return retval;} + glGetLightxvOES_t set_glGetLightxvOES(glGetLightxvOES_t f) { glGetLightxvOES_t retval = glGetLightxvOES; glGetLightxvOES = f; return retval;} + glGetMaterialxvOES_t set_glGetMaterialxvOES(glGetMaterialxvOES_t f) { glGetMaterialxvOES_t retval = glGetMaterialxvOES; glGetMaterialxvOES = f; return retval;} + glGetTexEnvxvOES_t set_glGetTexEnvxvOES(glGetTexEnvxvOES_t f) { glGetTexEnvxvOES_t retval = glGetTexEnvxvOES; glGetTexEnvxvOES = f; return retval;} + glGetTexParameterxvOES_t set_glGetTexParameterxvOES(glGetTexParameterxvOES_t f) { glGetTexParameterxvOES_t retval = glGetTexParameterxvOES; glGetTexParameterxvOES = f; return retval;} + glLightModelxOES_t set_glLightModelxOES(glLightModelxOES_t f) { glLightModelxOES_t retval = glLightModelxOES; glLightModelxOES = f; return retval;} + glLightModelxvOES_t set_glLightModelxvOES(glLightModelxvOES_t f) { glLightModelxvOES_t retval = glLightModelxvOES; glLightModelxvOES = f; return retval;} + glLightxOES_t set_glLightxOES(glLightxOES_t f) { glLightxOES_t retval = glLightxOES; glLightxOES = f; return retval;} + glLightxvOES_t set_glLightxvOES(glLightxvOES_t f) { glLightxvOES_t retval = glLightxvOES; glLightxvOES = f; return retval;} + glLineWidthxOES_t set_glLineWidthxOES(glLineWidthxOES_t f) { glLineWidthxOES_t retval = glLineWidthxOES; glLineWidthxOES = f; return retval;} + glLoadMatrixxOES_t set_glLoadMatrixxOES(glLoadMatrixxOES_t f) { glLoadMatrixxOES_t retval = glLoadMatrixxOES; glLoadMatrixxOES = f; return retval;} + glMaterialxOES_t set_glMaterialxOES(glMaterialxOES_t f) { glMaterialxOES_t retval = glMaterialxOES; glMaterialxOES = f; return retval;} + glMaterialxvOES_t set_glMaterialxvOES(glMaterialxvOES_t f) { glMaterialxvOES_t retval = glMaterialxvOES; glMaterialxvOES = f; return retval;} + glMultMatrixxOES_t set_glMultMatrixxOES(glMultMatrixxOES_t f) { glMultMatrixxOES_t retval = glMultMatrixxOES; glMultMatrixxOES = f; return retval;} + glMultiTexCoord4xOES_t set_glMultiTexCoord4xOES(glMultiTexCoord4xOES_t f) { glMultiTexCoord4xOES_t retval = glMultiTexCoord4xOES; glMultiTexCoord4xOES = f; return retval;} + glNormal3xOES_t set_glNormal3xOES(glNormal3xOES_t f) { glNormal3xOES_t retval = glNormal3xOES; glNormal3xOES = f; return retval;} + glOrthoxOES_t set_glOrthoxOES(glOrthoxOES_t f) { glOrthoxOES_t retval = glOrthoxOES; glOrthoxOES = f; return retval;} + glPointParameterxOES_t set_glPointParameterxOES(glPointParameterxOES_t f) { glPointParameterxOES_t retval = glPointParameterxOES; glPointParameterxOES = f; return retval;} + glPointParameterxvOES_t set_glPointParameterxvOES(glPointParameterxvOES_t f) { glPointParameterxvOES_t retval = glPointParameterxvOES; glPointParameterxvOES = f; return retval;} + glPointSizexOES_t set_glPointSizexOES(glPointSizexOES_t f) { glPointSizexOES_t retval = glPointSizexOES; glPointSizexOES = f; return retval;} + glPolygonOffsetxOES_t set_glPolygonOffsetxOES(glPolygonOffsetxOES_t f) { glPolygonOffsetxOES_t retval = glPolygonOffsetxOES; glPolygonOffsetxOES = f; return retval;} + glRotatexOES_t set_glRotatexOES(glRotatexOES_t f) { glRotatexOES_t retval = glRotatexOES; glRotatexOES = f; return retval;} + glSampleCoveragexOES_t set_glSampleCoveragexOES(glSampleCoveragexOES_t f) { glSampleCoveragexOES_t retval = glSampleCoveragexOES; glSampleCoveragexOES = f; return retval;} + glScalexOES_t set_glScalexOES(glScalexOES_t f) { glScalexOES_t retval = glScalexOES; glScalexOES = f; return retval;} + glTexEnvxOES_t set_glTexEnvxOES(glTexEnvxOES_t f) { glTexEnvxOES_t retval = glTexEnvxOES; glTexEnvxOES = f; return retval;} + glTexEnvxvOES_t set_glTexEnvxvOES(glTexEnvxvOES_t f) { glTexEnvxvOES_t retval = glTexEnvxvOES; glTexEnvxvOES = f; return retval;} + glTexParameterxOES_t set_glTexParameterxOES(glTexParameterxOES_t f) { glTexParameterxOES_t retval = glTexParameterxOES; glTexParameterxOES = f; return retval;} + glTexParameterxvOES_t set_glTexParameterxvOES(glTexParameterxvOES_t f) { glTexParameterxvOES_t retval = glTexParameterxvOES; glTexParameterxvOES = f; return retval;} + glTranslatexOES_t set_glTranslatexOES(glTranslatexOES_t f) { glTranslatexOES_t retval = glTranslatexOES; glTranslatexOES = f; return retval;} + glIsRenderbufferOES_t set_glIsRenderbufferOES(glIsRenderbufferOES_t f) { glIsRenderbufferOES_t retval = glIsRenderbufferOES; glIsRenderbufferOES = f; return retval;} + glBindRenderbufferOES_t set_glBindRenderbufferOES(glBindRenderbufferOES_t f) { glBindRenderbufferOES_t retval = glBindRenderbufferOES; glBindRenderbufferOES = f; return retval;} + glDeleteRenderbuffersOES_t set_glDeleteRenderbuffersOES(glDeleteRenderbuffersOES_t f) { glDeleteRenderbuffersOES_t retval = glDeleteRenderbuffersOES; glDeleteRenderbuffersOES = f; return retval;} + glGenRenderbuffersOES_t set_glGenRenderbuffersOES(glGenRenderbuffersOES_t f) { glGenRenderbuffersOES_t retval = glGenRenderbuffersOES; glGenRenderbuffersOES = f; return retval;} + glRenderbufferStorageOES_t set_glRenderbufferStorageOES(glRenderbufferStorageOES_t f) { glRenderbufferStorageOES_t retval = glRenderbufferStorageOES; glRenderbufferStorageOES = f; return retval;} + glGetRenderbufferParameterivOES_t set_glGetRenderbufferParameterivOES(glGetRenderbufferParameterivOES_t f) { glGetRenderbufferParameterivOES_t retval = glGetRenderbufferParameterivOES; glGetRenderbufferParameterivOES = f; return retval;} + glIsFramebufferOES_t set_glIsFramebufferOES(glIsFramebufferOES_t f) { glIsFramebufferOES_t retval = glIsFramebufferOES; glIsFramebufferOES = f; return retval;} + glBindFramebufferOES_t set_glBindFramebufferOES(glBindFramebufferOES_t f) { glBindFramebufferOES_t retval = glBindFramebufferOES; glBindFramebufferOES = f; return retval;} + glDeleteFramebuffersOES_t set_glDeleteFramebuffersOES(glDeleteFramebuffersOES_t f) { glDeleteFramebuffersOES_t retval = glDeleteFramebuffersOES; glDeleteFramebuffersOES = f; return retval;} + glGenFramebuffersOES_t set_glGenFramebuffersOES(glGenFramebuffersOES_t f) { glGenFramebuffersOES_t retval = glGenFramebuffersOES; glGenFramebuffersOES = f; return retval;} + glCheckFramebufferStatusOES_t set_glCheckFramebufferStatusOES(glCheckFramebufferStatusOES_t f) { glCheckFramebufferStatusOES_t retval = glCheckFramebufferStatusOES; glCheckFramebufferStatusOES = f; return retval;} + glFramebufferRenderbufferOES_t set_glFramebufferRenderbufferOES(glFramebufferRenderbufferOES_t f) { glFramebufferRenderbufferOES_t retval = glFramebufferRenderbufferOES; glFramebufferRenderbufferOES = f; return retval;} + glFramebufferTexture2DOES_t set_glFramebufferTexture2DOES(glFramebufferTexture2DOES_t f) { glFramebufferTexture2DOES_t retval = glFramebufferTexture2DOES; glFramebufferTexture2DOES = f; return retval;} + glGetFramebufferAttachmentParameterivOES_t set_glGetFramebufferAttachmentParameterivOES(glGetFramebufferAttachmentParameterivOES_t f) { glGetFramebufferAttachmentParameterivOES_t retval = glGetFramebufferAttachmentParameterivOES; glGetFramebufferAttachmentParameterivOES = f; return retval;} + glGenerateMipmapOES_t set_glGenerateMipmapOES(glGenerateMipmapOES_t f) { glGenerateMipmapOES_t retval = glGenerateMipmapOES; glGenerateMipmapOES = f; return retval;} + glMapBufferOES_t set_glMapBufferOES(glMapBufferOES_t f) { glMapBufferOES_t retval = glMapBufferOES; glMapBufferOES = f; return retval;} + glUnmapBufferOES_t set_glUnmapBufferOES(glUnmapBufferOES_t f) { glUnmapBufferOES_t retval = glUnmapBufferOES; glUnmapBufferOES = f; return retval;} + glGetBufferPointervOES_t set_glGetBufferPointervOES(glGetBufferPointervOES_t f) { glGetBufferPointervOES_t retval = glGetBufferPointervOES; glGetBufferPointervOES = f; return retval;} + glCurrentPaletteMatrixOES_t set_glCurrentPaletteMatrixOES(glCurrentPaletteMatrixOES_t f) { glCurrentPaletteMatrixOES_t retval = glCurrentPaletteMatrixOES; glCurrentPaletteMatrixOES = f; return retval;} + glLoadPaletteFromModelViewMatrixOES_t set_glLoadPaletteFromModelViewMatrixOES(glLoadPaletteFromModelViewMatrixOES_t f) { glLoadPaletteFromModelViewMatrixOES_t retval = glLoadPaletteFromModelViewMatrixOES; glLoadPaletteFromModelViewMatrixOES = f; return retval;} + glMatrixIndexPointerOES_t set_glMatrixIndexPointerOES(glMatrixIndexPointerOES_t f) { glMatrixIndexPointerOES_t retval = glMatrixIndexPointerOES; glMatrixIndexPointerOES = f; return retval;} + glWeightPointerOES_t set_glWeightPointerOES(glWeightPointerOES_t f) { glWeightPointerOES_t retval = glWeightPointerOES; glWeightPointerOES = f; return retval;} + glQueryMatrixxOES_t set_glQueryMatrixxOES(glQueryMatrixxOES_t f) { glQueryMatrixxOES_t retval = glQueryMatrixxOES; glQueryMatrixxOES = f; return retval;} + glDepthRangefOES_t set_glDepthRangefOES(glDepthRangefOES_t f) { glDepthRangefOES_t retval = glDepthRangefOES; glDepthRangefOES = f; return retval;} + glFrustumfOES_t set_glFrustumfOES(glFrustumfOES_t f) { glFrustumfOES_t retval = glFrustumfOES; glFrustumfOES = f; return retval;} + glOrthofOES_t set_glOrthofOES(glOrthofOES_t f) { glOrthofOES_t retval = glOrthofOES; glOrthofOES = f; return retval;} + glClipPlanefOES_t set_glClipPlanefOES(glClipPlanefOES_t f) { glClipPlanefOES_t retval = glClipPlanefOES; glClipPlanefOES = f; return retval;} + glGetClipPlanefOES_t set_glGetClipPlanefOES(glGetClipPlanefOES_t f) { glGetClipPlanefOES_t retval = glGetClipPlanefOES; glGetClipPlanefOES = f; return retval;} + glClearDepthfOES_t set_glClearDepthfOES(glClearDepthfOES_t f) { glClearDepthfOES_t retval = glClearDepthfOES; glClearDepthfOES = f; return retval;} + glTexGenfOES_t set_glTexGenfOES(glTexGenfOES_t f) { glTexGenfOES_t retval = glTexGenfOES; glTexGenfOES = f; return retval;} + glTexGenfvOES_t set_glTexGenfvOES(glTexGenfvOES_t f) { glTexGenfvOES_t retval = glTexGenfvOES; glTexGenfvOES = f; return retval;} + glTexGeniOES_t set_glTexGeniOES(glTexGeniOES_t f) { glTexGeniOES_t retval = glTexGeniOES; glTexGeniOES = f; return retval;} + glTexGenivOES_t set_glTexGenivOES(glTexGenivOES_t f) { glTexGenivOES_t retval = glTexGenivOES; glTexGenivOES = f; return retval;} + glTexGenxOES_t set_glTexGenxOES(glTexGenxOES_t f) { glTexGenxOES_t retval = glTexGenxOES; glTexGenxOES = f; return retval;} + glTexGenxvOES_t set_glTexGenxvOES(glTexGenxvOES_t f) { glTexGenxvOES_t retval = glTexGenxvOES; glTexGenxvOES = f; return retval;} + glGetTexGenfvOES_t set_glGetTexGenfvOES(glGetTexGenfvOES_t f) { glGetTexGenfvOES_t retval = glGetTexGenfvOES; glGetTexGenfvOES = f; return retval;} + glGetTexGenivOES_t set_glGetTexGenivOES(glGetTexGenivOES_t f) { glGetTexGenivOES_t retval = glGetTexGenivOES; glGetTexGenivOES = f; return retval;} + glGetTexGenxvOES_t set_glGetTexGenxvOES(glGetTexGenxvOES_t f) { glGetTexGenxvOES_t retval = glGetTexGenxvOES; glGetTexGenxvOES = f; return retval;} + glBindVertexArrayOES_t set_glBindVertexArrayOES(glBindVertexArrayOES_t f) { glBindVertexArrayOES_t retval = glBindVertexArrayOES; glBindVertexArrayOES = f; return retval;} + glDeleteVertexArraysOES_t set_glDeleteVertexArraysOES(glDeleteVertexArraysOES_t f) { glDeleteVertexArraysOES_t retval = glDeleteVertexArraysOES; glDeleteVertexArraysOES = f; return retval;} + glGenVertexArraysOES_t set_glGenVertexArraysOES(glGenVertexArraysOES_t f) { glGenVertexArraysOES_t retval = glGenVertexArraysOES; glGenVertexArraysOES = f; return retval;} + glIsVertexArrayOES_t set_glIsVertexArrayOES(glIsVertexArrayOES_t f) { glIsVertexArrayOES_t retval = glIsVertexArrayOES; glIsVertexArrayOES = f; return retval;} + glDiscardFramebufferEXT_t set_glDiscardFramebufferEXT(glDiscardFramebufferEXT_t f) { glDiscardFramebufferEXT_t retval = glDiscardFramebufferEXT; glDiscardFramebufferEXT = f; return retval;} + glMultiDrawArraysEXT_t set_glMultiDrawArraysEXT(glMultiDrawArraysEXT_t f) { glMultiDrawArraysEXT_t retval = glMultiDrawArraysEXT; glMultiDrawArraysEXT = f; return retval;} + glMultiDrawElementsEXT_t set_glMultiDrawElementsEXT(glMultiDrawElementsEXT_t f) { glMultiDrawElementsEXT_t retval = glMultiDrawElementsEXT; glMultiDrawElementsEXT = f; return retval;} + glClipPlanefIMG_t set_glClipPlanefIMG(glClipPlanefIMG_t f) { glClipPlanefIMG_t retval = glClipPlanefIMG; glClipPlanefIMG = f; return retval;} + glClipPlanexIMG_t set_glClipPlanexIMG(glClipPlanexIMG_t f) { glClipPlanexIMG_t retval = glClipPlanexIMG; glClipPlanexIMG = f; return retval;} + glRenderbufferStorageMultisampleIMG_t set_glRenderbufferStorageMultisampleIMG(glRenderbufferStorageMultisampleIMG_t f) { glRenderbufferStorageMultisampleIMG_t retval = glRenderbufferStorageMultisampleIMG; glRenderbufferStorageMultisampleIMG = f; return retval;} + glFramebufferTexture2DMultisampleIMG_t set_glFramebufferTexture2DMultisampleIMG(glFramebufferTexture2DMultisampleIMG_t f) { glFramebufferTexture2DMultisampleIMG_t retval = glFramebufferTexture2DMultisampleIMG; glFramebufferTexture2DMultisampleIMG = f; return retval;} + glDeleteFencesNV_t set_glDeleteFencesNV(glDeleteFencesNV_t f) { glDeleteFencesNV_t retval = glDeleteFencesNV; glDeleteFencesNV = f; return retval;} + glGenFencesNV_t set_glGenFencesNV(glGenFencesNV_t f) { glGenFencesNV_t retval = glGenFencesNV; glGenFencesNV = f; return retval;} + glIsFenceNV_t set_glIsFenceNV(glIsFenceNV_t f) { glIsFenceNV_t retval = glIsFenceNV; glIsFenceNV = f; return retval;} + glTestFenceNV_t set_glTestFenceNV(glTestFenceNV_t f) { glTestFenceNV_t retval = glTestFenceNV; glTestFenceNV = f; return retval;} + glGetFenceivNV_t set_glGetFenceivNV(glGetFenceivNV_t f) { glGetFenceivNV_t retval = glGetFenceivNV; glGetFenceivNV = f; return retval;} + glFinishFenceNV_t set_glFinishFenceNV(glFinishFenceNV_t f) { glFinishFenceNV_t retval = glFinishFenceNV; glFinishFenceNV = f; return retval;} + glSetFenceNV_t set_glSetFenceNV(glSetFenceNV_t f) { glSetFenceNV_t retval = glSetFenceNV; glSetFenceNV = f; return retval;} + glGetDriverControlsQCOM_t set_glGetDriverControlsQCOM(glGetDriverControlsQCOM_t f) { glGetDriverControlsQCOM_t retval = glGetDriverControlsQCOM; glGetDriverControlsQCOM = f; return retval;} + glGetDriverControlStringQCOM_t set_glGetDriverControlStringQCOM(glGetDriverControlStringQCOM_t f) { glGetDriverControlStringQCOM_t retval = glGetDriverControlStringQCOM; glGetDriverControlStringQCOM = f; return retval;} + glEnableDriverControlQCOM_t set_glEnableDriverControlQCOM(glEnableDriverControlQCOM_t f) { glEnableDriverControlQCOM_t retval = glEnableDriverControlQCOM; glEnableDriverControlQCOM = f; return retval;} + glDisableDriverControlQCOM_t set_glDisableDriverControlQCOM(glDisableDriverControlQCOM_t f) { glDisableDriverControlQCOM_t retval = glDisableDriverControlQCOM; glDisableDriverControlQCOM = f; return retval;} + glExtGetTexturesQCOM_t set_glExtGetTexturesQCOM(glExtGetTexturesQCOM_t f) { glExtGetTexturesQCOM_t retval = glExtGetTexturesQCOM; glExtGetTexturesQCOM = f; return retval;} + glExtGetBuffersQCOM_t set_glExtGetBuffersQCOM(glExtGetBuffersQCOM_t f) { glExtGetBuffersQCOM_t retval = glExtGetBuffersQCOM; glExtGetBuffersQCOM = f; return retval;} + glExtGetRenderbuffersQCOM_t set_glExtGetRenderbuffersQCOM(glExtGetRenderbuffersQCOM_t f) { glExtGetRenderbuffersQCOM_t retval = glExtGetRenderbuffersQCOM; glExtGetRenderbuffersQCOM = f; return retval;} + glExtGetFramebuffersQCOM_t set_glExtGetFramebuffersQCOM(glExtGetFramebuffersQCOM_t f) { glExtGetFramebuffersQCOM_t retval = glExtGetFramebuffersQCOM; glExtGetFramebuffersQCOM = f; return retval;} + glExtGetTexLevelParameterivQCOM_t set_glExtGetTexLevelParameterivQCOM(glExtGetTexLevelParameterivQCOM_t f) { glExtGetTexLevelParameterivQCOM_t retval = glExtGetTexLevelParameterivQCOM; glExtGetTexLevelParameterivQCOM = f; return retval;} + glExtTexObjectStateOverrideiQCOM_t set_glExtTexObjectStateOverrideiQCOM(glExtTexObjectStateOverrideiQCOM_t f) { glExtTexObjectStateOverrideiQCOM_t retval = glExtTexObjectStateOverrideiQCOM; glExtTexObjectStateOverrideiQCOM = f; return retval;} + glExtGetTexSubImageQCOM_t set_glExtGetTexSubImageQCOM(glExtGetTexSubImageQCOM_t f) { glExtGetTexSubImageQCOM_t retval = glExtGetTexSubImageQCOM; glExtGetTexSubImageQCOM = f; return retval;} + glExtGetBufferPointervQCOM_t set_glExtGetBufferPointervQCOM(glExtGetBufferPointervQCOM_t f) { glExtGetBufferPointervQCOM_t retval = glExtGetBufferPointervQCOM; glExtGetBufferPointervQCOM = f; return retval;} + glExtGetShadersQCOM_t set_glExtGetShadersQCOM(glExtGetShadersQCOM_t f) { glExtGetShadersQCOM_t retval = glExtGetShadersQCOM; glExtGetShadersQCOM = f; return retval;} + glExtGetProgramsQCOM_t set_glExtGetProgramsQCOM(glExtGetProgramsQCOM_t f) { glExtGetProgramsQCOM_t retval = glExtGetProgramsQCOM; glExtGetProgramsQCOM = f; return retval;} + glExtIsProgramBinaryQCOM_t set_glExtIsProgramBinaryQCOM(glExtIsProgramBinaryQCOM_t f) { glExtIsProgramBinaryQCOM_t retval = glExtIsProgramBinaryQCOM; glExtIsProgramBinaryQCOM = f; return retval;} + glExtGetProgramBinarySourceQCOM_t set_glExtGetProgramBinarySourceQCOM(glExtGetProgramBinarySourceQCOM_t f) { glExtGetProgramBinarySourceQCOM_t retval = glExtGetProgramBinarySourceQCOM; glExtGetProgramBinarySourceQCOM = f; return retval;} + glStartTilingQCOM_t set_glStartTilingQCOM(glStartTilingQCOM_t f) { glStartTilingQCOM_t retval = glStartTilingQCOM; glStartTilingQCOM = f; return retval;} + glEndTilingQCOM_t set_glEndTilingQCOM(glEndTilingQCOM_t f) { glEndTilingQCOM_t retval = glEndTilingQCOM; glEndTilingQCOM = f; return retval;} +}; + +gles_dispatch *create_gles_dispatch(void *gles_andorid); + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_emul.cfg b/emulator/opengl/tests/gles_android_wrapper/gles_emul.cfg new file mode 100644 index 0000000..a837807 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_emul.cfg @@ -0,0 +1,7 @@ +angeles +my-tritex +org.zeroxlab.benchmark +com.cooliris.media +com.polarbit.waveblazerlite +test-opengl-gl2_basic +com.trendy.ddapp diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_ftable.h b/emulator/opengl/tests/gles_android_wrapper/gles_ftable.h new file mode 100644 index 0000000..1895b18 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_ftable.h @@ -0,0 +1,292 @@ +/* +* 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. +*/ +static struct _gles_funcs_by_name { + const char *name; + void *proc; +} gles_funcs_by_name[] = { + {"glAlphaFunc", (void *)glAlphaFunc}, + {"glClearColor", (void *)glClearColor}, + {"glClearDepthf", (void *)glClearDepthf}, + {"glClipPlanef", (void *)glClipPlanef}, + {"glColor4f", (void *)glColor4f}, + {"glDepthRangef", (void *)glDepthRangef}, + {"glFogf", (void *)glFogf}, + {"glFogfv", (void *)glFogfv}, + {"glFrustumf", (void *)glFrustumf}, + {"glGetClipPlanef", (void *)glGetClipPlanef}, + {"glGetFloatv", (void *)glGetFloatv}, + {"glGetLightfv", (void *)glGetLightfv}, + {"glGetMaterialfv", (void *)glGetMaterialfv}, + {"glGetTexEnvfv", (void *)glGetTexEnvfv}, + {"glGetTexParameterfv", (void *)glGetTexParameterfv}, + {"glLightModelf", (void *)glLightModelf}, + {"glLightModelfv", (void *)glLightModelfv}, + {"glLightf", (void *)glLightf}, + {"glLightfv", (void *)glLightfv}, + {"glLineWidth", (void *)glLineWidth}, + {"glLoadMatrixf", (void *)glLoadMatrixf}, + {"glMaterialf", (void *)glMaterialf}, + {"glMaterialfv", (void *)glMaterialfv}, + {"glMultMatrixf", (void *)glMultMatrixf}, + {"glMultiTexCoord4f", (void *)glMultiTexCoord4f}, + {"glNormal3f", (void *)glNormal3f}, + {"glOrthof", (void *)glOrthof}, + {"glPointParameterf", (void *)glPointParameterf}, + {"glPointParameterfv", (void *)glPointParameterfv}, + {"glPointSize", (void *)glPointSize}, + {"glPolygonOffset", (void *)glPolygonOffset}, + {"glRotatef", (void *)glRotatef}, + {"glScalef", (void *)glScalef}, + {"glTexEnvf", (void *)glTexEnvf}, + {"glTexEnvfv", (void *)glTexEnvfv}, + {"glTexParameterf", (void *)glTexParameterf}, + {"glTexParameterfv", (void *)glTexParameterfv}, + {"glTranslatef", (void *)glTranslatef}, + {"glActiveTexture", (void *)glActiveTexture}, + {"glAlphaFuncx", (void *)glAlphaFuncx}, + {"glBindBuffer", (void *)glBindBuffer}, + {"glBindTexture", (void *)glBindTexture}, + {"glBlendFunc", (void *)glBlendFunc}, + {"glBufferData", (void *)glBufferData}, + {"glBufferSubData", (void *)glBufferSubData}, + {"glClear", (void *)glClear}, + {"glClearColorx", (void *)glClearColorx}, + {"glClearDepthx", (void *)glClearDepthx}, + {"glClearStencil", (void *)glClearStencil}, + {"glClientActiveTexture", (void *)glClientActiveTexture}, + {"glClipPlanex", (void *)glClipPlanex}, + {"glColor4ub", (void *)glColor4ub}, + {"glColor4x", (void *)glColor4x}, + {"glColorMask", (void *)glColorMask}, + {"glColorPointer", (void *)glColorPointer}, + {"glCompressedTexImage2D", (void *)glCompressedTexImage2D}, + {"glCompressedTexSubImage2D", (void *)glCompressedTexSubImage2D}, + {"glCopyTexImage2D", (void *)glCopyTexImage2D}, + {"glCopyTexSubImage2D", (void *)glCopyTexSubImage2D}, + {"glCullFace", (void *)glCullFace}, + {"glDeleteBuffers", (void *)glDeleteBuffers}, + {"glDeleteTextures", (void *)glDeleteTextures}, + {"glDepthFunc", (void *)glDepthFunc}, + {"glDepthMask", (void *)glDepthMask}, + {"glDepthRangex", (void *)glDepthRangex}, + {"glDisable", (void *)glDisable}, + {"glDisableClientState", (void *)glDisableClientState}, + {"glDrawArrays", (void *)glDrawArrays}, + {"glDrawElements", (void *)glDrawElements}, + {"glEnable", (void *)glEnable}, + {"glEnableClientState", (void *)glEnableClientState}, + {"glFinish", (void *)glFinish}, + {"glFlush", (void *)glFlush}, + {"glFogx", (void *)glFogx}, + {"glFogxv", (void *)glFogxv}, + {"glFrontFace", (void *)glFrontFace}, + {"glFrustumx", (void *)glFrustumx}, + {"glGetBooleanv", (void *)glGetBooleanv}, + {"glGetBufferParameteriv", (void *)glGetBufferParameteriv}, + {"glGetClipPlanex", (void *)glGetClipPlanex}, + {"glGenBuffers", (void *)glGenBuffers}, + {"glGenTextures", (void *)glGenTextures}, + {"glGetError", (void *)glGetError}, + {"glGetFixedv", (void *)glGetFixedv}, + {"glGetIntegerv", (void *)glGetIntegerv}, + {"glGetLightxv", (void *)glGetLightxv}, + {"glGetMaterialxv", (void *)glGetMaterialxv}, + {"glGetPointerv", (void *)glGetPointerv}, + {"glGetString", (void *)glGetString}, + {"glGetTexEnviv", (void *)glGetTexEnviv}, + {"glGetTexEnvxv", (void *)glGetTexEnvxv}, + {"glGetTexParameteriv", (void *)glGetTexParameteriv}, + {"glGetTexParameterxv", (void *)glGetTexParameterxv}, + {"glHint", (void *)glHint}, + {"glIsBuffer", (void *)glIsBuffer}, + {"glIsEnabled", (void *)glIsEnabled}, + {"glIsTexture", (void *)glIsTexture}, + {"glLightModelx", (void *)glLightModelx}, + {"glLightModelxv", (void *)glLightModelxv}, + {"glLightx", (void *)glLightx}, + {"glLightxv", (void *)glLightxv}, + {"glLineWidthx", (void *)glLineWidthx}, + {"glLoadIdentity", (void *)glLoadIdentity}, + {"glLoadMatrixx", (void *)glLoadMatrixx}, + {"glLogicOp", (void *)glLogicOp}, + {"glMaterialx", (void *)glMaterialx}, + {"glMaterialxv", (void *)glMaterialxv}, + {"glMatrixMode", (void *)glMatrixMode}, + {"glMultMatrixx", (void *)glMultMatrixx}, + {"glMultiTexCoord4x", (void *)glMultiTexCoord4x}, + {"glNormal3x", (void *)glNormal3x}, + {"glNormalPointer", (void *)glNormalPointer}, + {"glOrthox", (void *)glOrthox}, + {"glPixelStorei", (void *)glPixelStorei}, + {"glPointParameterx", (void *)glPointParameterx}, + {"glPointParameterxv", (void *)glPointParameterxv}, + {"glPointSizex", (void *)glPointSizex}, + {"glPolygonOffsetx", (void *)glPolygonOffsetx}, + {"glPopMatrix", (void *)glPopMatrix}, + {"glPushMatrix", (void *)glPushMatrix}, + {"glReadPixels", (void *)glReadPixels}, + {"glRotatex", (void *)glRotatex}, + {"glSampleCoverage", (void *)glSampleCoverage}, + {"glSampleCoveragex", (void *)glSampleCoveragex}, + {"glScalex", (void *)glScalex}, + {"glScissor", (void *)glScissor}, + {"glShadeModel", (void *)glShadeModel}, + {"glStencilFunc", (void *)glStencilFunc}, + {"glStencilMask", (void *)glStencilMask}, + {"glStencilOp", (void *)glStencilOp}, + {"glTexCoordPointer", (void *)glTexCoordPointer}, + {"glTexEnvi", (void *)glTexEnvi}, + {"glTexEnvx", (void *)glTexEnvx}, + {"glTexEnviv", (void *)glTexEnviv}, + {"glTexEnvxv", (void *)glTexEnvxv}, + {"glTexImage2D", (void *)glTexImage2D}, + {"glTexParameteri", (void *)glTexParameteri}, + {"glTexParameterx", (void *)glTexParameterx}, + {"glTexParameteriv", (void *)glTexParameteriv}, + {"glTexParameterxv", (void *)glTexParameterxv}, + {"glTexSubImage2D", (void *)glTexSubImage2D}, + {"glTranslatex", (void *)glTranslatex}, + {"glVertexPointer", (void *)glVertexPointer}, + {"glViewport", (void *)glViewport}, + {"glPointSizePointerOES", (void *)glPointSizePointerOES}, + {"glBlendEquationSeparateOES", (void *)glBlendEquationSeparateOES}, + {"glBlendFuncSeparateOES", (void *)glBlendFuncSeparateOES}, + {"glBlendEquationOES", (void *)glBlendEquationOES}, + {"glDrawTexsOES", (void *)glDrawTexsOES}, + {"glDrawTexiOES", (void *)glDrawTexiOES}, + {"glDrawTexxOES", (void *)glDrawTexxOES}, + {"glDrawTexsvOES", (void *)glDrawTexsvOES}, + {"glDrawTexivOES", (void *)glDrawTexivOES}, + {"glDrawTexxvOES", (void *)glDrawTexxvOES}, + {"glDrawTexfOES", (void *)glDrawTexfOES}, + {"glDrawTexfvOES", (void *)glDrawTexfvOES}, + {"glEGLImageTargetTexture2DOES", (void *)glEGLImageTargetTexture2DOES}, + {"glEGLImageTargetRenderbufferStorageOES", (void *)glEGLImageTargetRenderbufferStorageOES}, + {"glAlphaFuncxOES", (void *)glAlphaFuncxOES}, + {"glClearColorxOES", (void *)glClearColorxOES}, + {"glClearDepthxOES", (void *)glClearDepthxOES}, + {"glClipPlanexOES", (void *)glClipPlanexOES}, + {"glColor4xOES", (void *)glColor4xOES}, + {"glDepthRangexOES", (void *)glDepthRangexOES}, + {"glFogxOES", (void *)glFogxOES}, + {"glFogxvOES", (void *)glFogxvOES}, + {"glFrustumxOES", (void *)glFrustumxOES}, + {"glGetClipPlanexOES", (void *)glGetClipPlanexOES}, + {"glGetFixedvOES", (void *)glGetFixedvOES}, + {"glGetLightxvOES", (void *)glGetLightxvOES}, + {"glGetMaterialxvOES", (void *)glGetMaterialxvOES}, + {"glGetTexEnvxvOES", (void *)glGetTexEnvxvOES}, + {"glGetTexParameterxvOES", (void *)glGetTexParameterxvOES}, + {"glLightModelxOES", (void *)glLightModelxOES}, + {"glLightModelxvOES", (void *)glLightModelxvOES}, + {"glLightxOES", (void *)glLightxOES}, + {"glLightxvOES", (void *)glLightxvOES}, + {"glLineWidthxOES", (void *)glLineWidthxOES}, + {"glLoadMatrixxOES", (void *)glLoadMatrixxOES}, + {"glMaterialxOES", (void *)glMaterialxOES}, + {"glMaterialxvOES", (void *)glMaterialxvOES}, + {"glMultMatrixxOES", (void *)glMultMatrixxOES}, + {"glMultiTexCoord4xOES", (void *)glMultiTexCoord4xOES}, + {"glNormal3xOES", (void *)glNormal3xOES}, + {"glOrthoxOES", (void *)glOrthoxOES}, + {"glPointParameterxOES", (void *)glPointParameterxOES}, + {"glPointParameterxvOES", (void *)glPointParameterxvOES}, + {"glPointSizexOES", (void *)glPointSizexOES}, + {"glPolygonOffsetxOES", (void *)glPolygonOffsetxOES}, + {"glRotatexOES", (void *)glRotatexOES}, + {"glSampleCoveragexOES", (void *)glSampleCoveragexOES}, + {"glScalexOES", (void *)glScalexOES}, + {"glTexEnvxOES", (void *)glTexEnvxOES}, + {"glTexEnvxvOES", (void *)glTexEnvxvOES}, + {"glTexParameterxOES", (void *)glTexParameterxOES}, + {"glTexParameterxvOES", (void *)glTexParameterxvOES}, + {"glTranslatexOES", (void *)glTranslatexOES}, + {"glIsRenderbufferOES", (void *)glIsRenderbufferOES}, + {"glBindRenderbufferOES", (void *)glBindRenderbufferOES}, + {"glDeleteRenderbuffersOES", (void *)glDeleteRenderbuffersOES}, + {"glGenRenderbuffersOES", (void *)glGenRenderbuffersOES}, + {"glRenderbufferStorageOES", (void *)glRenderbufferStorageOES}, + {"glGetRenderbufferParameterivOES", (void *)glGetRenderbufferParameterivOES}, + {"glIsFramebufferOES", (void *)glIsFramebufferOES}, + {"glBindFramebufferOES", (void *)glBindFramebufferOES}, + {"glDeleteFramebuffersOES", (void *)glDeleteFramebuffersOES}, + {"glGenFramebuffersOES", (void *)glGenFramebuffersOES}, + {"glCheckFramebufferStatusOES", (void *)glCheckFramebufferStatusOES}, + {"glFramebufferRenderbufferOES", (void *)glFramebufferRenderbufferOES}, + {"glFramebufferTexture2DOES", (void *)glFramebufferTexture2DOES}, + {"glGetFramebufferAttachmentParameterivOES", (void *)glGetFramebufferAttachmentParameterivOES}, + {"glGenerateMipmapOES", (void *)glGenerateMipmapOES}, + {"glMapBufferOES", (void *)glMapBufferOES}, + {"glUnmapBufferOES", (void *)glUnmapBufferOES}, + {"glGetBufferPointervOES", (void *)glGetBufferPointervOES}, + {"glCurrentPaletteMatrixOES", (void *)glCurrentPaletteMatrixOES}, + {"glLoadPaletteFromModelViewMatrixOES", (void *)glLoadPaletteFromModelViewMatrixOES}, + {"glMatrixIndexPointerOES", (void *)glMatrixIndexPointerOES}, + {"glWeightPointerOES", (void *)glWeightPointerOES}, + {"glQueryMatrixxOES", (void *)glQueryMatrixxOES}, + {"glDepthRangefOES", (void *)glDepthRangefOES}, + {"glFrustumfOES", (void *)glFrustumfOES}, + {"glOrthofOES", (void *)glOrthofOES}, + {"glClipPlanefOES", (void *)glClipPlanefOES}, + {"glGetClipPlanefOES", (void *)glGetClipPlanefOES}, + {"glClearDepthfOES", (void *)glClearDepthfOES}, + {"glTexGenfOES", (void *)glTexGenfOES}, + {"glTexGenfvOES", (void *)glTexGenfvOES}, + {"glTexGeniOES", (void *)glTexGeniOES}, + {"glTexGenivOES", (void *)glTexGenivOES}, + {"glTexGenxOES", (void *)glTexGenxOES}, + {"glTexGenxvOES", (void *)glTexGenxvOES}, + {"glGetTexGenfvOES", (void *)glGetTexGenfvOES}, + {"glGetTexGenivOES", (void *)glGetTexGenivOES}, + {"glGetTexGenxvOES", (void *)glGetTexGenxvOES}, + {"glBindVertexArrayOES", (void *)glBindVertexArrayOES}, + {"glDeleteVertexArraysOES", (void *)glDeleteVertexArraysOES}, + {"glGenVertexArraysOES", (void *)glGenVertexArraysOES}, + {"glIsVertexArrayOES", (void *)glIsVertexArrayOES}, + {"glDiscardFramebufferEXT", (void *)glDiscardFramebufferEXT}, + {"glMultiDrawArraysEXT", (void *)glMultiDrawArraysEXT}, + {"glMultiDrawElementsEXT", (void *)glMultiDrawElementsEXT}, + {"glClipPlanefIMG", (void *)glClipPlanefIMG}, + {"glClipPlanexIMG", (void *)glClipPlanexIMG}, + {"glRenderbufferStorageMultisampleIMG", (void *)glRenderbufferStorageMultisampleIMG}, + {"glFramebufferTexture2DMultisampleIMG", (void *)glFramebufferTexture2DMultisampleIMG}, + {"glDeleteFencesNV", (void *)glDeleteFencesNV}, + {"glGenFencesNV", (void *)glGenFencesNV}, + {"glIsFenceNV", (void *)glIsFenceNV}, + {"glTestFenceNV", (void *)glTestFenceNV}, + {"glGetFenceivNV", (void *)glGetFenceivNV}, + {"glFinishFenceNV", (void *)glFinishFenceNV}, + {"glSetFenceNV", (void *)glSetFenceNV}, + {"glGetDriverControlsQCOM", (void *)glGetDriverControlsQCOM}, + {"glGetDriverControlStringQCOM", (void *)glGetDriverControlStringQCOM}, + {"glEnableDriverControlQCOM", (void *)glEnableDriverControlQCOM}, + {"glDisableDriverControlQCOM", (void *)glDisableDriverControlQCOM}, + {"glExtGetTexturesQCOM", (void *)glExtGetTexturesQCOM}, + {"glExtGetBuffersQCOM", (void *)glExtGetBuffersQCOM}, + {"glExtGetRenderbuffersQCOM", (void *)glExtGetRenderbuffersQCOM}, + {"glExtGetFramebuffersQCOM", (void *)glExtGetFramebuffersQCOM}, + {"glExtGetTexLevelParameterivQCOM", (void *)glExtGetTexLevelParameterivQCOM}, + {"glExtTexObjectStateOverrideiQCOM", (void *)glExtTexObjectStateOverrideiQCOM}, + {"glExtGetTexSubImageQCOM", (void *)glExtGetTexSubImageQCOM}, + {"glExtGetBufferPointervQCOM", (void *)glExtGetBufferPointervQCOM}, + {"glExtGetShadersQCOM", (void *)glExtGetShadersQCOM}, + {"glExtGetProgramsQCOM", (void *)glExtGetProgramsQCOM}, + {"glExtIsProgramBinaryQCOM", (void *)glExtIsProgramBinaryQCOM}, + {"glExtGetProgramBinarySourceQCOM", (void *)glExtGetProgramBinarySourceQCOM}, + {"glStartTilingQCOM", (void *)glStartTilingQCOM}, + {"glEndTilingQCOM", (void *)glEndTilingQCOM} +}; +static int gles_num_funcs = sizeof(gles_funcs_by_name) / sizeof(struct _gles_funcs_by_name); diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_proc.h b/emulator/opengl/tests/gles_android_wrapper/gles_proc.h new file mode 100644 index 0000000..afd94b9 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_proc.h @@ -0,0 +1,296 @@ +/* +* 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. +*/ +#ifndef _GLES_PROC_H +#define _GLES_PROC_H + +#include <GLES/gl.h> +#define GL_GLEXT_PROTOTYPES +#include <GLES/glext.h> + +typedef void (* glAlphaFunc_t) (GLenum, GLclampf); +typedef void (* glClearColor_t) (GLclampf, GLclampf, GLclampf, GLclampf); +typedef void (* glClearDepthf_t) (GLclampf); +typedef void (* glClipPlanef_t) (GLenum, const GLfloat*); +typedef void (* glColor4f_t) (GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glDepthRangef_t) (GLclampf, GLclampf); +typedef void (* glFogf_t) (GLenum, GLfloat); +typedef void (* glFogfv_t) (GLenum, const GLfloat*); +typedef void (* glFrustumf_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glGetClipPlanef_t) (GLenum, GLfloat*); +typedef void (* glGetFloatv_t) (GLenum, GLfloat*); +typedef void (* glGetLightfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetMaterialfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetTexEnvfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetTexParameterfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glLightModelf_t) (GLenum, GLfloat); +typedef void (* glLightModelfv_t) (GLenum, const GLfloat*); +typedef void (* glLightf_t) (GLenum, GLenum, GLfloat); +typedef void (* glLightfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glLineWidth_t) (GLfloat); +typedef void (* glLoadMatrixf_t) (const GLfloat*); +typedef void (* glMaterialf_t) (GLenum, GLenum, GLfloat); +typedef void (* glMaterialfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glMultMatrixf_t) (const GLfloat*); +typedef void (* glMultiTexCoord4f_t) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glNormal3f_t) (GLfloat, GLfloat, GLfloat); +typedef void (* glOrthof_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glPointParameterf_t) (GLenum, GLfloat); +typedef void (* glPointParameterfv_t) (GLenum, const GLfloat*); +typedef void (* glPointSize_t) (GLfloat); +typedef void (* glPolygonOffset_t) (GLfloat, GLfloat); +typedef void (* glRotatef_t) (GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glScalef_t) (GLfloat, GLfloat, GLfloat); +typedef void (* glTexEnvf_t) (GLenum, GLenum, GLfloat); +typedef void (* glTexEnvfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glTexParameterf_t) (GLenum, GLenum, GLfloat); +typedef void (* glTexParameterfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glTranslatef_t) (GLfloat, GLfloat, GLfloat); +typedef void (* glActiveTexture_t) (GLenum); +typedef void (* glAlphaFuncx_t) (GLenum, GLclampx); +typedef void (* glBindBuffer_t) (GLenum, GLuint); +typedef void (* glBindTexture_t) (GLenum, GLuint); +typedef void (* glBlendFunc_t) (GLenum, GLenum); +typedef void (* glBufferData_t) (GLenum, GLsizeiptr, const GLvoid*, GLenum); +typedef void (* glBufferSubData_t) (GLenum, GLintptr, GLsizeiptr, const GLvoid*); +typedef void (* glClear_t) (GLbitfield); +typedef void (* glClearColorx_t) (GLclampx, GLclampx, GLclampx, GLclampx); +typedef void (* glClearDepthx_t) (GLclampx); +typedef void (* glClearStencil_t) (GLint); +typedef void (* glClientActiveTexture_t) (GLenum); +typedef void (* glClipPlanex_t) (GLenum, const GLfixed*); +typedef void (* glColor4ub_t) (GLubyte, GLubyte, GLubyte, GLubyte); +typedef void (* glColor4x_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glColorMask_t) (GLboolean, GLboolean, GLboolean, GLboolean); +typedef void (* glColorPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glCompressedTexImage2D_t) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); +typedef void (* glCompressedTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); +typedef void (* glCopyTexImage2D_t) (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +typedef void (* glCopyTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +typedef void (* glCullFace_t) (GLenum); +typedef void (* glDeleteBuffers_t) (GLsizei, const GLuint*); +typedef void (* glDeleteTextures_t) (GLsizei, const GLuint*); +typedef void (* glDepthFunc_t) (GLenum); +typedef void (* glDepthMask_t) (GLboolean); +typedef void (* glDepthRangex_t) (GLclampx, GLclampx); +typedef void (* glDisable_t) (GLenum); +typedef void (* glDisableClientState_t) (GLenum); +typedef void (* glDrawArrays_t) (GLenum, GLint, GLsizei); +typedef void (* glDrawElements_t) (GLenum, GLsizei, GLenum, const GLvoid*); +typedef void (* glEnable_t) (GLenum); +typedef void (* glEnableClientState_t) (GLenum); +typedef void (* glFinish_t) (); +typedef void (* glFlush_t) (); +typedef void (* glFogx_t) (GLenum, GLfixed); +typedef void (* glFogxv_t) (GLenum, const GLfixed*); +typedef void (* glFrontFace_t) (GLenum); +typedef void (* glFrustumx_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glGetBooleanv_t) (GLenum, GLboolean*); +typedef void (* glGetBufferParameteriv_t) (GLenum, GLenum, GLint*); +typedef void (* glGetClipPlanex_t) (GLenum, GLfixed*); +typedef void (* glGenBuffers_t) (GLsizei, GLuint*); +typedef void (* glGenTextures_t) (GLsizei, GLuint*); +typedef GLenum (* glGetError_t) (); +typedef void (* glGetFixedv_t) (GLenum, GLfixed*); +typedef void (* glGetIntegerv_t) (GLenum, GLint*); +typedef void (* glGetLightxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetMaterialxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetPointerv_t) (GLenum, GLvoid**); +typedef const GLubyte* (* glGetString_t) (GLenum); +typedef void (* glGetTexEnviv_t) (GLenum, GLenum, GLint*); +typedef void (* glGetTexEnvxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetTexParameteriv_t) (GLenum, GLenum, GLint*); +typedef void (* glGetTexParameterxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glHint_t) (GLenum, GLenum); +typedef GLboolean (* glIsBuffer_t) (GLuint); +typedef GLboolean (* glIsEnabled_t) (GLenum); +typedef GLboolean (* glIsTexture_t) (GLuint); +typedef void (* glLightModelx_t) (GLenum, GLfixed); +typedef void (* glLightModelxv_t) (GLenum, const GLfixed*); +typedef void (* glLightx_t) (GLenum, GLenum, GLfixed); +typedef void (* glLightxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glLineWidthx_t) (GLfixed); +typedef void (* glLoadIdentity_t) (); +typedef void (* glLoadMatrixx_t) (const GLfixed*); +typedef void (* glLogicOp_t) (GLenum); +typedef void (* glMaterialx_t) (GLenum, GLenum, GLfixed); +typedef void (* glMaterialxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glMatrixMode_t) (GLenum); +typedef void (* glMultMatrixx_t) (const GLfixed*); +typedef void (* glMultiTexCoord4x_t) (GLenum, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glNormal3x_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glNormalPointer_t) (GLenum, GLsizei, const GLvoid*); +typedef void (* glOrthox_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glPixelStorei_t) (GLenum, GLint); +typedef void (* glPointParameterx_t) (GLenum, GLfixed); +typedef void (* glPointParameterxv_t) (GLenum, const GLfixed*); +typedef void (* glPointSizex_t) (GLfixed); +typedef void (* glPolygonOffsetx_t) (GLfixed, GLfixed); +typedef void (* glPopMatrix_t) (); +typedef void (* glPushMatrix_t) (); +typedef void (* glReadPixels_t) (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*); +typedef void (* glRotatex_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glSampleCoverage_t) (GLclampf, GLboolean); +typedef void (* glSampleCoveragex_t) (GLclampx, GLboolean); +typedef void (* glScalex_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glScissor_t) (GLint, GLint, GLsizei, GLsizei); +typedef void (* glShadeModel_t) (GLenum); +typedef void (* glStencilFunc_t) (GLenum, GLint, GLuint); +typedef void (* glStencilMask_t) (GLuint); +typedef void (* glStencilOp_t) (GLenum, GLenum, GLenum); +typedef void (* glTexCoordPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glTexEnvi_t) (GLenum, GLenum, GLint); +typedef void (* glTexEnvx_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexEnviv_t) (GLenum, GLenum, const GLint*); +typedef void (* glTexEnvxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTexImage2D_t) (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*); +typedef void (* glTexParameteri_t) (GLenum, GLenum, GLint); +typedef void (* glTexParameterx_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexParameteriv_t) (GLenum, GLenum, const GLint*); +typedef void (* glTexParameterxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*); +typedef void (* glTranslatex_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glVertexPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glViewport_t) (GLint, GLint, GLsizei, GLsizei); +typedef void (* glPointSizePointerOES_t) (GLenum, GLsizei, const GLvoid*); +typedef void (* glBlendEquationSeparateOES_t) (GLenum, GLenum); +typedef void (* glBlendFuncSeparateOES_t) (GLenum, GLenum, GLenum, GLenum); +typedef void (* glBlendEquationOES_t) (GLenum); +typedef void (* glDrawTexsOES_t) (GLshort, GLshort, GLshort, GLshort, GLshort); +typedef void (* glDrawTexiOES_t) (GLint, GLint, GLint, GLint, GLint); +typedef void (* glDrawTexxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glDrawTexsvOES_t) (const GLshort*); +typedef void (* glDrawTexivOES_t) (const GLint*); +typedef void (* glDrawTexxvOES_t) (const GLfixed*); +typedef void (* glDrawTexfOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glDrawTexfvOES_t) (const GLfloat*); +typedef void (* glEGLImageTargetTexture2DOES_t) (GLenum, GLeglImageOES); +typedef void (* glEGLImageTargetRenderbufferStorageOES_t) (GLenum, GLeglImageOES); +typedef void (* glAlphaFuncxOES_t) (GLenum, GLclampx); +typedef void (* glClearColorxOES_t) (GLclampx, GLclampx, GLclampx, GLclampx); +typedef void (* glClearDepthxOES_t) (GLclampx); +typedef void (* glClipPlanexOES_t) (GLenum, const GLfixed*); +typedef void (* glColor4xOES_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glDepthRangexOES_t) (GLclampx, GLclampx); +typedef void (* glFogxOES_t) (GLenum, GLfixed); +typedef void (* glFogxvOES_t) (GLenum, const GLfixed*); +typedef void (* glFrustumxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glGetClipPlanexOES_t) (GLenum, GLfixed*); +typedef void (* glGetFixedvOES_t) (GLenum, GLfixed*); +typedef void (* glGetLightxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetMaterialxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetTexEnvxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetTexParameterxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glLightModelxOES_t) (GLenum, GLfixed); +typedef void (* glLightModelxvOES_t) (GLenum, const GLfixed*); +typedef void (* glLightxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glLightxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glLineWidthxOES_t) (GLfixed); +typedef void (* glLoadMatrixxOES_t) (const GLfixed*); +typedef void (* glMaterialxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glMaterialxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glMultMatrixxOES_t) (const GLfixed*); +typedef void (* glMultiTexCoord4xOES_t) (GLenum, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glNormal3xOES_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glOrthoxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glPointParameterxOES_t) (GLenum, GLfixed); +typedef void (* glPointParameterxvOES_t) (GLenum, const GLfixed*); +typedef void (* glPointSizexOES_t) (GLfixed); +typedef void (* glPolygonOffsetxOES_t) (GLfixed, GLfixed); +typedef void (* glRotatexOES_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glSampleCoveragexOES_t) (GLclampx, GLboolean); +typedef void (* glScalexOES_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glTexEnvxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexEnvxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTexParameterxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexParameterxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTranslatexOES_t) (GLfixed, GLfixed, GLfixed); +typedef GLboolean (* glIsRenderbufferOES_t) (GLuint); +typedef void (* glBindRenderbufferOES_t) (GLenum, GLuint); +typedef void (* glDeleteRenderbuffersOES_t) (GLsizei, const GLuint*); +typedef void (* glGenRenderbuffersOES_t) (GLsizei, GLuint*); +typedef void (* glRenderbufferStorageOES_t) (GLenum, GLenum, GLsizei, GLsizei); +typedef void (* glGetRenderbufferParameterivOES_t) (GLenum, GLenum, GLint*); +typedef GLboolean (* glIsFramebufferOES_t) (GLuint); +typedef void (* glBindFramebufferOES_t) (GLenum, GLuint); +typedef void (* glDeleteFramebuffersOES_t) (GLsizei, const GLuint*); +typedef void (* glGenFramebuffersOES_t) (GLsizei, GLuint*); +typedef GLenum (* glCheckFramebufferStatusOES_t) (GLenum); +typedef void (* glFramebufferRenderbufferOES_t) (GLenum, GLenum, GLenum, GLuint); +typedef void (* glFramebufferTexture2DOES_t) (GLenum, GLenum, GLenum, GLuint, GLint); +typedef void (* glGetFramebufferAttachmentParameterivOES_t) (GLenum, GLenum, GLenum, GLint*); +typedef void (* glGenerateMipmapOES_t) (GLenum); +typedef void* (* glMapBufferOES_t) (GLenum, GLenum); +typedef GLboolean (* glUnmapBufferOES_t) (GLenum); +typedef void (* glGetBufferPointervOES_t) (GLenum, GLenum, GLvoid*); +typedef void (* glCurrentPaletteMatrixOES_t) (GLuint); +typedef void (* glLoadPaletteFromModelViewMatrixOES_t) (); +typedef void (* glMatrixIndexPointerOES_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glWeightPointerOES_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef GLbitfield (* glQueryMatrixxOES_t) (GLfixed*, GLint*); +typedef void (* glDepthRangefOES_t) (GLclampf, GLclampf); +typedef void (* glFrustumfOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glOrthofOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glClipPlanefOES_t) (GLenum, const GLfloat*); +typedef void (* glGetClipPlanefOES_t) (GLenum, GLfloat*); +typedef void (* glClearDepthfOES_t) (GLclampf); +typedef void (* glTexGenfOES_t) (GLenum, GLenum, GLfloat); +typedef void (* glTexGenfvOES_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glTexGeniOES_t) (GLenum, GLenum, GLint); +typedef void (* glTexGenivOES_t) (GLenum, GLenum, const GLint*); +typedef void (* glTexGenxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexGenxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glGetTexGenfvOES_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetTexGenivOES_t) (GLenum, GLenum, GLint*); +typedef void (* glGetTexGenxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glBindVertexArrayOES_t) (GLuint); +typedef void (* glDeleteVertexArraysOES_t) (GLsizei, const GLuint*); +typedef void (* glGenVertexArraysOES_t) (GLsizei, GLuint*); +typedef GLboolean (* glIsVertexArrayOES_t) (GLuint); +typedef void (* glDiscardFramebufferEXT_t) (GLenum, GLsizei, const GLenum*); +typedef void (* glMultiDrawArraysEXT_t) (GLenum, GLint*, GLsizei*, GLsizei); +typedef void (* glMultiDrawElementsEXT_t) (GLenum, const GLsizei*, GLenum, const GLvoid**, GLsizei); +typedef void (* glClipPlanefIMG_t) (GLenum, const GLfloat*); +typedef void (* glClipPlanexIMG_t) (GLenum, const GLfixed*); +typedef void (* glRenderbufferStorageMultisampleIMG_t) (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +typedef void (* glFramebufferTexture2DMultisampleIMG_t) (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +typedef void (* glDeleteFencesNV_t) (GLsizei, const GLuint*); +typedef void (* glGenFencesNV_t) (GLsizei, GLuint*); +typedef GLboolean (* glIsFenceNV_t) (GLuint); +typedef GLboolean (* glTestFenceNV_t) (GLuint); +typedef void (* glGetFenceivNV_t) (GLuint, GLenum, GLint*); +typedef void (* glFinishFenceNV_t) (GLuint); +typedef void (* glSetFenceNV_t) (GLuint, GLenum); +typedef void (* glGetDriverControlsQCOM_t) (GLint*, GLsizei, GLuint*); +typedef void (* glGetDriverControlStringQCOM_t) (GLuint, GLsizei, GLsizei*, GLchar*); +typedef void (* glEnableDriverControlQCOM_t) (GLuint); +typedef void (* glDisableDriverControlQCOM_t) (GLuint); +typedef void (* glExtGetTexturesQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetBuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetRenderbuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetFramebuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetTexLevelParameterivQCOM_t) (GLuint, GLenum, GLint, GLenum, GLint*); +typedef void (* glExtTexObjectStateOverrideiQCOM_t) (GLenum, GLenum, GLint); +typedef void (* glExtGetTexSubImageQCOM_t) (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, GLvoid*); +typedef void (* glExtGetBufferPointervQCOM_t) (GLenum, GLvoid**); +typedef void (* glExtGetShadersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetProgramsQCOM_t) (GLuint*, GLint, GLint*); +typedef GLboolean (* glExtIsProgramBinaryQCOM_t) (GLuint); +typedef void (* glExtGetProgramBinarySourceQCOM_t) (GLuint, GLenum, GLchar*, GLint*); +typedef void (* glStartTilingQCOM_t) (GLuint, GLuint, GLuint, GLuint, GLbitfield); +typedef void (* glEndTilingQCOM_t) (GLbitfield); + + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/glesv1_emul_ifc.cpp b/emulator/opengl/tests/gles_android_wrapper/glesv1_emul_ifc.cpp new file mode 100644 index 0000000..26c98a8 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/glesv1_emul_ifc.cpp @@ -0,0 +1,39 @@ +/* +* Copyright 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 <stdlib.h> +#include "ApiInitializer.h" +#include <dlfcn.h> +#include "gl_wrapper_context.h" + +extern "C" { + gl_wrapper_context_t *createFromLib(void *solib, gl_wrapper_context_t *(*accessor)()); +} + +gl_wrapper_context_t * createFromLib(void *solib, gl_wrapper_context_t *(accessor)()) +{ + gl_wrapper_context_t *ctx = new gl_wrapper_context_t; + if (ctx == NULL) { + return NULL; + } + ApiInitializer *initializer = new ApiInitializer(solib); + ctx->initDispatchByName(ApiInitializer::s_getProc, initializer); + gl_wrapper_context_t::setContextAccessor(accessor); + delete initializer; + return ctx; +} + + diff --git a/emulator/opengl/tests/gles_android_wrapper/glesv2_emul_ifc.cpp b/emulator/opengl/tests/gles_android_wrapper/glesv2_emul_ifc.cpp new file mode 100644 index 0000000..4ae13dd --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/glesv2_emul_ifc.cpp @@ -0,0 +1,40 @@ +/* +* Copyright 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 <stdlib.h> +#include "ApiInitializer.h" +#include <dlfcn.h> +#include "gl2_wrapper_context.h" + +extern "C" { + gl2_wrapper_context_t *createFromLib(void *solib, gl2_wrapper_context_t *(*accessor)()); +} + +gl2_wrapper_context_t * createFromLib(void *solib, gl2_wrapper_context_t *(*accessor)()) +{ + gl2_wrapper_context_t *ctx = new gl2_wrapper_context_t; + if (ctx == NULL) { + return NULL; + } + ApiInitializer *initializer = new ApiInitializer(solib); + ctx->initDispatchByName(ApiInitializer::s_getProc, initializer); + gl2_wrapper_context_t::setContextAccessor(accessor); + delete initializer; + return ctx; +} + + + diff --git a/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk b/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk new file mode 100644 index 0000000..77cd272 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk @@ -0,0 +1,32 @@ +LOCAL_PATH:= $(call my-dir) + +$(call emugl-begin-host-executable,triangleCM) +$(call emugl-import,libEGL_translator libGLES_CM_translator) + +PREBUILT := $(HOST_PREBUILT_TAG) +LOCAL_SDL_CONFIG ?= prebuilts/tools/$(PREBUILT)/sdl/bin/sdl-config +LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags) +LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs)) + +ifeq ($(HOST_OS),darwin) + DARWIN_VERSION := $(strip $(shell sw_vers -productVersion)) + ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),) + # Lion needs to be forced to link dylib to avoid problems + # with the dynamic function lookups in SDL 1.2 + LOCAL_SDL_LDLIBS += /usr/lib/dylib1.o + endif +endif + +LOCAL_SRC_FILES:= \ + triangleCM.cpp + +LOCAL_CFLAGS += $(LOCAL_SDL_CFLAGS) -g -O0 +LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS) + +LOCAL_STATIC_LIBRARIES += libSDL libSDLmain + +ifeq ($(HOST_OS),darwin) +$(call emugl-import,libMac_view) +endif + +$(call emugl-end-module) diff --git a/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp b/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp new file mode 100644 index 0000000..7547cd0 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp @@ -0,0 +1,463 @@ +/* +* Copyright 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +//#define GL_API +//#define GL_APIENTRY + +#undef ANDROID +#include <EGL/egl.h> +#include <GLES/gl.h> + +#ifdef __APPLE__ +extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height); +#endif + +#undef HAVE_MALLOC_H +#include <SDL.h> +#include <SDL_syswm.h> + + +#define WINDOW_WIDTH 500 +#define WINDOW_HEIGHT 500 + +#define TEX_WIDTH 256 +#define TEX_HEIGHT 256 + + +#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ + (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ + ((GLfixed) ((d) * 65536))) +#define X_to_F(x) ((float)(x))/65536.0f + +static EGLint const attribute_list[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE +}; + +unsigned char *genTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + if (j>(width/2)) col/=2; + for (int c = 0; c < comp; c++) { + *ptr = col; ptr++; + } + } + } + return img; +} + +unsigned char *genRedTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + memset(img,0,width*height*comp); + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + *ptr = col; + ptr+=comp; + } + } + return img; +} + +//mip 0; +unsigned char *genPalette4_rgb8(int width, int height,int color) +{ + int size = width*height/2 + 16*3/*palette size*/; + unsigned char *img = new unsigned char[size]; + + memset(img,0,size); + img[0] = 255; img[1] = 0; img[2] = 0; // red + img[3] = 0; img[4] = 0; img[5] = 255; //blue + img[7] = 128; img[8] = 0; img[9] = 128; //fucsia + //rest of the palette is empty + + unsigned char *ptr = img+(16*3); + for (int i = 0; i < (height*width/2); i++) { + ptr[i] = (i%2)?0x0|color:0x11|color; + } + return img; +} + +void usage(const char *progname) +{ + fprintf(stderr, "usage: %s [-n <nframes> -i -h]\n", progname); + fprintf(stderr, "\t-h: this message\n"); + fprintf(stderr, "\t-i: immidate mode\n"); + fprintf(stderr, "\t-n nframes: generate nframes\n"); + fprintf(stderr, "\t-e: use index arrays\n"); + fprintf(stderr, "\t-t: use texture\n"); + fprintf(stderr, "\t-f: use fixed points\n"); + fprintf(stderr, "\t-p: use point size OES extention\n"); +} + +#define SWITCH_SOURCE(add)\ + if(useConvertedType){ \ + if(useFixed){ \ + data = (GLvoid*)(fixedVertices+(add)); \ + } else { \ + data = (GLvoid*)(byteVertices +(add)); \ + } \ + } else { \ + data = (GLvoid*)(afVertices+(add)); \ + } \ + +#ifdef _WIN32 +int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +#else +int main(int argc, char **argv) +#endif +{ + GLuint ui32Vbo = 0; // Vertex buffer object handle + GLuint ui32IndexVbo; + GLuint ui32Texture; + + int nframes = 100; + bool immidateMode = false; + bool useIndices = true; + bool useTexture = false; + bool useCompTexture = false; + bool useConvertedType = true; + bool useFixed = false; + bool usePoints = false; + bool useCopy = false; + bool useSubCopy = false; + + int c; + extern char *optarg; + + #ifdef _WIN32 + HWND windowId = NULL; + #elif __linux__ + Window windowId = NULL; + #elif __APPLE__ + void* windowId = NULL; + #endif + + // // Inialize SDL window + // + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { + fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE); + if (surface == NULL) { + fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); + return -1; + } + + SDL_SysWMinfo wminfo; + memset(&wminfo, 0, sizeof(wminfo)); + SDL_GetWMInfo(&wminfo); + #ifdef _WIN32 + windowId = wminfo.window; + #elif __linux__ + windowId = wminfo.info.x11.window; + #elif __APPLE__ + windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT); + + #endif + + int major,minor,num_config; + EGLConfig configs[150]; + EGLSurface egl_surface; + EGLContext ctx; + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(d,&major,&minor); + printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor); + eglChooseConfig(d, attribute_list, configs, 150, &num_config); + printf("config returned %d\n",num_config); + egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL); + printf("before creating context..\n"); + ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,NULL); + printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx); + if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){ + printf("make current failed\n"); + return false; + } + printf("after make current\n"); + + GLenum err = glGetError(); + if(err != GL_NO_ERROR) { + printf("error before drawing ->>> %d \n",err); + } else { + printf("no error before drawing\n"); + } + + if (useTexture) { + + glEnable(GL_TEXTURE_2D); + ui32Texture = 1; + glBindTexture(GL_TEXTURE_2D, ui32Texture); + GLenum err = glGetError(); + + unsigned char *pixels = NULL; + if(useCompTexture) { + pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,3); + glCompressedTexImage2D(GL_TEXTURE_2D,0,GL_PALETTE4_RGB8_OES,TEX_WIDTH,TEX_HEIGHT,0,3*16+TEX_WIDTH*TEX_HEIGHT/2,pixels); + + } else { + pixels = genTexture(TEX_WIDTH, TEX_HEIGHT, 4); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + } + + delete pixels; + + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error %d after image \n",err); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error after min filter \n"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error after mag filter \n"); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error after env mode \n"); + + if(useCompTexture) { + pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,1); + glCompressedTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_PALETTE4_RGB8_OES,3*16+(TEX_WIDTH*TEX_HEIGHT/128),pixels); + } else { + pixels = genRedTexture(TEX_WIDTH/8, TEX_HEIGHT/8, 4); + glTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_RGBA,GL_UNSIGNED_BYTE,pixels); + } + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error %d after subimage \n",err); + delete pixels; + + } + + glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // clear blue + + float afVertices[] = { -0.4f,-0.4f,0.0f, // Position + 1.0f,0.0f,0.0f,1.0f, // Color + 0.0f, 0.0f, // texture + 12.f, //point size + + 0.4f,-0.4f,0.0f, + 0.0f,1.0f,0.0f,1.0f, + 1.0f, 0.0f, + 47.0f, + + 0.0f,0.4f,0.0f, + 0.0f,0.0f,1.0f,1.0f, + 0.5f, 1.0f, + 14.0f + }; + +#define MAX_T 1 +#define MID_T 0 +#define MIN_T 0 + + GLbyte byteVertices[] = { -1,-1,0, // Position + 255,0,0,255, // Color + MIN_T, MIN_T, // texture + 12, //point size + + 1,-1,0, + 0,255,0,255, + MAX_T,MIN_T, + 47, + + 0,1,0, + 0,0,255,255, + MID_T, MAX_T, + 14 + }; + + GLfixed fixedVertices[] = { F_to_X(-0.4f),F_to_X(-0.4f),F_to_X(0.0f), // Position + F_to_X(1.0f),F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f), // Color + F_to_X(0.0f),F_to_X(0.0f), // texture + F_to_X(12.0f),//points size + + F_to_X(0.4f),F_to_X(-0.4f),F_to_X(0.0f), + F_to_X(0.0f),F_to_X(1.0f),F_to_X(0.0f),F_to_X(1.0f), + F_to_X(1.0f),F_to_X( 0.0f), + F_to_X(30.0f), + + F_to_X(0.0f),F_to_X(0.4f),F_to_X(0.0f), + F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f),F_to_X(1.0f), + F_to_X(0.5f), F_to_X(1.0f), + F_to_X(30.0) + }; + + unsigned short indices[] = { 2, 1, 0 }; + + if (!immidateMode) { + glGenBuffers(1, &ui32Vbo); + ui32Vbo = 1; + printf("ui32Vbo = %d\n", ui32Vbo); + + glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo); + void* data = (void*)afVertices; + unsigned int uiSize = 3*(sizeof(float)*10); + if(useConvertedType){ + if(useFixed){ + data = (void*)fixedVertices; + } else { + data = (void*)byteVertices; + uiSize = 3*(sizeof(GLbyte)*10); + } + } + glBufferData(GL_ARRAY_BUFFER, uiSize,data, GL_STATIC_DRAW); + + ui32IndexVbo = 2; + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + } + + // Draws a triangle for 800 frames + float angle = 0.0; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + GLvoid* arr = NULL; + GLenum type; + GLenum drawType; + GLenum colorType; + int size_of; + + if(useConvertedType){ + if(useFixed) + { + arr = fixedVertices; + colorType = type = GL_FIXED; + size_of = sizeof(GLfixed); + } else { + arr = byteVertices; + colorType = GL_UNSIGNED_BYTE; + type = GL_BYTE; + size_of = sizeof(GLbyte); + } + }else { + arr = afVertices; + colorType = type = GL_FLOAT; + size_of = sizeof(float); + } + + if(usePoints) + { + drawType = GL_POINTS; + } + else + drawType = GL_TRIANGLES; + + GLvoid* data = NULL; + for (int i = 0; i < 100; i++) { + + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(angle, 0.0, 0.0, 1.0); + angle += 360.0 / nframes; + // Enable vertex arrays + glEnableClientState(GL_VERTEX_ARRAY); + if (immidateMode) { + glVertexPointer(3,type, size_of * 10, arr); + } else { + glVertexPointer(3,type, size_of * 10, 0); + } + + // Set color data in the same way + glEnableClientState(GL_COLOR_ARRAY); + if (immidateMode) { + SWITCH_SOURCE(3) + glColorPointer(4, colorType, size_of * 10, data); + } else { + glColorPointer(4,colorType,size_of * 10, (GLvoid*) (size_of * 3) ); + } + if (useTexture) { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (immidateMode) { + SWITCH_SOURCE(7) + glTexCoordPointer(2, type, size_of * 10,data); + } else { + glTexCoordPointer(2, type, size_of * 10, (GLvoid*)(size_of * 7)); + } + } + if(usePoints) + { + glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + if (immidateMode) { + SWITCH_SOURCE(9) + glPointSizePointerOES(type,size_of * 10,data); + } else { + glPointSizePointerOES(type,size_of * 10,(GLvoid*)(size_of * 9)); + } + } + + if (useIndices) { + if (immidateMode) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, indices); + } else { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); + glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, 0); + } + } else { + glDrawArrays(drawType, 0, 3); + } + + GLenum err = glGetError(); + if(err != GL_NO_ERROR) + printf(" error %d has occured while drawing\n",err); + + + glPopMatrix(); + eglSwapBuffers(d,egl_surface); + + if(useTexture && useCopy) + glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,256,256,0); + else if(useTexture && useSubCopy) + glCopyTexSubImage2D(GL_TEXTURE_2D,0,100,100,WINDOW_WIDTH/2,WINDOW_HEIGHT/2,50,50); + } + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error ->>> %d \n",err); + eglDestroySurface(d,egl_surface); + eglDestroyContext(d,ctx); + +// Just wait until the window is closed + SDL_Event ev; + while( SDL_WaitEvent(&ev) ) { + if (ev.type == SDL_QUIT) { + break; + } + } + return 0; +} + + diff --git a/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk b/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk new file mode 100644 index 0000000..53f774c --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:= $(call my-dir) + +$(call emugl-begin-host-executable,triangleV2) +$(call emugl-import,libEGL_translator libGLES_V2_translator) + +PREBUILT := $(HOST_PREBUILT_TAG) +LOCAL_SDL_CONFIG ?= prebuilts/tools/$(PREBUILT)/sdl/bin/sdl-config +LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags) +LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs)) + +LOCAL_SRC_FILES:= \ + triangleV2.cpp + +LOCAL_CFLAGS += $(LOCAL_SDL_CFLAGS) -g -O0 +LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS) + +LOCAL_STATIC_LIBRARIES += libSDL libSDLmain + +ifeq ($(HOST_OS),darwin) +DARWIN_VERSION := $(strip $(shell sw_vers -productVersion)) +ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),) + # Lion needs to be forced to link dylib to avoid problems + # with the dynamic function lookups in SDL 1.2 + LOCAL_LDLIBS += /usr/lib/dylib1.o +endif +$(call emugl-import,libMac_view) +endif + +$(call emugl-end-module) + diff --git a/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp b/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp new file mode 100644 index 0000000..59535c5 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp @@ -0,0 +1,457 @@ +/* +* Copyright 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +//#define GL_API +//#define GL_APIENTRY + +#undef ANDROID +#include <EGL/egl.h> +#include <GLES2/gl2.h> + +#ifdef __APPLE__ +extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height); +#endif + +#undef HAVE_MALLOC_H +#include <SDL.h> +#include <SDL_syswm.h> + + +#define WINDOW_WIDTH 500 +#define WINDOW_HEIGHT 500 + +#define TEX_WIDTH 256 +#define TEX_HEIGHT 256 + + +#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ + (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ + ((GLfixed) ((d) * 65536))) +#define X_to_F(x) ((float)(x))/65536.0f + +//#define __FIXED__ + +const char *def_vShaderStr = + "attribute vec4 vPosition; \n" + "void main() \n" + "{ \n" + " gl_Position = vPosition; \n" + "} \n"; + +const char *def_fShaderStr = + "precision mediump float; \n" + "void main() \n" + "{ \n" +#ifndef __FIXED__ + " gl_FragColor = vec4(0.2, 0.5, 0.1, 1.0); \n" +#else + " gl_FragColor = vec4(0.4, 0.3, 0.7, 1.0); \n" +#endif + "} \n"; + +static EGLint const attribute_list[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE +}; + +unsigned char *genTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + for (int c = 0; c < comp; c++) { + *ptr = col; ptr++; + } + } + } + return img; +} + +unsigned char *genRedTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + memset(img,0,width*height*comp); + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + *ptr = col; + ptr+=comp; + } + } + return img; +} + + +void printUsage(const char *progname) +{ + fprintf(stderr, "usage: %s [options]\n", progname); + fprintf(stderr, "\t-vs <filename> - vertex shader to use\n"); + fprintf(stderr, "\t-fs <filename> - fragment shader to use\n"); +} + + + +GLuint LoadShader(GLenum type,const char *shaderSrc) +{ + GLuint shader; + GLint compiled; + // Create the shader object + shader = glCreateShader(type); + if(shader == 0) + return 0; + // Load the shader source + glShaderSource(shader, 1, &shaderSrc, NULL); + // Compile the shader + glCompileShader(shader); + // Check the compile status + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + if(!compiled) + { + GLint infoLen = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); + if(infoLen > 1) + { + char* infoLog = (char*)malloc(sizeof(char) * infoLen); + glGetShaderInfoLog(shader, infoLen, NULL, infoLog); + printf("Error compiling shader:\n%s\n", infoLog); + free(infoLog); + } + glDeleteShader(shader); + return 0; + } + return shader; +} + +const char *readShader(const char *fileName) +{ + FILE *fp = fopen(fileName, "rb"); + if (!fp) return NULL; + + int bSize = 1024; + int nBufs = 1; + char *buf = (char *)malloc(bSize); + int n; + int len = 0; + n = fread(&buf[0], 1, bSize, fp); + while( n == bSize ) { + len += n; + nBufs++; + buf = (char *)realloc(buf, bSize * nBufs); + n = fread(&buf[len], 1, bSize, fp); + } + len += n; + + buf[len] = '\0'; + return (const char *)buf; +} + +void dumpUniforms(GLuint program) +{ + GLint numU; + glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numU); + printf("==== Program %d has %d active uniforms ===\n", program, numU); + char name[512]; + GLsizei len; + GLint size; + GLenum type; + for (int i=0; i<numU; i++) { + glGetActiveUniform(program, i, + 512, &len, &size, &type, name); + printf("\t%s : type=0x%x size=%d\n", name, type, size); + } +} + +/// +// Initialize the shader and program object +// +int Init(const char *vShaderStr, const char *fShaderStr) +{ + GLuint vertexShader; + GLuint fragmentShader; + GLuint programObject; + GLint linked; + // Load the vertex/fragment shaders + vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr); + fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr); + // Create the program object + programObject = glCreateProgram(); + if(programObject == 0) + return -1; + glAttachShader(programObject, vertexShader); + glAttachShader(programObject, fragmentShader); + // Bind vPosition to attribute 0 + glBindAttribLocation(programObject, 0, "vPosition"); + // Link the program + glLinkProgram(programObject); + // Check the link status + glGetProgramiv(programObject, GL_LINK_STATUS, &linked); + if(!linked) + { + GLint infoLen = 0; + glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen); + if(infoLen > 1) + { + char* infoLog = (char*)malloc(sizeof(char) * infoLen); + glGetProgramInfoLog(programObject, infoLen, NULL, infoLog); + printf("Error linking program:\n%s\n", infoLog); + free(infoLog); + } + glDeleteProgram(programObject); + return -1; + } + + // dump active uniforms + dumpUniforms(programObject); + + // Store the program object +#ifndef __FIXED__ + glClearColor(0.0f, 0.0f, 1.0f, 1.0f); +#else + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); +#endif + return programObject; +} + + +/// +// Draw a triangle using the shader pair created in Init() +// +void Draw(EGLDisplay display,EGLSurface surface,int width,int height,GLuint program) +{ +#ifndef __FIXED__ + GLfloat vVertices[] = {0.0f, 0.5f, 0.0f, + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f}; +#else + + GLfixed vVertices[] = {F_to_X(0.0f), F_to_X(0.5f),F_to_X(0.0f), + F_to_X(-0.5f),F_to_X(-0.5f), F_to_X(0.0f), + F_to_X(0.5f),F_to_X(-0.5f),F_to_X(0.0f)}; +#endif + + // Set the viewport + glViewport(0, 0,width,height); + // Clear the color buffer + glClear(GL_COLOR_BUFFER_BIT); + // Use the program object + glUseProgram(program); + // Load the vertex data +#ifndef __FIXED__ + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices); +#else + glVertexAttribPointer(0, 3, GL_FIXED, GL_FALSE, 0, vVertices); +#endif + glEnableVertexAttribArray(0); + glDrawArrays(GL_TRIANGLES, 0, 3); + eglSwapBuffers(display,surface); +} + +#ifdef _WIN32 +char **parseCmdLine(char *cmdLine, int *argc) +{ + int argvSize = 10; + char **argv = (char **)malloc(argvSize * sizeof(char *)); + *argc = 0; + int i=0; + bool prevIsSpace = true; + int argStart = 0; + + argv[(*argc)++] = strdup("playdump"); + + while(cmdLine[i] != '\0') { + bool isSpace = (cmdLine[i] == ' ' || cmdLine[i] == '\t'); + if ( !isSpace && prevIsSpace ) { + argStart = i; + } + else if (isSpace && !prevIsSpace) { + cmdLine[i] = '\0'; + if (*argc >= argvSize) { + argvSize *= 2; + argv = (char **)realloc(argv, argvSize * sizeof(char *)); + } + argv[(*argc)++] = &cmdLine[argStart]; + argStart = i+1; + } + + prevIsSpace = isSpace; + i++; + } + + if (i > argStart) { + argv[(*argc)++] = &cmdLine[argStart]; + } + return argv; +} +#endif + +#ifdef _WIN32 +int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +#else +int main(int argc, char **argv) +#endif +{ + GLuint ui32Vbo = 0; // Vertex buffer object handle + GLuint ui32IndexVbo; + GLuint ui32Texture; + + int nframes = 100; + bool immidateMode = false; + bool useIndices = false; + bool useTexture = true; + bool useCompTexture = false; + bool useFixed = true; + bool usePoints = false; + bool useCopy = false; + bool useSubCopy = false; + +#ifdef _WIN32 + int argc; + char **argv = parseCmdLine(lpCmdLine, &argc); +#endif + const char *vShader = def_vShaderStr; + const char *fShader = def_fShaderStr; + + for (int i=1; i<argc; i++) { + if (!strcmp(argv[i],"-vs")) { + if (++i >= argc) { + printUsage(argv[0]); + return -1; + } + vShader = readShader(argv[i]); + if (!vShader) { + vShader = def_vShaderStr; + printf("Failed to load vshader %s, using defualt\n", argv[i]); + } + else { + printf("Using vshader %s\n", argv[i]); + } + } + else if (!strcmp(argv[i],"-fs")) { + if (++i >= argc) { + printUsage(argv[0]); + return -1; + } + fShader = readShader(argv[i]); + if (!fShader) { + fShader = def_fShaderStr; + printf("Failed to load fshader %s, using defualt\n", argv[i]); + } + else { + printf("Using fshader %s\n", argv[i]); + } + } + else { + printUsage(argv[0]); + return -1; + } + } + + #ifdef _WIN32 + HWND windowId = NULL; + #elif __linux__ + Window windowId = NULL; + #elif __APPLE__ + void* windowId = NULL; + #endif + + // // Inialize SDL window + // + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { + fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE); + if (surface == NULL) { + fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); + return -1; + } + + SDL_SysWMinfo wminfo; + memset(&wminfo, 0, sizeof(wminfo)); + SDL_GetWMInfo(&wminfo); + #ifdef _WIN32 + windowId = wminfo.window; + #elif __linux__ + windowId = wminfo.info.x11.window; + #elif __APPLE__ + windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT); + #endif + + int major,minor,num_config; + int attrib_list[] ={ + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLConfig configs[150]; + EGLSurface egl_surface; + EGLContext ctx; + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(d,&major,&minor); + printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor); + eglChooseConfig(d, attribute_list, configs, 150, &num_config); + printf("config returned %d\n",num_config); + egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL); + ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,attrib_list); + printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx); + if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){ + printf("make current failed\n"); + return false; + } + printf("after make current\n"); + + GLenum err = glGetError(); + if(err != GL_NO_ERROR) { + printf("error before drawing ->>> %d \n",err); + } else { + printf("no error before drawing\n"); + } + + int program = Init(vShader, fShader); + if(program < 0){ + printf("failed init shaders\n"); + return false; + } + + Draw(d,egl_surface,WINDOW_WIDTH,WINDOW_HEIGHT,program); + + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error ->>> %d \n",err); + eglDestroySurface(d,egl_surface); + eglDestroyContext(d,ctx); + +// Just wait until the window is closed + SDL_Event ev; + while( SDL_WaitEvent(&ev) ) { + if (ev.type == SDL_QUIT) { + break; + } + } + return 0; +} + + diff --git a/emulator/opengl/tests/translator_tests/MacCommon/Android.mk b/emulator/opengl/tests/translator_tests/MacCommon/Android.mk new file mode 100644 index 0000000..4c4ae6b --- /dev/null +++ b/emulator/opengl/tests/translator_tests/MacCommon/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH := $(call my-dir) + +ifeq ($(HOST_OS),darwin) +$(call emugl-begin-host-static-library,libMac_view) + +LIBMACVIEW_FRAMEWORKS := AppKit AudioToolbox AudioUnit +LIBMACVIEW_PREFIX := -Wl,-framework, + +$(call emugl-export,LDLIBS,$(foreach _framework,$(LIBMACVIEW_FRAMEWORKS),$(LIBMACVIEW_PREFIX)$(_framework))) +LOCAL_SRC_FILES := setup_gl.m +LOCAL_CFLAGS += -g -O0 +$(call emugl-end-module) +endif # HOST_OS == darwin diff --git a/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m b/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m new file mode 100644 index 0000000..a300943 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m @@ -0,0 +1,35 @@ +/* +* Copyright 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 <stdio.h> +#include <Cocoa/Cocoa.h> + + void * createGLView(void *nsWindowPtr, int x, int y, int width, int height) +{ + NSRect contentRect = NSMakeRect(x, y, width, height); + NSView *glView = [[NSView alloc] initWithFrame:contentRect]; + if (glView == nil) { + printf("couldn't create opengl view\n"); + return nil; + } + [glView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + NSWindow *win = (NSWindow *)nsWindowPtr; + [[win contentView] addSubview:glView]; + [win makeKeyAndOrderFront:nil]; + return (void *)glView; +} + + diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk b/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk new file mode 100644 index 0000000..a5a01e8 --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-host-shared-library,libut_rendercontrol_dec) +$(call emugl-import, libOpenglCodecCommon) +$(call emugl-gen-decoder,$(EMUGL_PATH)/tests/ut_rendercontrol_enc,ut_rendercontrol) +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/tests/ut_rendercontrol_enc) +$(call emugl-end-module) diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk b/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk new file mode 100644 index 0000000..ae234b2 --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk @@ -0,0 +1,8 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-shared-library,libut_rendercontrol_enc) +$(call emugl-import,libOpenglCodecCommon) +$(call emugl-gen-encoder,$(LOCAL_PATH),ut_rendercontrol) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-end-module) + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.attrib b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.attrib new file mode 100644 index 0000000..c47a9f9 --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.attrib @@ -0,0 +1,4 @@ +GLOBAL + base_opcode 10000 + encoder_headers <stdint.h> + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.in b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.in new file mode 100644 index 0000000..0d5942f --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.in @@ -0,0 +1,11 @@ +GL_ENTRY(int, createContext, uint32_t pid, uint32_t handle, uint32_t shareCtx, int version) +GL_ENTRY(int, createSurface, uint32_t pid, uint32_t handle) +GL_ENTRY(int, makeCurrentContext, uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctxHandle) +GL_ENTRY(void, swapBuffers, uint32_t pid, uint32_t surface) +GL_ENTRY(int, destroyContext, uint32_t pid, uint32_t handle) +GL_ENTRY(int, destroySurface, uint32_t pid, uint32_t handle) + + + + + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.types b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.types new file mode 100644 index 0000000..9d945ab --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.types @@ -0,0 +1,2 @@ +uint32_t 32 0x%08x false + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol_types.h b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol_types.h new file mode 100644 index 0000000..9b7864d --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol_types.h @@ -0,0 +1,17 @@ +/* +* 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 <stdint.h> diff --git a/emulator/opengl/tests/ut_renderer/Android.mk b/emulator/opengl/tests/ut_renderer/Android.mk new file mode 100644 index 0000000..fe8e7ac --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:=$(call my-dir) + +ifeq ($(HOST_OS), linux) + +$(call emugl-begin-host-executable,ut_renderer) +$(call emugl-import,libut_rendercontrol_dec libGLESv1_dec libGLESv2_dec libEGL_host_wrapper) + +LOCAL_SRC_FILES := ut_renderer.cpp \ + RenderingThread.cpp \ + ReadBuffer.cpp \ + Renderer.cpp \ + RendererContext.cpp \ + RendererSurface.cpp \ + X11Windowing.cpp + +# define PVR_WAR to support imgtec PVR opengl-ES implementation +# +# specifically this MACRO enables code that work arounds a bug +# in the implementation where glTextureParameter(...,GL_TEXTURE_RECT,...) +# is called would cause a crash if the texture dimensions have not been +# defined yet. + +LOCAL_CFLAGS += -DPVR_WAR +#LOCAL_CFLAGS += -g -O0 + +LOCAL_LDLIBS += -lpthread -lX11 -lrt + +$(call emugl-end-module) + +endif # HOST_OS == linux diff --git a/emulator/opengl/tests/ut_renderer/NativeWindowing.h b/emulator/opengl/tests/ut_renderer/NativeWindowing.h new file mode 100644 index 0000000..9468066 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/NativeWindowing.h @@ -0,0 +1,28 @@ +/* +* 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. +*/ +#ifndef _NATIVE_WINDOWING_H +#define _NATIVE_WINDOWING_H + +#include <EGL/egl.h> + +class NativeWindowing { +public: + virtual NativeDisplayType getNativeDisplay() = 0; + virtual NativeWindowType createNativeWindow(NativeDisplayType dpy, int width, int height) = 0; + virtual int destroyNativeWindow(NativeDisplayType dpy, NativeWindowType win) = 0; +}; + +#endif diff --git a/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp b/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp new file mode 100644 index 0000000..e0073c0 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp @@ -0,0 +1,53 @@ +/* +* 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 "ReadBuffer.h" +#include <string.h> +#include <assert.h> + +ReadBuffer::ReadBuffer(SocketStream *stream, size_t bufsize) +{ + m_size = bufsize; + m_stream = stream; + m_buf = new unsigned char[m_size]; + m_validData = 0; + m_readPtr = m_buf; +} + +ReadBuffer::~ReadBuffer() +{ + delete m_buf; +} + +int ReadBuffer::getData() +{ + if (m_validData > 0) { + memcpy(m_buf, m_readPtr, m_validData); + } + m_readPtr = m_buf; + // get fresh data into the buffer; + int stat = m_stream->recv(m_buf + m_validData, m_size - m_validData); + if (stat > 0) { + m_validData += (size_t) stat; + } + return stat; +} + +void ReadBuffer::consume(size_t amount) +{ + assert(amount <= m_validData); + m_validData -= amount; + m_readPtr += amount; +} diff --git a/emulator/opengl/tests/ut_renderer/ReadBuffer.h b/emulator/opengl/tests/ut_renderer/ReadBuffer.h new file mode 100644 index 0000000..b039b19 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/ReadBuffer.h @@ -0,0 +1,36 @@ +/* +* 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. +*/ +#ifndef _READ_BUFFER_H +#define _READ_BUFFER_H + +#include "SocketStream.h" + +class ReadBuffer { +public: + ReadBuffer(SocketStream *stream, size_t bufSize); + ~ReadBuffer(); + int getData(); // get fresh data from the stream + unsigned char *buf() { return m_readPtr; } // return the next read location + size_t validData() { return m_validData; } // return the amount of valid data in readptr + void consume(size_t amount); // notify that 'amount' data has been consumed; +private: + unsigned char *m_buf; + unsigned char *m_readPtr; + size_t m_size; + size_t m_validData; + SocketStream *m_stream; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/Renderer.cpp b/emulator/opengl/tests/ut_renderer/Renderer.cpp new file mode 100644 index 0000000..22afadb --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/Renderer.cpp @@ -0,0 +1,183 @@ +/* +* 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 <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include "RenderingThread.h" +#include "Renderer.h" + +// include operating-system dependent windowing system impelemntation +#ifdef _WIN32 +# error "WINDOWS IS NOT SUPPORTED AT THE MOMENT" +#elif defined __APPLE__ +# error "Apple OS-X IS NOT SUPPORTED" +#elif defined (__unix__) +# include "X11Windowing.h" +#endif + + + + + +Renderer * Renderer::m_instance = NULL; + +Renderer * Renderer::instance() +{ + if (m_instance == NULL) m_instance = new Renderer; + return m_instance; +} + +Renderer::Renderer() +{ + // Unix specific, use your platform specific windowing implementation +#ifdef __unix__ + m_nw = new X11Windowing; +#endif + + m_dpy = eglGetDisplay(m_nw->getNativeDisplay()); + EGLint major, minor; + eglInitialize(m_dpy, &major, &minor); + fprintf(stderr, "egl initialized : %d.%d\n", major, minor); +} + +int Renderer::createSurface(RenderingThread *thread, const ClientHandle & handle) +{ + android::Mutex::Autolock(this->m_mutex); + + assert(m_surfaces.find(handle) == m_surfaces.end()); + if (handle.handle == 0) { + fprintf(stderr, "trying to create surface for EGL_NO_SURFACE !!!\n"); + return -1; + } else { + RendererSurface *surface = RendererSurface::create(m_dpy, RendererSurface::CONFIG_DEPTH, m_nw); + if (surface == NULL) { + printf("failed to create surface !!\n"); + return -1; + } + m_surfaces.insert(SurfaceMap::value_type(handle, surface)); + } + return 0; +} + +int Renderer::destroySurface(RenderingThread *thread, const ClientHandle &handle) +{ + android::Mutex::Autolock(this->m_mutex); + + SurfaceMap::iterator i = m_surfaces.find(handle); + if (i == m_surfaces.end()) { + printf("removing surface that doesn't exists\n"); + return -1; + } + if (i->second->destroy(m_nw)) { + m_surfaces.erase(handle); + } + return 0; +} + +int Renderer::createContext(RenderingThread *thread, const ClientHandle &handle, ClientHandle shareCtx, int version) +{ + android::Mutex::Autolock(this->m_mutex); + + assert(m_ctxs.find(handle) == m_ctxs.end()); + RendererContext *shared = NULL; + if (shareCtx.handle != 0) { + ContextMap::iterator sctx = m_ctxs.find(shareCtx); + if (sctx != m_ctxs.end()) { + shared = sctx->second; + } + } + + RendererContext *ctx = + RendererContext::create(m_dpy, + RendererSurface::getEglConfig(m_dpy, RendererSurface::CONFIG_DEPTH), + shared, version); + if (ctx == NULL) { + fprintf(stderr, "failed to create context\n"); + return -1; + } + m_ctxs.insert(ContextMap::value_type(handle, ctx)); + return 0; +} + +int Renderer::destroyContext(RenderingThread *thread, const ClientHandle &handle) +{ + android::Mutex::Autolock(this->m_mutex); + + ContextMap::iterator i = m_ctxs.find(handle); + if (i == m_ctxs.end()) { + printf("removing context that doesn't exists\n"); + return -1; + } + if (i->second->destroy()) { + m_ctxs.erase(handle); + } + return 0; +} + +int Renderer::makeCurrent(RenderingThread *thread, + const ClientHandle &drawSurface, + const ClientHandle &readSurface, + const ClientHandle & ctx) +{ + android::Mutex::Autolock(this->m_mutex); + + RendererContext *currentContext = thread->currentContext(); + + ContextMap::iterator c = m_ctxs.find(ctx); + EGLContext eglContext; + if (ctx.handle != 0 && c != m_ctxs.end()) { + if (c->second != currentContext) { + // new context is set + if (currentContext != NULL) currentContext->unref(); + c->second->ref(); + eglContext = c->second->eglContext(); + thread->setCurrentContext(c->second); + thread->glDecoder().setContextData(&c->second->decoderContextData()); + thread->gl2Decoder().setContextData(&c->second->decoderContextData()); + } else { + // same context is already set + eglContext = c->second->eglContext(); + } + } else { + eglContext = EGL_NO_CONTEXT; + if (currentContext != NULL) currentContext->unref(); + thread->setCurrentContext(NULL); + thread->glDecoder().setContextData(NULL); + thread->gl2Decoder().setContextData(NULL); + } + + EGLSurface draw = EGL_NO_SURFACE; + EGLSurface read = EGL_NO_SURFACE; + SurfaceMap::iterator i; + i = m_surfaces.find(drawSurface); if (i != m_surfaces.end()) draw = i->second->eglSurface(); + i = m_surfaces.find(readSurface); if (i != m_surfaces.end()) read = i->second->eglSurface(); + + return eglMakeCurrent(m_dpy, draw, read, eglContext); +} + +int Renderer::swapBuffers(RenderingThread *thread, + const ClientHandle &surface) +{ + android::Mutex::Autolock(this->m_mutex); + + SurfaceMap::iterator s = m_surfaces.find(surface); + if (s == m_surfaces.end()) { + fprintf(stderr, "swapping buffers for non existing surface\n"); + return -1; + } + return eglSwapBuffers(m_dpy, s->second->eglSurface()); +} diff --git a/emulator/opengl/tests/ut_renderer/Renderer.h b/emulator/opengl/tests/ut_renderer/Renderer.h new file mode 100644 index 0000000..cdf10b6 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/Renderer.h @@ -0,0 +1,62 @@ +/* +* 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. +*/ +#ifndef _RENDERER_H_ +#define _RENDERER_H_ +#include <map> +#include "RendererSurface.h" +#include "RendererContext.h" +#include "NativeWindowing.h" +#include <utils/threads.h> + +class RenderingThread; + +class Renderer { +public: + + class ClientHandle { + public: + unsigned int pid; + unsigned int handle; + ClientHandle(unsigned int _pid, unsigned int _handle) : pid(_pid), handle(_handle) {} + + bool operator< (const ClientHandle & p) const { + bool val = (pid == p.pid) ? handle < p.handle : pid < p.pid; + return val; + } + }; + + static Renderer *instance(); + int createSurface(RenderingThread *thread, const ClientHandle & handle); + int destroySurface(RenderingThread *thread, const ClientHandle &handle); + int createContext(RenderingThread *thread, const ClientHandle & ctx, const ClientHandle shareCtx, int version); + int destroyContext(RenderingThread *thread,const ClientHandle & ctx); + int makeCurrent(RenderingThread *thread, + const ClientHandle & drawSurface, const ClientHandle & readSurface, const ClientHandle & ctx); + int swapBuffers(RenderingThread *thread, const ClientHandle & surface); + +private: + typedef std::map<ClientHandle, RendererSurface *> SurfaceMap; + typedef std::map<ClientHandle, RendererContext *> ContextMap; + static Renderer *m_instance; + Renderer(); + SurfaceMap m_surfaces; + ContextMap m_ctxs; + NativeWindowing *m_nw; + EGLDisplay m_dpy; + + android::Mutex m_mutex; // single global mutex for the renderer class; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererContext.cpp b/emulator/opengl/tests/ut_renderer/RendererContext.cpp new file mode 100644 index 0000000..0f93acd --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererContext.cpp @@ -0,0 +1,66 @@ +/* +* 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 "RendererContext.h" +#include <stdio.h> +#include <stdlib.h> + +RendererContext * RendererContext::create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version) +{ + EGLContext ctx; + EGLContext shared = shareCtx == NULL ? EGL_NO_CONTEXT : shareCtx->eglContext(); + + EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; + context_attributes[1] = version; + + ctx = eglCreateContext(dpy, config, shared, context_attributes); + if (eglGetError() != EGL_SUCCESS) return NULL; + + return new RendererContext(dpy, ctx, version); +} + +int RendererContext::destroy() +{ + if (count() <= 0) { + eglDestroyContext(m_dpy, m_ctx); + return 1; + } + return 0; +} + +#ifdef PVR_WAR +void RendererContext::setActiveTexture(GLenum texture) +{ + m_activeTexture = texture - GL_TEXTURE0; +} + +void RendererContext::setTex2DBind(GLuint texture) +{ + m_tex2DBind[m_activeTexture] = texture; +} + +GLuint RendererContext::getTex2DBind() +{ + return m_tex2DBind[m_activeTexture]; +} + +void RendererContext::addPendingCropRect(const int *rect) +{ + PendingCropRect *r = new PendingCropRect; + r->texture = m_tex2DBind[m_activeTexture]; + memcpy(r->rect, rect, 4*sizeof(int)); + m_pendingCropRects.insert(r); +} +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererContext.h b/emulator/opengl/tests/ut_renderer/RendererContext.h new file mode 100644 index 0000000..bb24a2e --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererContext.h @@ -0,0 +1,127 @@ +/* +* 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. +*/ +#ifndef _RENDERER_CONTEXT_H_ +#define _RENDERER_CONTEXT_H_ + +#include "RendererObject.h" +#include "GLDecoderContextData.h" + +#include <EGL/egl.h> +#define GL_API +#define GL_APIENTRY +#include <GLES/gl.h> +#include <string.h> + +#ifdef PVR_WAR +#include <set> +struct PendingCropRect +{ + GLuint texture; + int rect[4]; +}; + +typedef std::set<PendingCropRect *> PendingCropRectSet; +#endif + +class RendererContext : public RendererObject { +public: + static RendererContext *create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version); + EGLContext eglContext() { return m_ctx; } + int destroy(); + GLDecoderContextData & decoderContextData() { return m_contextData; } +#ifdef PVR_WAR + void setActiveTexture(GLenum texture); + GLenum getActiveTexture() { return GL_TEXTURE0 + m_activeTexture; } + void setTex2DBind(GLuint texture); + void setTex2DEnable(bool enable) { + m_tex2DEnable[m_activeTexture] = enable; + } + bool isTex2DEnable(int texunit) { return m_tex2DEnable[texunit]; } + GLuint getTex2DBind(); + void addPendingCropRect(const int *rect); + PendingCropRectSet &getPendingCropRects() { return m_pendingCropRects; } + + void setClientActiveTexture(GLenum texture) { m_clientActiveTexture = texture - GL_TEXTURE0; } + GLenum getClientActiveTexture() { return m_clientActiveTexture + GL_TEXTURE0; } + void enableClientState(GLenum cap, bool enable) { + switch(cap) { + case GL_VERTEX_ARRAY: + m_clientStateEnable[0] = enable; + break; + case GL_NORMAL_ARRAY: + m_clientStateEnable[1] = enable; + break; + case GL_COLOR_ARRAY: + m_clientStateEnable[2] = enable; + break; + case GL_POINT_SIZE_ARRAY_OES: + m_clientStateEnable[3] = enable; + break; + case GL_TEXTURE_COORD_ARRAY: + m_clientStateEnable[4 + m_clientActiveTexture] = enable; + break; + } + } + + bool getClientState(GLenum cap, int texUnit) { + switch(cap) { + case GL_VERTEX_ARRAY: + return m_clientStateEnable[0]; + case GL_NORMAL_ARRAY: + return m_clientStateEnable[1]; + case GL_COLOR_ARRAY: + return m_clientStateEnable[2]; + case GL_POINT_SIZE_ARRAY_OES: + return m_clientStateEnable[3]; + break; + case GL_TEXTURE_COORD_ARRAY: + return m_clientStateEnable[4 + texUnit]; + break; + } + return false; + } +#endif + +private: + EGLDisplay m_dpy; + EGLContext m_ctx; + GLDecoderContextData m_contextData; + int m_version; + + RendererContext(EGLDisplay dpy, EGLContext ctx, int version) : + m_dpy(dpy), + m_ctx(ctx), + m_version(version) + { +#ifdef PVR_WAR + m_activeTexture = 0; + m_clientActiveTexture = 0; + memset(m_tex2DBind, 0, 8*sizeof(GLuint)); + memset(m_tex2DEnable, 0, 8*sizeof(bool)); + memset(m_clientStateEnable, 0, 16*sizeof(bool)); +#endif + } + +#ifdef PVR_WAR + int m_tex2DBind[8]; + bool m_tex2DEnable[8]; + int m_activeTexture; + int m_clientActiveTexture; + bool m_clientStateEnable[16]; + PendingCropRectSet m_pendingCropRects; +#endif +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererObject.h b/emulator/opengl/tests/ut_renderer/RendererObject.h new file mode 100644 index 0000000..18c89be --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererObject.h @@ -0,0 +1,29 @@ +/* +* 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. +*/ +#ifndef _RENDERER_OBJECT_H_ +#define _RENDERER_OBJECT_H_ + +class RendererObject { +public: + RendererObject() { m_count = 0; } + + int count() { return m_count; } + void ref() { m_count++; } + void unref() { m_count--; } +private: + int m_count; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererSurface.cpp b/emulator/opengl/tests/ut_renderer/RendererSurface.cpp new file mode 100644 index 0000000..7d8d8c6 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererSurface.cpp @@ -0,0 +1,108 @@ +/* +* 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 "RendererSurface.h" +#include <stdio.h> +#include <stdlib.h> + +#include "NativeWindowing.h" + +#define MAX_ATTRIB 100 + + +EGLConfig RendererSurface::getEglConfig(EGLDisplay eglDisplay, SurfaceConfig config) +{ + EGLConfig eglConfig; + int nConfigs; + + EGLint attrib[MAX_ATTRIB]; + int pos =0; + + attrib[pos++] = EGL_SURFACE_TYPE; attrib[pos++] = EGL_WINDOW_BIT; + if (config & CONFIG_DEPTH) {attrib[pos++] = EGL_DEPTH_SIZE; attrib[pos++] = 1;} + attrib[pos++] = EGL_NONE; + + if (!eglChooseConfig(eglDisplay, attrib, &eglConfig, 1, &nConfigs)) { + return 0; + } + /***/ + int ibuf; + if (eglGetConfigAttrib(eglDisplay, eglConfig, EGL_BUFFER_SIZE, &ibuf)) { + fprintf(stderr, "EGL COLOR Buffer size: %d\n", ibuf); + } else { + fprintf(stderr, "eglGetConfigAttrib error: %d\n", eglGetError()); + } + if (eglGetConfigAttrib(eglDisplay, eglConfig, EGL_DEPTH_SIZE, &ibuf)) { + fprintf(stderr, "EGL DEPTH Buffer size: %d\n", ibuf); + } else { + fprintf(stderr, "eglGetConfigAttrib error: %d\n", eglGetError()); + } + /***/ + + + if (nConfigs != 1) { + return 0; + } + return eglConfig; +} + +RendererSurface * RendererSurface::create(EGLDisplay eglDisplay, SurfaceConfig config, NativeWindowing *nw) +{ + int width = 0, height = 0; + const char* env; + + env = getenv("ANDROID_WINDOW_WIDTH"); + if (env && *env) { + width = atoi(env); + } + env = getenv("ANDROID_WINDOW_HEIGHT"); + if (env && *env) { + height = atoi(env); + } + if (width <= 160) + width = DEFAULT_WIDTH; + if (height <= 160) + height = DEFAULT_HEIGHT; + + printf("%s: Using width=%d height=%d\n", __FUNCTION__, width, height); + + EGLConfig eglConfig = getEglConfig(eglDisplay, config); + if (eglConfig == 0) { + return NULL; + } + + NativeWindowType window = nw->createNativeWindow(nw->getNativeDisplay(), width, height); + if (window == 0) { + return NULL; + } + + EGLSurface eglSurface = eglCreateWindowSurface(eglDisplay, + eglConfig, + window, NULL); + + if (eglGetError() != EGL_SUCCESS) { + return NULL; + } + + return new RendererSurface(eglDisplay, window, eglSurface, eglConfig); +} + +int RendererSurface::destroy(NativeWindowing *nw) +{ + eglDestroySurface(m_eglDisplay, m_eglSurface); + nw->destroyNativeWindow(nw->getNativeDisplay(), m_window); + return 1; +} + diff --git a/emulator/opengl/tests/ut_renderer/RendererSurface.h b/emulator/opengl/tests/ut_renderer/RendererSurface.h new file mode 100644 index 0000000..4f6709c --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererSurface.h @@ -0,0 +1,52 @@ +/* +* 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. +*/ +#ifndef _RENDERER_SURFACE_H_ +#define _RENDERER_SURFACE_H_ + +#include <EGL/egl.h> +#include "NativeWindowing.h" +#include "RendererObject.h" + +#define DEFAULT_HEIGHT 480 +#define DEFAULT_WIDTH 320 + +class RendererSurface : public RendererObject { +public: + typedef enum { CONFIG_DEPTH = 1 << 0 } SurfaceConfig; + + EGLSurface eglSurface() { return m_eglSurface; } + EGLConfig eglConfig() { return m_config; } + EGLDisplay eglDisplay() { return m_eglDisplay; } + + static RendererSurface * create(EGLDisplay eglDisplay, SurfaceConfig config, NativeWindowing *nw); + static EGLConfig getEglConfig(EGLDisplay eglDisplay, SurfaceConfig config); + + int destroy(NativeWindowing *nw); + +private: + RendererSurface(EGLDisplay display, NativeWindowType window, EGLSurface surface, EGLConfig config) : + m_eglDisplay(display), + m_config(config), + m_window(window), + m_eglSurface(surface) + {} + + EGLDisplay m_eglDisplay; + EGLConfig m_config; + NativeWindowType m_window; + EGLSurface m_eglSurface; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RenderingThread.cpp b/emulator/opengl/tests/ut_renderer/RenderingThread.cpp new file mode 100644 index 0000000..70eee20 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RenderingThread.cpp @@ -0,0 +1,387 @@ +/* +* 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 "RenderingThread.h" +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <pthread.h> +#include "ReadBuffer.h" +#include "Renderer.h" +#include "TimeUtils.h" + +#include <GLES/glext.h> + +__thread RenderingThread * RenderingThread::m_tls; + +#ifdef PVR_WAR +void RenderingThread::s_glTexParameteriv(GLenum target, GLenum param, const int *p) +{ + if (target == GL_TEXTURE_2D && param == GL_TEXTURE_CROP_RECT_OES) { + m_tls->m_currentContext->addPendingCropRect(p); + } else { + m_tls->m_glTexParameteriv(target, param, p); + } +} + +void RenderingThread::s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexfOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexsOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexiOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexxOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexfvOES(const GLfloat *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexfvOES(coords); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexsvOES(const GLshort *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexsvOES(coords); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexivOES(const GLint *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexivOES(coords); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexxvOES(const GLfixed *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexxvOES(coords); + m_tls->fixTextureEnable(); +} + + +void RenderingThread::s_glActiveTexture(GLenum texture) +{ + if (texture - GL_TEXTURE0 >= m_tls->m_backendCaps.maxTextureUnits) return; + + m_tls->m_currentContext->setActiveTexture(texture); + m_tls->m_glActiveTexture(texture); +} + +void RenderingThread::s_glBindTexture(GLenum target, GLuint texture) +{ + if (target == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DBind(texture); + m_tls->m_glBindTexture(target, texture); +} + +void RenderingThread::s_glEnable(GLenum cap) +{ + if (cap == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DEnable(true); + m_tls->m_glEnable(cap); +} + +void RenderingThread::s_glDisable(GLenum cap) +{ + if (cap == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DEnable(false); + m_tls->m_glDisable(cap); +} + +void RenderingThread::s_glClientActiveTexture(GLenum texture) +{ + if (texture - GL_TEXTURE0 >= m_tls->m_backendCaps.maxTextureUnits) return; + m_tls->m_currentContext->setClientActiveTexture(texture); + m_tls->m_glClientActiveTexture(texture); +} + +void RenderingThread::s_glEnableClientState(GLenum cap) +{ + m_tls->m_currentContext->enableClientState(cap, true); + m_tls->m_glEnableClientState(cap); +} + +void RenderingThread::s_glDisableClientState(GLenum cap) +{ + m_tls->m_currentContext->enableClientState(cap, false); + m_tls->m_glDisableClientState(cap); +} + +void RenderingThread::applyPendingCropRects() +{ + PendingCropRectSet &rset = m_currentContext->getPendingCropRects(); + if (rset.size() > 0) { + GLuint currBindedTex = m_currentContext->getTex2DBind(); + for (PendingCropRectSet::iterator i = rset.begin(); + i != rset.end(); + i++) { + m_glBindTexture(GL_TEXTURE_2D, (*i)->texture); + m_glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, (int *)(*i)->rect); + delete (*i); + } + m_glBindTexture(GL_TEXTURE_2D, currBindedTex); + rset.clear(); + } +} + +void RenderingThread::fixTextureEnable() +{ + // restore texture units enable state + for (unsigned int i=0; i<m_backendCaps.maxTextureUnits; i++) { + m_glActiveTexture(GL_TEXTURE0 + i); + if (m_currentContext->isTex2DEnable(i)) { + m_glEnable(GL_TEXTURE_2D); + } + else { + m_glDisable(GL_TEXTURE_2D); + } + m_glClientActiveTexture(GL_TEXTURE0 + i); + if (m_currentContext->getClientState(GL_TEXTURE_COORD_ARRAY, i)) { + m_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else { + m_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + } + // restore current active texture + m_glActiveTexture(m_currentContext->getActiveTexture()); + m_glClientActiveTexture(m_currentContext->getClientActiveTexture()); + + // restore other client state enable bits + if (m_currentContext->getClientState(GL_VERTEX_ARRAY, 0)) { + m_glEnableClientState(GL_VERTEX_ARRAY); + } + else { + m_glDisableClientState(GL_VERTEX_ARRAY); + } + + if (m_currentContext->getClientState(GL_NORMAL_ARRAY, 0)) { + m_glEnableClientState(GL_NORMAL_ARRAY); + } + else { + m_glDisableClientState(GL_NORMAL_ARRAY); + } + + if (m_currentContext->getClientState(GL_COLOR_ARRAY, 0)) { + m_glEnableClientState(GL_COLOR_ARRAY); + } + else { + m_glDisableClientState(GL_COLOR_ARRAY); + } + + if (m_currentContext->getClientState(GL_POINT_SIZE_ARRAY_OES, 0)) { + m_glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + } + else { + m_glDisableClientState(GL_POINT_SIZE_ARRAY_OES); + } +} +#endif + + +int RenderingThread::s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version) +{ + return Renderer::instance()->createContext(m_tls, Renderer::ClientHandle(pid, handle), + Renderer::ClientHandle(pid, shareCtx), + version); + +} + + +int RenderingThread::s_createSurface(uint32_t pid, uint32_t handle) +{ + return Renderer::instance()->createSurface(m_tls, Renderer::ClientHandle(pid, handle)); +} + +int RenderingThread::s_destroySurface(uint32_t pid, uint32_t handle) +{ + return Renderer::instance()->destroySurface(m_tls, Renderer::ClientHandle(pid, handle)); +} + +int RenderingThread::s_destroyContext(uint32_t pid, uint32_t handle) +{ + return Renderer::instance()->destroyContext(m_tls, Renderer::ClientHandle(pid, handle)); +} + + +int RenderingThread::s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx) +{ + int ret = Renderer::instance()->makeCurrent(m_tls, + Renderer::ClientHandle(pid, drawSurface), + Renderer::ClientHandle(pid, readSurface), + Renderer::ClientHandle(pid, ctx)); + + if (ret && ctx) { + m_tls->initBackendCaps(); + } + + return ret; +} + +void RenderingThread::s_swapBuffers(uint32_t pid, uint32_t surface) +{ + Renderer::instance()->swapBuffers(m_tls, Renderer::ClientHandle(pid, surface)); +} + + +RenderingThread::RenderingThread(SocketStream *stream) : + m_stream(stream), + m_currentContext(NULL) +{ + m_backendCaps.initialized = false; +} + +int RenderingThread::start(void) +{ + if (pthread_create(&m_thread, NULL, s_thread, this) < 0) { + perror("pthread_create"); + return -1; + } + return 0; +} + + +void * RenderingThread::s_thread(void *data) +{ + RenderingThread *self = (RenderingThread *)data; + m_tls = self; + return self->thread(); +} + +void RenderingThread::initBackendCaps() +{ + if (m_backendCaps.initialized) return; + + m_glDec.glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint *)&m_backendCaps.maxTextureUnits); + m_backendCaps.initialized = true; +} + +void *RenderingThread::thread() +{ + + // initialize our decoders; + m_glDec.initGL(); + +#ifdef PVR_WAR + m_glTexParameteriv = m_glDec.set_glTexParameteriv(s_glTexParameteriv); + m_glDrawTexfOES = m_glDec.set_glDrawTexfOES(s_glDrawTexfOES); + m_glDrawTexsOES = m_glDec.set_glDrawTexsOES(s_glDrawTexsOES); + m_glDrawTexiOES = m_glDec.set_glDrawTexiOES(s_glDrawTexiOES); + m_glDrawTexxOES = m_glDec.set_glDrawTexxOES(s_glDrawTexxOES); + m_glDrawTexfvOES = m_glDec.set_glDrawTexfvOES(s_glDrawTexfvOES); + m_glDrawTexsvOES = m_glDec.set_glDrawTexsvOES(s_glDrawTexsvOES); + m_glDrawTexivOES = m_glDec.set_glDrawTexivOES(s_glDrawTexivOES); + m_glDrawTexxvOES = m_glDec.set_glDrawTexxvOES(s_glDrawTexxvOES); + m_glActiveTexture = m_glDec.set_glActiveTexture(s_glActiveTexture); + m_glBindTexture = m_glDec.set_glBindTexture(s_glBindTexture); + m_glEnable = m_glDec.set_glEnable(s_glEnable); + m_glDisable = m_glDec.set_glDisable(s_glDisable); + m_glClientActiveTexture = m_glDec.set_glClientActiveTexture(s_glClientActiveTexture); + m_glEnableClientState = m_glDec.set_glEnableClientState(s_glEnableClientState); + m_glDisableClientState = m_glDec.set_glDisableClientState(s_glDisableClientState); +#endif + + m_gl2Dec.initGL(); + + m_utDec.set_swapBuffers(s_swapBuffers); + m_utDec.set_createContext(s_createContext); + m_utDec.set_destroyContext(s_destroyContext); + m_utDec.set_createSurface(s_createSurface); + m_utDec.set_destroySurface(s_destroySurface); + m_utDec.set_makeCurrentContext(s_makeCurrent); + + ReadBuffer readBuf(m_stream, DECODER_BUF_SIZE); + + int stats_totalBytes = 0; + long long stats_t0 = GetCurrentTimeMS(); + + while (1) { + + int stat = readBuf.getData(); + if (stat == 0) { + fprintf(stderr, "client shutdown\n"); + break; + } else if (stat < 0) { + perror("getData"); + break; + } + + // + // log received bandwidth statistics + // + stats_totalBytes += readBuf.validData(); + long long dt = GetCurrentTimeMS() - stats_t0; + if (dt > 1000) { + float dts = (float)dt / 1000.0f; + printf("Used Bandwidth %5.3f MB/s\n", ((float)stats_totalBytes / dts) / (1024.0f*1024.0f)); + stats_totalBytes = 0; + stats_t0 = GetCurrentTimeMS(); + } + + bool progress = true; + while (progress) { + progress = false; + // we need at least one header (8 bytes) in our buffer + if (readBuf.validData() >= 8) { + size_t last = m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + progress = true; + readBuf.consume(last); + } + } + + if (readBuf.validData() >= 8) { + size_t last = m_gl2Dec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + readBuf.consume(last); + progress = true; + } + } + + if (readBuf.validData() >= 8) { + size_t last = m_utDec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + readBuf.consume(last); + progress = true; + } + } + } + } + // shutdown + if (m_currentContext != NULL) { + m_currentContext->unref(); + } + + return NULL; +} diff --git a/emulator/opengl/tests/ut_renderer/RenderingThread.h b/emulator/opengl/tests/ut_renderer/RenderingThread.h new file mode 100644 index 0000000..0b4ebe6 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RenderingThread.h @@ -0,0 +1,117 @@ +/* +* 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. +*/ +#ifndef _RENDERING_THREAD_H_ +#define _RENDERING_THREAD_H_ + +#include "SocketStream.h" +#include "GLDecoder.h" +#include "GL2Decoder.h" +#include "ut_rendercontrol_dec.h" +#include <pthread.h> + +#define GL_API +#define GL_APIENTRY + +#include <GLES/egl.h> +#include <GLES/gl.h> + + +#define WINDOW_WIDTH 320 +#define WINDOW_HEIGHT 480 + +#define DECODER_BUF_SIZE (4 * 1024 * 1024) + +class RendererContext; + +class RenderingThread { +public: + RenderingThread(SocketStream *stream); + int start(); + void *thread(); + RendererContext *currentContext() { return m_currentContext; } + void setCurrentContext(RendererContext *ctx) { m_currentContext = ctx; } + GLDecoder & glDecoder() { return m_glDec; } + GL2Decoder & gl2Decoder() { return m_gl2Dec; } + +private: + void initBackendCaps(); + +private: + GLDecoder m_glDec; + ut_rendercontrol_decoder_context_t m_utDec; + GL2Decoder m_gl2Dec; + + SocketStream *m_stream; + pthread_t m_thread; + RendererContext * m_currentContext; + + struct BackendCaps { + bool initialized; + GLuint maxTextureUnits; + } m_backendCaps; + + static void * s_thread(void *data); + static __thread RenderingThread *m_tls; + + static int s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version); + static int s_createSurface(uint32_t pid, uint32_t handle); + static int s_destroySurface(uint32_t pid, uint32_t handle); + static int s_destroyContext(uint32_t pid, uint32_t handle); + static int s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx); + static void s_swapBuffers(uint32_t pid, uint32_t surface); +#ifdef PVR_WAR + static void s_glTexParameteriv(GLenum target, GLenum param, const int *p); + static void s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h); + static void s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h); + static void s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h); + static void s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h); + static void s_glDrawTexfvOES(const GLfloat *coords); + static void s_glDrawTexsvOES(const GLshort *coords); + static void s_glDrawTexivOES(const GLint *coords); + static void s_glDrawTexxvOES(const GLfixed *coords); + + static void s_glActiveTexture(GLenum texture); + static void s_glBindTexture(GLenum target, GLuint texture); + static void s_glEnable(GLenum cap); + static void s_glDisable(GLenum cap); + static void s_glClientActiveTexture(GLenum texture); + static void s_glEnableClientState(GLenum cap); + static void s_glDisableClientState(GLenum cap); + + void applyPendingCropRects(); + void fixTextureEnable(); + + glTexParameteriv_server_proc_t m_glTexParameteriv; + glDrawTexfOES_server_proc_t m_glDrawTexfOES; + glDrawTexiOES_server_proc_t m_glDrawTexiOES; + glDrawTexsOES_server_proc_t m_glDrawTexsOES; + glDrawTexxOES_server_proc_t m_glDrawTexxOES; + glDrawTexfvOES_server_proc_t m_glDrawTexfvOES; + glDrawTexivOES_server_proc_t m_glDrawTexivOES; + glDrawTexsvOES_server_proc_t m_glDrawTexsvOES; + glDrawTexxvOES_server_proc_t m_glDrawTexxvOES; + glActiveTexture_server_proc_t m_glActiveTexture; + glBindTexture_server_proc_t m_glBindTexture; + glEnable_server_proc_t m_glEnable; + glDisable_server_proc_t m_glDisable; + glClientActiveTexture_server_proc_t m_glClientActiveTexture; + glEnableClientState_server_proc_t m_glEnableClientState; + glDisableClientState_server_proc_t m_glDisableClientState; +#endif + +}; + +#endif diff --git a/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp b/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp new file mode 100644 index 0000000..121ee87 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp @@ -0,0 +1,69 @@ +/* +* 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 "X11RendererSurface.h" + +NativeDisplayType X11RendererSurface::getNativeDisplay() +{ + if (m_display == NULL) { + m_display = XOpenDisplay(NULL); + } + return NativeDisplayType(m_display); +} + +int X11RendererSurface::destoryNativeWindow(NativeWindowType win) +{ + if (m_display == NULL) return -1; + + Window x11Window = (Window)(win); + return XDestroyWindow(m_display, x11Window); +} + +NativeWindowType GlesX11Win::createNativeWindow() +{ + + getNativeDisplay(); + if (m_display == NULL) { + return -1; + } + + long defaultScreen = DefaultScreen( dpy ); + Window rootWindow = RootWindow(dpy, defaultScreen); + int depth = DefaultDepth(dpy, defaultScreen); + XVisualInfo *visualInfo = new XVisualInfo; + + XMatchVisualInfo(m_display, defaultScreen, , dpeth, TrueColor, visualInfo); + if (visualInfo == NULL) { + fprintf(stderr, "couldn't find matching visual\n"); + return -1; + } + + Colormap x11Colormap = XCreateColormap(m_display, rootWindow, visualInfo->visual, AllocNone); + XSetWindowAttributes sWA; + sWA.Colormap = x11Colormap; + sWA.event_mask = StructureNotifyMask | ExposureMask; + unsigned int eventMask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; + + Window win = XCreateWindow( m_display, + rootWindow, + 0, 0, width, height, + 0, CopyFromParent, InputOutput, + CopyFromParent, eventMask, &sWA); + + XMapWindow(m_display, win); + XFlush(m_display); + return NativeWindowType(win); +} + diff --git a/emulator/opengl/tests/ut_renderer/X11RendererSurface.h b/emulator/opengl/tests/ut_renderer/X11RendererSurface.h new file mode 100644 index 0000000..be9bcec --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11RendererSurface.h @@ -0,0 +1,37 @@ +/* +* 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. +*/ +#ifndef _X11_RENDERER_SURFACE_H_ +#define _X11_RENDERER_SURFACE_H_ + +#include <X11/Xutil.h> +#include <X11/Xlib.h> +#include <EGL/egl.h> + +include "RendererSurface.h" + +class X11RendererSurface : public RendererSurface +{ +public: + X11RendererSurface() : RendererSurface() { + m_display = NULL; + } + NativeDisplayType getNativeDisplay(); + NativeWindowType createNativeWindow(); + int destroyNativeWindow(NativeWindowType win); +private: + Display m_display; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/X11Windowing.cpp b/emulator/opengl/tests/ut_renderer/X11Windowing.cpp new file mode 100644 index 0000000..cc94fdd --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11Windowing.cpp @@ -0,0 +1,131 @@ +/* +* 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 "X11Windowing.h" + +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#define DEBUG 0 +#if DEBUG +# define D(...) printf(__VA_ARGS__), printf("\n") +#else +# define D(...) ((void)0) +#endif + +/* Try to remember the window position between creates/destroys */ +static int X11_wmXPos = 100; +static int X11_wmYPos = 100; + +static int X11_wmXAdjust = 0; +static int X11_wmYAdjust = 0; + +static void +get_window_pos( Display *disp, Window win, int *px, int *py ) +{ + Window child; + + XTranslateCoordinates( disp, win, DefaultRootWindow(disp), 0, 0, px, py, &child ); +} + + +static void +set_window_pos(Display *disp, Window win, int x, int y) +{ + int xNew, yNew; + int xAdjust = X11_wmXAdjust; + int yAdjust = X11_wmYAdjust; + + /* this code is tricky because some window managers, but not all, + * will translate the final window position by a given offset + * corresponding to the frame decoration. + * + * so we first try to move the window, get the position that the + * window manager has set, and if they are different, re-position the + * window again with an adjustment. + * + * this causes a slight flicker since the window 'jumps' very + * quickly from one position to the other. + */ + + D("%s: move to [%d,%d] adjusted to [%d,%d]", __FUNCTION__, + x, y, x+xAdjust, y+yAdjust); + XMoveWindow(disp, win, x + xAdjust, y + yAdjust); + XSync(disp, True); + get_window_pos(disp, win, &xNew, &yNew); + if (xNew != x || yNew != y) { + X11_wmXAdjust = xAdjust = x - xNew; + X11_wmYAdjust = yAdjust = y - yNew; + D("%s: read pos [%d,%d], recomputing adjust=[%d,%d] moving to [%d,%d]\n", + __FUNCTION__, xNew, yNew, xAdjust, yAdjust, x+xAdjust, y+yAdjust); + XMoveWindow(disp, win, x + xAdjust, y + yAdjust ); + } + XSync(disp, False); +} + + +NativeDisplayType X11Windowing::getNativeDisplay() +{ + Display *dpy = XOpenDisplay(NULL); + return (NativeDisplayType)dpy; +} + +NativeWindowType X11Windowing::createNativeWindow(NativeDisplayType _dpy, int width, int height) +{ + Display *dpy = (Display *) _dpy; + + long defaultScreen = DefaultScreen( dpy ); + Window rootWindow = RootWindow(dpy, defaultScreen); + int depth = DefaultDepth(dpy, defaultScreen); + XVisualInfo *visualInfo = new XVisualInfo; + + XMatchVisualInfo(dpy, defaultScreen, depth, TrueColor, visualInfo); + if (visualInfo == NULL) { + fprintf(stderr, "couldn't find matching visual\n"); + return NULL; + } + + Colormap x11Colormap = XCreateColormap(dpy, rootWindow, visualInfo->visual, AllocNone); + XSetWindowAttributes sWA; + sWA.colormap = x11Colormap; + sWA.event_mask = StructureNotifyMask | ExposureMask; + sWA.background_pixel = 0; + sWA.border_pixel = 0; + unsigned int attributes_mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; + + Window win = XCreateWindow( dpy, + rootWindow, + X11_wmXPos, X11_wmYPos, width, height, + 0, CopyFromParent, InputOutput, + CopyFromParent, attributes_mask, &sWA); + + XMapWindow(dpy, win); + XFlush(dpy); + set_window_pos(dpy, win, X11_wmXPos, X11_wmYPos); + return NativeWindowType(win); +} + +int X11Windowing::destroyNativeWindow(NativeDisplayType _dpy, NativeWindowType _win) +{ + Display *dpy = (Display *)_dpy; + Window win = (Window)_win; + get_window_pos(dpy, win, &X11_wmXPos, &X11_wmYPos); + D("%s: Saved window position [%d, %d]\n", __FUNCTION__, X11_wmXPos, X11_wmYPos); + XDestroyWindow(dpy, win); + XFlush(dpy); + return 0; +} diff --git a/emulator/opengl/tests/ut_renderer/X11Windowing.h b/emulator/opengl/tests/ut_renderer/X11Windowing.h new file mode 100644 index 0000000..0f0c76b --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11Windowing.h @@ -0,0 +1,27 @@ +/* +* 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. +*/ +#ifndef _X11WINDOWING_H_ +#define _X11WINDOWING_H_ + +#include "NativeWindowing.h" + +class X11Windowing : public NativeWindowing { + NativeDisplayType getNativeDisplay(); + NativeWindowType createNativeWindow(NativeDisplayType _dpy, int width, int height); + int destroyNativeWindow(NativeDisplayType dpy, NativeWindowType win); +}; + +#endif diff --git a/emulator/opengl/tests/ut_renderer/ut_renderer.cpp b/emulator/opengl/tests/ut_renderer/ut_renderer.cpp new file mode 100644 index 0000000..f2b2bc3 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/ut_renderer.cpp @@ -0,0 +1,63 @@ +/* +* 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 <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include "codec_defs.h" +#include "RenderingThread.h" +#include "TcpStream.h" +#ifndef _WIN32 +#include "UnixStream.h" +#endif + + +int main(int argc, char **argv) +{ +#ifdef _WIN32 + TcpStream *socket = new TcpStream(); + + if (socket->listen(CODEC_SERVER_PORT) < 0) { + perror("listen"); + exit(1); + } +#else + UnixStream *socket = new UnixStream(); + + if (socket->listen(CODEC_SERVER_PORT) < 0) { + perror("listen"); + exit(1); + } +#endif + + printf("waiting for client connection on port: %d\n", CODEC_SERVER_PORT); + while (1) { + // wait for client connection + SocketStream *glStream = socket->accept(); + if (glStream == NULL) { + printf("failed to get client.. aborting\n"); + exit(3); + } + printf("Got client connection, creating a rendering thread;\n"); + // create a thread to handle this connection + RenderingThread *rt = new RenderingThread(glStream); + rt->start(); + } + + return 0; +} + + |