1/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ 2static jobject 3android_eglCreateWindowSurface 4 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { 5 jint _exception = 0; 6 const char * _exceptionType = ""; 7 const char * _exceptionMessage = ""; 8 EGLSurface _returnValue = (EGLSurface) 0; 9 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 10 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 11 int attrib_list_sentinel = 0; 12 EGLint *attrib_list_base = (EGLint *) 0; 13 jint _remaining; 14 EGLint *attrib_list = (EGLint *) 0; 15 android::sp<ANativeWindow> window; 16 17 if (!attrib_list_ref) { 18 _exception = 1; 19 _exceptionType = "java/lang/IllegalArgumentException"; 20 _exceptionMessage = "attrib_list == null"; 21 goto exit; 22 } 23 if (offset < 0) { 24 _exception = 1; 25 _exceptionType = "java/lang/IllegalArgumentException"; 26 _exceptionMessage = "offset < 0"; 27 goto exit; 28 } 29 if (win == NULL) { 30not_valid_surface: 31 _exception = 1; 32 _exceptionType = "java/lang/IllegalArgumentException"; 33 _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; 34 goto exit; 35 } 36 37 window = android::android_view_Surface_getNativeWindow(_env, win); 38 39 if (window == NULL) 40 goto not_valid_surface; 41 42 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 43 attrib_list_base = (EGLint *) 44 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0); 45 attrib_list = attrib_list_base + offset; 46 attrib_list_sentinel = 0; 47 for (int i = _remaining - 1; i >= 0; i--) { 48 if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ 49 attrib_list_sentinel = 1; 50 break; 51 } 52 } 53 if (attrib_list_sentinel == 0) { 54 _exception = 1; 55 _exceptionType = "java/lang/IllegalArgumentException"; 56 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 57 goto exit; 58 } 59 60 _returnValue = eglCreateWindowSurface( 61 (EGLDisplay)dpy_native, 62 (EGLConfig)config_native, 63 (EGLNativeWindowType)window.get(), 64 (EGLint *)attrib_list 65 ); 66 67exit: 68 if (attrib_list_base) { 69 _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base, 70 JNI_ABORT); 71 } 72 if (_exception) { 73 jniThrowException(_env, _exceptionType, _exceptionMessage); 74 } 75 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 76} 77 78/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ 79static jobject 80android_eglCreateWindowSurfaceTexture 81 (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { 82 jint _exception = 0; 83 const char * _exceptionType = ""; 84 const char * _exceptionMessage = ""; 85 EGLSurface _returnValue = (EGLSurface) 0; 86 EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 87 EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 88 int attrib_list_sentinel = 0; 89 EGLint *attrib_list_base = (EGLint *) 0; 90 jint _remaining; 91 EGLint *attrib_list = (EGLint *) 0; 92 android::sp<ANativeWindow> window; 93 android::sp<android::IGraphicBufferProducer> producer; 94 95 if (!attrib_list_ref) { 96 _exception = 1; 97 _exceptionType = "java/lang/IllegalArgumentException"; 98 _exceptionMessage = "attrib_list == null"; 99 goto exit; 100 } 101 if (offset < 0) { 102 _exception = 1; 103 _exceptionType = "java/lang/IllegalArgumentException"; 104 _exceptionMessage = "offset < 0"; 105 goto exit; 106 } 107 if (win == NULL) { 108not_valid_surface: 109 _exception = 1; 110 _exceptionType = "java/lang/IllegalArgumentException"; 111 _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; 112 goto exit; 113 } 114 producer = android::SurfaceTexture_getProducer(_env, win); 115 116 if (producer == NULL) 117 goto not_valid_surface; 118 119 window = new android::Surface(producer, true); 120 121 if (window == NULL) 122 goto not_valid_surface; 123 124 _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 125 attrib_list_base = (EGLint *) 126 _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0); 127 attrib_list = attrib_list_base + offset; 128 attrib_list_sentinel = 0; 129 for (int i = _remaining - 1; i >= 0; i--) { 130 if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ 131 attrib_list_sentinel = 1; 132 break; 133 } 134 } 135 if (attrib_list_sentinel == 0) { 136 _exception = 1; 137 _exceptionType = "java/lang/IllegalArgumentException"; 138 _exceptionMessage = "attrib_list must contain EGL_NONE!"; 139 goto exit; 140 } 141 142 _returnValue = eglCreateWindowSurface( 143 (EGLDisplay)dpy_native, 144 (EGLConfig)config_native, 145 (EGLNativeWindowType)window.get(), 146 (EGLint *)attrib_list 147 ); 148 149exit: 150 if (attrib_list_base) { 151 _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base, 152 JNI_ABORT); 153 } 154 if (_exception) { 155 jniThrowException(_env, _exceptionType, _exceptionMessage); 156 } 157 return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 158} 159