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