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
16b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos    if (attrib_list_ref) {
17b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        if (offset < 0) {
18b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _exception = 1;
19b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _exceptionType = "java/lang/IllegalArgumentException";
20b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _exceptionMessage = "offset < 0";
21b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            goto exit;
22b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        }
23b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
24b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        attrib_list_base = (EGLint *)
25b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
26b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        attrib_list = attrib_list_base + offset;
27b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        attrib_list_sentinel = false;
28b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        for (int i = _remaining - 1; i >= 0; i--)  {
29b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            if (attrib_list[i] == EGL_NONE){
30b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos                attrib_list_sentinel = true;
31b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos                break;
32b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            }
33b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        }
34b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos        if (attrib_list_sentinel == false) {
35b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _exception = 1;
36b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _exceptionType = "java/lang/IllegalArgumentException";
37b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            _exceptionMessage = "attrib_list must contain EGL_NONE!";
38b62e242c4c2bdfe84ce28231d2fcc85e79517f8cPablo Ceballos            goto exit;
39ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        }
40ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
41ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
42ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    _returnValue = eglCreatePbufferFromClientBuffer(
43ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLDisplay)dpy_native,
44ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLenum)buftype,
45ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        reinterpret_cast<EGLClientBuffer>(buffer),
46ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLConfig)config_native,
47ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        (EGLint *)attrib_list
48ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    );
49ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
50ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatexit:
51ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (attrib_list_base) {
524e7de461c18278a31be83e7c9074a02fbb6e9475Hiroshi Yamauchi        _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
53ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat            JNI_ABORT);
54ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
55ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if (_exception) {
56ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        jniThrowException(_env, _exceptionType, _exceptionMessage);
57ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
58ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue);
59ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat}
60ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat
61ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatstatic jobject
62ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhatandroid_eglCreatePbufferFromClientBufferInt
63ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat  (JNIEnv *_env, jobject _this, jobject dpy, jint buftype, jint buffer, jobject config, jintArray attrib_list_ref, jint offset) {
64ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    if(sizeof(void*) != sizeof(uint32_t)) {
65ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        jniThrowException(_env, "java/lang/UnsupportedOperationException", "eglCreatePbufferFromClientBuffer");
66ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        return 0;
67ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
68ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    return android_eglCreatePbufferFromClientBuffer(_env, _this, dpy, buftype, buffer, config, attrib_list_ref, offset);
69ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat}
70