eglCreateWindowSurface.cpp revision 66a42db8cbfba902f72f0ace5ac448ef4bfd3951
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
3766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    window = android::android_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 *)
4466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(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) {
6966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(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;
9366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    android::sp<android::SurfaceTexture> surfaceTexture;
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    }
11466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    surfaceTexture = android::SurfaceTexture_getSurfaceTexture(_env, win);
11566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    window = new android::SurfaceTextureClient(surfaceTexture);
11666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
11766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (window == NULL)
11866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        goto not_valid_surface;
11966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
12066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
12166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    attrib_list_base = (EGLint *)
12266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
12366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    attrib_list = attrib_list_base + offset;
12466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    attrib_list_sentinel = 0;
12566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    for (int i = _remaining - 1; i >= 0; i--)  {
12666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        if (*((EGLint*)(attrib_list + i)) == EGL_NONE){
12766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer            attrib_list_sentinel = 1;
12866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer            break;
12966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        }
13066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
13166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (attrib_list_sentinel == 0) {
13266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _exception = 1;
13366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _exceptionType = "java/lang/IllegalArgumentException";
13466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _exceptionMessage = "attrib_list must contain EGL_NONE!";
13566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        goto exit;
13666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
13766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
13866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    _returnValue = eglCreateWindowSurface(
13966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        (EGLDisplay)dpy_native,
14066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        (EGLConfig)config_native,
14166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        (EGLNativeWindowType)window.get(),
14266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        (EGLint *)attrib_list
14366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    );
14466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
14566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferexit:
14666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (attrib_list_base) {
14766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
14866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer            JNI_ABORT);
14966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
15066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    if (_exception) {
15166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        jniThrowException(_env, _exceptionType, _exceptionMessage);
15266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
15366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
15466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer}
155