1 /* 2 ** Copyright 2012, 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 #include "jni.h" 20 #include "JNIHelp.h" 21 #include <android_runtime/AndroidRuntime.h> 22 #include <android_runtime/android_view_Surface.h> 23 #include <android_runtime/android_graphics_SurfaceTexture.h> 24 #include <utils/misc.h> 25 26 #include <assert.h> 27 #include <EGL/egl.h> 28 29 #include <gui/Surface.h> 30 #include <gui/GLConsumer.h> 31 #include <gui/Surface.h> 32 33 #include <ui/ANativeObjectBase.h> 34 35 static int initialized = 0; 36 37 static jclass egldisplayClass; 38 static jclass eglcontextClass; 39 static jclass eglsurfaceClass; 40 static jclass eglconfigClass; 41 42 static jmethodID egldisplayGetHandleID; 43 static jmethodID eglcontextGetHandleID; 44 static jmethodID eglsurfaceGetHandleID; 45 static jmethodID eglconfigGetHandleID; 46 47 static jmethodID egldisplayConstructor; 48 static jmethodID eglcontextConstructor; 49 static jmethodID eglsurfaceConstructor; 50 static jmethodID eglconfigConstructor; 51 52 static jobject eglNoContextObject; 53 static jobject eglNoDisplayObject; 54 static jobject eglNoSurfaceObject; 55 56 57 58 /* Cache method IDs each time the class is loaded. */ 59 60 static void 61 nativeClassInit(JNIEnv *_env, jclass glImplClass) 62 { 63 jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay"); 64 egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal); 65 jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext"); 66 eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal); 67 jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface"); 68 eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal); 69 jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig"); 70 eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal); 71 72 egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getHandle", "()I"); 73 eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getHandle", "()I"); 74 eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getHandle", "()I"); 75 eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getHandle", "()I"); 76 77 78 egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(I)V"); 79 eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(I)V"); 80 eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(I)V"); 81 eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(I)V"); 82 83 jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, (jint)EGL_NO_CONTEXT); 84 eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject); 85 jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, (jint)EGL_NO_DISPLAY); 86 eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject); 87 jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, (jint)EGL_NO_SURFACE); 88 eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject); 89 90 91 jclass eglClass = _env->FindClass("android/opengl/EGL14"); 92 jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;"); 93 _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject); 94 95 jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;"); 96 _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject); 97 98 jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;"); 99 _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject); 100 } 101 102 static void * 103 fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) { 104 if (obj == NULL){ 105 jniThrowException(_env, "java/lang/IllegalArgumentException", 106 "Object is set to null."); 107 } 108 109 return (void*) (_env->CallIntMethod(obj, mid)); 110 } 111 112 static jobject 113 toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void * handle) { 114 if (cls == eglcontextClass && 115 (EGLContext)handle == EGL_NO_CONTEXT) { 116 return eglNoContextObject; 117 } 118 119 if (cls == egldisplayClass && 120 (EGLDisplay)handle == EGL_NO_DISPLAY) { 121 return eglNoDisplayObject; 122 } 123 124 if (cls == eglsurfaceClass && 125 (EGLSurface)handle == EGL_NO_SURFACE) { 126 return eglNoSurfaceObject; 127 } 128 129 return _env->NewObject(cls, con, (jint)handle); 130 } 131 132 // -------------------------------------------------------------------------- 133 /* EGLint eglGetError ( void ) */ 134 static jint 135 android_eglGetError 136 (JNIEnv *_env, jobject _this) { 137 EGLint _returnValue = (EGLint) 0; 138 _returnValue = eglGetError(); 139 return (jint)_returnValue; 140 } 141 142 /* EGLDisplay eglGetDisplay ( EGLNativeDisplayType display_id ) */ 143 static jobject 144 android_eglGetDisplay 145 (JNIEnv *_env, jobject _this, jint display_id) { 146 EGLDisplay _returnValue = (EGLDisplay) 0; 147 _returnValue = eglGetDisplay( 148 (EGLNativeDisplayType)display_id 149 ); 150 return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue); 151 } 152 153 /* EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) */ 154 static jboolean 155 android_eglInitialize 156 (JNIEnv *_env, jobject _this, jobject dpy, jintArray major_ref, jint majorOffset, jintArray minor_ref, jint minorOffset) { 157 jint _exception = 0; 158 const char * _exceptionType = NULL; 159 const char * _exceptionMessage = NULL; 160 EGLBoolean _returnValue = (EGLBoolean) 0; 161 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 162 EGLint *major_base = (EGLint *) 0; 163 jint _majorRemaining; 164 EGLint *major = (EGLint *) 0; 165 EGLint *minor_base = (EGLint *) 0; 166 jint _minorRemaining; 167 EGLint *minor = (EGLint *) 0; 168 169 if (!major_ref) { 170 _exception = 1; 171 _exceptionType = "java/lang/IllegalArgumentException"; 172 _exceptionMessage = "major == null"; 173 goto exit; 174 } 175 if (majorOffset < 0) { 176 _exception = 1; 177 _exceptionType = "java/lang/IllegalArgumentException"; 178 _exceptionMessage = "majorOffset < 0"; 179 goto exit; 180 } 181 _majorRemaining = _env->GetArrayLength(major_ref) - majorOffset; 182 if (_majorRemaining < 1) { 183 _exception = 1; 184 _exceptionType = "java/lang/IllegalArgumentException"; 185 _exceptionMessage = "length - majorOffset < 1 < needed"; 186 goto exit; 187 } 188 major_base = (EGLint *) 189 _env->GetPrimitiveArrayCritical(major_ref, (jboolean *)0); 190 major = major_base + majorOffset; 191 192 if (!minor_ref) { 193 _exception = 1; 194 _exceptionType = "java/lang/IllegalArgumentException"; 195 _exceptionMessage = "minor == null"; 196 goto exit; 197 } 198 if (minorOffset < 0) { 199 _exception = 1; 200 _exceptionType = "java/lang/IllegalArgumentException"; 201 _exceptionMessage = "minorOffset < 0"; 202 goto exit; 203 } 204 _minorRemaining = _env->GetArrayLength(minor_ref) - minorOffset; 205 if (_minorRemaining < 1) { 206 _exception = 1; 207 _exceptionType = "java/lang/IllegalArgumentException"; 208 _exceptionMessage = "length - minorOffset < 1 < needed"; 209 goto exit; 210 } 211 minor_base = (EGLint *) 212 _env->GetPrimitiveArrayCritical(minor_ref, (jboolean *)0); 213 minor = minor_base + minorOffset; 214 215 _returnValue = eglInitialize( 216 (EGLDisplay)dpy_native, 217 (EGLint *)major, 218 (EGLint *)minor 219 ); 220 221 exit: 222 if (minor_base) { 223 _env->ReleasePrimitiveArrayCritical(minor_ref, minor_base, 224 _exception ? JNI_ABORT: 0); 225 } 226 if (major_base) { 227 _env->ReleasePrimitiveArrayCritical(major_ref, major_base, 228 _exception ? JNI_ABORT: 0); 229 } 230 if (_exception) { 231 jniThrowException(_env, _exceptionType, _exceptionMessage); 232 } 233 return (jboolean)_returnValue; 234 } 235 236 /* EGLBoolean eglTerminate ( EGLDisplay dpy ) */ 237 static jboolean 238 android_eglTerminate 239 (JNIEnv *_env, jobject _this, jobject dpy) { 240 EGLBoolean _returnValue = (EGLBoolean) 0; 241 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 242 243 _returnValue = eglTerminate( 244 (EGLDisplay)dpy_native 245 ); 246 return (jboolean)_returnValue; 247 } 248 249 /* const char * eglQueryString ( EGLDisplay dpy, EGLint name ) */ 250 static jstring 251 android_eglQueryString__Landroind_opengl_EGLDisplay_2I 252 (JNIEnv *_env, jobject _this, jobject dpy, jint name) { 253 const char* chars = (const char*) eglQueryString( 254 (EGLDisplay)fromEGLHandle(_env, egldisplayGetHandleID, dpy), 255 (EGLint)name 256 ); 257 return _env->NewStringUTF(chars); 258 } 259 /* EGLBoolean eglGetConfigs ( EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */ 260 static jboolean 261 android_eglGetConfigs 262 (JNIEnv *_env, jobject _this, jobject dpy, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) { 263 jint _exception = 0; 264 const char * _exceptionType = NULL; 265 const char * _exceptionMessage = NULL; 266 EGLBoolean _returnValue = (EGLBoolean) 0; 267 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 268 jint _configsRemaining; 269 EGLConfig *configs = (EGLConfig *) 0; 270 EGLint *num_config_base = (EGLint *) 0; 271 jint _num_configRemaining; 272 EGLint *num_config = (EGLint *) 0; 273 274 if (!configs_ref) { 275 _exception = 1; 276 _exceptionType = "java/lang/IllegalArgumentException"; 277 _exceptionMessage = "configs == null"; 278 goto exit; 279 } 280 if (configsOffset < 0) { 281 _exception = 1; 282 _exceptionType = "java/lang/IllegalArgumentException"; 283 _exceptionMessage = "configsOffset < 0"; 284 goto exit; 285 } 286 _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset; 287 if (_configsRemaining < config_size) { 288 _exception = 1; 289 _exceptionType = "java/lang/IllegalArgumentException"; 290 _exceptionMessage = "length - configsOffset < config_size < needed"; 291 goto exit; 292 } 293 configs = new EGLConfig[_configsRemaining]; 294 295 if (!num_config_ref) { 296 _exception = 1; 297 _exceptionType = "java/lang/IllegalArgumentException"; 298 _exceptionMessage = "num_config == null"; 299 goto exit; 300 } 301 if (num_configOffset < 0) { 302 _exception = 1; 303 _exceptionType = "java/lang/IllegalArgumentException"; 304 _exceptionMessage = "num_configOffset < 0"; 305 goto exit; 306 } 307 _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset; 308 num_config_base = (EGLint *) 309 _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0); 310 num_config = num_config_base + num_configOffset; 311 312 _returnValue = eglGetConfigs( 313 (EGLDisplay)dpy_native, 314 (EGLConfig *)configs, 315 (EGLint)config_size, 316 (EGLint *)num_config 317 ); 318 319 exit: 320 if (num_config_base) { 321 _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base, 322 _exception ? JNI_ABORT: 0); 323 } 324 if (configs) { 325 for (int i = 0; i < _configsRemaining; i++) { 326 jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]); 327 _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new); 328 } 329 delete[] configs; 330 } 331 if (_exception) { 332 jniThrowException(_env, _exceptionType, _exceptionMessage); 333 } 334 return (jboolean)_returnValue; 335 } 336 337 /* EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */ 338 static jboolean 339 android_eglChooseConfig 340 (JNIEnv *_env, jobject _this, jobject dpy, jintArray attrib_list_ref, jint attrib_listOffset, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) { 341 jint _exception = 0; 342 const char * _exceptionType = NULL; 343 const char * _exceptionMessage = NULL; 344 EGLBoolean _returnValue = (EGLBoolean) 0; 345 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 346 bool attrib_list_sentinel = false; 347 EGLint *attrib_list_base = (EGLint *) 0; 348 jint _attrib_listRemaining; 349 EGLint *attrib_list = (EGLint *) 0; 350 jint _configsRemaining; 351 EGLConfig *configs = (EGLConfig *) 0; 352 EGLint *num_config_base = (EGLint *) 0; 353 jint _num_configRemaining; 354 EGLint *num_config = (EGLint *) 0; 355 356 if (!attrib_list_ref) { 357 _exception = 1; 358 _exceptionType = "java/lang/IllegalArgumentException"; 359 _exceptionMessage = "attrib_list == null"; 360 goto exit; 361 } 362 if (attrib_listOffset < 0) { 363 _exception = 1; 364 _exceptionType = "java/lang/IllegalArgumentException"; 365 _exceptionMessage = "attrib_listOffset < 0"; 366 goto exit; 367 } 368 _attrib_listRemaining = _env->GetArrayLength(attrib_list_ref) - attrib_listOffset; 369 attrib_list_base = (EGLint *) 370 _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); 371 attrib_list = attrib_list_base + attrib_listOffset; 372 attrib_list_sentinel = false; 373 for (int i = _attrib_listRemaining - 1; i >= 0; i--) { 374 if (attrib_list[i] == EGL_NONE){ 375 attrib_list_sentinel = true; 376 break; 377 } 378 } 379 if (attrib_list_sentinel == false) { 380 _exception = 1; 381 _exceptionType = "java/lang/IllegalArgumentException"; 382 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 383 goto exit; 384 } 385 386 if (!configs_ref) { 387 _exception = 1; 388 _exceptionType = "java/lang/IllegalArgumentException"; 389 _exceptionMessage = "configs == null"; 390 goto exit; 391 } 392 if (configsOffset < 0) { 393 _exception = 1; 394 _exceptionType = "java/lang/IllegalArgumentException"; 395 _exceptionMessage = "configsOffset < 0"; 396 goto exit; 397 } 398 _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset; 399 if (_configsRemaining < config_size) { 400 _exception = 1; 401 _exceptionType = "java/lang/IllegalArgumentException"; 402 _exceptionMessage = "length - configsOffset < config_size < needed"; 403 goto exit; 404 } 405 configs = new EGLConfig[_configsRemaining]; 406 407 if (!num_config_ref) { 408 _exception = 1; 409 _exceptionType = "java/lang/IllegalArgumentException"; 410 _exceptionMessage = "num_config == null"; 411 goto exit; 412 } 413 if (num_configOffset < 0) { 414 _exception = 1; 415 _exceptionType = "java/lang/IllegalArgumentException"; 416 _exceptionMessage = "num_configOffset < 0"; 417 goto exit; 418 } 419 _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset; 420 if (_num_configRemaining < 1) { 421 _exception = 1; 422 _exceptionType = "java/lang/IllegalArgumentException"; 423 _exceptionMessage = "length - num_configOffset < 1 < needed"; 424 goto exit; 425 } 426 num_config_base = (EGLint *) 427 _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0); 428 num_config = num_config_base + num_configOffset; 429 430 _returnValue = eglChooseConfig( 431 (EGLDisplay)dpy_native, 432 (EGLint *)attrib_list, 433 (EGLConfig *)configs, 434 (EGLint)config_size, 435 (EGLint *)num_config 436 ); 437 438 exit: 439 if (num_config_base) { 440 _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base, 441 _exception ? JNI_ABORT: 0); 442 } 443 if (attrib_list_base) { 444 _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, 445 JNI_ABORT); 446 } 447 if (configs) { 448 for (int i = 0; i < _configsRemaining; i++) { 449 jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]); 450 _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new); 451 } 452 delete[] configs; 453 } 454 if (_exception) { 455 jniThrowException(_env, _exceptionType, _exceptionMessage); 456 } 457 return (jboolean)_returnValue; 458 } 459 460 /* EGLBoolean eglGetConfigAttrib ( EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value ) */ 461 static jboolean 462 android_eglGetConfigAttrib 463 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint attribute, jintArray value_ref, jint offset) { 464 jint _exception = 0; 465 const char * _exceptionType = NULL; 466 const char * _exceptionMessage = NULL; 467 EGLBoolean _returnValue = (EGLBoolean) 0; 468 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 469 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 470 EGLint *value_base = (EGLint *) 0; 471 jint _remaining; 472 EGLint *value = (EGLint *) 0; 473 474 if (!value_ref) { 475 _exception = 1; 476 _exceptionType = "java/lang/IllegalArgumentException"; 477 _exceptionMessage = "value == null"; 478 goto exit; 479 } 480 if (offset < 0) { 481 _exception = 1; 482 _exceptionType = "java/lang/IllegalArgumentException"; 483 _exceptionMessage = "offset < 0"; 484 goto exit; 485 } 486 _remaining = _env->GetArrayLength(value_ref) - offset; 487 if (_remaining < 1) { 488 _exception = 1; 489 _exceptionType = "java/lang/IllegalArgumentException"; 490 _exceptionMessage = "length - offset < 1 < needed"; 491 goto exit; 492 } 493 value_base = (EGLint *) 494 _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0); 495 value = value_base + offset; 496 497 _returnValue = eglGetConfigAttrib( 498 (EGLDisplay)dpy_native, 499 (EGLConfig)config_native, 500 (EGLint)attribute, 501 (EGLint *)value 502 ); 503 504 exit: 505 if (value_base) { 506 _env->ReleasePrimitiveArrayCritical(value_ref, value_base, 507 _exception ? JNI_ABORT: 0); 508 } 509 if (_exception) { 510 jniThrowException(_env, _exceptionType, _exceptionMessage); 511 } 512 return (jboolean)_returnValue; 513 } 514 515 /* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ 516 static jobject 517 android_eglCreateWindowSurface 518 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { 519 jint _exception = 0; 520 const char * _exceptionType = ""; 521 const char * _exceptionMessage = ""; 522 EGLSurface _returnValue = (EGLSurface) 0; 523 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 524 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 525 int attrib_list_sentinel = 0; 526 EGLint *attrib_list_base = (EGLint *) 0; 527 jint _remaining; 528 EGLint *attrib_list = (EGLint *) 0; 529 android::sp<ANativeWindow> window; 530 531 if (!attrib_list_ref) { 532 _exception = 1; 533 _exceptionType = "java/lang/IllegalArgumentException"; 534 _exceptionMessage = "attrib_list == null"; 535 goto exit; 536 } 537 if (offset < 0) { 538 _exception = 1; 539 _exceptionType = "java/lang/IllegalArgumentException"; 540 _exceptionMessage = "offset < 0"; 541 goto exit; 542 } 543 if (win == NULL) { 544 not_valid_surface: 545 _exception = 1; 546 _exceptionType = "java/lang/IllegalArgumentException"; 547 _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; 548 goto exit; 549 } 550 551 window = android::android_view_Surface_getNativeWindow(_env, win); 552 553 if (window == NULL) 554 goto not_valid_surface; 555 556 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 557 attrib_list_base = (EGLint *) 558 _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); 559 attrib_list = attrib_list_base + offset; 560 attrib_list_sentinel = 0; 561 for (int i = _remaining - 1; i >= 0; i--) { 562 if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ 563 attrib_list_sentinel = 1; 564 break; 565 } 566 } 567 if (attrib_list_sentinel == 0) { 568 _exception = 1; 569 _exceptionType = "java/lang/IllegalArgumentException"; 570 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 571 goto exit; 572 } 573 574 _returnValue = eglCreateWindowSurface( 575 (EGLDisplay)dpy_native, 576 (EGLConfig)config_native, 577 (EGLNativeWindowType)window.get(), 578 (EGLint *)attrib_list 579 ); 580 581 exit: 582 if (attrib_list_base) { 583 _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, 584 JNI_ABORT); 585 } 586 if (_exception) { 587 jniThrowException(_env, _exceptionType, _exceptionMessage); 588 } 589 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 590 } 591 592 /* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ 593 static jobject 594 android_eglCreateWindowSurfaceTexture 595 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { 596 jint _exception = 0; 597 const char * _exceptionType = ""; 598 const char * _exceptionMessage = ""; 599 EGLSurface _returnValue = (EGLSurface) 0; 600 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 601 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 602 int attrib_list_sentinel = 0; 603 EGLint *attrib_list_base = (EGLint *) 0; 604 jint _remaining; 605 EGLint *attrib_list = (EGLint *) 0; 606 android::sp<ANativeWindow> window; 607 android::sp<android::IGraphicBufferProducer> producer; 608 609 if (!attrib_list_ref) { 610 _exception = 1; 611 _exceptionType = "java/lang/IllegalArgumentException"; 612 _exceptionMessage = "attrib_list == null"; 613 goto exit; 614 } 615 if (offset < 0) { 616 _exception = 1; 617 _exceptionType = "java/lang/IllegalArgumentException"; 618 _exceptionMessage = "offset < 0"; 619 goto exit; 620 } 621 if (win == NULL) { 622 not_valid_surface: 623 _exception = 1; 624 _exceptionType = "java/lang/IllegalArgumentException"; 625 _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; 626 goto exit; 627 } 628 producer = android::SurfaceTexture_getProducer(_env, win); 629 630 if (producer == NULL) 631 goto not_valid_surface; 632 633 window = new android::Surface(producer); 634 635 if (window == NULL) 636 goto not_valid_surface; 637 638 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 639 attrib_list_base = (EGLint *) 640 _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); 641 attrib_list = attrib_list_base + offset; 642 attrib_list_sentinel = 0; 643 for (int i = _remaining - 1; i >= 0; i--) { 644 if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ 645 attrib_list_sentinel = 1; 646 break; 647 } 648 } 649 if (attrib_list_sentinel == 0) { 650 _exception = 1; 651 _exceptionType = "java/lang/IllegalArgumentException"; 652 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 653 goto exit; 654 } 655 656 _returnValue = eglCreateWindowSurface( 657 (EGLDisplay)dpy_native, 658 (EGLConfig)config_native, 659 (EGLNativeWindowType)window.get(), 660 (EGLint *)attrib_list 661 ); 662 663 exit: 664 if (attrib_list_base) { 665 _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, 666 JNI_ABORT); 667 } 668 if (_exception) { 669 jniThrowException(_env, _exceptionType, _exceptionMessage); 670 } 671 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 672 } 673 /* EGLSurface eglCreatePbufferSurface ( EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list ) */ 674 static jobject 675 android_eglCreatePbufferSurface 676 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jintArray attrib_list_ref, jint offset) { 677 jint _exception = 0; 678 const char * _exceptionType = NULL; 679 const char * _exceptionMessage = NULL; 680 EGLSurface _returnValue = (EGLSurface) 0; 681 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 682 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 683 bool attrib_list_sentinel = false; 684 EGLint *attrib_list_base = (EGLint *) 0; 685 jint _remaining; 686 EGLint *attrib_list = (EGLint *) 0; 687 688 if (!attrib_list_ref) { 689 _exception = 1; 690 _exceptionType = "java/lang/IllegalArgumentException"; 691 _exceptionMessage = "attrib_list == null"; 692 goto exit; 693 } 694 if (offset < 0) { 695 _exception = 1; 696 _exceptionType = "java/lang/IllegalArgumentException"; 697 _exceptionMessage = "offset < 0"; 698 goto exit; 699 } 700 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 701 attrib_list_base = (EGLint *) 702 _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); 703 attrib_list = attrib_list_base + offset; 704 attrib_list_sentinel = false; 705 for (int i = _remaining - 1; i >= 0; i--) { 706 if (attrib_list[i] == EGL_NONE){ 707 attrib_list_sentinel = true; 708 break; 709 } 710 } 711 if (attrib_list_sentinel == false) { 712 _exception = 1; 713 _exceptionType = "java/lang/IllegalArgumentException"; 714 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 715 goto exit; 716 } 717 718 _returnValue = eglCreatePbufferSurface( 719 (EGLDisplay)dpy_native, 720 (EGLConfig)config_native, 721 (EGLint *)attrib_list 722 ); 723 724 exit: 725 if (attrib_list_base) { 726 _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, 727 JNI_ABORT); 728 } 729 if (_exception) { 730 jniThrowException(_env, _exceptionType, _exceptionMessage); 731 } 732 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 733 } 734 735 /* EGLSurface eglCreatePixmapSurface ( EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list ) */ 736 static jobject 737 android_eglCreatePixmapSurface 738 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint pixmap, jintArray attrib_list_ref, jint offset) { 739 jniThrowException(_env, "java/lang/UnsupportedOperationException", 740 "eglCreatePixmapSurface"); 741 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, (EGLSurface) 0); 742 } 743 744 /* EGLBoolean eglDestroySurface ( EGLDisplay dpy, EGLSurface surface ) */ 745 static jboolean 746 android_eglDestroySurface 747 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface) { 748 EGLBoolean _returnValue = (EGLBoolean) 0; 749 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 750 EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface); 751 752 _returnValue = eglDestroySurface( 753 (EGLDisplay)dpy_native, 754 (EGLSurface)surface_native 755 ); 756 return (jboolean)_returnValue; 757 } 758 759 /* EGLBoolean eglQuerySurface ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value ) */ 760 static jboolean 761 android_eglQuerySurface 762 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jintArray value_ref, jint offset) { 763 jint _exception = 0; 764 const char * _exceptionType = NULL; 765 const char * _exceptionMessage = NULL; 766 EGLBoolean _returnValue = (EGLBoolean) 0; 767 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 768 EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface); 769 EGLint *value_base = (EGLint *) 0; 770 jint _remaining; 771 EGLint *value = (EGLint *) 0; 772 773 if (!value_ref) { 774 _exception = 1; 775 _exceptionType = "java/lang/IllegalArgumentException"; 776 _exceptionMessage = "value == null"; 777 goto exit; 778 } 779 if (offset < 0) { 780 _exception = 1; 781 _exceptionType = "java/lang/IllegalArgumentException"; 782 _exceptionMessage = "offset < 0"; 783 goto exit; 784 } 785 _remaining = _env->GetArrayLength(value_ref) - offset; 786 if (_remaining < 1) { 787 _exception = 1; 788 _exceptionType = "java/lang/IllegalArgumentException"; 789 _exceptionMessage = "length - offset < 1 < needed"; 790 goto exit; 791 } 792 value_base = (EGLint *) 793 _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0); 794 value = value_base + offset; 795 796 _returnValue = eglQuerySurface( 797 (EGLDisplay)dpy_native, 798 (EGLSurface)surface_native, 799 (EGLint)attribute, 800 (EGLint *)value 801 ); 802 803 exit: 804 if (value_base) { 805 _env->ReleasePrimitiveArrayCritical(value_ref, value_base, 806 _exception ? JNI_ABORT: 0); 807 } 808 if (_exception) { 809 jniThrowException(_env, _exceptionType, _exceptionMessage); 810 } 811 return (jboolean)_returnValue; 812 } 813 814 /* EGLBoolean eglBindAPI ( EGLenum api ) */ 815 static jboolean 816 android_eglBindAPI 817 (JNIEnv *_env, jobject _this, jint api) { 818 EGLBoolean _returnValue = (EGLBoolean) 0; 819 _returnValue = eglBindAPI( 820 (EGLenum)api 821 ); 822 return (jboolean)_returnValue; 823 } 824 825 /* EGLenum eglQueryAPI ( void ) */ 826 static jint 827 android_eglQueryAPI 828 (JNIEnv *_env, jobject _this) { 829 EGLenum _returnValue = (EGLenum) 0; 830 _returnValue = eglQueryAPI(); 831 return (jint)_returnValue; 832 } 833 834 /* EGLBoolean eglWaitClient ( void ) */ 835 static jboolean 836 android_eglWaitClient 837 (JNIEnv *_env, jobject _this) { 838 EGLBoolean _returnValue = (EGLBoolean) 0; 839 _returnValue = eglWaitClient(); 840 return (jboolean)_returnValue; 841 } 842 843 /* EGLBoolean eglReleaseThread ( void ) */ 844 static jboolean 845 android_eglReleaseThread 846 (JNIEnv *_env, jobject _this) { 847 EGLBoolean _returnValue = (EGLBoolean) 0; 848 _returnValue = eglReleaseThread(); 849 return (jboolean)_returnValue; 850 } 851 852 /* EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) */ 853 static jobject 854 android_eglCreatePbufferFromClientBuffer 855 (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) { 856 jint _exception = 0; 857 const char * _exceptionType = NULL; 858 const char * _exceptionMessage = NULL; 859 EGLSurface _returnValue = (EGLSurface) 0; 860 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 861 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 862 bool attrib_list_sentinel = false; 863 EGLint *attrib_list_base = (EGLint *) 0; 864 jint _remaining; 865 EGLint *attrib_list = (EGLint *) 0; 866 867 if (!attrib_list_ref) { 868 _exception = 1; 869 _exceptionType = "java/lang/IllegalArgumentException"; 870 _exceptionMessage = "attrib_list == null"; 871 goto exit; 872 } 873 if (offset < 0) { 874 _exception = 1; 875 _exceptionType = "java/lang/IllegalArgumentException"; 876 _exceptionMessage = "offset < 0"; 877 goto exit; 878 } 879 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 880 attrib_list_base = (EGLint *) 881 _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); 882 attrib_list = attrib_list_base + offset; 883 attrib_list_sentinel = false; 884 for (int i = _remaining - 1; i >= 0; i--) { 885 if (attrib_list[i] == EGL_NONE){ 886 attrib_list_sentinel = true; 887 break; 888 } 889 } 890 if (attrib_list_sentinel == false) { 891 _exception = 1; 892 _exceptionType = "java/lang/IllegalArgumentException"; 893 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 894 goto exit; 895 } 896 897 _returnValue = eglCreatePbufferFromClientBuffer( 898 (EGLDisplay)dpy_native, 899 (EGLenum)buftype, 900 (EGLClientBuffer)buffer, 901 (EGLConfig)config_native, 902 (EGLint *)attrib_list 903 ); 904 905 exit: 906 if (attrib_list_base) { 907 _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, 908 JNI_ABORT); 909 } 910 if (_exception) { 911 jniThrowException(_env, _exceptionType, _exceptionMessage); 912 } 913 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 914 } 915 916 /* EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) */ 917 static jboolean 918 android_eglSurfaceAttrib 919 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jint value) { 920 EGLBoolean _returnValue = (EGLBoolean) 0; 921 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 922 EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface); 923 924 _returnValue = eglSurfaceAttrib( 925 (EGLDisplay)dpy_native, 926 (EGLSurface)surface_native, 927 (EGLint)attribute, 928 (EGLint)value 929 ); 930 return (jboolean)_returnValue; 931 } 932 933 /* EGLBoolean eglBindTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */ 934 static jboolean 935 android_eglBindTexImage 936 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint buffer) { 937 EGLBoolean _returnValue = (EGLBoolean) 0; 938 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 939 EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface); 940 941 _returnValue = eglBindTexImage( 942 (EGLDisplay)dpy_native, 943 (EGLSurface)surface_native, 944 (EGLint)buffer 945 ); 946 return (jboolean)_returnValue; 947 } 948 949 /* EGLBoolean eglReleaseTexImage ( EGLDisplay dpy, EGLSurface surface, EGLint buffer ) */ 950 static jboolean 951 android_eglReleaseTexImage 952 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint buffer) { 953 EGLBoolean _returnValue = (EGLBoolean) 0; 954 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 955 EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface); 956 957 _returnValue = eglReleaseTexImage( 958 (EGLDisplay)dpy_native, 959 (EGLSurface)surface_native, 960 (EGLint)buffer 961 ); 962 return (jboolean)_returnValue; 963 } 964 965 /* EGLBoolean eglSwapInterval ( EGLDisplay dpy, EGLint interval ) */ 966 static jboolean 967 android_eglSwapInterval 968 (JNIEnv *_env, jobject _this, jobject dpy, jint interval) { 969 EGLBoolean _returnValue = (EGLBoolean) 0; 970 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 971 972 _returnValue = eglSwapInterval( 973 (EGLDisplay)dpy_native, 974 (EGLint)interval 975 ); 976 return (jboolean)_returnValue; 977 } 978 979 /* EGLContext eglCreateContext ( EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list ) */ 980 static jobject 981 android_eglCreateContext 982 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject share_context, jintArray attrib_list_ref, jint offset) { 983 jint _exception = 0; 984 const char * _exceptionType = NULL; 985 const char * _exceptionMessage = NULL; 986 EGLContext _returnValue = (EGLContext) 0; 987 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 988 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 989 EGLContext share_context_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, share_context); 990 bool attrib_list_sentinel = false; 991 EGLint *attrib_list_base = (EGLint *) 0; 992 jint _remaining; 993 EGLint *attrib_list = (EGLint *) 0; 994 995 if (!attrib_list_ref) { 996 _exception = 1; 997 _exceptionType = "java/lang/IllegalArgumentException"; 998 _exceptionMessage = "attrib_list == null"; 999 goto exit; 1000 } 1001 if (offset < 0) { 1002 _exception = 1; 1003 _exceptionType = "java/lang/IllegalArgumentException"; 1004 _exceptionMessage = "offset < 0"; 1005 goto exit; 1006 } 1007 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 1008 attrib_list_base = (EGLint *) 1009 _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); 1010 attrib_list = attrib_list_base + offset; 1011 attrib_list_sentinel = false; 1012 for (int i = _remaining - 1; i >= 0; i--) { 1013 if (attrib_list[i] == EGL_NONE){ 1014 attrib_list_sentinel = true; 1015 break; 1016 } 1017 } 1018 if (attrib_list_sentinel == false) { 1019 _exception = 1; 1020 _exceptionType = "java/lang/IllegalArgumentException"; 1021 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 1022 goto exit; 1023 } 1024 1025 _returnValue = eglCreateContext( 1026 (EGLDisplay)dpy_native, 1027 (EGLConfig)config_native, 1028 (EGLContext)share_context_native, 1029 (EGLint *)attrib_list 1030 ); 1031 1032 exit: 1033 if (attrib_list_base) { 1034 _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, 1035 JNI_ABORT); 1036 } 1037 if (_exception) { 1038 jniThrowException(_env, _exceptionType, _exceptionMessage); 1039 } 1040 return toEGLHandle(_env, eglcontextClass, eglcontextConstructor, _returnValue); 1041 } 1042 1043 /* EGLBoolean eglDestroyContext ( EGLDisplay dpy, EGLContext ctx ) */ 1044 static jboolean 1045 android_eglDestroyContext 1046 (JNIEnv *_env, jobject _this, jobject dpy, jobject ctx) { 1047 EGLBoolean _returnValue = (EGLBoolean) 0; 1048 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 1049 EGLContext ctx_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, ctx); 1050 1051 _returnValue = eglDestroyContext( 1052 (EGLDisplay)dpy_native, 1053 (EGLContext)ctx_native 1054 ); 1055 return (jboolean)_returnValue; 1056 } 1057 1058 /* EGLBoolean eglMakeCurrent ( EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx ) */ 1059 static jboolean 1060 android_eglMakeCurrent 1061 (JNIEnv *_env, jobject _this, jobject dpy, jobject draw, jobject read, jobject ctx) { 1062 EGLBoolean _returnValue = (EGLBoolean) 0; 1063 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 1064 EGLSurface draw_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, draw); 1065 EGLSurface read_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, read); 1066 EGLContext ctx_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, ctx); 1067 1068 _returnValue = eglMakeCurrent( 1069 (EGLDisplay)dpy_native, 1070 (EGLSurface)draw_native, 1071 (EGLSurface)read_native, 1072 (EGLContext)ctx_native 1073 ); 1074 return (jboolean)_returnValue; 1075 } 1076 1077 /* EGLContext eglGetCurrentContext ( void ) */ 1078 static jobject 1079 android_eglGetCurrentContext 1080 (JNIEnv *_env, jobject _this) { 1081 EGLContext _returnValue = (EGLContext) 0; 1082 _returnValue = eglGetCurrentContext(); 1083 return toEGLHandle(_env, eglcontextClass, eglcontextConstructor, _returnValue); 1084 } 1085 1086 /* EGLSurface eglGetCurrentSurface ( EGLint readdraw ) */ 1087 static jobject 1088 android_eglGetCurrentSurface 1089 (JNIEnv *_env, jobject _this, jint readdraw) { 1090 EGLSurface _returnValue = (EGLSurface) 0; 1091 _returnValue = eglGetCurrentSurface( 1092 (EGLint)readdraw 1093 ); 1094 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 1095 } 1096 1097 /* EGLDisplay eglGetCurrentDisplay ( void ) */ 1098 static jobject 1099 android_eglGetCurrentDisplay 1100 (JNIEnv *_env, jobject _this) { 1101 EGLDisplay _returnValue = (EGLDisplay) 0; 1102 _returnValue = eglGetCurrentDisplay(); 1103 return toEGLHandle(_env, egldisplayClass, egldisplayConstructor, _returnValue); 1104 } 1105 1106 /* EGLBoolean eglQueryContext ( EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value ) */ 1107 static jboolean 1108 android_eglQueryContext 1109 (JNIEnv *_env, jobject _this, jobject dpy, jobject ctx, jint attribute, jintArray value_ref, jint offset) { 1110 jint _exception = 0; 1111 const char * _exceptionType = NULL; 1112 const char * _exceptionMessage = NULL; 1113 EGLBoolean _returnValue = (EGLBoolean) 0; 1114 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 1115 EGLContext ctx_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, ctx); 1116 EGLint *value_base = (EGLint *) 0; 1117 jint _remaining; 1118 EGLint *value = (EGLint *) 0; 1119 1120 if (!value_ref) { 1121 _exception = 1; 1122 _exceptionType = "java/lang/IllegalArgumentException"; 1123 _exceptionMessage = "value == null"; 1124 goto exit; 1125 } 1126 if (offset < 0) { 1127 _exception = 1; 1128 _exceptionType = "java/lang/IllegalArgumentException"; 1129 _exceptionMessage = "offset < 0"; 1130 goto exit; 1131 } 1132 _remaining = _env->GetArrayLength(value_ref) - offset; 1133 if (_remaining < 1) { 1134 _exception = 1; 1135 _exceptionType = "java/lang/IllegalArgumentException"; 1136 _exceptionMessage = "length - offset < 1 < needed"; 1137 goto exit; 1138 } 1139 value_base = (EGLint *) 1140 _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0); 1141 value = value_base + offset; 1142 1143 _returnValue = eglQueryContext( 1144 (EGLDisplay)dpy_native, 1145 (EGLContext)ctx_native, 1146 (EGLint)attribute, 1147 (EGLint *)value 1148 ); 1149 1150 exit: 1151 if (value_base) { 1152 _env->ReleasePrimitiveArrayCritical(value_ref, value_base, 1153 _exception ? JNI_ABORT: 0); 1154 } 1155 if (_exception) { 1156 jniThrowException(_env, _exceptionType, _exceptionMessage); 1157 } 1158 return (jboolean)_returnValue; 1159 } 1160 1161 /* EGLBoolean eglWaitGL ( void ) */ 1162 static jboolean 1163 android_eglWaitGL 1164 (JNIEnv *_env, jobject _this) { 1165 EGLBoolean _returnValue = (EGLBoolean) 0; 1166 _returnValue = eglWaitGL(); 1167 return (jboolean)_returnValue; 1168 } 1169 1170 /* EGLBoolean eglWaitNative ( EGLint engine ) */ 1171 static jboolean 1172 android_eglWaitNative 1173 (JNIEnv *_env, jobject _this, jint engine) { 1174 EGLBoolean _returnValue = (EGLBoolean) 0; 1175 _returnValue = eglWaitNative( 1176 (EGLint)engine 1177 ); 1178 return (jboolean)_returnValue; 1179 } 1180 1181 /* EGLBoolean eglSwapBuffers ( EGLDisplay dpy, EGLSurface surface ) */ 1182 static jboolean 1183 android_eglSwapBuffers 1184 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface) { 1185 EGLBoolean _returnValue = (EGLBoolean) 0; 1186 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 1187 EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface); 1188 1189 _returnValue = eglSwapBuffers( 1190 (EGLDisplay)dpy_native, 1191 (EGLSurface)surface_native 1192 ); 1193 return (jboolean)_returnValue; 1194 } 1195 1196 /* EGLBoolean eglCopyBuffers ( EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target ) */ 1197 static jboolean 1198 android_eglCopyBuffers 1199 (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint target) { 1200 jniThrowException(_env, "java/lang/UnsupportedOperationException", 1201 "eglCopyBuffers"); 1202 return (EGLBoolean) 0; 1203 } 1204 1205 static const char *classPathName = "android/opengl/EGL14"; 1206 1207 static JNINativeMethod methods[] = { 1208 {"_nativeClassInit", "()V", (void*)nativeClassInit }, 1209 {"eglGetError", "()I", (void *) android_eglGetError }, 1210 {"eglGetDisplay", "(I)Landroid/opengl/EGLDisplay;", (void *) android_eglGetDisplay }, 1211 {"eglInitialize", "(Landroid/opengl/EGLDisplay;[II[II)Z", (void *) android_eglInitialize }, 1212 {"eglTerminate", "(Landroid/opengl/EGLDisplay;)Z", (void *) android_eglTerminate }, 1213 {"eglQueryString", "(Landroid/opengl/EGLDisplay;I)Ljava/lang/String;", (void *) android_eglQueryString__Landroind_opengl_EGLDisplay_2I }, 1214 {"eglGetConfigs", "(Landroid/opengl/EGLDisplay;[Landroid/opengl/EGLConfig;II[II)Z", (void *) android_eglGetConfigs }, 1215 {"eglChooseConfig", "(Landroid/opengl/EGLDisplay;[II[Landroid/opengl/EGLConfig;II[II)Z", (void *) android_eglChooseConfig }, 1216 {"eglGetConfigAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;I[II)Z", (void *) android_eglGetConfigAttrib }, 1217 {"_eglCreateWindowSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/lang/Object;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreateWindowSurface }, 1218 {"_eglCreateWindowSurfaceTexture", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Ljava/lang/Object;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreateWindowSurfaceTexture }, 1219 {"eglCreatePbufferSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferSurface }, 1220 {"eglCreatePixmapSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;I[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePixmapSurface }, 1221 {"eglDestroySurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;)Z", (void *) android_eglDestroySurface }, 1222 {"eglQuerySurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I[II)Z", (void *) android_eglQuerySurface }, 1223 {"eglBindAPI", "(I)Z", (void *) android_eglBindAPI }, 1224 {"eglQueryAPI", "()I", (void *) android_eglQueryAPI }, 1225 {"eglWaitClient", "()Z", (void *) android_eglWaitClient }, 1226 {"eglReleaseThread", "()Z", (void *) android_eglReleaseThread }, 1227 {"eglCreatePbufferFromClientBuffer", "(Landroid/opengl/EGLDisplay;IILandroid/opengl/EGLConfig;[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePbufferFromClientBuffer }, 1228 {"eglSurfaceAttrib", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;II)Z", (void *) android_eglSurfaceAttrib }, 1229 {"eglBindTexImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglBindTexImage }, 1230 {"eglReleaseTexImage", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglReleaseTexImage }, 1231 {"eglSwapInterval", "(Landroid/opengl/EGLDisplay;I)Z", (void *) android_eglSwapInterval }, 1232 {"eglCreateContext", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;Landroid/opengl/EGLContext;[II)Landroid/opengl/EGLContext;", (void *) android_eglCreateContext }, 1233 {"eglDestroyContext", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLContext;)Z", (void *) android_eglDestroyContext }, 1234 {"eglMakeCurrent", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;Landroid/opengl/EGLSurface;Landroid/opengl/EGLContext;)Z", (void *) android_eglMakeCurrent }, 1235 {"eglGetCurrentContext", "()Landroid/opengl/EGLContext;", (void *) android_eglGetCurrentContext }, 1236 {"eglGetCurrentSurface", "(I)Landroid/opengl/EGLSurface;", (void *) android_eglGetCurrentSurface }, 1237 {"eglGetCurrentDisplay", "()Landroid/opengl/EGLDisplay;", (void *) android_eglGetCurrentDisplay }, 1238 {"eglQueryContext", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLContext;I[II)Z", (void *) android_eglQueryContext }, 1239 {"eglWaitGL", "()Z", (void *) android_eglWaitGL }, 1240 {"eglWaitNative", "(I)Z", (void *) android_eglWaitNative }, 1241 {"eglSwapBuffers", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;)Z", (void *) android_eglSwapBuffers }, 1242 {"eglCopyBuffers", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLSurface;I)Z", (void *) android_eglCopyBuffers }, 1243 }; 1244 1245 int register_android_opengl_jni_EGL14(JNIEnv *_env) 1246 { 1247 int err; 1248 err = android::AndroidRuntime::registerNativeMethods(_env, classPathName, methods, NELEM(methods)); 1249 return err; 1250 } 1251