eglCreatePbufferFromClientBuffer.cpp revision ab6fc2a86f34be455c144a2d691e94909998c959
1ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat/* EGLSurface eglCreatePbufferFromClientBuffer ( EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list ) */
2ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatstatic jobject
3ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatandroid_eglCreatePbufferFromClientBuffer
4ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat  (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jlong buffer, jobject config, jintArray attrib_list_ref, jint offset) {
5ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    jint _exception = 0;
6ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    const char * _exceptionType = NULL;
7ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    const char * _exceptionMessage = NULL;
8ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    EGLSurface _returnValue = (EGLSurface) 0;
9ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
10ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config);
11ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    bool attrib_list_sentinel = false;
12ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    EGLint *attrib_list_base = (EGLint *) 0;
13ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    jint _remaining;
14ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    EGLint *attrib_list = (EGLint *) 0;
15ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
16ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (!attrib_list_ref) {
17ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exception = 1;
18ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exceptionType = "java/lang/IllegalArgumentException";
19ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exceptionMessage = "attrib_list == null";
20ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        goto exit;
21ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
22ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (offset < 0) {
23ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exception = 1;
24ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exceptionType = "java/lang/IllegalArgumentException";
25ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exceptionMessage = "offset < 0";
26ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        goto exit;
27ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
28ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
29ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    attrib_list_base = (EGLint *)
30ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
31ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    attrib_list = attrib_list_base + offset;
32ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    attrib_list_sentinel = false;
33ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    for (int i = _remaining - 1; i >= 0; i--)  {
34ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        if (attrib_list[i] == EGL_NONE){
35ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat            attrib_list_sentinel = true;
36ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat            break;
37ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        }
38ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
39ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (attrib_list_sentinel == false) {
40ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exception = 1;
41ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exceptionType = "java/lang/IllegalArgumentException";
42ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _exceptionMessage = "attrib_list must contain EGL_NONE!";
43ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        goto exit;
44ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
45ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
46ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    _returnValue = eglCreatePbufferFromClientBuffer(
47ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLDisplay)dpy_native,
48ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLenum)buftype,
49ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        reinterpret_cast<EGLClientBuffer>(buffer),
50ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLConfig)config_native,
51ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLint *)attrib_list
52ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    );
53ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
54ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatexit:
55ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (attrib_list_base) {
56ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
57ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat            JNI_ABORT);
58ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
59ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (_exception) {
60ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        jniThrowException(_env, _exceptionType, _exceptionMessage);
61ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
62ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
63ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat}
64ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
65ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatstatic jobject
66ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatandroid_eglCreatePbufferFromClientBufferInt
67ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat  (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) {
68ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if(sizeof(void*) != sizeof(uint32_t)) {
69ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePbufferFromClientBuffer");
70ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        return 0;
71ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
72ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    return android_eglCreatePbufferFromClientBuffer(_env, _this, dpy, buftype, buffer, config, attrib_list_ref, offset);
73ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat}
74ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
75