166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ 266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jobject 366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferandroid_eglCreateWindowSurface 466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { 566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer jint _exception = 0; 666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer const char * _exceptionType = ""; 766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer const char * _exceptionMessage = ""; 866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLSurface _returnValue = (EGLSurface) 0; 966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 1066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 1166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer int attrib_list_sentinel = 0; 1266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLint *attrib_list_base = (EGLint *) 0; 1366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer jint _remaining; 1466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLint *attrib_list = (EGLint *) 0; 1566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer android::sp<ANativeWindow> window; 1666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 1766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (!attrib_list_ref) { 1866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 1966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 2066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "attrib_list == null"; 2166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 2266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 2366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (offset < 0) { 2466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 2566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 2666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "offset < 0"; 2766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 2866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 2966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (win == NULL) { 3066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofernot_valid_surface: 3166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 3266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 3366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; 3466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 3566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 3666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 3754c2818abe6d366815aec67dfcede1b1e008a52eMathias Agopian window = android::android_view_Surface_getNativeWindow(_env, win); 3866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 3966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (window == NULL) 4066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto not_valid_surface; 4166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 4266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 4366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list_base = (EGLint *) 444e7de461c18278a31be83e7c9074a02fbb6e9475Hiroshi Yamauchi _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0); 4566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list = attrib_list_base + offset; 4666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list_sentinel = 0; 4766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer for (int i = _remaining - 1; i >= 0; i--) { 4866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ 4966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list_sentinel = 1; 5066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer break; 5166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 5266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 5366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (attrib_list_sentinel == 0) { 5466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 5566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 5666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "attrib_list must contain EGL_NONE!"; 5766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 5866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 5966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 6066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _returnValue = eglCreateWindowSurface( 6166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLDisplay)dpy_native, 6266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLConfig)config_native, 6366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLNativeWindowType)window.get(), 6466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLint *)attrib_list 6566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer ); 6666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 6766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferexit: 6866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (attrib_list_base) { 694e7de461c18278a31be83e7c9074a02fbb6e9475Hiroshi Yamauchi _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base, 7066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer JNI_ABORT); 7166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 7266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (_exception) { 7366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer jniThrowException(_env, _exceptionType, _exceptionMessage); 7466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 7566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 7666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer} 7766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 7866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ 7966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferstatic jobject 8066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferandroid_eglCreateWindowSurfaceTexture 8166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { 8266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer jint _exception = 0; 8366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer const char * _exceptionType = ""; 8466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer const char * _exceptionMessage = ""; 8566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLSurface _returnValue = (EGLSurface) 0; 8666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); 8766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); 8866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer int attrib_list_sentinel = 0; 8966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLint *attrib_list_base = (EGLint *) 0; 9066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer jint _remaining; 9166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer EGLint *attrib_list = (EGLint *) 0; 9266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer android::sp<ANativeWindow> window; 93db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian android::sp<android::IGraphicBufferProducer> producer; 9466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 9566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (!attrib_list_ref) { 9666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 9766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 9866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "attrib_list == null"; 9966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 10066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 10166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (offset < 0) { 10266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 10366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 10466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "offset < 0"; 10566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 10666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 10766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (win == NULL) { 10866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofernot_valid_surface: 10966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 11066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 11166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; 11266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 11366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 114db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian producer = android::SurfaceTexture_getProducer(_env, win); 11554c2818abe6d366815aec67dfcede1b1e008a52eMathias Agopian 116db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian if (producer == NULL) 11754c2818abe6d366815aec67dfcede1b1e008a52eMathias Agopian goto not_valid_surface; 11854c2818abe6d366815aec67dfcede1b1e008a52eMathias Agopian 11950166d117307a278a2cb95d59ac60780c010e4c1Andy McFadden window = new android::Surface(producer, true); 12066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 12166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (window == NULL) 12266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto not_valid_surface; 12366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 12466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _remaining = _env->GetArrayLength(attrib_list_ref) - offset; 12566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list_base = (EGLint *) 1264e7de461c18278a31be83e7c9074a02fbb6e9475Hiroshi Yamauchi _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0); 12766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list = attrib_list_base + offset; 12866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list_sentinel = 0; 12966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer for (int i = _remaining - 1; i >= 0; i--) { 13066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ 13166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer attrib_list_sentinel = 1; 13266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer break; 13366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 13466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 13566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (attrib_list_sentinel == 0) { 13666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exception = 1; 13766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionType = "java/lang/IllegalArgumentException"; 13866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _exceptionMessage = "attrib_list must contain EGL_NONE!"; 13966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer goto exit; 14066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 14166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 14266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer _returnValue = eglCreateWindowSurface( 14366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLDisplay)dpy_native, 14466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLConfig)config_native, 14566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLNativeWindowType)window.get(), 14666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer (EGLint *)attrib_list 14766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer ); 14866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer 14966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferexit: 15066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (attrib_list_base) { 1514e7de461c18278a31be83e7c9074a02fbb6e9475Hiroshi Yamauchi _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base, 15266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer JNI_ABORT); 15366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 15466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer if (_exception) { 15566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer jniThrowException(_env, _exceptionType, _exceptionMessage); 15666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 15766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); 15866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer} 159