1 ** 2 ** Copyright 2006, The Android Open Source Project 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17 // This source file is automatically generated 18 19 #pragma GCC diagnostic ignored "-Wunused-variable" 20 #pragma GCC diagnostic ignored "-Wunused-but-set-variable" 21 #pragma GCC diagnostic ignored "-Wunused-function" 22 23 #include "jni.h" 24 #include <nativehelper/JNIPlatformHelp.h> 25 #include <android_runtime/AndroidRuntime.h> 26 #include <utils/misc.h> 27 28 #include <assert.h> 29 #include <GLES/gl.h> 30 #include <GLES/glext.h> 31 32 // Work around differences between the generated name and the actual name. 33 34 #define glBlendEquation glBlendEquationOES 35 #define glBlendEquationSeparate glBlendEquationSeparateOES 36 #define glBlendFuncSeparate glBlendFuncSeparateOES 37 #define glGetTexGenfv glGetTexGenfvOES 38 #define glGetTexGeniv glGetTexGenivOES 39 #define glGetTexGenxv glGetTexGenxvOES 40 #define glTexGenf glTexGenfOES 41 #define glTexGenfv glTexGenfvOES 42 #define glTexGeni glTexGeniOES 43 #define glTexGeniv glTexGenivOES 44 #define glTexGenx glTexGenxOES 45 #define glTexGenxv glTexGenxvOES 46 47 48 49 /* special calls implemented in Android's GLES wrapper used to more 50 * efficiently bound-check passed arrays */ 51 extern "C" { 52 GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, 53 const GLvoid *ptr, GLsizei count); 54 GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, 55 const GLvoid *pointer, GLsizei count); 56 GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, 57 GLsizei stride, const GLvoid *pointer, GLsizei count); 58 GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, 59 GLsizei stride, const GLvoid *pointer, GLsizei count); 60 GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, 61 GLsizei stride, const GLvoid *pointer, GLsizei count); 62 GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, 63 GLsizei stride, const GLvoid *pointer, GLsizei count); 64 GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, 65 GLsizei stride, const GLvoid *pointer, GLsizei count); 66 } 67 68 static jclass G11ImplClass; 69 static jfieldID haveCheckedExtensionsID; 70 static jfieldID have_OES_blend_equation_separateID; 71 static jfieldID have_OES_blend_subtractID; 72 static jfieldID have_OES_framebuffer_objectID; 73 static jfieldID have_OES_texture_cube_mapID; 74 75 /* Cache method IDs each time the class is loaded. */ 76 77 static void 78 nativeClassInit(JNIEnv *_env, jclass glImplClass) 79 { 80 jclass g11impClassLocal = _env->FindClass("com/google/android/gles_jni/GLImpl"); 81 G11ImplClass = (jclass) _env->NewGlobalRef(g11impClassLocal); 82 haveCheckedExtensionsID = _env->GetFieldID(G11ImplClass, "haveCheckedExtensions", "Z"); 83 have_OES_blend_equation_separateID = _env->GetFieldID(G11ImplClass, "have_OES_blend_equation_separate", "Z"); 84 have_OES_blend_subtractID = _env->GetFieldID(G11ImplClass, "have_OES_blend_subtract", "Z"); 85 have_OES_framebuffer_objectID = _env->GetFieldID(G11ImplClass, "have_OES_framebuffer_object", "Z"); 86 have_OES_texture_cube_mapID = _env->GetFieldID(G11ImplClass, "have_OES_texture_cube_map", "Z"); 87 } 88 89 static void * 90 getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset) 91 { 92 jint position; 93 jint limit; 94 jint elementSizeShift; 95 jlong pointer; 96 97 pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); 98 *remaining = (limit - position) << elementSizeShift; 99 if (pointer != 0L) { 100 *array = nullptr; 101 pointer += position << elementSizeShift; 102 return reinterpret_cast<void*>(pointer); 103 } 104 105 *array = jniGetNioBufferBaseArray(_env, buffer); 106 *offset = jniGetNioBufferBaseArrayOffset(_env, buffer); 107 return nullptr; 108 } 109 110 static void 111 releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) 112 { 113 _env->ReleasePrimitiveArrayCritical(array, data, 114 commit ? 0 : JNI_ABORT); 115 } 116 117 extern "C" { 118 extern char* __progname; 119 } 120 121 static void * 122 getDirectBufferPointer(JNIEnv *_env, jobject buffer) { 123 if (buffer == nullptr) { 124 return nullptr; 125 } 126 127 jint position; 128 jint limit; 129 jint elementSizeShift; 130 jlong pointer; 131 pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift); 132 if (pointer == 0) { 133 jniThrowException(_env, "java/lang/IllegalArgumentException", 134 "Must use a native order direct Buffer"); 135 return nullptr; 136 } 137 pointer += position << elementSizeShift; 138 return reinterpret_cast<void*>(pointer); 139 } 140 141 static int 142 getNumCompressedTextureFormats() { 143 int numCompressedTextureFormats = 0; 144 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats); 145 return numCompressedTextureFormats; 146 } 147 148 // Check if the extension at the head of pExtensions is pExtension. Note that pExtensions is 149 // terminated by either 0 or space, while pExtension is terminated by 0. 150 151 static bool 152 extensionEqual(const GLubyte* pExtensions, const GLubyte* pExtension) { 153 while (true) { 154 char a = *pExtensions++; 155 char b = *pExtension++; 156 bool aEnd = a == '\0' || a == ' '; 157 bool bEnd = b == '\0'; 158 if ( aEnd || bEnd) { 159 return aEnd == bEnd; 160 } 161 if ( a != b ) { 162 return false; 163 } 164 } 165 } 166 167 static const GLubyte* 168 nextExtension(const GLubyte* pExtensions) { 169 while (true) { 170 char a = *pExtensions++; 171 if ( a == '\0') { 172 return pExtensions-1; 173 } else if ( a == ' ') { 174 return pExtensions; 175 } 176 } 177 } 178 179 static bool 180 checkForExtension(const GLubyte* pExtensions, const GLubyte* pExtension) { 181 for (;*pExtensions != '\0'; pExtensions = nextExtension(pExtensions)) { 182 if (extensionEqual(pExtensions, pExtension)) { 183 return true; 184 } 185 } 186 return false; 187 } 188 189 static bool 190 supportsExtension(JNIEnv *_env, jobject impl, jfieldID fieldId) { 191 if (!_env->GetBooleanField(impl, haveCheckedExtensionsID)) { 192 _env->SetBooleanField(impl, haveCheckedExtensionsID, true); 193 const GLubyte* sExtensions = glGetString(GL_EXTENSIONS); 194 _env->SetBooleanField(impl, have_OES_blend_equation_separateID, 195 checkForExtension(sExtensions, (const GLubyte*) "GL_OES_blend_equation_separate")); 196 _env->SetBooleanField(impl, have_OES_blend_subtractID, 197 checkForExtension(sExtensions, (const GLubyte*) "GL_OES_blend_subtract")); 198 _env->SetBooleanField(impl, have_OES_framebuffer_objectID, 199 checkForExtension(sExtensions, (const GLubyte*) "GL_OES_framebuffer_object")); 200 _env->SetBooleanField(impl, have_OES_texture_cube_mapID, 201 checkForExtension(sExtensions, (const GLubyte*) "GL_OES_texture_cube_map")); 202 } 203 return _env->GetBooleanField(impl, fieldId); 204 } 205 206 // -------------------------------------------------------------------------- 207