xref: /aosp_15_r20/frameworks/native/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2 ** Copyright 2018, The Android Open Source Project
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 **     http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
17 // This source file is automatically generated
18 
19 #pragma GCC diagnostic ignored "-Wunused-variable"
20 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
21 #pragma GCC diagnostic ignored "-Wunused-function"
22 
23 #include "jni.h"
24 #include <nativehelper/JNIPlatformHelp.h>
25 #include <android_runtime/AndroidRuntime.h>
26 #include <utils/misc.h>
27 
28 #include <assert.h>
29 #include <vector>
30 #include <EGL/egl.h>
31 
32 #include <ui/ANativeObjectBase.h>
33 
34 // classes from EGL 1.4
35 static jclass egldisplayClass;
36 static jclass eglsurfaceClass;
37 static jclass eglconfigClass;
38 static jclass eglcontextClass;
39 
40 static jmethodID egldisplayGetHandleID;
41 static jmethodID eglconfigGetHandleID;
42 static jmethodID eglcontextGetHandleID;
43 static jmethodID eglsurfaceGetHandleID;
44 
45 static jmethodID egldisplayConstructor;
46 static jmethodID eglcontextConstructor;
47 static jmethodID eglsurfaceConstructor;
48 static jmethodID eglconfigConstructor;
49 
50 static jobject eglNoContextObject;
51 static jobject eglNoDisplayObject;
52 static jobject eglNoSurfaceObject;
53 
54 // classes from EGL 1.5
55 static jclass eglimageClass;
56 static jclass eglsyncClass;
57 
58 static jmethodID eglimageGetHandleID;
59 static jmethodID eglsyncGetHandleID;
60 
61 static jmethodID eglimageConstructor;
62 static jmethodID eglsyncConstructor;
63 
64 static jobject eglNoImageObject;
65 static jobject eglNoSyncObject;
66 
67 /* Cache method IDs each time the class is loaded. */
68 
69 static void
nativeClassInit(JNIEnv * _env,jclass glImplClass)70 nativeClassInit(JNIEnv *_env, jclass glImplClass)
71 {
72     // EGL 1.4 Init
73     jclass eglconfigClassLocal = _env->FindClass("android/opengl/EGLConfig");
74     eglconfigClass = (jclass) _env->NewGlobalRef(eglconfigClassLocal);
75     jclass eglcontextClassLocal = _env->FindClass("android/opengl/EGLContext");
76     eglcontextClass = (jclass) _env->NewGlobalRef(eglcontextClassLocal);
77     jclass egldisplayClassLocal = _env->FindClass("android/opengl/EGLDisplay");
78     egldisplayClass = (jclass) _env->NewGlobalRef(egldisplayClassLocal);
79     jclass eglsurfaceClassLocal = _env->FindClass("android/opengl/EGLSurface");
80     eglsurfaceClass = (jclass) _env->NewGlobalRef(eglsurfaceClassLocal);
81 
82     eglconfigGetHandleID = _env->GetMethodID(eglconfigClass, "getNativeHandle", "()J");
83     eglcontextGetHandleID = _env->GetMethodID(eglcontextClass, "getNativeHandle", "()J");
84     egldisplayGetHandleID = _env->GetMethodID(egldisplayClass, "getNativeHandle", "()J");
85     eglsurfaceGetHandleID = _env->GetMethodID(eglsurfaceClass, "getNativeHandle", "()J");
86 
87     eglconfigConstructor = _env->GetMethodID(eglconfigClass, "<init>", "(J)V");
88     eglcontextConstructor = _env->GetMethodID(eglcontextClass, "<init>", "(J)V");
89     egldisplayConstructor = _env->GetMethodID(egldisplayClass, "<init>", "(J)V");
90     eglsurfaceConstructor = _env->GetMethodID(eglsurfaceClass, "<init>", "(J)V");
91 
92     jobject localeglNoContextObject = _env->NewObject(eglcontextClass, eglcontextConstructor, reinterpret_cast<jlong>(EGL_NO_CONTEXT));
93     eglNoContextObject = _env->NewGlobalRef(localeglNoContextObject);
94     jobject localeglNoDisplayObject = _env->NewObject(egldisplayClass, egldisplayConstructor, reinterpret_cast<jlong>(EGL_NO_DISPLAY));
95     eglNoDisplayObject = _env->NewGlobalRef(localeglNoDisplayObject);
96     jobject localeglNoSurfaceObject = _env->NewObject(eglsurfaceClass, eglsurfaceConstructor, reinterpret_cast<jlong>(EGL_NO_SURFACE));
97     eglNoSurfaceObject = _env->NewGlobalRef(localeglNoSurfaceObject);
98 
99     jclass eglClass = _env->FindClass("android/opengl/EGL15");
100     jfieldID noContextFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_CONTEXT", "Landroid/opengl/EGLContext;");
101     _env->SetStaticObjectField(eglClass, noContextFieldID, eglNoContextObject);
102 
103     jfieldID noDisplayFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_DISPLAY", "Landroid/opengl/EGLDisplay;");
104     _env->SetStaticObjectField(eglClass, noDisplayFieldID, eglNoDisplayObject);
105 
106     jfieldID noSurfaceFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SURFACE", "Landroid/opengl/EGLSurface;");
107     _env->SetStaticObjectField(eglClass, noSurfaceFieldID, eglNoSurfaceObject);
108 
109     // EGL 1.5 init
110     jclass eglimageClassLocal = _env->FindClass("android/opengl/EGLImage");
111     eglimageClass = (jclass) _env->NewGlobalRef(eglimageClassLocal);
112     jclass eglsyncClassLocal = _env->FindClass("android/opengl/EGLSync");
113     eglsyncClass = (jclass) _env->NewGlobalRef(eglsyncClassLocal);
114 
115     eglimageGetHandleID = _env->GetMethodID(eglimageClass, "getNativeHandle", "()J");
116     eglsyncGetHandleID = _env->GetMethodID(eglsyncClass, "getNativeHandle", "()J");
117 
118     eglimageConstructor = _env->GetMethodID(eglimageClass, "<init>", "(J)V");
119     eglsyncConstructor = _env->GetMethodID(eglsyncClass, "<init>", "(J)V");
120 
121     jfieldID noImageFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_IMAGE", "Landroid/opengl/EGLImage;");
122     _env->SetStaticObjectField(eglClass, noImageFieldID, eglNoImageObject);
123 
124     jfieldID noSyncFieldID = _env->GetStaticFieldID(eglClass, "EGL_NO_SYNC", "Landroid/opengl/EGLSync;");
125     _env->SetStaticObjectField(eglClass, noSyncFieldID, eglNoSyncObject);
126 }
127 
128 static void *
getPointer(JNIEnv * _env,jobject buffer,jarray * array,jint * remaining,jint * offset)129 getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
130 {
131     jint position;
132     jint limit;
133     jint elementSizeShift;
134     jlong pointer;
135 
136     pointer = jniGetNioBufferFields(_env, buffer, &position, &limit, &elementSizeShift);
137     *remaining = (limit - position) << elementSizeShift;
138     if (pointer != 0L) {
139         *array = nullptr;
140         pointer += position << elementSizeShift;
141         return reinterpret_cast<void*>(pointer);
142     }
143 
144     *array = jniGetNioBufferBaseArray(_env, buffer);
145     *offset = jniGetNioBufferBaseArrayOffset(_env, buffer);
146     return nullptr;
147 }
148 
149 static void
releasePointer(JNIEnv * _env,jarray array,void * data,jboolean commit)150 releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
151 {
152     _env->ReleasePrimitiveArrayCritical(array, data,
153                        commit ? 0 : JNI_ABORT);
154 }
155 
156 static void *
fromEGLHandle(JNIEnv * _env,jmethodID mid,jobject obj)157 fromEGLHandle(JNIEnv *_env, jmethodID mid, jobject obj) {
158     if (obj == NULL) {
159         jniThrowException(_env, "java/lang/IllegalArgumentException",
160                           "Object is set to null.");
161         return nullptr;
162     }
163 
164     jlong handle = _env->CallLongMethod(obj, mid);
165     return reinterpret_cast<void*>(handle);
166 }
167 
168 static jobject
toEGLHandle(JNIEnv * _env,jclass cls,jmethodID con,void * handle)169 toEGLHandle(JNIEnv *_env, jclass cls, jmethodID con, void *handle) {
170     if (cls == eglimageClass && (EGLImage)handle == EGL_NO_IMAGE) {
171         return eglNoImageObject;
172     }
173 
174     return _env->NewObject(cls, con, reinterpret_cast<jlong>(handle));
175 }
176 
177 struct WrappedEGLAttribs {
178 private:
179     std::vector<EGLAttrib> backing; // only for 32-bit
180 public:
181     EGLAttrib *attribs;
WrappedEGLAttribsWrappedEGLAttribs182     WrappedEGLAttribs(): attribs(nullptr) { };
initWrappedEGLAttribs183     void init(jlong *array, jint size) {
184         if (sizeof(EGLAttrib) != sizeof(jlong)) {
185             for (jint i = 0; i < size; ++i) {
186                 backing.push_back(array[i]);
187             }
188             attribs = backing.data();
189         } else {
190             attribs = (EGLAttrib*)array;
191         }
192     }
193 };
194 
195 // --------------------------------------------------------------------------
196