diff options
Diffstat (limited to 'opengl')
83 files changed, 3382 insertions, 378 deletions
diff --git a/opengl/include/EGL/eglext.h b/opengl/include/EGL/eglext.h index 2d41aa7..8578874 100644 --- a/opengl/include/EGL/eglext.h +++ b/opengl/include/EGL/eglext.h @@ -234,6 +234,16 @@ struct ANativeWindowBuffer; #define EGL_RECORDABLE_ANDROID 0x3142 /* EGLConfig attribute */ #endif +/* EGL_EXT_create_context_robustness + */ +#ifndef EGL_EXT_create_context_robustness +#define EGL_EXT_create_context_robustness 1 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138 +#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF +#endif + /* EGL_NV_system_time */ #ifndef EGL_NV_system_time @@ -270,6 +280,37 @@ typedef EGLBoolean (EGLAPIENTRYP PFEGLHIBERNATEPROCESSIMGPROC)(void); typedef EGLBoolean (EGLAPIENTRYP PFEGLAWAKENPROCESSIMGPROC)(void); #endif +/* EGL_ANDROID_native_fence_sync + */ +#ifndef EGL_ANDROID_native_fence_sync +#define EGL_ANDROID_native_fence_sync 1 +#define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144 +#define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145 +#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1 +#define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync); +#endif +typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROID) (EGLDisplay dpy, EGLSyncKHR sync); +#endif + +/* EGL_ANDROID_wait_sync + */ +#ifndef EGL_ANDROID_wait_sync +#define EGL_ANDROID_wait_sync +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLint EGLAPIENTRY eglWaitSyncANDROID(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +#endif +typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCANDROID) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +#endif + +/* EGL_ANDROID_framebuffer_target + */ +#ifndef EGL_ANDROID_framebuffer_target +#define EGL_ANDROID_framebuffer_target +#define EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147 +#endif + #ifdef __cplusplus } #endif diff --git a/opengl/include/GLES2/gl2.h b/opengl/include/GLES2/gl2.h index e1d3b87..c139c25 100644 --- a/opengl/include/GLES2/gl2.h +++ b/opengl/include/GLES2/gl2.h @@ -528,7 +528,7 @@ GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures); GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); -GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); +GL_APICALL GLint GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params); GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); GL_APICALL GLenum GL_APIENTRY glGetError (void); @@ -547,7 +547,7 @@ GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum p GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params); GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params); GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params); -GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); +GL_APICALL GLint GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer); diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk index 15e58f2..9b8d3fe 100644 --- a/opengl/libagl/Android.mk +++ b/opengl/libagl/Android.mk @@ -26,7 +26,7 @@ LOCAL_CFLAGS += -DLOG_TAG=\"libagl\" LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_CFLAGS += -fvisibility=hidden -LOCAL_SHARED_LIBRARIES := libcutils libhardware libutils libpixelflinger libETC1 +LOCAL_SHARED_LIBRARIES := libcutils libhardware libutils libpixelflinger libETC1 libui LOCAL_LDLIBS := -lpthread -ldl ifeq ($(TARGET_ARCH),arm) @@ -34,16 +34,14 @@ ifeq ($(TARGET_ARCH),arm) LOCAL_CFLAGS += -fstrict-aliasing endif -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER +ifeq ($(TARGET_ARCH),mips) + LOCAL_SRC_FILES += arch-$(TARGET_ARCH)/fixed_asm.S + LOCAL_CFLAGS += -fstrict-aliasing + # The graphics code can generate division by zero + LOCAL_CFLAGS += -mno-check-zero-division endif # we need to access the private Bionic header <bionic_tls.h> -# on ARM platforms, we need to mirror the ARCH_ARM_HAVE_TLS_REGISTER -# behavior from the bionic Android.mk file -ifeq ($(TARGET_ARCH)-$(ARCH_ARM_HAVE_TLS_REGISTER),arm-true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif LOCAL_C_INCLUDES += bionic/libc/private LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/egl diff --git a/opengl/libagl/arch-mips/fixed_asm.S b/opengl/libagl/arch-mips/fixed_asm.S new file mode 100644 index 0000000..e1a53bc --- /dev/null +++ b/opengl/libagl/arch-mips/fixed_asm.S @@ -0,0 +1,61 @@ +/* libs/opengles/arch-mips/fixed_asm.S +** +** Copyright 2012, 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. +*/ + + + .text + .align + +/* + * this version rounds-to-nearest and saturates numbers + * outside the range (but not NaNs). + */ + + .global gglFloatToFixed + .ent gglFloatToFixed + .type gglFloatToFixed, @function +gglFloatToFixed: +#if !defined(__mips_soft_float) + mfc1 $a0,$f12 +#endif + srl $t0,$a0,31 /* t0 <- sign bit */ + srl $t1,$a0,23 + andi $t1,$t1,0xff /* get the e */ + li $t2,0x8e + subu $t1,$t2,$t1 /* t1=127+15-e */ + blez $t1,0f /* t1<=0? */ + sll $t2,$a0,8 /* mantissa<<8 */ + lui $t3,0x8000 + or $t2,$t2,$t3 /* add the missing 1 */ + subu $t1,$t1,1 + srl $v0,$t2,$t1 + sltiu $t3,$t1,32 /* t3=1 if t1<32, else t3=0. t1>=32 means the float value is too small. */ + andi $t4,$v0,0x1 + srl $v0,$v0,1 /* scale to 16.16 */ + addu $v0,$v0,$t4 /* round-to-nearest */ + subu $t2,$zero,$v0 + movn $v0,$t2,$t0 /* if negative? */ + or $t1,$a0,$zero /* a0=0? */ + movz $v0,$zero,$t1 + movz $v0,$zero,$t3 /* t3=0 then res=0 */ + jr $ra +0: + lui $t1,0x8000 + and $v0,$a0,$t1 /* keep only the sign bit */ + li $t1,0x7fffffff + movz $v0,$t1,$t0 /* positive, maximum value */ + jr $ra + .end gglFloatToFixed diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp index c31aebf..172ef95 100644 --- a/opengl/libagl/egl.cpp +++ b/opengl/libagl/egl.cpp @@ -31,6 +31,7 @@ #include <utils/threads.h> #include <ui/ANativeObjectBase.h> +#include <ui/Fence.h> #include <EGL/egl.h> #include <EGL/eglext.h> @@ -372,7 +373,16 @@ EGLBoolean egl_window_surface_v2_t::connect() GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); // dequeue a buffer - if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) != NO_ERROR) { + int fenceFd = -1; + if (nativeWindow->dequeueBuffer(nativeWindow, &buffer, + &fenceFd) != NO_ERROR) { + return setError(EGL_BAD_ALLOC, EGL_FALSE); + } + + // wait for the buffer + sp<Fence> fence(new Fence(fenceFd)); + if (fence->wait(Fence::TIMEOUT_NEVER) != NO_ERROR) { + nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd); return setError(EGL_BAD_ALLOC, EGL_FALSE); } @@ -392,8 +402,6 @@ EGLBoolean egl_window_surface_v2_t::connect() // keep a reference on the buffer buffer->common.incRef(&buffer->common); - // Lock the buffer - nativeWindow->lockBuffer(nativeWindow, buffer); // pin the buffer down if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) { @@ -412,7 +420,7 @@ void egl_window_surface_v2_t::disconnect() unlock(buffer); } // enqueue the last frame - nativeWindow->queueBuffer(nativeWindow, buffer); + nativeWindow->queueBuffer(nativeWindow, buffer, -1); if (buffer) { buffer->common.decRef(&buffer->common); buffer = 0; @@ -517,15 +525,17 @@ EGLBoolean egl_window_surface_v2_t::swapBuffers() unlock(buffer); previousBuffer = buffer; - nativeWindow->queueBuffer(nativeWindow, buffer); + nativeWindow->queueBuffer(nativeWindow, buffer, -1); buffer = 0; // dequeue a new buffer - if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) == NO_ERROR) { - - // TODO: lockBuffer should rather be executed when the very first - // direct rendering occurs. - nativeWindow->lockBuffer(nativeWindow, buffer); + int fenceFd = -1; + if (nativeWindow->dequeueBuffer(nativeWindow, &buffer, &fenceFd) == NO_ERROR) { + sp<Fence> fence(new Fence(fenceFd)); + if (fence->wait(Fence::TIMEOUT_NEVER)) { + nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd); + return setError(EGL_BAD_ALLOC, EGL_FALSE); + } // reallocate the depth-buffer if needed if ((width != buffer->width) || (height != buffer->height)) { diff --git a/opengl/libagl/fp.cpp b/opengl/libagl/fp.cpp index ae5f1fe..aea4449 100644 --- a/opengl/libagl/fp.cpp +++ b/opengl/libagl/fp.cpp @@ -19,7 +19,7 @@ // ---------------------------------------------------------------------------- -#if !defined(__arm__) +#if !defined(__arm__) && !defined(__mips__) GGLfixed gglFloatToFixed(float v) { return GGLfixed(floorf(v * 65536.0f + 0.5f)); } diff --git a/opengl/libagl/light.cpp b/opengl/libagl/light.cpp index ca715db..fafec3f 100644 --- a/opengl/libagl/light.cpp +++ b/opengl/libagl/light.cpp @@ -381,7 +381,14 @@ void lightVertex(ogles_context_t* c, vertex_t* v) // compute vertex-to-light vector if (ggl_unlikely(l.position.w)) { // lightPos/1.0 - vertex/vertex.w == lightPos*vertex.w - vertex +#if !OBJECT_SPACE_LIGHTING + vec4_t o; + const transform_t& mv = c->transforms.modelview.transform; + mv.point4(&mv, &o, &v->obj); + vss3(d.v, l.objPosition.v, o.w, o.v); +#else vss3(d.v, l.objPosition.v, v->obj.w, v->obj.v); +#endif sqDist = dot3(d.v, d.v); vscale3(d.v, d.v, gglSqrtRecipx(sqDist)); } else { diff --git a/opengl/libagl/matrix.h b/opengl/libagl/matrix.h index c9a38a9..5bd717a 100644 --- a/opengl/libagl/matrix.h +++ b/opengl/libagl/matrix.h @@ -74,6 +74,30 @@ GLfixed vsquare3(GLfixed a, GLfixed b, GLfixed c) ); return r; +#elif defined(__mips__) + + GLfixed res; + int32_t t1,t2,t3; + asm( + "mult %[a], %[a] \r\n" + "li %[res],0x8000 \r\n" + "madd %[b],%[b] \r\n" + "move %[t3],$zero \r\n" + "madd %[c],%[c] \r\n" + "mflo %[t1]\r\n" + "mfhi %[t2]\r\n" + "addu %[t1],%[res],%[t1]\r\n" /*add 0x8000*/ + "sltu %[t3],%[t1],%[res]\r\n" + "addu %[t2],%[t2],%[t3]\r\n" + "srl %[res],%[t1],16\r\n" + "sll %[t2],%[t2],16\r\n" + "or %[res],%[res],%[t2]\r\n" + : [res]"=&r"(res),[t1]"=&r"(t1),[t2]"=&r"(t2),[t3]"=&r"(t3) + : [a] "r" (a),[b] "r" (b),[c] "r" (c) + : "%hi","%lo" + ); + return res; + #else return (( int64_t(a)*a + @@ -136,6 +160,26 @@ static inline GLfixed mla3a( GLfixed a0, GLfixed b0, ); return r; +#elif defined(__mips__) + + GLfixed res; + int32_t t1,t2; + asm( + "mult %[a0],%[b0] \r\n" + "madd %[a1],%[b1] \r\n" + "madd %[a2],%[b2] \r\n" + "mflo %[t2]\r\n" + "mfhi %[t1]\r\n" + "srl %[t2],%[t2],16\r\n" + "sll %[t1],%[t1],16\r\n" + "or %[t2],%[t2],%[t1]\r\n" + "addu %[res],%[t2],%[c]" + : [res]"=&r"(res),[t1]"=&r"(t1),[t2]"=&r"(t2) + : [a0] "r" (a0),[b0] "r" (b0),[a1] "r" (a1),[b1] "r" (b1),[a2] "r" (a2),[b2] "r" (b2),[c] "r" (c) + : "%hi","%lo" + ); + return res; + #else return (( int64_t(a0)*b0 + diff --git a/opengl/libs/Android.mk b/opengl/libs/Android.mk index 42aaa24..d025ae8 100644 --- a/opengl/libs/Android.mk +++ b/opengl/libs/Android.mk @@ -23,11 +23,6 @@ LOCAL_LDLIBS := -lpthread -ldl LOCAL_MODULE:= libEGL LOCAL_LDFLAGS += -Wl,--exclude-libs=ALL LOCAL_SHARED_LIBRARIES += libdl -# Bionic's private TLS header relies on the ARCH_ARM_HAVE_TLS_REGISTER to -# select the appropriate TLS codepath -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif # we need to access the private Bionic header <bionic_tls.h> LOCAL_C_INCLUDES += bionic/libc/private @@ -49,14 +44,14 @@ ifeq ($(TARGET_BOARD_PLATFORM), s5pc110) LOCAL_CFLAGS += -DSYSTEMUI_PBSIZE_HACK=1 endif -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif - ifneq ($(MAX_EGL_CACHE_ENTRY_SIZE),) LOCAL_CFLAGS += -DMAX_EGL_CACHE_ENTRY_SIZE=$(MAX_EGL_CACHE_ENTRY_SIZE) endif +ifneq ($(MAX_EGL_CACHE_KEY_SIZE),) + LOCAL_CFLAGS += -DMAX_EGL_CACHE_KEY_SIZE=$(MAX_EGL_CACHE_KEY_SIZE) +endif + ifneq ($(MAX_EGL_CACHE_SIZE),) LOCAL_CFLAGS += -DMAX_EGL_CACHE_SIZE=$(MAX_EGL_CACHE_SIZE) endif @@ -96,19 +91,12 @@ LOCAL_MODULE:= libGLESv1_CM LOCAL_SHARED_LIBRARIES += libdl # we need to access the private Bionic header <bionic_tls.h> -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif LOCAL_C_INCLUDES += bionic/libc/private LOCAL_CFLAGS += -DLOG_TAG=\"libGLESv1\" LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_CFLAGS += -fvisibility=hidden -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif - include $(BUILD_SHARED_LIBRARY) @@ -122,25 +110,18 @@ LOCAL_SRC_FILES:= \ GLES2/gl2.cpp.arm \ # -LOCAL_SHARED_LIBRARIES += libcutils libEGL +LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL LOCAL_LDLIBS := -lpthread -ldl LOCAL_MODULE:= libGLESv2 LOCAL_SHARED_LIBRARIES += libdl # we need to access the private Bionic header <bionic_tls.h> -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif LOCAL_C_INCLUDES += bionic/libc/private LOCAL_CFLAGS += -DLOG_TAG=\"libGLESv2\" LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_CFLAGS += -fvisibility=hidden -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif - include $(BUILD_SHARED_LIBRARY) ############################################################################### diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index b658240..0d4bed5 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -62,12 +62,18 @@ EGLAPI pthread_key_t gGLTraceKey = -1; // ---------------------------------------------------------------------------- /** - * There are two different tracing methods: - * 1. libs/EGL/trace.cpp: Traces all functions to logcat. + * There are three different tracing methods: + * 1. libs/EGL/trace.cpp: Traces all functions to systrace. + * To enable: + * - set system property "debug.egl.trace" to "systrace" to trace all apps. + * 2. libs/EGL/trace.cpp: Logs a stack trace for GL errors after each function call. + * To enable: + * - set system property "debug.egl.trace" to "error" to trace all apps. + * 3. libs/EGL/trace.cpp: Traces all functions to logcat. * To enable: * - set system property "debug.egl.trace" to 1 to trace all apps. * - or call setGLTraceLevel(1) from an app to enable tracing for that app. - * 2. libs/GLES_trace: Traces all functions via protobuf to host. + * 4. libs/GLES_trace: Traces all functions via protobuf to host. * To enable: * - set system property "debug.egl.debug_proc" to the application name. * - or call setGLDebugLevel(1) from the app. @@ -75,10 +81,15 @@ EGLAPI pthread_key_t gGLTraceKey = -1; static int sEGLTraceLevel; static int sEGLApplicationTraceLevel; +static bool sEGLSystraceEnabled; +static bool sEGLGetErrorEnabled; + int gEGLDebugLevel; static int sEGLApplicationDebugLevel; extern gl_hooks_t gHooksTrace; +extern gl_hooks_t gHooksSystrace; +extern gl_hooks_t gHooksErrorTrace; static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { pthread_setspecific(gGLTraceKey, value); @@ -91,6 +102,20 @@ gl_hooks_t const* getGLTraceThreadSpecific() { void initEglTraceLevel() { char value[PROPERTY_VALUE_MAX]; property_get("debug.egl.trace", value, "0"); + + sEGLGetErrorEnabled = !strcasecmp(value, "error"); + if (sEGLGetErrorEnabled) { + sEGLSystraceEnabled = false; + sEGLTraceLevel = 0; + return; + } + + sEGLSystraceEnabled = !strcasecmp(value, "systrace"); + if (sEGLSystraceEnabled) { + sEGLTraceLevel = 0; + return; + } + int propertyLevel = atoi(value); int applicationLevel = sEGLApplicationTraceLevel; sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; @@ -99,6 +124,12 @@ void initEglTraceLevel() { void initEglDebugLevel() { int propertyLevel = 0; char value[PROPERTY_VALUE_MAX]; + + // check system property only on userdebug or eng builds + property_get("ro.debuggable", value, "0"); + if (value[0] == '0') + return; + property_get("debug.egl.debug_proc", value, ""); if (strlen(value) > 0) { long pid = getpid(); @@ -125,7 +156,13 @@ void initEglDebugLevel() { } void setGLHooksThreadSpecific(gl_hooks_t const *value) { - if (sEGLTraceLevel > 0) { + if (sEGLGetErrorEnabled) { + setGlTraceThreadSpecific(value); + setGlThreadSpecific(&gHooksErrorTrace); + } else if (sEGLSystraceEnabled) { + setGlTraceThreadSpecific(value); + setGlThreadSpecific(&gHooksSystrace); + } else if (sEGLTraceLevel > 0) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksTrace); } else if (gEGLDebugLevel > 0 && value != &gHooksNoContext) { @@ -166,8 +203,13 @@ void setGLHooksThreadSpecific(gl_hooks_t const *value) { static int gl_no_context() { if (egl_tls_t::logNoContextCall()) { - ALOGE("call to OpenGL ES API with no current context " - "(logged once per thread)"); + char const* const error = "call to OpenGL ES API with " + "no current context (logged once per thread)"; + if (LOG_NDEBUG) { + ALOGE(error); + } else { + LOG_ALWAYS_FATAL(error); + } char value[PROPERTY_VALUE_MAX]; property_get("debug.egl.callstack", value, "0"); if (atoi(value)) { diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index c943ec1..c25612d 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -204,6 +204,59 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, egl_connection_t* const cnx = &gEGLImpl; if (cnx->dso) { + if (attrib_list) { + char value[PROPERTY_VALUE_MAX]; + property_get("debug.egl.force_msaa", value, "false"); + + if (!strcmp(value, "true")) { + size_t attribCount = 0; + EGLint attrib = attrib_list[0]; + + // Only enable MSAA if the context is OpenGL ES 2.0 and + // if no caveat is requested + const EGLint *attribRendererable = NULL; + const EGLint *attribCaveat = NULL; + + // Count the number of attributes and look for + // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT + while (attrib != EGL_NONE) { + attrib = attrib_list[attribCount]; + switch (attrib) { + case EGL_RENDERABLE_TYPE: + attribRendererable = &attrib_list[attribCount]; + break; + case EGL_CONFIG_CAVEAT: + attribCaveat = &attrib_list[attribCount]; + break; + } + attribCount++; + } + + if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && + (!attribCaveat || attribCaveat[1] != EGL_NONE)) { + + // Insert 2 extra attributes to force-enable MSAA 4x + EGLint aaAttribs[attribCount + 4]; + aaAttribs[0] = EGL_SAMPLE_BUFFERS; + aaAttribs[1] = 1; + aaAttribs[2] = EGL_SAMPLES; + aaAttribs[3] = 4; + + memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); + + EGLint numConfigAA; + EGLBoolean resAA = cnx->egl.eglChooseConfig( + dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); + + if (resAA == EGL_TRUE && numConfigAA > 0) { + ALOGD("Enabling MSAA 4x"); + *num_config = numConfigAA; + return resAA; + } + } + } + } + res = cnx->egl.eglChooseConfig( dp->disp.dpy, attrib_list, configs, config_size, num_config); } @@ -419,6 +472,12 @@ EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, GLTrace_eglCreateContext(version, c); #endif return c; + } else { + EGLint error = eglGetError(); + ALOGE_IF(error == EGL_SUCCESS, + "eglCreateContext(%p, %p, %p, %p) returned EGL_NO_CONTEXT " + "but no EGL error!", + dpy, config, share_list, attrib_list); } } return EGL_NO_CONTEXT; @@ -657,6 +716,8 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) // These extensions should not be exposed to applications. They're used // internally by the Android EGL layer. if (!strcmp(procname, "eglSetBlobCacheFuncsANDROID") || + !strcmp(procname, "eglDupNativeFenceFDANDROID") || + !strcmp(procname, "eglWaitSyncANDROID") || !strcmp(procname, "eglHibernateProcessIMG") || !strcmp(procname, "eglAwakenProcessIMG")) { return NULL; @@ -704,8 +765,8 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) egl_connection_t* const cnx = &gEGLImpl; if (cnx->dso && cnx->egl.eglGetProcAddress) { - found = true; // Extensions are independent of the bound context + addr = cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = #if EGL_TRACE @@ -713,10 +774,13 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) gHooksTrace.ext.extensions[slot] = #endif cnx->egl.eglGetProcAddress(procname); + if (addr) found = true; } if (found) { +#if USE_FAST_TLS_KEY addr = gExtensionForwarders[slot]; +#endif sGLExtentionMap.add(name, addr); sGLExtentionSlot++; } @@ -1115,11 +1179,12 @@ EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; + EGLBoolean result = EGL_FALSE; egl_connection_t* const cnx = &gEGLImpl; if (cnx->dso && cnx->egl.eglDestroyImageKHR) { - cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); + result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); } - return EGL_TRUE; + return result; } // ---------------------------------------------------------------------------- @@ -1195,7 +1260,35 @@ EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, // ANDROID extensions // ---------------------------------------------------------------------------- -/* ANDROID extensions entry-point go here */ +EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) +{ + clearError(); + + const egl_display_ptr dp = validate_display(dpy); + if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; + + EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; + egl_connection_t* const cnx = &gEGLImpl; + if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { + result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); + } + return result; +} + +EGLint eglWaitSyncANDROID(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) +{ + clearError(); + + const egl_display_ptr dp = validate_display(dpy); + if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; + + EGLint result = EGL_FALSE; + egl_connection_t* const cnx = &gEGLImpl; + if (cnx->dso && cnx->egl.eglWaitSyncANDROID) { + result = cnx->egl.eglWaitSyncANDROID(dp->disp.dpy, sync, flags); + } + return result; +} // ---------------------------------------------------------------------------- // NVIDIA extensions diff --git a/opengl/libs/EGL/egl_cache.cpp b/opengl/libs/EGL/egl_cache.cpp index ed2bef3..72655df 100644 --- a/opengl/libs/EGL/egl_cache.cpp +++ b/opengl/libs/EGL/egl_cache.cpp @@ -29,12 +29,16 @@ #define MAX_EGL_CACHE_ENTRY_SIZE (16 * 1024); #endif +#ifndef MAX_EGL_CACHE_KEY_SIZE +#define MAX_EGL_CACHE_KEY_SIZE (1024); +#endif + #ifndef MAX_EGL_CACHE_SIZE #define MAX_EGL_CACHE_SIZE (64 * 1024); #endif // Cache size limits. -static const size_t maxKeySize = 1024; +static const size_t maxKeySize = MAX_EGL_CACHE_KEY_SIZE; static const size_t maxValueSize = MAX_EGL_CACHE_ENTRY_SIZE; static const size_t maxTotalSize = MAX_EGL_CACHE_SIZE; diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index a46aa38..7ca9e40 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -52,13 +52,16 @@ static char const * const sExtensionString = "EGL_KHR_gl_texture_cubemap_image " "EGL_KHR_gl_renderbuffer_image " "EGL_KHR_fence_sync " + "EGL_EXT_create_context_robustness " "EGL_NV_system_time " "EGL_ANDROID_image_native_buffer " // mandatory ; // extensions not exposed to applications but used by the ANDROID system // "EGL_ANDROID_recordable " // mandatory +// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 // "EGL_ANDROID_blob_cache " // strongly recommended +// "EGL_ANDROID_native_fence_sync " // strongly recommended // "EGL_IMG_hibernate_process " // optional extern void initEglTraceLevel(); @@ -263,7 +266,13 @@ EGLBoolean egl_display_t::terminate() { Mutex::Autolock _l(lock); if (refs == 0) { - return setError(EGL_NOT_INITIALIZED, EGL_FALSE); + /* + * From the EGL spec (3.2): + * "Termination of a display that has already been terminated, + * (...), is allowed, but the only effect of such a call is + * to return EGL_TRUE (...) + */ + return EGL_TRUE; } // this is specific to Android, display termination is ref-counted. @@ -286,6 +295,10 @@ EGLBoolean egl_display_t::terminate() { mHibernation.setDisplayValid(false); + // Reset the extension string since it will be regenerated if we get + // reinitialized. + mExtensionString.setTo(""); + // Mark all objects remaining in the list as terminated, unless // there are no reference to them, it which case, we're free to // delete them. diff --git a/opengl/libs/EGL/egl_entries.in b/opengl/libs/EGL/egl_entries.in index 9feb716..2ffd417 100644 --- a/opengl/libs/EGL/egl_entries.in +++ b/opengl/libs/EGL/egl_entries.in @@ -62,6 +62,8 @@ EGL_ENTRY(EGLBoolean, eglGetSyncAttribKHR, EGLDisplay, EGLSyncKHR, EGLint, EGL_ENTRY(EGLBoolean, eglSetSwapRectangleANDROID, EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint) EGL_ENTRY(EGLClientBuffer, eglGetRenderBufferANDROID, EGLDisplay, EGLSurface) +EGL_ENTRY(EGLint, eglDupNativeFenceFDANDROID, EGLDisplay, EGLSyncKHR) +EGL_ENTRY(EGLint, eglWaitSyncANDROID, EGLDisplay, EGLSyncKHR, EGLint) /* NVIDIA extensions */ diff --git a/opengl/libs/EGL/getProcAddress.cpp b/opengl/libs/EGL/getProcAddress.cpp index 8dcf38d..d23da7a 100644 --- a/opengl/libs/EGL/getProcAddress.cpp +++ b/opengl/libs/EGL/getProcAddress.cpp @@ -37,14 +37,9 @@ namespace android { #if USE_FAST_TLS_KEY - #ifdef HAVE_ARM_TLS_REGISTER - #define GET_TLS(reg) \ - "mrc p15, 0, " #reg ", c13, c0, 3 \n" - #else - #define GET_TLS(reg) \ - "mov " #reg ", #0xFFFF0FFF \n" \ - "ldr " #reg ", [" #reg ", #-15] \n" - #endif + #if defined(__arm__) + + #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" #define API_ENTRY(_api) __attribute__((naked)) _api @@ -64,6 +59,41 @@ namespace android { : \ ); + #elif defined(__mips__) + + #define API_ENTRY(_api) __attribute__((noinline)) _api + + #define CALL_GL_EXTENSION_API(_api, ...) \ + register unsigned int t0 asm("t0"); \ + register unsigned int fn asm("t1"); \ + register unsigned int tls asm("v1"); \ + asm volatile( \ + ".set push\n\t" \ + ".set noreorder\n\t" \ + ".set mips32r2\n\t" \ + "rdhwr %[tls], $29\n\t" \ + "lw %[t0], %[OPENGL_API](%[tls])\n\t" \ + "beqz %[t0], 1f\n\t" \ + " move %[fn], $ra\n\t" \ + "lw %[fn], %[API](%[t0])\n\t" \ + "movz %[fn], $ra, %[fn]\n\t" \ + "1:\n\t" \ + "j %[fn]\n\t" \ + " nop\n\t" \ + ".set pop\n\t" \ + : [fn] "=c"(fn), \ + [tls] "=&r"(tls), \ + [t0] "=&r"(t0) \ + : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ + [API] "I"(__builtin_offsetof(gl_hooks_t, \ + ext.extensions[_api])) \ + : \ + ); + + #else + #error Unsupported architecture + #endif + #define GL_EXTENSION_NAME(_n) __glExtFwd##_n #define GL_EXTENSION(_n) \ diff --git a/opengl/libs/EGL/trace.cpp b/opengl/libs/EGL/trace.cpp index 52907c1..a51b086 100644 --- a/opengl/libs/EGL/trace.cpp +++ b/opengl/libs/EGL/trace.cpp @@ -26,6 +26,11 @@ #include <cutils/log.h> +#define ATRACE_TAG ATRACE_TAG_GRAPHICS +#include <utils/Trace.h> + +#include <utils/CallStack.h> + #include "egl_tls.h" #include "hooks.h" @@ -314,6 +319,10 @@ static void TraceGL(const char* name, int numArgs, ...) { va_end(argp); } +/////////////////////////////////////////////////////////////////////////// +// Log trace +/////////////////////////////////////////////////////////////////////////// + #undef TRACE_GL_VOID #undef TRACE_GL @@ -349,7 +358,6 @@ EGLAPI gl_hooks_t gHooksTrace = { }; #undef GL_ENTRY - #undef TRACE_GL_VOID #undef TRACE_GL @@ -372,6 +380,99 @@ extern "C" { #include "../debug.in" } +/////////////////////////////////////////////////////////////////////////// +// Systrace +/////////////////////////////////////////////////////////////////////////// + +#undef TRACE_GL_VOID +#undef TRACE_GL + +#define TRACE_GL_VOID(_api, _args, _argList, ...) \ +static void Systrace_ ## _api _args { \ + ATRACE_NAME(#_api); \ + gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl; \ + _c->_api _argList; \ +} + +#define TRACE_GL(_type, _api, _args, _argList, ...) \ +static _type Systrace_ ## _api _args { \ + ATRACE_NAME(#_api); \ + gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl; \ + return _c->_api _argList; \ +} + +extern "C" { +#include "../trace.in" +} + +#undef TRACE_GL_VOID +#undef TRACE_GL + +#define GL_ENTRY(_r, _api, ...) Systrace_ ## _api, +EGLAPI gl_hooks_t gHooksSystrace = { + { + #include "entries.in" + }, + { + {0} + } +}; +#undef GL_ENTRY + +/////////////////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////////////////// + +#undef TRACE_GL_VOID +#undef TRACE_GL + +#define CHECK_ERROR(_c, _api) \ + GLenum status = GL_NO_ERROR; \ + bool error = false; \ + while ((status = _c->glGetError()) != GL_NO_ERROR) { \ + ALOGD("[" #_api "] 0x%x", status); \ + error = true; \ + } \ + if (error) { \ + CallStack s; \ + s.update(); \ + s.dump("glGetError:" #_api); \ + } \ + +#define TRACE_GL_VOID(_api, _args, _argList, ...) \ +static void ErrorTrace_ ## _api _args { \ + gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl; \ + _c->_api _argList; \ + CHECK_ERROR(_c, _api); \ +} + +#define TRACE_GL(_type, _api, _args, _argList, ...) \ +static _type ErrorTrace_ ## _api _args { \ + gl_hooks_t::gl_t const * const _c = &getGLTraceThreadSpecific()->gl; \ + _type _r = _c->_api _argList; \ + CHECK_ERROR(_c, _api); \ + return _r; \ +} + +extern "C" { +#include "../trace.in" +} + +#undef TRACE_GL_VOID +#undef TRACE_GL + +#define GL_ENTRY(_r, _api, ...) ErrorTrace_ ## _api, +EGLAPI gl_hooks_t gHooksErrorTrace = { + { + #include "entries.in" + }, + { + {0} + } +}; +#undef GL_ENTRY +#undef CHECK_ERROR + #undef TRACE_GL_VOID #undef TRACE_GL diff --git a/opengl/libs/GLES2/gl2.cpp b/opengl/libs/GLES2/gl2.cpp index 4345c2b..fb890fc 100644 --- a/opengl/libs/GLES2/gl2.cpp +++ b/opengl/libs/GLES2/gl2.cpp @@ -39,18 +39,11 @@ using namespace android; #undef CALL_GL_API #undef CALL_GL_API_RETURN -#define DEBUG_CALL_GL_API 0 - #if USE_FAST_TLS_KEY - #ifdef HAVE_ARM_TLS_REGISTER - #define GET_TLS(reg) \ - "mrc p15, 0, " #reg ", c13, c0, 3 \n" - #else - #define GET_TLS(reg) \ - "mov " #reg ", #0xFFFF0FFF \n" \ - "ldr " #reg ", [" #reg ", #-15] \n" - #endif + #if defined(__arm__) + + #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" #define API_ENTRY(_api) __attribute__((naked)) _api @@ -68,6 +61,44 @@ using namespace android; : \ ); + #elif defined(__mips__) + + #define API_ENTRY(_api) __attribute__((noinline)) _api + + #define CALL_GL_API(_api, ...) \ + register unsigned int t0 asm("t0"); \ + register unsigned int fn asm("t1"); \ + register unsigned int tls asm("v1"); \ + register unsigned int v0 asm("v0"); \ + asm volatile( \ + ".set push\n\t" \ + ".set noreorder\n\t" \ + ".set mips32r2\n\t" \ + "rdhwr %[tls], $29\n\t" \ + "lw %[t0], %[OPENGL_API](%[tls])\n\t" \ + "beqz %[t0], 1f\n\t" \ + " move %[fn],$ra\n\t" \ + "lw %[fn], %[API](%[t0])\n\t" \ + "movz %[fn], $ra, %[fn]\n\t" \ + "1:\n\t" \ + "j %[fn]\n\t" \ + " move %[v0], $0\n\t" \ + ".set pop\n\t" \ + : [fn] "=c"(fn), \ + [tls] "=&r"(tls), \ + [t0] "=&r"(t0), \ + [v0] "=&r"(v0) \ + : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ + [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ + : \ + ); + + #else + + #error Unsupported architecture + + #endif + #define CALL_GL_API_RETURN(_api, ...) \ CALL_GL_API(_api, __VA_ARGS__) \ return 0; // placate gcc's warnings. never reached. @@ -76,24 +107,10 @@ using namespace android; #define API_ENTRY(_api) _api -#if DEBUG_CALL_GL_API - - #define CALL_GL_API(_api, ...) \ - gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ - _c->_api(__VA_ARGS__); \ - GLenum status = GL_NO_ERROR; \ - while ((status = glGetError()) != GL_NO_ERROR) { \ - ALOGD("[" #_api "] 0x%x", status); \ - } - -#else - #define CALL_GL_API(_api, ...) \ gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ _c->_api(__VA_ARGS__); -#endif - #define CALL_GL_API_RETURN(_api, ...) \ gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ return _c->_api(__VA_ARGS__) diff --git a/opengl/libs/GLES2/gl2_api.in b/opengl/libs/GLES2/gl2_api.in index 9a89a52..cccf46c 100644 --- a/opengl/libs/GLES2/gl2_api.in +++ b/opengl/libs/GLES2/gl2_api.in @@ -169,7 +169,7 @@ void API_ENTRY(glGetActiveUniform)(GLuint program, GLuint index, GLsizei bufsize void API_ENTRY(glGetAttachedShaders)(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) { CALL_GL_API(glGetAttachedShaders, program, maxcount, count, shaders); } -int API_ENTRY(glGetAttribLocation)(GLuint program, const GLchar* name) { +GLint API_ENTRY(glGetAttribLocation)(GLuint program, const GLchar* name) { CALL_GL_API_RETURN(glGetAttribLocation, program, name); } void API_ENTRY(glGetBooleanv)(GLenum pname, GLboolean* params) { @@ -226,7 +226,7 @@ void API_ENTRY(glGetUniformfv)(GLuint program, GLint location, GLfloat* params) void API_ENTRY(glGetUniformiv)(GLuint program, GLint location, GLint* params) { CALL_GL_API(glGetUniformiv, program, location, params); } -int API_ENTRY(glGetUniformLocation)(GLuint program, const GLchar* name) { +GLint API_ENTRY(glGetUniformLocation)(GLuint program, const GLchar* name) { CALL_GL_API_RETURN(glGetUniformLocation, program, name); } void API_ENTRY(glGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat* params) { diff --git a/opengl/libs/GLES_CM/gl.cpp b/opengl/libs/GLES_CM/gl.cpp index adcb60d..bd08942 100644 --- a/opengl/libs/GLES_CM/gl.cpp +++ b/opengl/libs/GLES_CM/gl.cpp @@ -97,14 +97,9 @@ GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, #if USE_FAST_TLS_KEY && !CHECK_FOR_GL_ERRORS - #ifdef HAVE_ARM_TLS_REGISTER - #define GET_TLS(reg) \ - "mrc p15, 0, " #reg ", c13, c0, 3 \n" - #else - #define GET_TLS(reg) \ - "mov " #reg ", #0xFFFF0FFF \n" \ - "ldr " #reg ", [" #reg ", #-15] \n" - #endif + #if defined(__arm__) + + #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" #define API_ENTRY(_api) __attribute__((naked)) _api @@ -122,6 +117,42 @@ GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, : \ ); + #elif defined(__mips__) + + #define API_ENTRY(_api) __attribute__((noinline)) _api + + #define CALL_GL_API(_api, ...) \ + register unsigned int t0 asm("t0"); \ + register unsigned int fn asm("t1"); \ + register unsigned int tls asm("v1"); \ + register unsigned int v0 asm("v0"); \ + asm volatile( \ + ".set push\n\t" \ + ".set noreorder\n\t" \ + ".set mips32r2\n\t" \ + "rdhwr %[tls], $29\n\t" \ + "lw %[t0], %[OPENGL_API](%[tls])\n\t" \ + "beqz %[t0], 1f\n\t" \ + " move %[fn], $ra\n\t" \ + "lw %[fn], %[API](%[t0])\n\t" \ + "movz %[fn], $ra, %[fn]\n\t" \ + "1:\n\t" \ + "j %[fn]\n\t" \ + " move %[v0], $0\n\t" \ + ".set pop\n\t" \ + : [fn] "=c"(fn), \ + [tls] "=&r"(tls), \ + [t0] "=&r"(t0), \ + [v0] "=&r"(v0) \ + : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ + [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ + : \ + ); + + #else + #error Unsupported architecture + #endif + #define CALL_GL_API_RETURN(_api, ...) \ CALL_GL_API(_api, __VA_ARGS__) \ return 0; // placate gcc's warnings. never reached. diff --git a/opengl/libs/GLES_trace/Android.mk b/opengl/libs/GLES_trace/Android.mk index 465b6b2..9dec020 100644 --- a/opengl/libs/GLES_trace/Android.mk +++ b/opengl/libs/GLES_trace/Android.mk @@ -24,18 +24,9 @@ LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI LOCAL_STATIC_LIBRARIES := libprotobuf-cpp-2.3.0-lite liblzf LOCAL_SHARED_LIBRARIES := libcutils libutils libstlport -ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif - LOCAL_CFLAGS += -DLOG_TAG=\"libGLES_trace\" # we need to access the private Bionic header <bionic_tls.h> -# on ARM platforms, we need to mirror the ARCH_ARM_HAVE_TLS_REGISTER -# behavior from the bionic Android.mk file -ifeq ($(TARGET_ARCH)-$(ARCH_ARM_HAVE_TLS_REGISTER),arm-true) - LOCAL_CFLAGS += -DHAVE_ARM_TLS_REGISTER -endif LOCAL_C_INCLUDES += bionic/libc/private LOCAL_MODULE:= libGLES_trace diff --git a/opengl/libs/GLES_trace/src/gltrace_api.cpp b/opengl/libs/GLES_trace/src/gltrace_api.cpp index cef6cbb..2ae4b11 100644 --- a/opengl/libs/GLES_trace/src/gltrace_api.cpp +++ b/opengl/libs/GLES_trace/src/gltrace_api.cpp @@ -2214,7 +2214,7 @@ void GLTrace_glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* cou glContext->traceGLMessage(&glmsg); } -int GLTrace_glGetAttribLocation(GLuint program, const GLchar* name) { +GLint GLTrace_glGetAttribLocation(GLuint program, const GLchar* name) { GLMessage glmsg; GLTraceContext *glContext = getGLTraceContext(); @@ -2235,7 +2235,7 @@ int GLTrace_glGetAttribLocation(GLuint program, const GLchar* name) { // call function nsecs_t wallStartTime = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t threadStartTime = systemTime(SYSTEM_TIME_THREAD); - int retValue = glContext->hooks->gl.glGetAttribLocation(program, name); + GLint retValue = glContext->hooks->gl.glGetAttribLocation(program, name); nsecs_t threadEndTime = systemTime(SYSTEM_TIME_THREAD); nsecs_t wallEndTime = systemTime(SYSTEM_TIME_MONOTONIC); @@ -2996,7 +2996,7 @@ void GLTrace_glGetUniformiv(GLuint program, GLint location, GLint* params) { glContext->traceGLMessage(&glmsg); } -int GLTrace_glGetUniformLocation(GLuint program, const GLchar* name) { +GLint GLTrace_glGetUniformLocation(GLuint program, const GLchar* name) { GLMessage glmsg; GLTraceContext *glContext = getGLTraceContext(); @@ -3017,7 +3017,7 @@ int GLTrace_glGetUniformLocation(GLuint program, const GLchar* name) { // call function nsecs_t wallStartTime = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t threadStartTime = systemTime(SYSTEM_TIME_THREAD); - int retValue = glContext->hooks->gl.glGetUniformLocation(program, name); + GLint retValue = glContext->hooks->gl.glGetUniformLocation(program, name); nsecs_t threadEndTime = systemTime(SYSTEM_TIME_THREAD); nsecs_t wallEndTime = systemTime(SYSTEM_TIME_MONOTONIC); diff --git a/opengl/libs/GLES_trace/src/gltrace_api.h b/opengl/libs/GLES_trace/src/gltrace_api.h index debcac0..309afcb 100644 --- a/opengl/libs/GLES_trace/src/gltrace_api.h +++ b/opengl/libs/GLES_trace/src/gltrace_api.h @@ -78,7 +78,7 @@ void GLTrace_glGenTextures(GLsizei n, GLuint* textures); void GLTrace_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); void GLTrace_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); void GLTrace_glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); -int GLTrace_glGetAttribLocation(GLuint program, const GLchar* name); +GLint GLTrace_glGetAttribLocation(GLuint program, const GLchar* name); void GLTrace_glGetBooleanv(GLenum pname, GLboolean* params); void GLTrace_glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params); GLenum GLTrace_glGetError(void); @@ -97,7 +97,7 @@ void GLTrace_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); void GLTrace_glGetTexParameteriv(GLenum target, GLenum pname, GLint* params); void GLTrace_glGetUniformfv(GLuint program, GLint location, GLfloat* params); void GLTrace_glGetUniformiv(GLuint program, GLint location, GLint* params); -int GLTrace_glGetUniformLocation(GLuint program, const GLchar* name); +GLint GLTrace_glGetUniformLocation(GLuint program, const GLchar* name); void GLTrace_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); void GLTrace_glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params); void GLTrace_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer); diff --git a/opengl/libs/GLES_trace/src/gltrace_context.cpp b/opengl/libs/GLES_trace/src/gltrace_context.cpp index 45dbb43..3a8decc 100644 --- a/opengl/libs/GLES_trace/src/gltrace_context.cpp +++ b/opengl/libs/GLES_trace/src/gltrace_context.cpp @@ -119,7 +119,7 @@ GLTraceContext *GLTraceState::createTraceContext(int version, EGLContext eglCont const size_t DEFAULT_BUFFER_SIZE = 8192; BufferedOutputStream *stream = new BufferedOutputStream(mStream, DEFAULT_BUFFER_SIZE); - GLTraceContext *traceContext = new GLTraceContext(id, this, stream); + GLTraceContext *traceContext = new GLTraceContext(id, version, this, stream); mPerContextState[eglContext] = traceContext; return traceContext; @@ -129,8 +129,10 @@ GLTraceContext *GLTraceState::getTraceContext(EGLContext c) { return mPerContextState[c]; } -GLTraceContext::GLTraceContext(int id, GLTraceState *state, BufferedOutputStream *stream) : +GLTraceContext::GLTraceContext(int id, int version, GLTraceState *state, + BufferedOutputStream *stream) : mId(id), + mVersion(version), mState(state), mBufferedOutputStream(stream), mElementArrayBuffers(DefaultKeyedVector<GLuint, ElementArrayBuffer*>(NULL)) @@ -143,6 +145,10 @@ int GLTraceContext::getId() { return mId; } +int GLTraceContext::getVersion() { + return mVersion; +} + GLTraceState *GLTraceContext::getGlobalTraceState() { return mState; } @@ -203,6 +209,8 @@ void GLTraceContext::traceGLMessage(GLMessage *msg) { GLMessage_Function func = msg->function(); if (func == GLMessage::eglSwapBuffers + || func == GLMessage::eglCreateContext + || func == GLMessage::eglMakeCurrent || func == GLMessage::glDrawArrays || func == GLMessage::glDrawElements) { mBufferedOutputStream->flush(); diff --git a/opengl/libs/GLES_trace/src/gltrace_context.h b/opengl/libs/GLES_trace/src/gltrace_context.h index 323cfdc..4c38bba 100644 --- a/opengl/libs/GLES_trace/src/gltrace_context.h +++ b/opengl/libs/GLES_trace/src/gltrace_context.h @@ -50,6 +50,7 @@ public: /** GL Trace Context info associated with each EGLContext */ class GLTraceContext { int mId; /* unique context id */ + int mVersion; /* GL version, e.g: egl_connection_t::GLESv2_INDEX */ GLTraceState *mState; /* parent GL Trace state (for per process GL Trace State Info) */ void *fbcontents; /* memory area to read framebuffer contents */ @@ -65,8 +66,9 @@ class GLTraceContext { public: gl_hooks_t *hooks; - GLTraceContext(int id, GLTraceState *state, BufferedOutputStream *stream); + GLTraceContext(int id, int version, GLTraceState *state, BufferedOutputStream *stream); int getId(); + int getVersion(); GLTraceState *getGlobalTraceState(); void getCompressedFB(void **fb, unsigned *fbsize, unsigned *fbwidth, unsigned *fbheight, diff --git a/opengl/libs/GLES_trace/src/gltrace_fixup.cpp b/opengl/libs/GLES_trace/src/gltrace_fixup.cpp index 3597b26..36ae314 100644 --- a/opengl/libs/GLES_trace/src/gltrace_fixup.cpp +++ b/opengl/libs/GLES_trace/src/gltrace_fixup.cpp @@ -15,6 +15,7 @@ */ #include <cutils/log.h> +#include <EGL/egldefs.h> #include <GLES/gl.h> #include <GLES/glext.h> #include <GLES2/gl2.h> @@ -340,7 +341,7 @@ void fixup_glLinkProgram(GLMessage *glmsg) { /** Given a glGetActive[Uniform|Attrib] call, obtain the location * of the variable of given name in the call. */ -int getShaderVariableLocation(GLTraceContext *context, GLMessage *glmsg, GLchar *name) { +GLint getShaderVariableLocation(GLTraceContext *context, GLMessage *glmsg, GLchar *name) { GLMessage_Function func = glmsg->function(); if (func != GLMessage::glGetActiveAttrib && func != GLMessage::glGetActiveUniform) { return -1; @@ -373,7 +374,7 @@ void fixup_glGetActiveAttribOrUniform(GLTraceContext *context, GLMessage *glmsg, // In order to make things simpler for the debugger, we also pass // a hidden location argument that stores the actual location. // append the location value to the end of the argument list - int location = getShaderVariableLocation(context, glmsg, (GLchar*)pointersToFixup[3]); + GLint location = getShaderVariableLocation(context, glmsg, (GLchar*)pointersToFixup[3]); GLMessage_DataType *arg_location = glmsg->add_args(); arg_location->set_isarray(false); arg_location->set_type(GLMessage::DataType::INT); @@ -592,6 +593,11 @@ void trace_VertexAttribPointerData(GLTraceContext *context, } void trace_VertexAttribPointerDataForGlDrawArrays(GLTraceContext *context, GLMessage *glmsg) { + if (context->getVersion() == egl_connection_t::GLESv1_INDEX) { + // only supported for GLES2 and above + return; + } + /* void glDrawArrays(GLenum mode, GLint first, GLsizei count) */ GLsizei count = glmsg->args(2).intvalue(0); @@ -604,6 +610,11 @@ void trace_VertexAttribPointerDataForGlDrawArrays(GLTraceContext *context, GLMes void trace_VertexAttribPointerDataForGlDrawElements(GLTraceContext *context, GLMessage *glmsg, GLvoid *indices) { + if (context->getVersion() == egl_connection_t::GLESv1_INDEX) { + // only supported for GLES2 and above + return; + } + /* void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) */ GLsizei count = glmsg->args(1).intvalue(0); GLenum type = glmsg->args(2).intvalue(0); diff --git a/opengl/libs/entries.in b/opengl/libs/entries.in index 6316d78..b9a51a4 100644 --- a/opengl/libs/entries.in +++ b/opengl/libs/entries.in @@ -160,7 +160,7 @@ GL_ENTRY(void, glGenerateMipmapOES, GLenum target) GL_ENTRY(void, glGetActiveAttrib, GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) GL_ENTRY(void, glGetActiveUniform, GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) GL_ENTRY(void, glGetAttachedShaders, GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) -GL_ENTRY(int, glGetAttribLocation, GLuint program, const GLchar* name) +GL_ENTRY(GLint, glGetAttribLocation, GLuint program, const GLchar* name) GL_ENTRY(void, glGetBooleanv, GLenum pname, GLboolean *params) GL_ENTRY(void, glGetBufferParameteriv, GLenum target, GLenum pname, GLint *params) GL_ENTRY(void, glGetBufferPointervOES, GLenum target, GLenum pname, GLvoid ** params) @@ -218,7 +218,7 @@ GL_ENTRY(void, glGetTexParameterfv, GLenum target, GLenum pname, GLfloat *params GL_ENTRY(void, glGetTexParameteriv, GLenum target, GLenum pname, GLint *params) GL_ENTRY(void, glGetTexParameterxv, GLenum target, GLenum pname, GLfixed *params) GL_ENTRY(void, glGetTexParameterxvOES, GLenum target, GLenum pname, GLfixed *params) -GL_ENTRY(int, glGetUniformLocation, GLuint program, const GLchar* name) +GL_ENTRY(GLint, glGetUniformLocation, GLuint program, const GLchar* name) GL_ENTRY(void, glGetUniformfv, GLuint program, GLint location, GLfloat* params) GL_ENTRY(void, glGetUniformiv, GLuint program, GLint location, GLint* params) GL_ENTRY(void, glGetVertexAttribPointerv, GLuint index, GLenum pname, GLvoid** pointer) diff --git a/opengl/libs/hooks.h b/opengl/libs/hooks.h index 8b1b389..e0ceb60 100644 --- a/opengl/libs/hooks.h +++ b/opengl/libs/hooks.h @@ -30,7 +30,7 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> -#if !defined(__arm__) +#if !defined(__arm__) && !defined(__mips__) #define USE_SLOW_BINDING 1 #else #define USE_SLOW_BINDING 0 diff --git a/opengl/libs/trace.in b/opengl/libs/trace.in index a5c5c84..e89e456 100644 --- a/opengl/libs/trace.in +++ b/opengl/libs/trace.in @@ -160,7 +160,7 @@ TRACE_GL_VOID(glGenerateMipmapOES, (GLenum target), (target), 1, "GLenum", targe TRACE_GL_VOID(glGetActiveAttrib, (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name), (program, index, bufsize, length, size, type, name), 7, "GLuint", program, "GLuint", index, "GLsizei", bufsize, "GLsizei*", length, "GLint*", size, "GLenum*", type, "GLchar*", name) TRACE_GL_VOID(glGetActiveUniform, (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name), (program, index, bufsize, length, size, type, name), 7, "GLuint", program, "GLuint", index, "GLsizei", bufsize, "GLsizei*", length, "GLint*", size, "GLenum*", type, "GLchar*", name) TRACE_GL_VOID(glGetAttachedShaders, (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders), (program, maxcount, count, shaders), 4, "GLuint", program, "GLsizei", maxcount, "GLsizei*", count, "GLuint*", shaders) -TRACE_GL(int, glGetAttribLocation, (GLuint program, const GLchar* name), (program, name), 2, "GLuint", program, "const GLchar*", name) +TRACE_GL(GLint, glGetAttribLocation, (GLuint program, const GLchar* name), (program, name), 2, "GLuint", program, "const GLchar*", name) TRACE_GL_VOID(glGetBooleanv, (GLenum pname, GLboolean *params), (pname, params), 2, "GLenum", pname, "GLboolean *", params) TRACE_GL_VOID(glGetBufferParameteriv, (GLenum target, GLenum pname, GLint *params), (target, pname, params), 3, "GLenum", target, "GLenum", pname, "GLint *", params) TRACE_GL_VOID(glGetBufferPointervOES, (GLenum target, GLenum pname, GLvoid ** params), (target, pname, params), 3, "GLenum", target, "GLenum", pname, "GLvoid **", params) @@ -218,7 +218,7 @@ TRACE_GL_VOID(glGetTexParameterfv, (GLenum target, GLenum pname, GLfloat *params TRACE_GL_VOID(glGetTexParameteriv, (GLenum target, GLenum pname, GLint *params), (target, pname, params), 3, "GLenum", target, "GLenum", pname, "GLint *", params) TRACE_GL_VOID(glGetTexParameterxv, (GLenum target, GLenum pname, GLfixed *params), (target, pname, params), 3, "GLenum", target, "GLenum", pname, "GLfixed *", params) TRACE_GL_VOID(glGetTexParameterxvOES, (GLenum target, GLenum pname, GLfixed *params), (target, pname, params), 3, "GLenum", target, "GLenum", pname, "GLfixed *", params) -TRACE_GL(int, glGetUniformLocation, (GLuint program, const GLchar* name), (program, name), 2, "GLuint", program, "const GLchar*", name) +TRACE_GL(GLint, glGetUniformLocation, (GLuint program, const GLchar* name), (program, name), 2, "GLuint", program, "const GLchar*", name) TRACE_GL_VOID(glGetUniformfv, (GLuint program, GLint location, GLfloat* params), (program, location, params), 3, "GLuint", program, "GLint", location, "GLfloat*", params) TRACE_GL_VOID(glGetUniformiv, (GLuint program, GLint location, GLint* params), (program, location, params), 3, "GLuint", program, "GLint", location, "GLint*", params) TRACE_GL_VOID(glGetVertexAttribPointerv, (GLuint index, GLenum pname, GLvoid** pointer), (index, pname, pointer), 3, "GLuint", index, "GLenum", pname, "GLvoid**", pointer) diff --git a/opengl/specs/EGL_ANDROID_framebuffer_target.txt b/opengl/specs/EGL_ANDROID_framebuffer_target.txt new file mode 100644 index 0000000..273414c --- /dev/null +++ b/opengl/specs/EGL_ANDROID_framebuffer_target.txt @@ -0,0 +1,102 @@ +Name + + ANDROID_framebuffer_target + +Name Strings + + EGL_ANDROID_framebuffer_target + +Contributors + + Jamie Gennis + +Contact + + Jamie Gennis, Google Inc. (jgennis 'at' google.com) + +Status + + Draft. + +Version + + Version 1, September 20, 2012 + +Number + + EGL Extension #XXX + +Dependencies + + Requires EGL 1.0 + + This extension is written against the wording of the EGL 1.4 Specification + +Overview + + Android supports a number of different ANativeWindow implementations that + can be used to create an EGLSurface. One implementation, which is used to + send the result of performing window composition to a display, may have + some device-specific restrictions. Because of this, some EGLConfigs may + be incompatible with these ANativeWindows. This extension introduces a + new boolean EGLConfig attribute that indicates whether the EGLConfig + supports rendering to an ANativeWindow for which the buffers are passed to + the HWComposer HAL as a framebuffer target layer. + +New Types + + None. + +New Procedures and Functions + + None. + +New Tokens + + Accepted by the <attribute> parameter of eglGetConfigAttrib and + the <attrib_list> parameter of eglChooseConfig: + + EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147 + +Changes to Chapter 3 of the EGL 1.4 Specification (EGL Functions and Errors) + + Section 3.4, Configuration Management, add a row to Table 3.1. + + Attribute Type Notes + ------------------------------ ------- --------------------------- + EGL_FRAMEBUFFER_TARGET_ANDROID boolean whether use as a HWComposer + framebuffer target layer is + supported + + Section 3.4, Configuration Management, add a row to Table 3.4. + + Attribute Default Selection Sort Sort + Criteria Order Priority + ------------------------------ ------------- --------- ----- -------- + EGL_FRAMEBUFFER_TARGET_ANDROID EGL_DONT_CARE Exact None + + Section 3.4, Configuration Management, add a paragraph at the end of the + subsection titled Other EGLConfig Attribute Descriptions. + + EGL_FRAMEBUFFER_TARGET_ANDROID is a boolean indicating whether the + config may be used to create an EGLSurface from an ANativeWindow for + which the buffers are to be passed to HWComposer as a framebuffer + target layer. + + Section 3.4.1, Querying Configurations, change the last paragraph as follow + + EGLConfigs are not sorted with respect to the parameters + EGL_BIND_TO_TEXTURE_RGB, EGL_BIND_TO_TEXTURE_RGBA, EGL_CONFORMANT, + EGL_LEVEL, EGL_NATIVE_RENDERABLE, EGL_MAX_SWAP_INTERVAL, + EGL_MIN_SWAP_INTERVAL, EGL_RENDERABLE_TYPE, EGL_SURFACE_TYPE, + EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RED_VALUE, + EGL_TRANSPARENT_GREEN_VALUE, EGL_TRANSPARENT_BLUE_VALUE, and + EGL_RECORDABLE_ANDROID. + +Issues + + +Revision History + +#1 (Jamie Gennis, September 20, 2012) + - Initial draft. diff --git a/opengl/specs/EGL_ANDROID_native_fence_sync.txt b/opengl/specs/EGL_ANDROID_native_fence_sync.txt new file mode 100644 index 0000000..ee05b40 --- /dev/null +++ b/opengl/specs/EGL_ANDROID_native_fence_sync.txt @@ -0,0 +1,281 @@ +Name + + ANDROID_native_fence_sync + +Name Strings + + EGL_ANDROID_native_fence_sync + +Contributors + + Jamie Gennis + +Contact + + Jamie Gennis, Google Inc. (jgennis 'at' google.com) + +Status + + Draft. + +Version + + Version 3, September 4, 2012 + +Number + + EGL Extension #XXX + +Dependencies + + Requires EGL 1.1 + + This extension is written against the wording of the EGL 1.2 Specification + + EGL_KHR_fence_sync is required. + +Overview + + This extension enables the creation of EGL fence sync objects that are + associated with a native synchronization fence object that is referenced + using a file descriptor. These EGL fence sync objects have nearly + identical semantics to those defined by the KHR_fence_sync extension, + except that they have an additional attribute storing the file descriptor + referring to the native fence object. + + This extension assumes the existence of a native fence synchronization + object that behaves similarly to an EGL fence sync object. These native + objects must have a signal status like that of an EGLSyncKHR object that + indicates whether the fence has ever been signaled. Once signaled the + native object's signal status may not change again. + +New Types + + None. + +New Procedures and Functions + + EGLint eglDupNativeFenceFDANDROID( + EGLDisplay dpy, + EGLSyncKHR); + +New Tokens + + Accepted by the <type> parameter of eglCreateSyncKHR, and returned + in <value> when eglGetSyncAttribKHR is called with <attribute> + EGL_SYNC_TYPE_KHR: + + EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144 + + Accepted by the <attrib_list> parameter of eglCreateSyncKHR: + + EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145 + + Accepted by the <attrib_list> parameter of eglCreateSyncKHR, and returned + by eglDupNativeFenceFDANDROID in the event of an error: + + EGL_NO_NATIVE_FENCE_FD_ANDROID -1 + + Returned in <value> when eglGetSyncAttribKHR is called with <attribute> + EGL_SYNC_CONDITION_KHR: + + EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146 + +Changes to Chapter 3 of the EGL 1.2 Specification (EGL Functions and Errors) + + Add the following after the sixth paragraph of Section 3.8.1 (Sync + Objects), added by KHR_fence_sync + + "If <type> is EGL_SYNC_NATIVE_FENCE_ANDROID, an EGL native fence sync + object is created. In this case the EGL_SYNC_NATIVE_FENCE_FD_ANDROID + attribute may optionally be specified. If this attribute is specified, it + must be set to either a file descriptor that refers to a native fence + object or to the value EGL_NO_NATIVE_FENCE_FD_ANDROID. + + The default values for the EGL native fence sync object attributes are as + follows: + + Attribute Name Initial Attribute Value(s) + --------------- -------------------------- + EGL_SYNC_TYPE_KHR EGL_SYNC_NATIVE_FENCE_ANDROID + EGL_SYNC_STATUS_KHR EGL_UNSIGNALED_KHR + EGL_SYNC_CONDITION_KHR EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR + EGL_SYNC_NATIVE_FENCE_FD_ANDROID EGL_NO_NATIVE_FENCE_FD_ANDROID + + If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute is not + EGL_NO_NATIVE_FENCE_FD_ANDROID then the EGL_SYNC_CONDITION_KHR attribute is + set to EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID and the EGL_SYNC_STATUS_KHR + attribute is set to reflect the signal status of the native fence object. + Additionally, the EGL implementation assumes ownership of the file + descriptor, so the caller must not use it after calling eglCreateSyncKHR." + + Modify Section 3.8.1 (Sync Objects), added by KHR_fence_sync, starting at + the seventh paragraph + + "When a fence sync object is created or when an EGL native fence sync + object is created with the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute set + to EGL_NO_NATIVE_FENCE_FD_ANDROID, eglCreateSyncKHR also inserts a fence + command into the command stream of the bound client API's current context + (i.e., the context returned by eglGetCurrentContext), and associates it + with the newly created sync object. + + After associating the fence command with an EGL native fence sync object, + the next Flush() operation performed by the current client API causes a + new native fence object to be created, and the + EGL_SYNC_NATIVE_FENCE_ANDROID attribute of the EGL native fence object is + set to a file descriptor that refers to the new native fence object. This + new native fence object is signaled when the EGL native fence sync object + is signaled. + + When the condition of the sync object is satisfied by the fence command, + the sync is signaled by the associated client API context, causing any + eglClientWaitSyncKHR commands (see below) blocking on <sync> to unblock. + If the sync object is an EGL native fence sync object then the native + fence object is also signaled when the condition is satisfied. The + EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR condition is satisfied by completion + of the fence command corresponding to the sync object and all preceding + commands in the associated client API context's command stream. The sync + object will not be signaled until all effects from these commands on the + client API's internal and framebuffer state are fully realized. No other + state is affected by execution of the fence command. + + The EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID condition is satisfied by the + signaling of the native fence object referred to by the + EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute. When this happens any + eglClientWaitSyncKHR commands blocking on <sync> unblock." + + Modify the list of eglCreateSyncKHR errors in Section 3.8.1 (Sync Objects), + added by KHR_fence_sync + + "Errors + ------ + + * If <dpy> is not the name of a valid, initialized EGLDisplay, + EGL_NO_SYNC_KHR is returned and an EGL_BAD_DISPLAY error is + generated. + * If <type> is EGL_SYNC_FENCE_KHR and <attrib_list> is neither NULL nor + empty (containing only EGL_NONE), EGL_NO_SYNC_KHR is returned and an + EGL_BAD_ATTRIBUTE error is generated. + * If <type> is EGL_SYNC_NATIVE_FENCE_ANDROID and <attrib_list> contains + an attribute other than EGL_SYNC_NATIVE_FENCE_FD_ANDROID, + EGL_NO_SYNC_KHR is returned and an EGL_BAD_ATTRIBUTE error is + generated. + * If <type> is not a supported type of sync object, + EGL_NO_SYNC_KHR is returned and an EGL_BAD_ATTRIBUTE error is + generated. + * If <type> is EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID and + no context is current for the bound API (i.e., eglGetCurrentContext + returns EGL_NO_CONTEXT), EGL_NO_SYNC_KHR is returned and an + EGL_BAD_MATCH error is generated. + * If <type> is EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID and + <dpy> does not match the EGLDisplay of the currently bound context for + the currently bound client API (the EGLDisplay returned by + eglGetCurrentDisplay()) then EGL_NO_SYNC_KHR is returned and an + EGL_BAD_MATCH error is generated. + * If <type> is EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID and + the currently bound client API does not support the client API + extension indicating it can place fence commands, then EGL_NO_SYNC_KHR + is returned and an EGL_BAD_MATCH error is generated." + + Modify table 3.cc in Section 3.8.1 (Sync Objects), added by KHR_fence_sync + + " + Attribute Description Supported Sync Objects + ----------------- ----------------------- ---------------------- + EGL_SYNC_TYPE_KHR Type of the sync object All + EGL_SYNC_STATUS_KHR Status of the sync object All + EGL_SYNC_CONDITION_KHR Signaling condition EGL_SYNC_FENCE_KHR and + EGL_SYNC_NATIVE_FENCE_ANDROID only + " + + Modify the second paragraph description of eglDestroySyncKHR in Section + 3.8.1 (Sync Objects), added by KHR_fence_sync + + "If no errors are generated, EGL_TRUE is returned, and <sync> will no + longer be the handle of a valid sync object. Additionally, if <sync> is an + EGL native fence sync object and the EGL_SYNC_NATIVE_FENCE_FD_ANDROID + attribute is not EGL_NO_NATIVE_FENCE_FD_ANDROID then that file descriptor + is closed." + + Add the following after the last paragraph of Section 3.8.1 (Sync + Objects), added by KHR_fence_sync + + The command + + EGLint eglDupNativeFenceFDANDROID( + EGLDisplay dpy, + EGLSyncKHR sync); + + duplicates the file descriptor stored in the + EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute of an EGL native fence sync + object and returns the new file descriptor. + + Errors + ------ + + * If <sync> is not a valid sync object for <dpy>, + EGL_NO_NATIVE_FENCE_FD_ANDROID is returned and an EGL_BAD_PARAMETER + error is generated. + * If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute of <sync> is + EGL_NO_NATIVE_FENCE_FD_ANDROID, EGL_NO_NATIVE_FENCE_FD_ANDROID is + returned and an EGL_BAD_PARAMETER error is generated. + * If <dpy> does not match the display passed to eglCreateSyncKHR + when <sync> was created, the behaviour is undefined." + +Issues + + 1. Should EGLSyncKHR objects that wrap native fence objects use the + EGL_SYNC_FENCE_KHR type? + + RESOLVED: A new sync object type will be added. + + We don't want to require all EGL fence sync objects to wrap native fence + objects, so we need some way to tell the EGL implementation at sync object + creation whether the sync object should support querying the native fence + FD attribute. We could do this with either a new sync object type or with a + boolean attribute. It might be nice to pick up future signaling conditions + that might be added for fence sync objects, but there may be things that + get added that don't make sense in the context of native fence objects. + + 2. Who is responsible for dup'ing the native fence file descriptors? + + RESOLVED: Whenever a file descriptor is passed into or returned from an + EGL call in this extension, ownership of that file descriptor is + transfered. The recipient of the file descriptor must close it when it is + no longer needed, and the provider of the file descriptor must dup it + before providing it if they require continued use of the native fence. + + 3. Can the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute be queried? + + RESOLVED: No. + + Returning the file descriptor owned by the EGL implementation would + violate the file descriptor ownership rule described in issue #2. Having + eglGetSyncAttribKHR return a different (dup'd) file descriptor each time + it's called seems wrong, so a new function was added to explicitly dup the + file descriptor. + + That said, the attribute is useful both as a way to pass an existing file + descriptor to eglCreateSyncKHR and as a way to describe the subsequent + behavior of EGL native fence sync objects, so it is left as an attribute + for which the value cannot be queried. + +Revision History + +#3 (Jamie Gennis, September 4, 2012) + - Reworded the extension to refer to "native fence" objects rather than + "Android fence" objects. + - Added a paragraph to the overview that describes assumptions about the + native fence sync objects. + +#2 (Jamie Gennis, July 23, 2012) + - Changed the file descriptor ownership transferring behavior. + - Added the eglDupAndroidFenceFDANDROID function. + - Removed EGL_SYNC_NATIVE_FENCE_FD_ANDROID from the table of gettable + attributes. + - Added language specifying that a native Android fence is created at the + flush following the creation of an EGL Android fence sync object that is + not passed an existing native fence. + +#1 (Jamie Gennis, May 29, 2012) + - Initial draft. diff --git a/opengl/specs/README b/opengl/specs/README index 16b278f..eb86869 100644 --- a/opengl/specs/README +++ b/opengl/specs/README @@ -8,6 +8,10 @@ for use by Android extensions. ---------------- ---------------------------------- 0x3140 EGL_ANDROID_image_native_buffer 0x3141 (unused) -0x3142 EGL_ANDROID_recordable +0x3142 EGL_RECORDABLE_ANDROID (EGL_ANDROID_recordable) 0x3143 EGL_VERSION_HW_ANDROID (internal use) -0x3144 - 0x314F (unused) +0x3144 EGL_SYNC_NATIVE_FENCE_ANDROID (EGL_ANDROID_native_fence_sync) +0x3145 EGL_SYNC_NATIVE_FENCE_FD_ANDROID (EGL_ANDROID_native_fence_sync) +0x3146 EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID (EGL_ANDROID_native_fence_sync) +0x3147 EGL_FRAMEBUFFER_TARGET_ANDROID (EGL_ANDROID_framebuffer_target) +0x3148 - 0x314F (unused) diff --git a/opengl/tests/Android.mk b/opengl/tests/Android.mk index 071c679..3ae3b4e 100644 --- a/opengl/tests/Android.mk +++ b/opengl/tests/Android.mk @@ -20,7 +20,7 @@ dirs := \ textures \ tritex \ -ifneq ($(TARGET_BUILD_PDK), true) +ifneq (,$(TARGET_BUILD_JAVA_SUPPORT_LEVEL)) dirs += \ gl2_cameraeye \ gl2_java \ @@ -29,11 +29,16 @@ dirs += \ gl_jni \ gl_perfapp \ lighting1709 \ - testFramerate \ testLatency \ testPauseResume \ testViewport \ -endif +endif # JAVA_SUPPORT + +ifeq (platform,$(TARGET_BUILD_JAVA_SUPPORT_LEVEL)) +dirs += \ + testFramerate + +endif # JAVA_SUPPORT platform include $(call all-named-subdir-makefiles, $(dirs)) diff --git a/opengl/tests/gl2_jni/Android.mk b/opengl/tests/gl2_jni/Android.mk index 5d90ff6..25187c9 100644 --- a/opengl/tests/gl2_jni/Android.mk +++ b/opengl/tests/gl2_jni/Android.mk @@ -30,7 +30,7 @@ include $(CLEAR_VARS) # Optional tag would mean it doesn't get installed by default LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror -Wno-error=unused-parameter LOCAL_SRC_FILES:= \ gl_code.cpp diff --git a/opengl/tests/gl2_jni/jni/gl_code.cpp b/opengl/tests/gl2_jni/jni/gl_code.cpp index fa6bd93..ed896a4 100644 --- a/opengl/tests/gl2_jni/jni/gl_code.cpp +++ b/opengl/tests/gl2_jni/jni/gl_code.cpp @@ -153,7 +153,7 @@ extern "C" { JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_step(JNIEnv * env, jobject obj); }; -JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height)
+JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height) { setupGraphics(width, height); } diff --git a/opengl/tests/gl_jni/Android.mk b/opengl/tests/gl_jni/Android.mk index 3d20e72..80b4bac 100644 --- a/opengl/tests/gl_jni/Android.mk +++ b/opengl/tests/gl_jni/Android.mk @@ -30,7 +30,7 @@ include $(CLEAR_VARS) # Optional tag would mean it doesn't get installed by default LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror -Wno-error=unused-parameter LOCAL_SRC_FILES:= \ gl_code.cpp diff --git a/opengl/tests/gl_perf/fill_common.cpp b/opengl/tests/gl_perf/fill_common.cpp index 389381f..fefedc0 100644 --- a/opengl/tests/gl_perf/fill_common.cpp +++ b/opengl/tests/gl_perf/fill_common.cpp @@ -189,7 +189,7 @@ static void setupVA() { } static void randUniform(int pgm, const char *var) { - int loc = glGetUniformLocation(pgm, var); + GLint loc = glGetUniformLocation(pgm, var); if (loc >= 0) { float x = ((float)rand()) / RAND_MAX; float y = ((float)rand()) / RAND_MAX; @@ -211,7 +211,7 @@ static void doLoop(bool warmup, int pgm, uint32_t passCount) { startTimer(); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); for (uint32_t ct=0; ct < passCount; ct++) { - int loc = glGetUniformLocation(pgm, "u_texOff"); + GLint loc = glGetUniformLocation(pgm, "u_texOff"); glUniform2f(loc, ((float)ct) / passCount, ((float)ct) / 2.f / passCount); randUniform(pgm, "u_color"); @@ -271,7 +271,7 @@ static void doSingleTest(uint32_t pgmNum, int tex) { printf("error running test\n"); return; } - int loc = glGetUniformLocation(pgm, "u_tex0"); + GLint loc = glGetUniformLocation(pgm, "u_tex0"); if (loc >= 0) glUniform1i(loc, 0); loc = glGetUniformLocation(pgm, "u_tex1"); if (loc >= 0) glUniform1i(loc, 1); diff --git a/opengl/tests/gl_perfapp/Android.mk b/opengl/tests/gl_perfapp/Android.mk index 65e50e9..45a5516 100644 --- a/opengl/tests/gl_perfapp/Android.mk +++ b/opengl/tests/gl_perfapp/Android.mk @@ -33,7 +33,7 @@ include $(CLEAR_VARS) # Optional tag would mean it doesn't get installed by default LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror -Wno-error=unused-parameter LOCAL_SRC_FILES:= \ gl_code.cpp diff --git a/opengl/tests/gldual/Android.mk b/opengl/tests/gldual/Android.mk index b4b378e..42094c8 100644 --- a/opengl/tests/gldual/Android.mk +++ b/opengl/tests/gldual/Android.mk @@ -30,7 +30,7 @@ include $(CLEAR_VARS) # Optional tag would mean it doesn't get installed by default LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror -Wno-error=unused-parameter LOCAL_SRC_FILES:= \ gl_code.cpp diff --git a/opengl/tests/hwc/hwcColorEquiv.cpp b/opengl/tests/hwc/hwcColorEquiv.cpp index bb305dc..160906d 100644 --- a/opengl/tests/hwc/hwcColorEquiv.cpp +++ b/opengl/tests/hwc/hwcColorEquiv.cpp @@ -124,7 +124,7 @@ const float defaultEndDelay = 2.0; // Default delay after rendering graphics // Globals static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_RARELY; -static hwc_composer_device_t *hwcDevice; +static hwc_composer_device_1_t *hwcDevice; static EGLDisplay dpy; static EGLSurface surface; static EGLint width, height; @@ -344,16 +344,16 @@ main(int argc, char *argv[]) hwcTestFillColorHBlend(equivFrame.get(), refFormat->format, startRefColor, endRefColor); - hwc_layer_list_t *list; - size_t size = sizeof(hwc_layer_list) + numFrames * sizeof(hwc_layer_t); - if ((list = (hwc_layer_list_t *) calloc(1, size)) == NULL) { + hwc_display_contents_1_t *list; + size_t size = sizeof(hwc_display_contents_1_t) + numFrames * sizeof(hwc_layer_1_t); + if ((list = (hwc_display_contents_1_t *) calloc(1, size)) == NULL) { testPrintE("Allocate list failed"); exit(11); } list->flags = HWC_GEOMETRY_CHANGED; list->numHwLayers = numFrames; - hwc_layer_t *layer = &list->hwLayers[0]; + hwc_layer_1_t *layer = &list->hwLayers[0]; layer->handle = refFrame->handle; layer->blending = HWC_BLENDING_NONE; layer->sourceCrop.left = 0; @@ -383,7 +383,7 @@ main(int argc, char *argv[]) // Perform prepare operation if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); } - hwcDevice->prepare(hwcDevice, list); + hwcDevice->prepare(hwcDevice, 1, &list); if (verbose) { testPrintI("Post Prepare:"); hwcTestDisplayListPrepareModifiable(list); @@ -393,7 +393,9 @@ main(int argc, char *argv[]) list->flags &= ~HWC_GEOMETRY_CHANGED; if (verbose) {hwcTestDisplayListHandles(list); } - hwcDevice->set(hwcDevice, dpy, surface, list); + list->dpy = dpy; + list->sur = surface; + hwcDevice->set(hwcDevice, 1, &list); testDelay(endDelay); diff --git a/opengl/tests/hwc/hwcCommit.cpp b/opengl/tests/hwc/hwcCommit.cpp index efa646c..3681fbb 100644 --- a/opengl/tests/hwc/hwcCommit.cpp +++ b/opengl/tests/hwc/hwcCommit.cpp @@ -230,7 +230,7 @@ private: // Globals static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_RARELY; -static hwc_composer_device_t *hwcDevice; +static hwc_composer_device_1_t *hwcDevice; static EGLDisplay dpy; static EGLSurface surface; static EGLint width, height; @@ -1397,7 +1397,7 @@ void Rational::double2Rational(double f, Range nRange, Range dRange, // Given a list of rectangles, determine how many HWC will commit to render uint32_t numOverlays(list<Rectangle>& rectList) { - hwc_layer_list_t *hwcList; + hwc_display_contents_1_t *hwcList; list<sp<GraphicBuffer> > buffers; hwcList = hwcTestCreateLayerList(rectList.size()); @@ -1406,7 +1406,7 @@ uint32_t numOverlays(list<Rectangle>& rectList) exit(30); } - hwc_layer_t *layer = &hwcList->hwLayers[0]; + hwc_layer_1_t *layer = &hwcList->hwLayers[0]; for (std::list<Rectangle>::iterator it = rectList.begin(); it != rectList.end(); ++it, ++layer) { // Allocate the texture for the source frame @@ -1430,7 +1430,7 @@ uint32_t numOverlays(list<Rectangle>& rectList) // Perform prepare operation if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(hwcList); } - hwcDevice->prepare(hwcDevice, hwcList); + hwcDevice->prepare(hwcDevice, 1, &hwcList); if (verbose) { testPrintI("Post Prepare:"); hwcTestDisplayListPrepareModifiable(hwcList); diff --git a/opengl/tests/hwc/hwcRects.cpp b/opengl/tests/hwc/hwcRects.cpp index 906c169..ec0403f 100644 --- a/opengl/tests/hwc/hwcRects.cpp +++ b/opengl/tests/hwc/hwcRects.cpp @@ -165,7 +165,7 @@ public: list<Rectangle> rectangle; static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_RARELY; -static hwc_composer_device_t *hwcDevice; +static hwc_composer_device_1_t *hwcDevice; static EGLDisplay dpy; static EGLSurface surface; static EGLint width, height; @@ -307,14 +307,14 @@ main(int argc, char *argv[]) } // Create list of frames - hwc_layer_list_t *list; + hwc_display_contents_1_t *list; list = hwcTestCreateLayerList(rectangle.size()); if (list == NULL) { testPrintE("hwcTestCreateLayerList failed"); exit(5); } - hwc_layer_t *layer = &list->hwLayers[0]; + hwc_layer_1_t *layer = &list->hwLayers[0]; for (std::list<Rectangle>::iterator it = rectangle.begin(); it != rectangle.end(); ++it, ++layer) { layer->handle = it->texture->handle; @@ -329,7 +329,7 @@ main(int argc, char *argv[]) // Perform prepare operation if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); } - hwcDevice->prepare(hwcDevice, list); + hwcDevice->prepare(hwcDevice, 1, &list); if (verbose) { testPrintI("Post Prepare:"); hwcTestDisplayListPrepareModifiable(list); @@ -341,7 +341,9 @@ main(int argc, char *argv[]) // Perform the set operation(s) if (verbose) {testPrintI("Set:"); } if (verbose) { hwcTestDisplayListHandles(list); } - hwcDevice->set(hwcDevice, dpy, surface, list); + list->dpy = dpy; + list->sur = surface; + hwcDevice->set(hwcDevice, 1, &list); testDelay(endDelay); diff --git a/opengl/tests/hwc/hwcStress.cpp b/opengl/tests/hwc/hwcStress.cpp index b02a424..3e8ea8d 100644 --- a/opengl/tests/hwc/hwcStress.cpp +++ b/opengl/tests/hwc/hwcStress.cpp @@ -192,7 +192,7 @@ const vector<unsigned int> vecTransformFlags(transformFlags, // File scope globals static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_RARELY; -static hwc_composer_device_t *hwcDevice; +static hwc_composer_device_1_t *hwcDevice; static EGLDisplay dpy; static EGLSurface surface; static EGLint width, height; @@ -409,7 +409,7 @@ main(int argc, char *argv[]) // generated for this pass. srand48(pass); - hwc_layer_list_t *list; + hwc_display_contents_1_t *list; list = hwcTestCreateLayerList(testRandMod(frames.size()) + 1); if (list == NULL) { testPrintE("hwcTestCreateLayerList failed"); @@ -428,7 +428,7 @@ main(int argc, char *argv[]) for (unsigned int n1 = 0; n1 < list->numHwLayers; n1++) { unsigned int idx = testRandMod(selectedFrames[n1].size()); sp<GraphicBuffer> gBuf = selectedFrames[n1][idx]; - hwc_layer_t *layer = &list->hwLayers[n1]; + hwc_layer_1_t *layer = &list->hwLayers[n1]; layer->handle = gBuf->handle; layer->blending = blendingOps[testRandMod(NUMA(blendingOps))]; @@ -478,7 +478,7 @@ main(int argc, char *argv[]) // Perform prepare operation if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); } - hwcDevice->prepare(hwcDevice, list); + hwcDevice->prepare(hwcDevice, 1, &list); if (verbose) { testPrintI("Post Prepare:"); hwcTestDisplayListPrepareModifiable(list); @@ -491,13 +491,15 @@ main(int argc, char *argv[]) if (verbose) {testPrintI("Set:"); } for (unsigned int n1 = 0; n1 < numSet; n1++) { if (verbose) { hwcTestDisplayListHandles(list); } - hwcDevice->set(hwcDevice, dpy, surface, list); + list->dpy = dpy; + list->sur = surface; + hwcDevice->set(hwcDevice, 1, &list); // Prandomly select a new set of handles for (unsigned int n1 = 0; n1 < list->numHwLayers; n1++) { unsigned int idx = testRandMod(selectedFrames[n1].size()); sp<GraphicBuffer> gBuf = selectedFrames[n1][idx]; - hwc_layer_t *layer = &list->hwLayers[n1]; + hwc_layer_1_t *layer = &list->hwLayers[n1]; layer->handle = (native_handle_t *) gBuf->handle; } diff --git a/opengl/tests/hwc/hwcTestLib.cpp b/opengl/tests/hwc/hwcTestLib.cpp index 28e0c3f..d567e6e 100644 --- a/opengl/tests/hwc/hwcTestLib.cpp +++ b/opengl/tests/hwc/hwcTestLib.cpp @@ -134,7 +134,7 @@ void hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface, } // Open Hardware Composer Device -void hwcTestOpenHwc(hwc_composer_device_t **hwcDevicePtr) +void hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr) { int rv; hw_module_t const *hwcModule; @@ -145,7 +145,7 @@ void hwcTestOpenHwc(hwc_composer_device_t **hwcDevicePtr) perror(NULL); exit(77); } - if ((rv = hwc_open(hwcModule, hwcDevicePtr)) != 0) { + if ((rv = hwc_open_1(hwcModule, hwcDevicePtr)) != 0) { testPrintE("hwc_open failed, rv: %i", rv); errno = -rv; perror(NULL); @@ -399,12 +399,12 @@ const char *hwcTestGraphicFormat2str(uint32_t format) * Dynamically creates layer list with numLayers worth * of hwLayers entries. */ -hwc_layer_list_t *hwcTestCreateLayerList(size_t numLayers) +hwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers) { - hwc_layer_list_t *list; + hwc_display_contents_1_t *list; - size_t size = sizeof(hwc_layer_list) + numLayers * sizeof(hwc_layer_t); - if ((list = (hwc_layer_list_t *) calloc(1, size)) == NULL) { + size_t size = sizeof(hwc_display_contents_1_t) + numLayers * sizeof(hwc_layer_1_t); + if ((list = (hwc_display_contents_1_t *) calloc(1, size)) == NULL) { return NULL; } list->flags = HWC_GEOMETRY_CHANGED; @@ -417,13 +417,13 @@ hwc_layer_list_t *hwcTestCreateLayerList(size_t numLayers) * hwcTestFreeLayerList * Frees memory previous allocated via hwcTestCreateLayerList(). */ -void hwcTestFreeLayerList(hwc_layer_list_t *list) +void hwcTestFreeLayerList(hwc_display_contents_1_t *list) { free(list); } // Display the settings of the layer list pointed to by list -void hwcTestDisplayList(hwc_layer_list_t *list) +void hwcTestDisplayList(hwc_display_contents_1_t *list) { testPrintI(" flags: %#x%s", list->flags, (list->flags & HWC_GEOMETRY_CHANGED) ? " GEOMETRY_CHANGED" : ""); @@ -494,7 +494,7 @@ void hwcTestDisplayList(hwc_layer_list_t *list) * Displays the portions of a list that are meant to be modified by * a prepare call. */ -void hwcTestDisplayListPrepareModifiable(hwc_layer_list_t *list) +void hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list) { uint32_t numOverlays = 0; for (unsigned int layer = 0; layer < list->numHwLayers; layer++) { @@ -522,7 +522,7 @@ void hwcTestDisplayListPrepareModifiable(hwc_layer_list_t *list) * * Displays the handles of all the graphic buffers in the list. */ -void hwcTestDisplayListHandles(hwc_layer_list_t *list) +void hwcTestDisplayListHandles(hwc_display_contents_1_t *list) { const unsigned int maxLayersPerLine = 6; diff --git a/opengl/tests/hwc/hwcTestLib.h b/opengl/tests/hwc/hwcTestLib.h index b0c3012..d7d5837 100644 --- a/opengl/tests/hwc/hwcTestLib.h +++ b/opengl/tests/hwc/hwcTestLib.h @@ -107,17 +107,17 @@ class HwcTestDim { // Function Prototypes void hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface, EGLint *width, EGLint *height); -void hwcTestOpenHwc(hwc_composer_device_t **hwcDevicePtr); +void hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr); const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(const char *desc); const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(uint32_t id); const char *hwcTestGraphicFormat2str(uint32_t format); std::string hwcTestRect2str(const struct hwc_rect& rect); -hwc_layer_list_t *hwcTestCreateLayerList(size_t numLayers); -void hwcTestFreeLayerList(hwc_layer_list_t *list); -void hwcTestDisplayList(hwc_layer_list_t *list); -void hwcTestDisplayListPrepareModifiable(hwc_layer_list_t *list); -void hwcTestDisplayListHandles(hwc_layer_list_t *list); +hwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers); +void hwcTestFreeLayerList(hwc_display_contents_1_t *list); +void hwcTestDisplayList(hwc_display_contents_1_t *list); +void hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list); +void hwcTestDisplayListHandles(hwc_display_contents_1_t *list); uint32_t hwcTestColor2Pixel(uint32_t format, ColorFract color, float alpha); void hwcTestColorConvert(uint32_t fromFormat, uint32_t toFormat, diff --git a/opengl/tools/glgen/gen b/opengl/tools/glgen/gen index 31f4190..3359a22 100755 --- a/opengl/tools/glgen/gen +++ b/opengl/tools/glgen/gen @@ -12,6 +12,7 @@ mkdir -p out/javax/microedition/khronos/opengles mkdir -p out/com/google/android/gles_jni mkdir -p out/android/app mkdir -p out/android/graphics +mkdir -p out/android/view mkdir -p out/android/opengl mkdir -p out/android/content mkdir -p out/android/content/pm @@ -24,15 +25,33 @@ echo "public interface Canvas {}" >> out/android/graphics/Canvas.java echo "package android.app; import android.content.pm.IPackageManager; public class AppGlobals { public static IPackageManager getPackageManager() { return null;} }" > out/android/app/AppGlobals.java # echo "package android.content; import android.content.pm.PackageManager; public interface Context { public PackageManager getPackageManager(); }" > out/android/content/Context.java echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java -echo "package android.content.pm; public interface IPackageManager {ApplicationInfo getApplicationInfo(java.lang.String packageName, int flags) throws android.os.RemoteException;}" > out/android/content/pm/IPackageManager.java +echo "package android.content.pm; public interface IPackageManager {ApplicationInfo getApplicationInfo(java.lang.String packageName, int flags, java.lang.String userId) throws android.os.RemoteException;}" > out/android/content/pm/IPackageManager.java echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 3;}; }" > out/android/os/Build.java +echo "package android.os; public class UserId {public static String myUserId() { return \"\"; } }" > out/android/os/UserId.java echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java echo "package android.util; public class Log {public static void w(String a, String b) {} public static void e(String a, String b) {}}" > out/android/util/Log.java +echo "package android.opengl; public abstract class EGLObjectHandle { public int getHandle() { return 0; } }" > out/android/opengl/EGLObjectHandle.java +echo "package android.opengl; public class EGLSurface extends EGLObjectHandle { }" > out/android/opengl/EGLSurface.java +echo "package android.opengl; public class EGLContext extends EGLObjectHandle { }" > out/android/opengl/EGLContext.java +echo "package android.opengl; public class EGLDisplay extends EGLObjectHandle { }" > out/android/opengl/EGLDisplay.java +echo "package android.opengl; public class EGLConfig extends EGLObjectHandle { }" > out/android/opengl/EGLConfig.java + + +echo "package android.graphics;" > out/android/graphics/SurfaceTexture.java +echo "public interface SurfaceTexture {}" >> out/android/graphics/SurfaceTexture.java +echo "package android.view;" > out/android/view/SurfaceView.java +echo "public interface SurfaceView { SurfaceHolder getHolder(); }" >> out/android/view/SurfaceView.java +echo "package android.view;" > out/android/view/Surface.java +echo "public interface Surface {}" >> out/android/view/Surface.java +echo "package android.view;" > out/android/view/SurfaceHolder.java +echo "public interface SurfaceHolder { Surface getSurface(); }" >> out/android/view/SurfaceHolder.java + + GLFILE=out/javax/microedition/khronos/opengles/GL.java cp stubs/jsr239/GLHeader.java-if $GLFILE -GLGEN_FILES="CFunc.java CType.java CodeEmitter.java GenerateGL.java GenerateGLES.java GLESCodeEmitter.java JFunc.java JniCodeEmitter.java JType.java Jsr239CodeEmitter.java ParameterChecker.java" +GLGEN_FILES="CFunc.java CType.java CodeEmitter.java EGLCodeEmitter.java GenerateEGL.java GenerateGL.java GenerateGLES.java GLESCodeEmitter.java JFunc.java JniCodeEmitter.java JType.java Jsr239CodeEmitter.java ParameterChecker.java" pushd src > /dev/null javac ${GLGEN_FILES} @@ -59,11 +78,19 @@ if [ $JAVA_RESULT -ne 0 ]; then exit $JAVA_RESULT fi +echo "Generating static EGL 1.4 bindings" +java -classpath src GenerateEGL +JAVA_RESULT=$? +if [ $JAVA_RESULT -ne 0 ]; then + echo "Could not run GenerateEGL." + exit $JAVA_RESULT +fi + rm src/*.class pushd out > /dev/null mkdir classes -javac -d classes com/google/android/gles_jni/GLImpl.java javax/microedition/khronos/opengles/GL10.java javax/microedition/khronos/opengles/GL10Ext.java javax/microedition/khronos/opengles/GL11.java javax/microedition/khronos/opengles/GL11Ext.java javax/microedition/khronos/opengles/GL11ExtensionPack.java android/opengl/GLES10.java android/opengl/GLES10Ext.java android/opengl/GLES11.java android/opengl/GLES11Ext.java android/opengl/GLES20.java +javac -d classes android/opengl/EGL14.java com/google/android/gles_jni/GLImpl.java javax/microedition/khronos/opengles/GL10.java javax/microedition/khronos/opengles/GL10Ext.java javax/microedition/khronos/opengles/GL11.java javax/microedition/khronos/opengles/GL11Ext.java javax/microedition/khronos/opengles/GL11ExtensionPack.java android/opengl/GLES10.java android/opengl/GLES10Ext.java android/opengl/GLES11.java android/opengl/GLES11Ext.java android/opengl/GLES20.java popd > /dev/null JAVA_RESULT=$? if [ $JAVA_RESULT -ne 0 ]; then @@ -90,6 +117,7 @@ compareGenerated() { if cmp -s $1/$3 $2/$3 ; then echo "# " $3 unchanged else + echo "# " $3 changed if [ $SAID_PLEASE == "0" ] ; then echo Please evaluate the following commands: echo @@ -101,18 +129,18 @@ compareGenerated() { fi } -compareGenerated ../../../core/jni generated/C com_google_android_gles_jni_GLImpl.cpp -compareGenerated ../../java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java +compareGenerated ../../../../base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp +compareGenerated ../../../../base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java do - compareGenerated ../../java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x + compareGenerated ../../../../base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x done -for x in GLES10 GLES10Ext GLES11 GLES11Ext GLES20 +for x in EGL14 GLES10 GLES10Ext GLES11 GLES11Ext GLES20 do - compareGenerated ../../java/android/opengl generated/android/opengl ${x}.java - compareGenerated ../../../core/jni generated/C android_opengl_${x}.cpp + compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java + compareGenerated ../../../../base/core/jni generated/C android_opengl_${x}.cpp done if [ $KEEP_GENERATED == "0" ] ; then diff --git a/opengl/tools/glgen/specs/egl/EGL14.spec b/opengl/tools/glgen/specs/egl/EGL14.spec new file mode 100644 index 0000000..828e114 --- /dev/null +++ b/opengl/tools/glgen/specs/egl/EGL14.spec @@ -0,0 +1,33 @@ +EGLint eglGetError ( void ) +EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) +EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) +EGLBoolean eglTerminate ( EGLDisplay dpy ) +const char * eglQueryString ( EGLDisplay dpy, EGLint name ) +EGLBoolean eglGetConfigs ( EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config ) +EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config ) +EGLBoolean eglGetConfigAttrib ( EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value ) +EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) +EGLSurface eglCreatePbufferSurface ( EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list ) +EGLSurface eglCreatePixmapSurface ( EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list ) +EGLBoolean eglDestroySurface ( EGLDisplay dpy, EGLSurface surface ) +EGLBoolean eglQuerySurface ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value ) +EGLBoolean eglBindAPI ( EGLenum api ) +EGLenum eglQueryAPI ( void ) +EGLBoolean eglWaitClient ( void ) +EGLBoolean eglReleaseThread ( void ) +EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) +EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) +EGLBoolean eglBindTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) +EGLBoolean eglReleaseTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) +EGLBoolean eglSwapInterval ( EGLDisplay dpy, EGLint interval ) +EGLContext eglCreateContext ( EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list ) +EGLBoolean eglDestroyContext ( EGLDisplay dpy, EGLContext ctx ) +EGLBoolean eglMakeCurrent ( EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx ) +EGLContext eglGetCurrentContext ( void ) +EGLSurface eglGetCurrentSurface ( EGLint readdraw ) +EGLDisplay eglGetCurrentDisplay ( void ) +EGLBoolean eglQueryContext ( EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value ) +EGLBoolean eglWaitGL ( void ) +EGLBoolean eglWaitNative ( EGLint engine ) +EGLBoolean eglSwapBuffers ( EGLDisplay dpy, EGLSurface surface ) +EGLBoolean eglCopyBuffers ( EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target ) diff --git a/opengl/tools/glgen/specs/egl/checks.spec b/opengl/tools/glgen/specs/egl/checks.spec new file mode 100644 index 0000000..34fb1ee --- /dev/null +++ b/opengl/tools/glgen/specs/egl/checks.spec @@ -0,0 +1,13 @@ +eglInitialize check major 1 check minor 1 +eglGetConfigs check configs config_size +eglChooseConfig check configs config_size check num_config 1 sentinel attrib_list EGL_NONE +eglGetConfigAttrib check value 1 +//STUB function: //eglCreateWindowSurface sentinel attrib_list EGL_NONE +eglCreatePbufferSurface sentinel attrib_list EGL_NONE +//unsupported: eglCreatePixmapSurface sentinel attrib_list EGL_NONE +eglCreatePixmapSurface unsupported +eglCopyBuffers unsupported +eglQuerySurface check value 1 +eglCreatePbufferFromClientBuffer sentinel attrib_list EGL_NONE +eglCreateContext sentinel attrib_list EGL_NONE +eglQueryContext check value 1 diff --git a/opengl/tools/glgen/specs/gles11/GLES20.spec b/opengl/tools/glgen/specs/gles11/GLES20.spec index ee88f59..dda746e 100644 --- a/opengl/tools/glgen/specs/gles11/GLES20.spec +++ b/opengl/tools/glgen/specs/gles11/GLES20.spec @@ -56,7 +56,7 @@ void glGenTextures ( GLsizei n, GLuint *textures ) void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )
void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )
void glGetAttachedShaders ( GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders )
-int glGetAttribLocation ( GLuint program, const char *name )
+GLint glGetAttribLocation ( GLuint program, const char *name )
void glGetBooleanv ( GLenum pname, GLboolean *params )
void glGetBufferParameteriv ( GLenum target, GLenum pname, GLint *params )
GLenum glGetError ( void )
@@ -75,7 +75,7 @@ void glGetTexParameterfv ( GLenum target, GLenum pname, GLfloat *params ) void glGetTexParameteriv ( GLenum target, GLenum pname, GLint *params )
void glGetUniformfv ( GLuint program, GLint location, GLfloat *params )
void glGetUniformiv ( GLuint program, GLint location, GLint *params )
-int glGetUniformLocation ( GLuint program, const char *name )
+GLint glGetUniformLocation ( GLuint program, const char *name )
void glGetVertexAttribfv ( GLuint index, GLenum pname, GLfloat *params )
void glGetVertexAttribiv ( GLuint index, GLenum pname, GLint *params )
// void glGetVertexAttribPointerv ( GLuint index, GLenum pname, void **pointer )
diff --git a/opengl/tools/glgen/src/CFunc.java b/opengl/tools/glgen/src/CFunc.java index 4847694..a192c00 100644 --- a/opengl/tools/glgen/src/CFunc.java +++ b/opengl/tools/glgen/src/CFunc.java @@ -28,6 +28,7 @@ public class CFunc { boolean hasPointerArg = false; boolean hasTypedPointerArg = false; + boolean hasEGLHandleArg = false; public CFunc(String original) { this.original = original; @@ -63,6 +64,9 @@ public class CFunc { if (argType.isTypedPointer()) { hasTypedPointerArg = true; } + if (argType.isEGLHandle()) { + hasEGLHandleArg = true; + } } public int getNumArgs() { @@ -95,6 +99,10 @@ public class CFunc { return hasTypedPointerArg; } + public boolean hasEGLHandleArg() { + return hasEGLHandleArg; + } + @Override public String toString() { String s = "Function " + fname + " returns " + ftype + ": "; diff --git a/opengl/tools/glgen/src/CType.java b/opengl/tools/glgen/src/CType.java index e0f0ca6..92950ea 100644 --- a/opengl/tools/glgen/src/CType.java +++ b/opengl/tools/glgen/src/CType.java @@ -53,6 +53,16 @@ public class CType { return isPointer; } + public boolean isEGLHandle() { + if(baseType.equals("EGLContext") + || baseType.equals("EGLConfig") + || baseType.equals("EGLSurface") + || baseType.equals("EGLDisplay")) { + return true; + } + return false; + } + boolean isVoid() { String baseType = getBaseType(); return baseType.equals("GLvoid") || diff --git a/opengl/tools/glgen/src/EGLCodeEmitter.java b/opengl/tools/glgen/src/EGLCodeEmitter.java new file mode 100644 index 0000000..300f776 --- /dev/null +++ b/opengl/tools/glgen/src/EGLCodeEmitter.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012 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. + */ + +import java.io.PrintStream; + +/** + * Emits a Java interface and Java & C implementation for a C function. + * + * <p> The Java interface will have Buffer and array variants for functions that + * have a typed pointer argument. The array variant will convert a single "<type> *data" + * argument to a pair of arguments "<type>[] data, int offset". + */ +public class EGLCodeEmitter extends JniCodeEmitter { + + PrintStream mJavaImplStream; + PrintStream mCStream; + + PrintStream mJavaInterfaceStream; + + /** + */ + public EGLCodeEmitter(String classPathName, + ParameterChecker checker, + PrintStream javaImplStream, + PrintStream cStream) { + mClassPathName = classPathName; + mChecker = checker; + + mJavaImplStream = javaImplStream; + mCStream = cStream; + mUseContextPointer = false; + mUseStaticMethods = true; + mUseSimpleMethodNames = true; + mUseHideCommentForAPI = false; + } + + public void emitCode(CFunc cfunc, String original) { + emitCode(cfunc, original, null, mJavaImplStream, + mCStream); + } + + public void emitNativeRegistration(String nativeRegistrationName) { + emitNativeRegistration(nativeRegistrationName, mCStream); + } +} diff --git a/opengl/tools/glgen/src/GenerateEGL.java b/opengl/tools/glgen/src/GenerateEGL.java new file mode 100644 index 0000000..aaa748c --- /dev/null +++ b/opengl/tools/glgen/src/GenerateEGL.java @@ -0,0 +1,109 @@ +/* + * Copyright 2012 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. + */ + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; + +public class GenerateEGL { + + private static void copy(String filename, PrintStream out) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(filename)); + String s; + while ((s = br.readLine()) != null) { + out.println(s); + } + } + + private static void emit(EGLCodeEmitter emitter, + BufferedReader specReader, + PrintStream glStream, + PrintStream cStream) throws Exception { + String s = null; + while ((s = specReader.readLine()) != null) { + if (s.trim().startsWith("//")) { + continue; + } + + CFunc cfunc = CFunc.parseCFunc(s); + + String fname = cfunc.getName(); + String stubRoot = "stubs/egl/" + fname; + String javaPath = stubRoot + ".java"; + File f = new File(javaPath); + if (f.exists()) { + System.out.println("Special-casing function " + fname); + copy(javaPath, glStream); + copy(stubRoot + ".cpp", cStream); + + // Register native function names + // This should be improved to require fewer discrete files + String filename = stubRoot + ".nativeReg"; + BufferedReader br = + new BufferedReader(new FileReader(filename)); + String nfunc; + while ((nfunc = br.readLine()) != null) { + emitter.addNativeRegistration(nfunc); + } + } else { + emitter.emitCode(cfunc, s); + } + } + } + + public static void main(String[] args) throws Exception { + int aidx = 0; + while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) { + switch (args[aidx].charAt(1)) { + default: + System.err.println("Unknown flag: " + args[aidx]); + System.exit(1); + } + + aidx++; + } + + BufferedReader checksReader = + new BufferedReader(new FileReader("specs/egl/checks.spec")); + ParameterChecker checker = new ParameterChecker(checksReader); + + + BufferedReader specReader = + new BufferedReader(new FileReader("specs/egl/EGL14.spec")); + + String egljFilename = "android/opengl/EGL14.java"; + String eglcFilename = "android_opengl_EGL14.cpp"; + PrintStream egljStream = + new PrintStream(new FileOutputStream("out/" + egljFilename)); + PrintStream eglcStream = + new PrintStream(new FileOutputStream("out/" + eglcFilename)); + egljStream.println("/*"); + eglcStream.println("/*"); + copy("stubs/egl/EGL14Header.java-if", egljStream); + copy("stubs/egl/EGL14cHeader.cpp", eglcStream); + EGLCodeEmitter emitter = new EGLCodeEmitter( + "android/opengl/EGL14", + checker, egljStream, eglcStream); + emit(emitter, specReader, egljStream, eglcStream); + emitter.emitNativeRegistration("register_android_opengl_jni_EGL14"); + egljStream.println("}"); + egljStream.close(); + eglcStream.close(); + } +} diff --git a/opengl/tools/glgen/src/JType.java b/opengl/tools/glgen/src/JType.java index deb2f01..3f7cb73 100644 --- a/opengl/tools/glgen/src/JType.java +++ b/opengl/tools/glgen/src/JType.java @@ -48,6 +48,22 @@ public class JType { typeMapping.put(new CType("char", true, true), new JType("String", false, false)); typeMapping.put(new CType("int"), new JType("int")); + // EGL primitive types + typeMapping.put(new CType("EGLint"), new JType("int")); + typeMapping.put(new CType("EGLBoolean"), new JType("boolean")); + typeMapping.put(new CType("EGLenum"), new JType("int")); + typeMapping.put(new CType("EGLNativePixmapType"), new JType("int")); + typeMapping.put(new CType("EGLNativeWindowType"), new JType("int")); + typeMapping.put(new CType("EGLNativeDisplayType"), new JType("int")); + typeMapping.put(new CType("EGLClientBuffer"), new JType("int")); + + // EGL nonprimitive types + typeMapping.put(new CType("EGLConfig"), new JType("EGLConfig", true, false)); + typeMapping.put(new CType("EGLContext"), new JType("EGLContext", true, false)); + typeMapping.put(new CType("EGLDisplay"), new JType("EGLDisplay", true, false)); + typeMapping.put(new CType("EGLSurface"), new JType("EGLSurface", true, false)); + + // Untyped pointers map to untyped Buffers typeMapping.put(new CType("GLvoid", true, true), new JType("java.nio.Buffer", true, false)); @@ -88,7 +104,7 @@ public class JType { arrayTypeMapping.put(new CType("char", false, true), new JType("byte", false, true)); arrayTypeMapping.put(new CType("GLboolean", false, true), - new JType("boolean", false, true)); + new JType("boolean", false, true)); arrayTypeMapping.put(new CType("GLenum", false, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLfixed", true, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLfixed", false, true), new JType("int", false, true)); @@ -103,6 +119,13 @@ public class JType { arrayTypeMapping.put(new CType("GLuint", true, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLintptr"), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLsizeiptr"), new JType("int", false, true)); + + //EGL typed pointers map to arrays + offsets + arrayTypeMapping.put(new CType("EGLint", false, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("EGLint", true, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("EGLConfig", false, true), new JType("EGLConfig", true, true)); + arrayTypeMapping.put(new CType("EGLConfig", true, true), new JType("EGLConfig", true, true)); + } public JType() { @@ -158,6 +181,11 @@ public class JType { (baseType.indexOf("Buffer") != -1); } + public boolean isEGLHandle() { + return !isPrimitive() && + (baseType.startsWith("EGL")); + } + public static JType convert(CType ctype, boolean useArray) { JType javaType = null; if (useArray) { diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 9fa2b74..774f40c 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -25,6 +25,8 @@ public class JniCodeEmitter { static final boolean mUseCPlusPlus = true; protected boolean mUseContextPointer = true; protected boolean mUseStaticMethods = false; + protected boolean mUseSimpleMethodNames = false; + protected boolean mUseHideCommentForAPI = false; protected String mClassPathName; protected ParameterChecker mChecker; protected List<String> nativeRegistrations = new ArrayList<String>(); @@ -34,7 +36,9 @@ public class JniCodeEmitter { public static String getJniName(JType jType) { String jniName = ""; - if (jType.isClass()) { + if (jType.isEGLHandle()) { + return (jType.isArray() ? "[" : "" ) + "Landroid/opengl/" + jType.getBaseType() + ";"; + } else if (jType.isClass()) { return "L" + jType.getBaseType() + ";"; } else if (jType.isArray()) { jniName = "["; @@ -63,7 +67,6 @@ public class JniCodeEmitter { return jniName; } - public void emitCode(CFunc cfunc, String original, PrintStream javaInterfaceStream, PrintStream javaImplStream, @@ -96,6 +99,10 @@ public class JniCodeEmitter { if (!duplicate) { emitJniCode(jfunc, cStream); } + // Don't create IOBuffer versions of the EGL functions + if (cfunc.hasEGLHandleArg()) { + return; + } } jfunc = JFunc.convert(cfunc, false); @@ -121,8 +128,13 @@ public class JniCodeEmitter { } public void emitNativeDeclaration(JFunc jfunc, PrintStream out) { - out.println(" // C function " + jfunc.getCFunc().getOriginal()); - out.println(); + if (mUseHideCommentForAPI) { + out.println(" /* @hide C function " + jfunc.getCFunc().getOriginal() + " */"); + out.println(); + } else { + out.println(" // C function " + jfunc.getCFunc().getOriginal()); + out.println(); + } emitFunction(jfunc, out, true, false); } @@ -197,15 +209,17 @@ public class JniCodeEmitter { out.println(iii + "}"); out.println(iii + "if (" + remaining + " < _needed) {"); - if (emitExceptionCheck) { - out.println(iii + indent + "_exception = 1;"); - } - out.println(iii + indent + "jniThrowException(_env, " + - "\"java/lang/IllegalArgumentException\", " + - "\"" + (isBuffer ? "remaining()" : "length - " + offset) + " < needed\");"); + out.println(iii + indent + "_exception = 1;"); + out.println(iii + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(iii + indent + + "_exceptionMessage = \"" + + (isBuffer ? "remaining()" : "length - " + offset) + + " < needed\";"); out.println(iii + indent + "goto exit;"); - needsExit = true; out.println(iii + "}"); + + needsExit = true; } boolean isNullAllowed(CFunc cfunc) { @@ -213,28 +227,70 @@ public class JniCodeEmitter { int index = 1; if (checks != null) { while (index < checks.length) { - if (checks[index].equals("return")) { - index += 2; - } else if (checks[index].startsWith("check")) { - index += 3; - } else if (checks[index].equals("ifcheck")) { - index += 5; - } else if (checks[index].equals("unsupported")) { - index += 1; - } else if (checks[index].equals("requires")) { - index += 2; - } else if (checks[index].equals("nullAllowed")) { + if (checks[index].equals("nullAllowed")) { return true; } else { - System.out.println("Error: unknown keyword \"" + - checks[index] + "\""); - System.exit(0); + index = skipOneCheck(checks, index); } } } return false; } + boolean hasCheckTest(CFunc cfunc) { + String[] checks = mChecker.getChecks(cfunc.getName()); + int index = 1; + if (checks != null) { + while (index < checks.length) { + if (checks[index].startsWith("check")) { + return true; + } else { + index = skipOneCheck(checks, index); + } + } + } + return false; + } + + boolean hasIfTest(CFunc cfunc) { + String[] checks = mChecker.getChecks(cfunc.getName()); + int index = 1; + if (checks != null) { + while (index < checks.length) { + if (checks[index].startsWith("ifcheck")) { + return true; + } else { + index = skipOneCheck(checks, index); + } + } + } + return false; + } + + int skipOneCheck(String[] checks, int index) { + if (checks[index].equals("return")) { + index += 2; + } else if (checks[index].startsWith("check")) { + index += 3; + } else if (checks[index].startsWith("sentinel")) { + index += 3; + } else if (checks[index].equals("ifcheck")) { + index += 5; + } else if (checks[index].equals("unsupported")) { + index += 1; + } else if (checks[index].equals("requires")) { + index += 2; + } else if (checks[index].equals("nullAllowed")) { + index += 1; + } else { + System.out.println("Error: unknown keyword \"" + + checks[index] + "\""); + System.exit(0); + } + + return index; + } + String getErrorReturnValue(CFunc cfunc) { CType returnType = cfunc.getType(); boolean isVoid = returnType.isVoid(); @@ -242,6 +298,10 @@ public class JniCodeEmitter { return null; } + if (returnType.getBaseType().startsWith("EGL")) { + return "(" + returnType.getDeclaration() + ") 0"; + } + String[] checks = mChecker.getChecks(cfunc.getName()); int index = 1; @@ -249,20 +309,8 @@ public class JniCodeEmitter { while (index < checks.length) { if (checks[index].equals("return")) { return checks[index + 1]; - } else if (checks[index].startsWith("check")) { - index += 3; - } else if (checks[index].equals("ifcheck")) { - index += 5; - } else if (checks[index].equals("unsupported")) { - index += 1; - } else if (checks[index].equals("requires")) { - index += 2; - } else if (checks[index].equals("nullAllowed")) { - index += 1; } else { - System.out.println("Error: unknown keyword \"" + - checks[index] + "\""); - System.exit(0); + index = skipOneCheck(checks, index); } } } @@ -277,20 +325,8 @@ public class JniCodeEmitter { while (index < checks.length) { if (checks[index].equals("unsupported")) { return true; - } else if (checks[index].equals("requires")) { - index += 2; - } else if (checks[index].equals("return")) { - index += 2; - } else if (checks[index].startsWith("check")) { - index += 3; - } else if (checks[index].equals("ifcheck")) { - index += 5; - } else if (checks[index].equals("nullAllowed")) { - index += 1; } else { - System.out.println("Error: unknown keyword \"" + - checks[index] + "\""); - System.exit(0); + index = skipOneCheck(checks, index); } } } @@ -302,22 +338,10 @@ public class JniCodeEmitter { int index = 1; if (checks != null) { while (index < checks.length) { - if (checks[index].equals("unsupported")) { - index += 1; - } else if (checks[index].equals("requires")) { + if (checks[index].equals("requires")) { return checks[index+1]; - } else if (checks[index].equals("return")) { - index += 2; - } else if (checks[index].startsWith("check")) { - index += 3; - } else if (checks[index].equals("ifcheck")) { - index += 5; - } else if (checks[index].equals("nullAllowed")) { - index += 1; } else { - System.out.println("Error: unknown keyword \"" + - checks[index] + "\""); - System.exit(0); + index = skipOneCheck(checks, index); } } } @@ -345,9 +369,7 @@ public class JniCodeEmitter { continue; } out.println(iii + "if (" + remaining + " < " + checks[index + 2] + ") {"); - if (emitExceptionCheck) { - out.println(iii + indent + "_exception = 1;"); - } + out.println(iii + indent + "_exception = 1;"); String exceptionClassName = "java/lang/IllegalArgumentException"; // If the "check" keyword was of the form // "check_<class name>", use the class name in the @@ -361,14 +383,19 @@ public class JniCodeEmitter { throw new RuntimeException("unknown exception abbreviation: " + abbr); } } - out.println(iii + indent + "jniThrowException(_env, " + - "\"" + exceptionClassName + "\", " + - "\"" + (isBuffer ? "remaining()" : "length - " + offset) + " < " + checks[index + 2] + "\");"); + out.println(iii + indent + + "_exceptionType = \""+exceptionClassName+"\";"); + out.println(iii + indent + + "_exceptionMessage = \"" + + (isBuffer ? "remaining()" : "length - " + + offset) + " < " + checks[index + 2] + + " < needed\";"); out.println(iii + indent + "goto exit;"); - needsExit = true; out.println(iii + "}"); + needsExit = true; + index += 3; } else if (checks[index].equals("ifcheck")) { String[] matches = checks[index + 4].split(","); @@ -388,21 +415,8 @@ public class JniCodeEmitter { lastWasIfcheck = true; index += 5; - } else if (checks[index].equals("return")) { - // ignore - index += 2; - } else if (checks[index].equals("unsupported")) { - // ignore - index += 1; - } else if (checks[index].equals("requires")) { - // ignore - index += 2; - } else if (checks[index].equals("nullAllowed")) { - // ignore - index += 1; } else { - System.out.println("Error: unknown keyword \"" + checks[index] + "\""); - System.exit(0); + index = skipOneCheck(checks, index); } } } @@ -412,6 +426,69 @@ public class JniCodeEmitter { } } + void emitSentinelCheck(CFunc cfunc, String cname, PrintStream out, + boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { + + String[] checks = mChecker.getChecks(cfunc.getName()); + + int index = 1; + if (checks != null) { + while (index < checks.length) { + if (checks[index].startsWith("sentinel")) { + if (cname != null && !cname.equals(checks[index + 1])) { + index += 3; + continue; + } + + out.println(iii + cname + "_sentinel = false;"); + out.println(iii + "for (int i = " + remaining + + " - 1; i >= 0; i--) {"); + out.println(iii + indent + "if (" + cname + + "[i] == " + checks[index + 2] + "){"); + out.println(iii + indent + indent + + cname + "_sentinel = true;"); + out.println(iii + indent + indent + "break;"); + out.println(iii + indent + "}"); + out.println(iii + "}"); + out.println(iii + + "if (" + cname + "_sentinel == false) {"); + out.println(iii + indent + "_exception = 1;"); + out.println(iii + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(iii + indent + "_exceptionMessage = \"" + cname + + " must contain " + checks[index + 2] + "!\";"); + out.println(iii + indent + "goto exit;"); + out.println(iii + "}"); + + needsExit = true; + index += 3; + } else { + index = skipOneCheck(checks, index); + } + } + } + } + + void emitLocalVariablesForSentinel(CFunc cfunc, PrintStream out) { + + String[] checks = mChecker.getChecks(cfunc.getName()); + + int index = 1; + if (checks != null) { + while (index < checks.length) { + if (checks[index].startsWith("sentinel")) { + String cname = checks[index + 1]; + out.println(indent + "bool " + cname + "_sentinel = false;"); + + index += 3; + + } else { + index = skipOneCheck(checks, index); + } + } + } + } + boolean hasNonConstArg(JFunc jfunc, CFunc cfunc, List<Integer> nonPrimitiveArgs) { if (nonPrimitiveArgs.size() > 0) { for (int i = nonPrimitiveArgs.size() - 1; i >= 0; i--) { @@ -638,7 +715,7 @@ public class JniCodeEmitter { return "j" + baseType; } } else if (jType.isArray()) { - return "j" + baseType + "Array"; + return jType.isClass() ? "jobjectArray" : "j" + baseType + "Array"; } else { return "jobject"; } @@ -698,8 +775,10 @@ public class JniCodeEmitter { // Append signature to function name String sig = getJniMangledName(signature).replace('.', '_').replace('/', '_'); - out.print("__" + sig); - outName += "__" + sig; + if (!mUseSimpleMethodNames) { + out.print("__" + sig); + outName += "__" + sig; + } signature = signature.replace('.', '/'); rsignature = rsignature.replace('.', '/'); @@ -734,11 +813,11 @@ public class JniCodeEmitter { for (int i = 0; i < numArgs; i++) { out.print(", "); JType argType = jfunc.getArgType(i); - String suffix; + String suffix = ""; if (!argType.isPrimitive()) { if (argType.isArray()) { suffix = "_ref"; - } else { + } else if (argType.isBuffer()) { suffix = "_buf"; } nonPrimitiveArgs.add(new Integer(i)); @@ -748,9 +827,8 @@ public class JniCodeEmitter { bufferArgNames.add(cname); numBufferArgs++; } - } else { - suffix = ""; } + if (argType.isString()) { stringArgs.add(new Integer(i)); } @@ -801,7 +879,14 @@ public class JniCodeEmitter { " \"" + cfunc.getName() + "\");"); if (!isVoid) { String retval = getErrorReturnValue(cfunc); - out.println(indent + "return " + retval + ";"); + if (cfunc.getType().isEGLHandle()) { + String baseType = cfunc.getType().getBaseType().toLowerCase(); + out.println(indent + + "return toEGLHandle(_env, " + baseType + "Class, " + + baseType + "Constructor, " + retval + ");"); + } else { + out.println(indent + "return " + retval + ";"); + } } out.println("}"); out.println(); @@ -820,7 +905,14 @@ public class JniCodeEmitter { out.println(indent + indent + " return;"); } else { String retval = getErrorReturnValue(cfunc); - out.println(indent + indent + " return " + retval + ";"); + if (cfunc.getType().isEGLHandle()) { + String baseType = cfunc.getType().getBaseType().toLowerCase(); + out.println(indent + + "return toEGLHandle(_env, " + baseType + "Class, " + + baseType + "Constructor, " + retval + ");"); + } else { + out.println(indent + "return " + retval + ";"); + } } out.println(indent + "}"); } @@ -830,23 +922,30 @@ public class JniCodeEmitter { } boolean initializeReturnValue = stringArgs.size() > 0; - - boolean emitExceptionCheck = (numArrays > 0 || numBuffers > 0 || numStrings > 0) && - hasNonConstArg(jfunc, cfunc, nonPrimitiveArgs); + boolean emitExceptionCheck = ((numArrays > 0 || numStrings > 0) + && (hasNonConstArg(jfunc, cfunc, nonPrimitiveArgs) + || (cfunc.hasPointerArg() && numArrays > 0)) + || hasCheckTest(cfunc) + || hasIfTest(cfunc)) + || (stringArgs.size() > 0); // mChecker.getChecks(cfunc.getName()) != null - // Emit an _exeption variable if there will be error checks if (emitExceptionCheck) { out.println(indent + "jint _exception = 0;"); + out.println(indent + "const char * _exceptionType;"); + out.println(indent + "const char * _exceptionMessage;"); } // Emit a single _array or multiple _XXXArray variables if (numBufferArgs == 1) { out.println(indent + "jarray _array = (jarray) 0;"); + out.println(indent + "jint _bufferOffset = (jint) 0;"); } else { for (int i = 0; i < numBufferArgs; i++) { out.println(indent + "jarray _" + bufferArgNames.get(i) + "Array = (jarray) 0;"); + out.println(indent + "jint _" + bufferArgNames.get(i) + + "BufferOffset = (jint) 0;"); } } if (!isVoid) { @@ -856,13 +955,49 @@ public class JniCodeEmitter { " _returnValue = " + retval + ";"); } else if (initializeReturnValue) { out.println(indent + returnType.getDeclaration() + - " _returnValue = 0;"); + " _returnValue = 0;"); } else { out.println(indent + returnType.getDeclaration() + " _returnValue;"); } } + // Emit local variable declarations for EGL Handles + // + // Example: + // + // EGLSurface surface_native = (EGLHandle)fromEGLHandle(_env, surfaceClass, surfaceConstructor, surface); + // + if (nonPrimitiveArgs.size() > 0) { + for (int i = 0; i < nonPrimitiveArgs.size(); i++) { + int idx = nonPrimitiveArgs.get(i).intValue(); + int cIndex = jfunc.getArgCIndex(idx); + String cname = cfunc.getArgName(cIndex); + + if (jfunc.getArgType(idx).isBuffer() + || jfunc.getArgType(idx).isArray() + || !jfunc.getArgType(idx).isEGLHandle()) + continue; + + CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); + String decl = type.getDeclaration(); + out.println(indent + + decl + " " + cname + "_native = (" + + decl + ") fromEGLHandle(_env, " + + type.getBaseType().toLowerCase() + + "GetHandleID, " + jfunc.getArgName(idx) + + ");"); + } + } + + // Emit local variable declarations for element/sentinel checks + // + // Example: + // + // bool attrib_list_sentinel_found = false; + // + emitLocalVariablesForSentinel(cfunc, out); + // Emit local variable declarations for pointer arguments // // Example: @@ -878,9 +1013,12 @@ public class JniCodeEmitter { int cIndex = jfunc.getArgCIndex(idx); String cname = cfunc.getArgName(cIndex); + if (!jfunc.getArgType(idx).isBuffer() && !jfunc.getArgType(idx).isArray()) + continue; + CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); String decl = type.getDeclaration(); - if (jfunc.getArgType(idx).isArray()) { + if (jfunc.getArgType(idx).isArray() && !jfunc.getArgType(idx).isClass()) { out.println(indent + decl + (decl.endsWith("*") ? "" : " ") + @@ -892,10 +1030,10 @@ public class JniCodeEmitter { out.println(indent + "jint " + remaining + ";"); out.println(indent + - decl + - (decl.endsWith("*") ? "" : " ") + - jfunc.getArgName(idx) + - " = (" + decl + ") 0;"); + decl + + (decl.endsWith("*") ? "" : " ") + + jfunc.getArgName(idx) + + " = (" + decl + ") 0;"); } out.println(); @@ -923,11 +1061,13 @@ public class JniCodeEmitter { CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); String decl = type.getDeclaration(); - out.println(indent + "if (!" + cname + ") {"); - out.println(indent + " jniThrowException(_env, " + - "\"java/lang/IllegalArgumentException\", \"" + cname + " == null\");"); - out.println(indent + " goto exit;"); needsExit = true; + out.println(indent + "if (!" + cname + ") {"); + out.println(indent + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(indent + indent + + "_exceptionMessage = \"" + cname + " == null\";"); + out.println(indent + indent + "goto exit;"); out.println(indent + "}"); out.println(indent + "_native" + cname + " = _env->GetStringUTFChars(" + cname + ", 0);"); @@ -936,9 +1076,8 @@ public class JniCodeEmitter { out.println(); } - // Emit 'GetPrimitiveArrayCritical' for arrays + // Emit 'GetPrimitiveArrayCritical' for non-object arrays // Emit 'GetPointer' calls for Buffer pointers - int bufArgIdx = 0; if (nonPrimitiveArgs.size() > 0) { for (int i = 0; i < nonPrimitiveArgs.size(); i++) { int idx = nonPrimitiveArgs.get(i).intValue(); @@ -950,29 +1089,24 @@ public class JniCodeEmitter { remaining = ((numArrays + numBuffers) <= 1) ? "_remaining" : "_" + cname + "Remaining"; - if (jfunc.getArgType(idx).isArray()) { - out.println(indent + - "if (!" + - cname + - "_ref) {"); - if (emitExceptionCheck) { - out.println(indent + indent + "_exception = 1;"); - } - out.println(indent + " jniThrowException(_env, " + - "\"java/lang/IllegalArgumentException\", " + - "\"" + cname + " == null\");"); - out.println(indent + " goto exit;"); + if (jfunc.getArgType(idx).isArray() + && !jfunc.getArgType(idx).isEGLHandle()) { needsExit = true; + out.println(indent + "if (!" + cname + "_ref) {"); + out.println(indent + indent + "_exception = 1;"); + out.println(indent + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(indent + indent + + "_exceptionMessage = \"" + cname +" == null\";"); + out.println(indent + indent + "goto exit;"); out.println(indent + "}"); - out.println(indent + "if (" + offset + " < 0) {"); - if (emitExceptionCheck) { - out.println(indent + indent + "_exception = 1;"); - } - out.println(indent + " jniThrowException(_env, " + - "\"java/lang/IllegalArgumentException\", \"" + offset + " < 0\");"); - out.println(indent + " goto exit;"); - needsExit = true; + out.println(indent + indent + "_exception = 1;"); + out.println(indent + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(indent + indent + + "_exceptionMessage = \"" + offset +" < 0\";"); + out.println(indent + indent + "goto exit;"); out.println(indent + "}"); out.println(indent + remaining + " = " + @@ -997,12 +1131,48 @@ public class JniCodeEmitter { jfunc.getArgName(idx) + "_ref, (jboolean *)0);"); out.println(indent + - cname + " = " + cname + "_base + " + offset + - ";"); + cname + " = " + cname + "_base + " + offset + ";"); + + emitSentinelCheck(cfunc, cname, out, false, + emitExceptionCheck, offset, + remaining, indent); out.println(); - } else { + } else if (jfunc.getArgType(idx).isArray() + && jfunc.getArgType(idx).isEGLHandle()) { + needsExit = true; + out.println(indent + "if (!" + cname + "_ref) {"); + out.println(indent + indent + "_exception = 1;"); + out.println(indent + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(indent + indent + "_exceptionMessage = \"" + cname +" == null\";"); + out.println(indent + indent + "goto exit;"); + out.println(indent + "}"); + out.println(indent + "if (" + offset + " < 0) {"); + out.println(indent + indent + "_exception = 1;"); + out.println(indent + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(indent + indent + "_exceptionMessage = \"" + offset +" < 0\";"); + out.println(indent + indent + "goto exit;"); + out.println(indent + "}"); + + out.println(indent + remaining + " = " + + (mUseCPlusPlus ? "_env" : "(*_env)") + + "->GetArrayLength(" + + (mUseCPlusPlus ? "" : "_env, ") + + cname + "_ref) - " + offset + ";"); + emitNativeBoundsChecks(cfunc, cname, out, false, + emitExceptionCheck, + offset, remaining, " "); + out.println(indent + + jfunc.getArgName(idx) + " = new " + + cfunc.getArgType(cIndex).getBaseType() + + "["+ remaining + "];"); + out.println(); + } else if (jfunc.getArgType(idx).isBuffer()) { String array = numBufferArgs <= 1 ? "_array" : - "_" + bufferArgNames.get(bufArgIdx++) + "Array"; + "_" + cfunc.getArgName(cIndex) + "Array"; + String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" : + "_" + cfunc.getArgName(cIndex) + "BufferOffset"; boolean nullAllowed = isNullAllowed(cfunc) || isPointerFunc; if (nullAllowed) { @@ -1019,7 +1189,7 @@ public class JniCodeEmitter { cname + "_buf);"); String iii = " "; out.println(iii + indent + "if ( ! " + cname + " ) {"); - out.println(iii + iii + indent + "return;"); + out.println(iii + indent + indent + "return;"); out.println(iii + indent + "}"); } else { out.println(indent + @@ -1028,7 +1198,7 @@ public class JniCodeEmitter { cfunc.getArgType(cIndex).getDeclaration() + ")getPointer(_env, " + cname + - "_buf, &" + array + ", &" + remaining + + "_buf, &" + array + ", &" + remaining + ", &" + bufferOffset + ");"); } @@ -1043,6 +1213,33 @@ public class JniCodeEmitter { } } + // Emit 'GetPrimitiveArrayCritical' for pointers if needed + if (nonPrimitiveArgs.size() > 0) { + for (int i = 0; i < nonPrimitiveArgs.size(); i++) { + int idx = nonPrimitiveArgs.get(i).intValue(); + int cIndex = jfunc.getArgCIndex(idx); + + if(!jfunc.getArgType(idx).isBuffer() || isPointerFunc) continue; + + String cname = cfunc.getArgName(cIndex); + String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" : + "_" + cname + "BufferOffset"; + String array = numBufferArgs <= 1 ? "_array" : + "_" + cfunc.getArgName(cIndex) + "Array"; + + boolean nullAllowed = isNullAllowed(cfunc) || isPointerFunc; + if (nullAllowed) { + out.println(indent + "if (" + cname + "_buf && " + cname +" == NULL) {"); + } else { + out.println(indent + "if (" + cname +" == NULL) {"); + } + out.println(indent + indent + "char * _" + cname + "Base = (char *)_env->GetPrimitiveArrayCritical(" + array + ", (jboolean *) 0);"); + out.println(indent + indent + cname + " = (" +cfunc.getArgType(cIndex).getDeclaration() +") (_" + cname + "Base + " + bufferOffset + ");"); + out.println(indent + "}"); + } + } + + if (!isVoid) { out.print(indent + "_returnValue = "); } else { @@ -1075,18 +1272,23 @@ public class JniCodeEmitter { for (int i = 0; i < numArgs; i++) { String typecast; if (i == numArgs - 1 && isVBOPointerFunc) { - typecast = "const GLvoid *"; + typecast = "(const GLvoid *)"; } else { - typecast = cfunc.getArgType(i).getDeclaration(); + typecast = "(" + cfunc.getArgType(i).getDeclaration() + ")"; } out.print(indent + indent + - "(" + - typecast + - ")"); + typecast); + if (cfunc.getArgType(i).isConstCharPointer()) { out.print("_native"); } - out.print(cfunc.getArgName(i)); + + if (cfunc.getArgType(i).isEGLHandle() && + !cfunc.getArgType(i).isPointer()){ + out.print(cfunc.getArgName(i)+"_native"); + } else { + out.print(cfunc.getArgName(i)); + } if (i == numArgs - 1) { if (isPointerFunc) { @@ -1108,13 +1310,13 @@ public class JniCodeEmitter { needsExit = false; } - bufArgIdx = 0; + if (nonPrimitiveArgs.size() > 0) { for (int i = nonPrimitiveArgs.size() - 1; i >= 0; i--) { int idx = nonPrimitiveArgs.get(i).intValue(); int cIndex = jfunc.getArgCIndex(idx); - if (jfunc.getArgType(idx).isArray()) { + if (jfunc.getArgType(idx).isArray() && !jfunc.getArgType(idx).isClass()) { // If the argument is 'const', GL will not write to it. // In this case, we can use the 'JNI_ABORT' flag to avoid @@ -1130,22 +1332,21 @@ public class JniCodeEmitter { "_base,"); out.println(indent + indent + indent + (cfunc.getArgType(cIndex).isConst() ? - "JNI_ABORT" : - "_exception ? JNI_ABORT: 0") + + "JNI_ABORT" : "_exception ? JNI_ABORT: 0" ) + ");"); out.println(indent + "}"); } else if (jfunc.getArgType(idx).isBuffer()) { if (! isPointerFunc) { String array = numBufferArgs <= 1 ? "_array" : - "_" + bufferArgNames.get(bufArgIdx++) + "Array"; + "_" + cfunc.getArgName(cIndex) + "Array"; out.println(indent + "if (" + array + ") {"); out.println(indent + indent + "releasePointer(_env, " + array + ", " + cfunc.getArgName(cIndex) + ", " + (cfunc.getArgType(cIndex).isConst() ? - "JNI_FALSE" : "_exception ? JNI_FALSE :" + - " JNI_TRUE") + + "JNI_FALSE" : (emitExceptionCheck ? + "_exception ? JNI_FALSE : JNI_TRUE" : "JNI_TRUE")) + ");"); out.println(indent + "}"); } @@ -1168,9 +1369,60 @@ public class JniCodeEmitter { out.println(); } + // Copy results back to java arrays + if (nonPrimitiveArgs.size() > 0) { + for (int i = nonPrimitiveArgs.size() - 1; i >= 0; i--) { + int idx = nonPrimitiveArgs.get(i).intValue(); + int cIndex = jfunc.getArgCIndex(idx); + String baseType = cfunc.getArgType(cIndex).getBaseType().toLowerCase(); + if (jfunc.getArgType(idx).isArray() && jfunc.getArgType(idx).isClass()) { + remaining = ((numArrays + numBuffers) <= 1) ? "_remaining" : + "_" + cfunc.getArgName(cIndex) + "Remaining"; + offset = numArrays <= 1 ? "offset" : cfunc.getArgName(cIndex) + "Offset"; + out.println(indent + + "if (" + jfunc.getArgName(idx) + ") {"); + out.println(indent + indent + + "for (int i = 0; i < " + remaining + "; i++) {"); + out.println(indent + indent + indent + + "jobject " + cfunc.getArgName(cIndex) + + "_new = toEGLHandle(_env, " + baseType + + "Class, " + baseType + "Constructor, " + + cfunc.getArgName(cIndex) + "[i]);"); + out.println(indent + indent + indent + + (mUseCPlusPlus ? "_env" : "(*_env)") + + "->SetObjectArrayElement(" + + (mUseCPlusPlus ? "" : "_env, ") + + cfunc.getArgName(cIndex) + + "_ref, i + " + offset + ", " + + cfunc.getArgName(cIndex) + "_new);"); + out.println(indent + indent + "}"); + out.println(indent + indent + + "delete[] " + jfunc.getArgName(idx) + ";"); + out.println(indent + "}"); + } + } + } + + + // Throw exception if there is one + if (emitExceptionCheck) { + out.println(indent + "if (_exception) {"); + out.println(indent + indent + + "jniThrowException(_env, _exceptionType, _exceptionMessage);"); + out.println(indent + "}"); + + } + if (!isVoid) { - out.println(indent + "return _returnValue;"); + if (cfunc.getType().isEGLHandle()) { + String baseType = cfunc.getType().getBaseType().toLowerCase(); + out.println(indent + + "return toEGLHandle(_env, " + baseType + "Class, " + + baseType + "Constructor, _returnValue);"); + } else { + out.println(indent + "return _returnValue;"); + } } out.println("}"); diff --git a/opengl/tools/glgen/static/egl/EGLConfig.java b/opengl/tools/glgen/static/egl/EGLConfig.java new file mode 100644 index 0000000..d457c9f --- /dev/null +++ b/opengl/tools/glgen/static/egl/EGLConfig.java @@ -0,0 +1,37 @@ +/* +** +** Copyright 2012, 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. +*/ + +package android.opengl; + +/** + * Wrapper class for native EGLConfig objects. + * + */ +public class EGLConfig extends EGLObjectHandle { + private EGLConfig(int handle) { + super(handle); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + EGLConfig that = (EGLConfig) o; + return getHandle() == that.getHandle(); + } +} diff --git a/opengl/tools/glgen/static/egl/EGLContext.java b/opengl/tools/glgen/static/egl/EGLContext.java new file mode 100644 index 0000000..41b8ef1 --- /dev/null +++ b/opengl/tools/glgen/static/egl/EGLContext.java @@ -0,0 +1,37 @@ +/* +** +** Copyright 2012, 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. +*/ + +package android.opengl; + +/** + * Wrapper class for native EGLContext objects. + * + */ +public class EGLContext extends EGLObjectHandle { + private EGLContext(int handle) { + super(handle); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + EGLContext that = (EGLContext) o; + return getHandle() == that.getHandle(); + } +} diff --git a/opengl/tools/glgen/static/egl/EGLDisplay.java b/opengl/tools/glgen/static/egl/EGLDisplay.java new file mode 100644 index 0000000..17d1a64 --- /dev/null +++ b/opengl/tools/glgen/static/egl/EGLDisplay.java @@ -0,0 +1,37 @@ +/* +** +** Copyright 2012, 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. +*/ + +package android.opengl; + +/** + * Wrapper class for native EGLDisplay objects. + * + */ +public class EGLDisplay extends EGLObjectHandle { + private EGLDisplay(int handle) { + super(handle); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + EGLDisplay that = (EGLDisplay) o; + return getHandle() == that.getHandle(); + } +} diff --git a/opengl/tools/glgen/static/egl/EGLObjectHandle.java b/opengl/tools/glgen/static/egl/EGLObjectHandle.java new file mode 100644 index 0000000..d2710de --- /dev/null +++ b/opengl/tools/glgen/static/egl/EGLObjectHandle.java @@ -0,0 +1,47 @@ +/* +** +** Copyright 2012, 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. +*/ + +package android.opengl; + +/** + * Base class for wrapped EGL objects. + * + */ +public abstract class EGLObjectHandle { + private final int mHandle; + + protected EGLObjectHandle(int handle) { + mHandle = handle; + } + + /** + * Returns the native handle of the wrapped EGL object. This handle can be + * cast to the corresponding native type on the native side. + * + * For example, EGLDisplay dpy = (EGLDisplay)handle; + * + * @return the native handle of the wrapped EGL object. + */ + public int getHandle() { + return mHandle; + } + + @Override + public int hashCode() { + return getHandle(); + } +} diff --git a/opengl/tools/glgen/static/egl/EGLSurface.java b/opengl/tools/glgen/static/egl/EGLSurface.java new file mode 100644 index 0000000..65bec4f --- /dev/null +++ b/opengl/tools/glgen/static/egl/EGLSurface.java @@ -0,0 +1,37 @@ +/* +** +** Copyright 2012, 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. +*/ + +package android.opengl; + +/** + * Wrapper class for native EGLSurface objects. + * + */ +public class EGLSurface extends EGLObjectHandle { + private EGLSurface(int handle) { + super(handle); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + EGLSurface that = (EGLSurface) o; + return getHandle() == that.getHandle(); + } +} diff --git a/opengl/tools/glgen/stubs/egl/EGL14Header.java-if b/opengl/tools/glgen/stubs/egl/EGL14Header.java-if new file mode 100644 index 0000000..0c29d5c --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/EGL14Header.java-if @@ -0,0 +1,151 @@ +** +** Copyright 2012, 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. +*/ + +// This source file is automatically generated + +package android.opengl; + +import android.graphics.SurfaceTexture; +import android.view.Surface; +import android.view.SurfaceView; +import android.view.SurfaceHolder; + +/** + * EGL 1.4 + * + */ +public class EGL14 { + +public static final int EGL_DEFAULT_DISPLAY = 0; +public static EGLContext EGL_NO_CONTEXT = null; +public static EGLDisplay EGL_NO_DISPLAY = null; +public static EGLSurface EGL_NO_SURFACE = null; + +public static final int EGL_FALSE = 0; +public static final int EGL_TRUE = 1; +public static final int EGL_SUCCESS = 0x3000; +public static final int EGL_NOT_INITIALIZED = 0x3001; +public static final int EGL_BAD_ACCESS = 0x3002; +public static final int EGL_BAD_ALLOC = 0x3003; +public static final int EGL_BAD_ATTRIBUTE = 0x3004; +public static final int EGL_BAD_CONFIG = 0x3005; +public static final int EGL_BAD_CONTEXT = 0x3006; +public static final int EGL_BAD_CURRENT_SURFACE = 0x3007; +public static final int EGL_BAD_DISPLAY = 0x3008; +public static final int EGL_BAD_MATCH = 0x3009; +public static final int EGL_BAD_NATIVE_PIXMAP = 0x300A; +public static final int EGL_BAD_NATIVE_WINDOW = 0x300B; +public static final int EGL_BAD_PARAMETER = 0x300C; +public static final int EGL_BAD_SURFACE = 0x300D; +public static final int EGL_CONTEXT_LOST = 0x300E; +public static final int EGL_BUFFER_SIZE = 0x3020; +public static final int EGL_ALPHA_SIZE = 0x3021; +public static final int EGL_BLUE_SIZE = 0x3022; +public static final int EGL_GREEN_SIZE = 0x3023; +public static final int EGL_RED_SIZE = 0x3024; +public static final int EGL_DEPTH_SIZE = 0x3025; +public static final int EGL_STENCIL_SIZE = 0x3026; +public static final int EGL_CONFIG_CAVEAT = 0x3027; +public static final int EGL_CONFIG_ID = 0x3028; +public static final int EGL_LEVEL = 0x3029; +public static final int EGL_MAX_PBUFFER_HEIGHT = 0x302A; +public static final int EGL_MAX_PBUFFER_PIXELS = 0x302B; +public static final int EGL_MAX_PBUFFER_WIDTH = 0x302C; +public static final int EGL_NATIVE_RENDERABLE = 0x302D; +public static final int EGL_NATIVE_VISUAL_ID = 0x302E; +public static final int EGL_NATIVE_VISUAL_TYPE = 0x302F; +public static final int EGL_SAMPLES = 0x3031; +public static final int EGL_SAMPLE_BUFFERS = 0x3032; +public static final int EGL_SURFACE_TYPE = 0x3033; +public static final int EGL_TRANSPARENT_TYPE = 0x3034; +public static final int EGL_TRANSPARENT_BLUE_VALUE = 0x3035; +public static final int EGL_TRANSPARENT_GREEN_VALUE = 0x3036; +public static final int EGL_TRANSPARENT_RED_VALUE = 0x3037; +public static final int EGL_NONE = 0x3038; +public static final int EGL_BIND_TO_TEXTURE_RGB = 0x3039; +public static final int EGL_BIND_TO_TEXTURE_RGBA = 0x303A; +public static final int EGL_MIN_SWAP_INTERVAL = 0x303B; +public static final int EGL_MAX_SWAP_INTERVAL = 0x303C; +public static final int EGL_LUMINANCE_SIZE = 0x303D; +public static final int EGL_ALPHA_MASK_SIZE = 0x303E; +public static final int EGL_COLOR_BUFFER_TYPE = 0x303F; +public static final int EGL_RENDERABLE_TYPE = 0x3040; +public static final int EGL_MATCH_NATIVE_PIXMAP = 0x3041; +public static final int EGL_CONFORMANT = 0x3042; +public static final int EGL_SLOW_CONFIG = 0x3050; +public static final int EGL_NON_CONFORMANT_CONFIG = 0x3051; +public static final int EGL_TRANSPARENT_RGB = 0x3052; +public static final int EGL_RGB_BUFFER = 0x308E; +public static final int EGL_LUMINANCE_BUFFER = 0x308F; +public static final int EGL_NO_TEXTURE = 0x305C; +public static final int EGL_TEXTURE_RGB = 0x305D; +public static final int EGL_TEXTURE_RGBA = 0x305E; +public static final int EGL_TEXTURE_2D = 0x305F; +public static final int EGL_PBUFFER_BIT = 0x0001; +public static final int EGL_PIXMAP_BIT = 0x0002; +public static final int EGL_WINDOW_BIT = 0x0004; +public static final int EGL_VG_COLORSPACE_LINEAR_BIT = 0x0020; +public static final int EGL_VG_ALPHA_FORMAT_PRE_BIT = 0x0040; +public static final int EGL_MULTISAMPLE_RESOLVE_BOX_BIT = 0x0200; +public static final int EGL_SWAP_BEHAVIOR_PRESERVED_BIT = 0x0400; +public static final int EGL_OPENGL_ES_BIT = 0x0001; +public static final int EGL_OPENVG_BIT = 0x0002; +public static final int EGL_OPENGL_ES2_BIT = 0x0004; +public static final int EGL_OPENGL_BIT = 0x0008; +public static final int EGL_VENDOR = 0x3053; +public static final int EGL_VERSION = 0x3054; +public static final int EGL_EXTENSIONS = 0x3055; +public static final int EGL_CLIENT_APIS = 0x308D; +public static final int EGL_HEIGHT = 0x3056; +public static final int EGL_WIDTH = 0x3057; +public static final int EGL_LARGEST_PBUFFER = 0x3058; +public static final int EGL_TEXTURE_FORMAT = 0x3080; +public static final int EGL_TEXTURE_TARGET = 0x3081; +public static final int EGL_MIPMAP_TEXTURE = 0x3082; +public static final int EGL_MIPMAP_LEVEL = 0x3083; +public static final int EGL_RENDER_BUFFER = 0x3086; +public static final int EGL_VG_COLORSPACE = 0x3087; +public static final int EGL_VG_ALPHA_FORMAT = 0x3088; +public static final int EGL_HORIZONTAL_RESOLUTION = 0x3090; +public static final int EGL_VERTICAL_RESOLUTION = 0x3091; +public static final int EGL_PIXEL_ASPECT_RATIO = 0x3092; +public static final int EGL_SWAP_BEHAVIOR = 0x3093; +public static final int EGL_MULTISAMPLE_RESOLVE = 0x3099; +public static final int EGL_BACK_BUFFER = 0x3084; +public static final int EGL_SINGLE_BUFFER = 0x3085; +public static final int EGL_VG_COLORSPACE_sRGB = 0x3089; +public static final int EGL_VG_COLORSPACE_LINEAR = 0x308A; +public static final int EGL_VG_ALPHA_FORMAT_NONPRE = 0x308B; +public static final int EGL_VG_ALPHA_FORMAT_PRE = 0x308C; +public static final int EGL_DISPLAY_SCALING = 10000; +public static final int EGL_BUFFER_PRESERVED = 0x3094; +public static final int EGL_BUFFER_DESTROYED = 0x3095; +public static final int EGL_OPENVG_IMAGE = 0x3096; +public static final int EGL_CONTEXT_CLIENT_TYPE = 0x3097; +public static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; +public static final int EGL_MULTISAMPLE_RESOLVE_DEFAULT = 0x309A; +public static final int EGL_MULTISAMPLE_RESOLVE_BOX = 0x309B; +public static final int EGL_OPENGL_ES_API = 0x30A0; +public static final int EGL_OPENVG_API = 0x30A1; +public static final int EGL_OPENGL_API = 0x30A2; +public static final int EGL_DRAW = 0x3059; +public static final int EGL_READ = 0x305A; +public static final int EGL_CORE_NATIVE_ENGINE = 0x305B; + + native private static void _nativeClassInit(); + static { + _nativeClassInit(); + } diff --git a/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp b/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp new file mode 100644 index 0000000..7904ac7 --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp @@ -0,0 +1,132 @@ +** +** Copyright 2012, 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. +*/ + +// This source file is automatically generated + +#include "jni.h" +#include "JNIHelp.h" +#include <android_runtime/AndroidRuntime.h> +#include <android_runtime/android_view_Surface.h> +#include <android_runtime/android_graphics_SurfaceTexture.h> +#include <utils/misc.h> + +#include <assert.h> +#include <EGL/egl.h> + +#include <gui/Surface.h> +#include <gui/SurfaceTexture.h> +#include <gui/SurfaceTextureClient.h> + +#include <ui/ANativeObjectBase.h> + +static int initialized = 0; + +static jclass egldisplayClass; +static jclass eglcontextClass; +static jclass eglsurfaceClass; +static jclass eglconfigClass; + +static jmethodID egldisplayGetHandleID; +static jmethodID eglcontextGetHandleID; +static jmethodID eglsurfaceGetHandleID; +static jmethodID eglconfigGetHandleID; + +static jmethodID egldisplayConstructor; +static jmethodID eglcontextConstructor; +static jmethodID eglsurfaceConstructor; +static jmethodID eglconfigConstructor; + +static jobject eglNoContextObject; +static jobject eglNoDisplayObject; +static jobject eglNoSurfaceObject; + + + +/* Cache method IDs each time the class is loaded. */ + +static void +nativeClassInit(JNIEnv *_env, jclass glImplClass) +{ + jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay"); + egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal); + jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext"); + eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal); + jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface"); + eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal); + jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); + eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); + + egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getHandle", "()I"); + eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getHandle", "()I"); + eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getHandle", "()I"); + eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getHandle", "()I"); + + + egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(I)V"); + eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(I)V"); + eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(I)V"); + eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(I)V"); + + jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, (jint)EGL_NO_CONTEXT); + eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); + jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, (jint)EGL_NO_DISPLAY); + eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); + jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, (jint)EGL_NO_SURFACE); + eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); + + + jclass eglClass = _env->FindClass("android/opengl/EGL14"); + jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;"); + _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject); + + jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;"); + _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject); + + jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;"); + _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject); +} + +static void * +fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { + if (obj == NULL){ + jniThrowException(_env, "java/lang/IllegalArgumentException", + "Object is set to null."); + } + + return (void*) (_env->CallIntMethod(obj, mid)); +} + +static jobject +toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) { + if (cls == eglcontextClass && + (EGLContext)handle == EGL_NO_CONTEXT) { + return eglNoContextObject; + } + + if (cls == egldisplayClass && + (EGLDisplay)handle == EGL_NO_DISPLAY) { + return eglNoDisplayObject; + } + + if (cls == eglsurfaceClass && + (EGLSurface)handle == EGL_NO_SURFACE) { + return eglNoSurfaceObject; + } + + return _env->NewObject(cls, con, (jint)handle); +} + +// -------------------------------------------------------------------------- diff --git a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp new file mode 100644 index 0000000..610cde5 --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp @@ -0,0 +1,154 @@ +/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ +static jobject +android_eglCreateWindowSurface + (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { + jint _exception = 0; + const char * _exceptionType = ""; + const char * _exceptionMessage = ""; + EGLSurface _returnValue = (EGLSurface) 0; + EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); + EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); + int attrib_list_sentinel = 0; + EGLint *attrib_list_base = (EGLint *) 0; + jint _remaining; + EGLint *attrib_list = (EGLint *) 0; + android::sp<ANativeWindow> window; + + if (!attrib_list_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "attrib_list == null"; + goto exit; + } + if (offset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "offset < 0"; + goto exit; + } + if (win == NULL) { +not_valid_surface: + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; + goto exit; + } + + window = android::android_Surface_getNativeWindow(_env, win); + + if (window == NULL) + goto not_valid_surface; + + _remaining = _env->GetArrayLength(attrib_list_ref) - offset; + attrib_list_base = (EGLint *) + _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); + attrib_list = attrib_list_base + offset; + attrib_list_sentinel = 0; + for (int i = _remaining - 1; i >= 0; i--) { + if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ + attrib_list_sentinel = 1; + break; + } + } + if (attrib_list_sentinel == 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "attrib_list must contain EGL_NONE!"; + goto exit; + } + + _returnValue = eglCreateWindowSurface( + (EGLDisplay)dpy_native, + (EGLConfig)config_native, + (EGLNativeWindowType)window.get(), + (EGLint *)attrib_list + ); + +exit: + if (attrib_list_base) { + _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, + JNI_ABORT); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } + return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); +} + +/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ +static jobject +android_eglCreateWindowSurfaceTexture + (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { + jint _exception = 0; + const char * _exceptionType = ""; + const char * _exceptionMessage = ""; + EGLSurface _returnValue = (EGLSurface) 0; + EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); + EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); + int attrib_list_sentinel = 0; + EGLint *attrib_list_base = (EGLint *) 0; + jint _remaining; + EGLint *attrib_list = (EGLint *) 0; + android::sp<ANativeWindow> window; + android::sp<android::SurfaceTexture> surfaceTexture; + + if (!attrib_list_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "attrib_list == null"; + goto exit; + } + if (offset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "offset < 0"; + goto exit; + } + if (win == NULL) { +not_valid_surface: + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; + goto exit; + } + surfaceTexture = android::SurfaceTexture_getSurfaceTexture(_env, win); + window = new android::SurfaceTextureClient(surfaceTexture); + + if (window == NULL) + goto not_valid_surface; + + _remaining = _env->GetArrayLength(attrib_list_ref) - offset; + attrib_list_base = (EGLint *) + _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); + attrib_list = attrib_list_base + offset; + attrib_list_sentinel = 0; + for (int i = _remaining - 1; i >= 0; i--) { + if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ + attrib_list_sentinel = 1; + break; + } + } + if (attrib_list_sentinel == 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "attrib_list must contain EGL_NONE!"; + goto exit; + } + + _returnValue = eglCreateWindowSurface( + (EGLDisplay)dpy_native, + (EGLConfig)config_native, + (EGLNativeWindowType)window.get(), + (EGLint *)attrib_list + ); + +exit: + if (attrib_list_base) { + _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, + JNI_ABORT); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } + return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); +} diff --git a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.java b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.java new file mode 100644 index 0000000..e42334e --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.java @@ -0,0 +1,48 @@ + // C function EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) + + private static native EGLSurface _eglCreateWindowSurface( + EGLDisplay dpy, + EGLConfig config, + Object win, + int[] attrib_list, + int offset + ); + + private static native EGLSurface _eglCreateWindowSurfaceTexture( + EGLDisplay dpy, + EGLConfig config, + Object win, + int[] attrib_list, + int offset + ); + + public static EGLSurface eglCreateWindowSurface(EGLDisplay dpy, + EGLConfig config, + Object win, + int[] attrib_list, + int offset + ){ + Surface sur = null; + if (win instanceof SurfaceView) { + SurfaceView surfaceView = (SurfaceView)win; + sur = surfaceView.getHolder().getSurface(); + } else if (win instanceof SurfaceHolder) { + SurfaceHolder holder = (SurfaceHolder)win; + sur = holder.getSurface(); + } + + EGLSurface surface; + if (sur != null) { + surface = _eglCreateWindowSurface(dpy, config, sur, attrib_list, offset); + } else if (win instanceof SurfaceTexture) { + surface = _eglCreateWindowSurfaceTexture(dpy, config, + win, attrib_list, offset); + } else { + throw new java.lang.UnsupportedOperationException( + "eglCreateWindowSurface() can only be called with an instance of " + + "SurfaceView, SurfaceTexture or SurfaceHolder at the moment, " + + "this will be fixed later."); + } + + return surface; + } diff --git a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.nativeReg b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.nativeReg new file mode 100644 index 0000000..c37d05b --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.nativeReg @@ -0,0 +1,2 @@ +{"_eglCreateWindowSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/lang/Object;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreateWindowSurface }, +{"_eglCreateWindowSurfaceTexture", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/lang/Object;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreateWindowSurfaceTexture }, diff --git a/opengl/tools/glgen/stubs/egl/eglQueryString.cpp b/opengl/tools/glgen/stubs/egl/eglQueryString.cpp new file mode 100644 index 0000000..625dad7 --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/eglQueryString.cpp @@ -0,0 +1,10 @@ +/* const char * eglQueryString ( EGLDisplay dpy, EGLint name ) */ +static jstring +android_eglQueryString__Landroind_opengl_EGLDisplay_2I + (JNIEnv *_env, jobject _this, jobject dpy, jint name) { + const char* chars = (const char*) eglQueryString( + (EGLDisplay)fromEGLHandle(_env, egldisplayGetHandleID, dpy), + (EGLint)name + ); + return _env->NewStringUTF(chars); +} diff --git a/opengl/tools/glgen/stubs/egl/eglQueryString.java b/opengl/tools/glgen/stubs/egl/eglQueryString.java new file mode 100644 index 0000000..f5d5a38 --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/eglQueryString.java @@ -0,0 +1,6 @@ + // C function const char * eglQueryString ( EGLDisplay dpy, EGLint name ) + + public static native String eglQueryString( + EGLDisplay dpy, + int name + ); diff --git a/opengl/tools/glgen/stubs/egl/eglQueryString.nativeReg b/opengl/tools/glgen/stubs/egl/eglQueryString.nativeReg new file mode 100644 index 0000000..8276cdb --- /dev/null +++ b/opengl/tools/glgen/stubs/egl/eglQueryString.nativeReg @@ -0,0 +1 @@ +{"eglQueryString", "(Landroid/opengl/EGLDisplay;I)Ljava/lang/String;", (void *) android_eglQueryString__Landroind_opengl_EGLDisplay_2I },
diff --git a/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp index 5d418d7..172c0e7 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES10ExtcHeader.cpp @@ -62,14 +62,12 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) { jint position; jint limit; jint elementSizeShift; jlong pointer; - jint offset; - void *data; position = _env->GetIntField(buffer, positionID); limit = _env->GetIntField(buffer, limitID); @@ -84,11 +82,10 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, getBaseArrayID, buffer); - offset = _env->CallStaticIntMethod(nioAccessClass, + *offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - return (void *) ((char *) data + offset); + return NULL; } diff --git a/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp index 35a3c33..4ef815b 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES10cHeader.cpp @@ -74,14 +74,12 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) } static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) { jint position; jint limit; jint elementSizeShift; jlong pointer; - jint offset; - void *data; position = _env->GetIntField(buffer, positionID); limit = _env->GetIntField(buffer, limitID); @@ -96,11 +94,10 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, getBaseArrayID, buffer); - offset = _env->CallStaticIntMethod(nioAccessClass, + *offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - return (void *) ((char *) data + offset); + return NULL; } static void diff --git a/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp index 9b29a44..0df95f4 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES11ExtcHeader.cpp @@ -71,14 +71,12 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) { jint position; jint limit; jint elementSizeShift; jlong pointer; - jint offset; - void *data; position = _env->GetIntField(buffer, positionID); limit = _env->GetIntField(buffer, limitID); @@ -93,11 +91,9 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, getBaseArrayID, buffer); - offset = _env->CallStaticIntMethod(nioAccessClass, + *offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - - return (void *) ((char *) data + offset); + return NULL; } diff --git a/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp index 823079f..dd860d5 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES11cHeader.cpp @@ -69,14 +69,12 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) { jint position; jint limit; jint elementSizeShift; jlong pointer; - jint offset; - void *data; position = _env->GetIntField(buffer, positionID); limit = _env->GetIntField(buffer, limitID); @@ -91,11 +89,10 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, getBaseArrayID, buffer); - offset = _env->CallStaticIntMethod(nioAccessClass, + *offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - return (void *) ((char *) data + offset); + return NULL; } diff --git a/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp index 13a2577..996f441 100644 --- a/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp +++ b/opengl/tools/glgen/stubs/gles11/GLES20cHeader.cpp @@ -62,14 +62,12 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) { jint position; jint limit; jint elementSizeShift; jlong pointer; - jint offset; - void *data; position = _env->GetIntField(buffer, positionID); limit = _env->GetIntField(buffer, limitID); @@ -84,11 +82,10 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, getBaseArrayID, buffer); - offset = _env->CallStaticIntMethod(nioAccessClass, + *offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - return (void *) ((char *) data + offset); + return NULL; } diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.cpp b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.cpp new file mode 100644 index 0000000..27b91fc --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.cpp @@ -0,0 +1,328 @@ +/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static void +android_glGetActiveAttrib__III_3II_3II_3II_3BI + (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jintArray length_ref, jint lengthOffset, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset, jbyteArray name_ref, jint nameOffset) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + GLsizei *length_base = (GLsizei *) 0; + jint _lengthRemaining; + GLsizei *length = (GLsizei *) 0; + GLint *size_base = (GLint *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + GLenum *type_base = (GLenum *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + char *name_base = (char *) 0; + jint _nameRemaining; + char *name = (char *) 0; + + if (!length_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "length == null"; + goto exit; + } + if (lengthOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "lengthOffset < 0"; + goto exit; + } + _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset; + length_base = (GLsizei *) + _env->GetPrimitiveArrayCritical(length_ref, (jboolean *)0); + length = length_base + lengthOffset; + + if (!size_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "size == null"; + goto exit; + } + if (sizeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "sizeOffset < 0"; + goto exit; + } + _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset; + size_base = (GLint *) + _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0); + size = size_base + sizeOffset; + + if (!type_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "type == null"; + goto exit; + } + if (typeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "typeOffset < 0"; + goto exit; + } + _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset; + type_base = (GLenum *) + _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0); + type = type_base + typeOffset; + + if (!name_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "name == null"; + goto exit; + } + if (nameOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "nameOffset < 0"; + goto exit; + } + _nameRemaining = _env->GetArrayLength(name_ref) - nameOffset; + name_base = (char *) + _env->GetPrimitiveArrayCritical(name_ref, (jboolean *)0); + name = name_base + nameOffset; + + glGetActiveAttrib( + (GLuint)program, + (GLuint)index, + (GLsizei)bufsize, + (GLsizei *)length, + (GLint *)size, + (GLenum *)type, + (char *)name + ); + +exit: + if (name_base) { + _env->ReleasePrimitiveArrayCritical(name_ref, name_base, + _exception ? JNI_ABORT: 0); + } + if (type_base) { + _env->ReleasePrimitiveArrayCritical(type_ref, type_base, + _exception ? JNI_ABORT: 0); + } + if (size_base) { + _env->ReleasePrimitiveArrayCritical(size_ref, size_base, + _exception ? JNI_ABORT: 0); + } + if (length_base) { + _env->ReleasePrimitiveArrayCritical(length_ref, length_base, + _exception ? JNI_ABORT: 0); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } +} + +/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static void +android_glGetActiveAttrib__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B + (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jobject length_buf, jobject size_buf, jobject type_buf, jbyte name) { + jarray _lengthArray = (jarray) 0; + jint _lengthBufferOffset = (jint) 0; + jarray _sizeArray = (jarray) 0; + jint _sizeBufferOffset = (jint) 0; + jarray _typeArray = (jarray) 0; + jint _typeBufferOffset = (jint) 0; + jint _lengthRemaining; + GLsizei *length = (GLsizei *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + + length = (GLsizei *)getPointer(_env, length_buf, &_lengthArray, &_lengthRemaining, &_lengthBufferOffset); + size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset); + type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset); + if (length == NULL) { + char * _lengthBase = (char *)_env->GetPrimitiveArrayCritical(_lengthArray, (jboolean *) 0); + length = (GLsizei *) (_lengthBase + _lengthBufferOffset); + } + if (size == NULL) { + char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0); + size = (GLint *) (_sizeBase + _sizeBufferOffset); + } + if (type == NULL) { + char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0); + type = (GLenum *) (_typeBase + _typeBufferOffset); + } + glGetActiveAttrib( + (GLuint)program, + (GLuint)index, + (GLsizei)bufsize, + (GLsizei *)length, + (GLint *)size, + (GLenum *)type, + (char *)name + ); + if (_typeArray) { + releasePointer(_env, _typeArray, type, JNI_TRUE); + } + if (_sizeArray) { + releasePointer(_env, _sizeArray, size, JNI_TRUE); + } + if (_lengthArray) { + releasePointer(_env, _lengthArray, length, JNI_TRUE); + } +} + +/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static jstring +android_glGetActiveAttrib1 + (JNIEnv *_env, jobject _this, jint program, jint index, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + GLint *size_base = (GLint *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + GLenum *type_base = (GLenum *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + + jstring result = 0; + + GLint len = 0; + glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len); + if (!len) { + return _env->NewStringUTF(""); + } + char* buf = (char*) malloc(len); + + if (buf == NULL) { + jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); + return NULL; + } + if (!size_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "size == null"; + goto exit; + } + if (sizeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "sizeOffset < 0"; + goto exit; + } + _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset; + size_base = (GLint *) + _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0); + size = size_base + sizeOffset; + + if (!type_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "type == null"; + goto exit; + } + if (typeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "typeOffset < 0"; + goto exit; + } + _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset; + type_base = (GLenum *) + _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0); + type = type_base + typeOffset; + + glGetActiveAttrib( + (GLuint)program, + (GLuint)index, + (GLsizei)len, + NULL, + (GLint *)size, + (GLenum *)type, + (char *)buf + ); +exit: + if (type_base) { + _env->ReleasePrimitiveArrayCritical(type_ref, type_base, + _exception ? JNI_ABORT: 0); + } + if (size_base) { + _env->ReleasePrimitiveArrayCritical(size_ref, size_base, + _exception ? JNI_ABORT: 0); + } + if (_exception != 1) { + result = _env->NewStringUTF(buf); + } + if (buf) { + free(buf); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } + if (result == 0) { + result = _env->NewStringUTF(""); + } + + return result; +} + +/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static jstring +android_glGetActiveAttrib2 + (JNIEnv *_env, jobject _this, jint program, jint index, jobject size_buf, jobject type_buf) { + jarray _sizeArray = (jarray) 0; + jint _sizeBufferOffset = (jint) 0; + jarray _typeArray = (jarray) 0; + jint _typeBufferOffset = (jint) 0; + jint _lengthRemaining; + GLsizei *length = (GLsizei *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + + jstring result = 0; + + GLint len = 0; + glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len); + if (!len) { + return _env->NewStringUTF(""); + } + char* buf = (char*) malloc(len); + + if (buf == NULL) { + jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); + return NULL; + } + + size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset); + type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset); + if (size == NULL) { + char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0); + size = (GLint *) (_sizeBase + _sizeBufferOffset); + } + if (type == NULL) { + char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0); + type = (GLenum *) (_typeBase + _typeBufferOffset); + } + glGetActiveAttrib( + (GLuint)program, + (GLuint)index, + (GLsizei)len, + NULL, + (GLint *)size, + (GLenum *)type, + (char *)buf + ); + + if (_typeArray) { + releasePointer(_env, _typeArray, type, JNI_TRUE); + } + if (_sizeArray) { + releasePointer(_env, _sizeArray, size, JNI_TRUE); + } + result = _env->NewStringUTF(buf); + if (buf) { + free(buf); + } + return result; +} diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java new file mode 100644 index 0000000..bad2137 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java @@ -0,0 +1,47 @@ + // C function void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native void glGetActiveAttrib( + int program, + int index, + int bufsize, + int[] length, + int lengthOffset, + int[] size, + int sizeOffset, + int[] type, + int typeOffset, + byte[] name, + int nameOffset + ); + + // C function void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native void glGetActiveAttrib( + int program, + int index, + int bufsize, + java.nio.IntBuffer length, + java.nio.IntBuffer size, + java.nio.IntBuffer type, + byte name + ); + + // C function void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native String glGetActiveAttrib( + int program, + int index, + int[] size, + int sizeOffset, + int[] type, + int typeOffset + ); + + // C function void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native String glGetActiveAttrib( + int program, + int index, + java.nio.IntBuffer size, + java.nio.IntBuffer type + ); diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.nativeReg new file mode 100644 index 0000000..f54c0a0 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.nativeReg @@ -0,0 +1,4 @@ +{"glGetActiveAttrib", "(III[II[II[II[BI)V", (void *) android_glGetActiveAttrib__III_3II_3II_3II_3BI }, +{"glGetActiveAttrib", "(IIILjava/nio/IntBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;B)V", (void *) android_glGetActiveAttrib__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B }, +{"glGetActiveAttrib", "(II[II[II)Ljava/lang/String;", (void *) android_glGetActiveAttrib1 }, +{"glGetActiveAttrib", "(IILjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/lang/String;", (void *) android_glGetActiveAttrib2 }, diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.cpp b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.cpp new file mode 100644 index 0000000..58f704c --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.cpp @@ -0,0 +1,329 @@ +/* void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static void +android_glGetActiveUniform__III_3II_3II_3II_3BI + (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jintArray length_ref, jint lengthOffset, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset, jbyteArray name_ref, jint nameOffset) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + GLsizei *length_base = (GLsizei *) 0; + jint _lengthRemaining; + GLsizei *length = (GLsizei *) 0; + GLint *size_base = (GLint *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + GLenum *type_base = (GLenum *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + char *name_base = (char *) 0; + jint _nameRemaining; + char *name = (char *) 0; + + if (!length_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "length == null"; + goto exit; + } + if (lengthOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "lengthOffset < 0"; + goto exit; + } + _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset; + length_base = (GLsizei *) + _env->GetPrimitiveArrayCritical(length_ref, (jboolean *)0); + length = length_base + lengthOffset; + + if (!size_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "size == null"; + goto exit; + } + if (sizeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "sizeOffset < 0"; + goto exit; + } + _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset; + size_base = (GLint *) + _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0); + size = size_base + sizeOffset; + + if (!type_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "type == null"; + goto exit; + } + if (typeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "typeOffset < 0"; + goto exit; + } + _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset; + type_base = (GLenum *) + _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0); + type = type_base + typeOffset; + + if (!name_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "name == null"; + goto exit; + } + if (nameOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "nameOffset < 0"; + goto exit; + } + _nameRemaining = _env->GetArrayLength(name_ref) - nameOffset; + name_base = (char *) + _env->GetPrimitiveArrayCritical(name_ref, (jboolean *)0); + name = name_base + nameOffset; + + glGetActiveUniform( + (GLuint)program, + (GLuint)index, + (GLsizei)bufsize, + (GLsizei *)length, + (GLint *)size, + (GLenum *)type, + (char *)name + ); + +exit: + if (name_base) { + _env->ReleasePrimitiveArrayCritical(name_ref, name_base, + _exception ? JNI_ABORT: 0); + } + if (type_base) { + _env->ReleasePrimitiveArrayCritical(type_ref, type_base, + _exception ? JNI_ABORT: 0); + } + if (size_base) { + _env->ReleasePrimitiveArrayCritical(size_ref, size_base, + _exception ? JNI_ABORT: 0); + } + if (length_base) { + _env->ReleasePrimitiveArrayCritical(length_ref, length_base, + _exception ? JNI_ABORT: 0); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } +} + +/* void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static void +android_glGetActiveUniform__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B + (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jobject length_buf, jobject size_buf, jobject type_buf, jbyte name) { + jarray _lengthArray = (jarray) 0; + jint _lengthBufferOffset = (jint) 0; + jarray _sizeArray = (jarray) 0; + jint _sizeBufferOffset = (jint) 0; + jarray _typeArray = (jarray) 0; + jint _typeBufferOffset = (jint) 0; + jint _lengthRemaining; + GLsizei *length = (GLsizei *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + + length = (GLsizei *)getPointer(_env, length_buf, &_lengthArray, &_lengthRemaining, &_lengthBufferOffset); + size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset); + type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset); + if (length == NULL) { + char * _lengthBase = (char *)_env->GetPrimitiveArrayCritical(_lengthArray, (jboolean *) 0); + length = (GLsizei *) (_lengthBase + _lengthBufferOffset); + } + if (size == NULL) { + char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0); + size = (GLint *) (_sizeBase + _sizeBufferOffset); + } + if (type == NULL) { + char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0); + type = (GLenum *) (_typeBase + _typeBufferOffset); + } + glGetActiveUniform( + (GLuint)program, + (GLuint)index, + (GLsizei)bufsize, + (GLsizei *)length, + (GLint *)size, + (GLenum *)type, + (char *)name + ); + if (_typeArray) { + releasePointer(_env, _typeArray, type, JNI_TRUE); + } + if (_sizeArray) { + releasePointer(_env, _sizeArray, size, JNI_TRUE); + } + if (_lengthArray) { + releasePointer(_env, _lengthArray, length, JNI_TRUE); + } +} + +/* void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static jstring +android_glGetActiveUniform1 + (JNIEnv *_env, jobject _this, jint program, jint index, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + + GLint *size_base = (GLint *) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + + GLenum *type_base = (GLenum *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + + jstring result = 0; + + GLint len = 0; + glGetProgramiv((GLuint)program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &len); + if (!len) { + return _env->NewStringUTF(""); + } + char* buf = (char*) malloc(len); + + if (buf == NULL) { + jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); + return NULL; + } + + if (!size_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "size == null"; + goto exit; + } + if (sizeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "sizeOffset < 0"; + goto exit; + } + _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset; + size_base = (GLint *) + _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0); + size = size_base + sizeOffset; + + if (!type_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "type == null"; + goto exit; + } + if (typeOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "typeOffset < 0"; + goto exit; + } + _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset; + type_base = (GLenum *) + _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0); + type = type_base + typeOffset; + + glGetActiveUniform( + (GLuint)program, + (GLuint)index, + (GLsizei)len, + NULL, + (GLint *)size, + (GLenum *)type, + (char *)buf + ); + +exit: + if (type_base) { + _env->ReleasePrimitiveArrayCritical(type_ref, type_base, + _exception ? JNI_ABORT: 0); + } + if (size_base) { + _env->ReleasePrimitiveArrayCritical(size_ref, size_base, + _exception ? JNI_ABORT: 0); + } + if (_exception != 1) { + result = _env->NewStringUTF(buf); + } + if (buf) { + free(buf); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } + if (result == 0) { + result = _env->NewStringUTF(""); + } + return result; +} + +/* void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ +static jstring +android_glGetActiveUniform2 + (JNIEnv *_env, jobject _this, jint program, jint index, jobject size_buf, jobject type_buf) { + jarray _sizeArray = (jarray) 0; + jint _sizeBufferOffset = (jint) 0; + jarray _typeArray = (jarray) 0; + jint _typeBufferOffset = (jint) 0; + jint _sizeRemaining; + GLint *size = (GLint *) 0; + jint _typeRemaining; + GLenum *type = (GLenum *) 0; + + jstring result = 0; + GLint len = 0; + glGetProgramiv((GLuint)program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &len); + if (!len) { + return _env->NewStringUTF(""); + } + char* buf = (char*) malloc(len); + + if (buf == NULL) { + jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); + return NULL; + } + + size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset); + type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset); + + if (size == NULL) { + char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0); + size = (GLint *) (_sizeBase + _sizeBufferOffset); + } + if (type == NULL) { + char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0); + type = (GLenum *) (_typeBase + _typeBufferOffset); + } + glGetActiveUniform( + (GLuint)program, + (GLuint)index, + len, + NULL, + (GLint *)size, + (GLenum *)type, + (char *)buf + ); + + if (_typeArray) { + releasePointer(_env, _typeArray, type, JNI_TRUE); + } + if (_sizeArray) { + releasePointer(_env, _sizeArray, size, JNI_TRUE); + } + result = _env->NewStringUTF(buf); + if (buf) { + free(buf); + } + return result; +} diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java new file mode 100644 index 0000000..28aaa78 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java @@ -0,0 +1,46 @@ + // C function void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native void glGetActiveUniform( + int program, + int index, + int bufsize, + int[] length, + int lengthOffset, + int[] size, + int sizeOffset, + int[] type, + int typeOffset, + byte[] name, + int nameOffset + ); + + // C function void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native void glGetActiveUniform( + int program, + int index, + int bufsize, + java.nio.IntBuffer length, + java.nio.IntBuffer size, + java.nio.IntBuffer type, + byte name + ); + // C function void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native String glGetActiveUniform( + int program, + int index, + int[] size, + int sizeOffset, + int[] type, + int typeOffset + ); + + // C function void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) + + public static native String glGetActiveUniform( + int program, + int index, + java.nio.IntBuffer size, + java.nio.IntBuffer type + ); diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.nativeReg new file mode 100644 index 0000000..f0b5fd9 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.nativeReg @@ -0,0 +1,4 @@ +{"glGetActiveUniform", "(III[II[II[II[BI)V", (void *) android_glGetActiveUniform__III_3II_3II_3II_3BI }, +{"glGetActiveUniform", "(II[II[II)Ljava/lang/String;", (void *) android_glGetActiveUniform1 }, +{"glGetActiveUniform", "(IIILjava/nio/IntBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;B)V", (void *) android_glGetActiveUniform__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B }, +{"glGetActiveUniform", "(IILjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/lang/String;", (void *) android_glGetActiveUniform2 }, diff --git a/opengl/tools/glgen/stubs/gles11/glGetShaderSource.cpp b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.cpp new file mode 100644 index 0000000..a7e1cd2 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.cpp @@ -0,0 +1,111 @@ +/* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */ +static void +android_glGetShaderSource__II_3II_3BI + (JNIEnv *_env, jobject _this, jint shader, jint bufsize, jintArray length_ref, jint lengthOffset, jbyteArray source_ref, jint sourceOffset) { + jint _exception = 0; + const char * _exceptionType; + const char * _exceptionMessage; + GLsizei *length_base = (GLsizei *) 0; + jint _lengthRemaining; + GLsizei *length = (GLsizei *) 0; + char *source_base = (char *) 0; + jint _sourceRemaining; + char *source = (char *) 0; + + if (!length_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "length == null"; + goto exit; + } + if (lengthOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "lengthOffset < 0"; + goto exit; + } + _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset; + length_base = (GLsizei *) + _env->GetPrimitiveArrayCritical(length_ref, (jboolean *)0); + length = length_base + lengthOffset; + + if (!source_ref) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "source == null"; + goto exit; + } + if (sourceOffset < 0) { + _exception = 1; + _exceptionType = "java/lang/IllegalArgumentException"; + _exceptionMessage = "sourceOffset < 0"; + goto exit; + } + _sourceRemaining = _env->GetArrayLength(source_ref) - sourceOffset; + source_base = (char *) + _env->GetPrimitiveArrayCritical(source_ref, (jboolean *)0); + source = source_base + sourceOffset; + + glGetShaderSource( + (GLuint)shader, + (GLsizei)bufsize, + (GLsizei *)length, + (char *)source + ); + +exit: + if (source_base) { + _env->ReleasePrimitiveArrayCritical(source_ref, source_base, + _exception ? JNI_ABORT: 0); + } + if (length_base) { + _env->ReleasePrimitiveArrayCritical(length_ref, length_base, + _exception ? JNI_ABORT: 0); + } + if (_exception) { + jniThrowException(_env, _exceptionType, _exceptionMessage); + } +} + +/* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */ +static void +android_glGetShaderSource__IILjava_nio_IntBuffer_2B + (JNIEnv *_env, jobject _this, jint shader, jint bufsize, jobject length_buf, jbyte source) { + jarray _array = (jarray) 0; + jint _bufferOffset = (jint) 0; + jint _remaining; + GLsizei *length = (GLsizei *) 0; + + length = (GLsizei *)getPointer(_env, length_buf, &_array, &_remaining, &_bufferOffset); + if (length == NULL) { + char * _lengthBase = (char *)_env->GetPrimitiveArrayCritical(_array, (jboolean *) 0); + length = (GLsizei *) (_lengthBase + _bufferOffset); + } + glGetShaderSource( + (GLuint)shader, + (GLsizei)bufsize, + (GLsizei *)length, + (char *)source + ); + if (_array) { + releasePointer(_env, _array, length, JNI_TRUE); + } +} + +/* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */ +static jstring android_glGetShaderSource(JNIEnv *_env, jobject, jint shader) { + GLint shaderLen = 0; + glGetShaderiv((GLuint)shader, GL_SHADER_SOURCE_LENGTH, &shaderLen); + if (!shaderLen) { + return _env->NewStringUTF(""); + } + char* buf = (char*) malloc(shaderLen); + if (buf == NULL) { + jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); + return NULL; + } + glGetShaderSource(shader, shaderLen, NULL, buf); + jstring result = _env->NewStringUTF(buf); + free(buf); + return result; +} diff --git a/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java new file mode 100644 index 0000000..199d93a --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java @@ -0,0 +1,25 @@ + // C function void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) + + public static native void glGetShaderSource( + int shader, + int bufsize, + int[] length, + int lengthOffset, + byte[] source, + int sourceOffset + ); + + // C function void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) + + public static native void glGetShaderSource( + int shader, + int bufsize, + java.nio.IntBuffer length, + byte source + ); + + // C function void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) + + public static native String glGetShaderSource( + int shader + ); diff --git a/opengl/tools/glgen/stubs/gles11/glGetShaderSource.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.nativeReg new file mode 100644 index 0000000..acb47a5 --- /dev/null +++ b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.nativeReg @@ -0,0 +1,3 @@ +{"glGetShaderSource", "(II[II[BI)V", (void *) android_glGetShaderSource__II_3II_3BI }, +{"glGetShaderSource", "(IILjava/nio/IntBuffer;B)V", (void *) android_glGetShaderSource__IILjava_nio_IntBuffer_2B }, +{"glGetShaderSource", "(I)Ljava/lang/String;", (void *) android_glGetShaderSource }, diff --git a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp index f7315ee..cc10336 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp +++ b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp @@ -113,14 +113,12 @@ nativeClassInit(JNIEnv *_env, jclass glImplClass) } static void * -getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) +getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) { jint position; jint limit; jint elementSizeShift; jlong pointer; - jint offset; - void *data; position = _env->GetIntField(buffer, positionID); limit = _env->GetIntField(buffer, limitID); @@ -138,11 +136,10 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) if (*array == NULL) { return (void*) NULL; } - offset = _env->CallStaticIntMethod(nioAccessClass, + *offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); - data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - return (void *) ((char *) data + offset); + return NULL; } static void @@ -180,10 +177,12 @@ getDirectBufferPointer(JNIEnv *_env, jobject buffer) { if (allowIndirectBuffers(_env)) { jarray array = 0; jint remaining; - buf = getPointer(_env, buffer, &array, &remaining); + jint offset; + buf = getPointer(_env, buffer, &array, &remaining, &offset); if (array) { releasePointer(_env, array, buf, 0); } + buf = buf + offset; } else { jniThrowException(_env, "java/lang/IllegalArgumentException", "Must use a native order direct Buffer"); diff --git a/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl b/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl index cd730aa..e3aea76 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl +++ b/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl @@ -22,6 +22,7 @@ import android.app.AppGlobals; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.os.Build; +import android.os.UserId; import android.util.Log; import java.nio.Buffer; @@ -66,7 +67,7 @@ public class GLImpl implements GL10, GL10Ext, GL11, GL11Ext, GL11ExtensionPack { int version = 0; IPackageManager pm = AppGlobals.getPackageManager(); try { - ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0); + ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0, UserId.myUserId()); if (applicationInfo != null) { version = applicationInfo.targetSdkVersion; } |