| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.android.gles_jni; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
import android.graphics.SurfaceTexture; |
| 21 |
import android.view.Surface; |
| 22 |
import android.view.SurfaceHolder; |
| 23 |
import android.view.SurfaceView; |
| 24 |
|
| 25 |
import javax.microedition.khronos.egl.EGL10; |
| 26 |
import javax.microedition.khronos.egl.EGLConfig; |
| 27 |
import javax.microedition.khronos.egl.EGLContext; |
| 28 |
import javax.microedition.khronos.egl.EGLDisplay; |
| 29 |
import javax.microedition.khronos.egl.EGLSurface; |
| 30 |
|
| 31 |
public class EGLImpl implements EGL10 { |
| 32 |
private EGLContextImpl mContext = new EGLContextImpl(-1); |
| 33 |
private EGLDisplayImpl mDisplay = new EGLDisplayImpl(-1); |
| 34 |
private EGLSurfaceImpl mSurface = new EGLSurfaceImpl(-1); |
| 35 |
|
| 36 |
public native boolean eglInitialize(EGLDisplay display, int[] major_minor); |
| 37 |
public native boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value); |
| 38 |
public native boolean eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value); |
| 39 |
|
| 40 |
public native boolean eglReleaseThread(); |
| 41 |
public native boolean eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config); |
| 42 |
public native boolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value); |
| 43 |
public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config); |
| 44 |
public native int eglGetError(); |
| 45 |
public native boolean eglDestroyContext(EGLDisplay display, EGLContext context); |
| 46 |
public native boolean eglDestroySurface(EGLDisplay display, EGLSurface surface); |
| 47 |
public native boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context); |
| 48 |
public native String eglQueryString(EGLDisplay display, int name); |
| 49 |
public native boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface); |
| 50 |
public native boolean eglTerminate(EGLDisplay display); |
| 51 |
public native boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, Object native_pixmap); |
| 52 |
public native boolean eglWaitGL(); |
| 53 |
public native boolean eglWaitNative(int engine, Object bindTarget); |
| 54 |
|
| 55 |
|
| 56 |
public static native int getInitCount(EGLDisplay display); |
| 57 |
|
| 58 |
@UnsupportedAppUsage |
| 59 |
public EGLImpl() { |
| 60 |
} |
| 61 |
|
| 62 |
public EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list) { |
| 63 |
long eglContextId = _eglCreateContext(display, config, share_context, attrib_list); |
| 64 |
if (eglContextId == 0) { |
| 65 |
return EGL10.EGL_NO_CONTEXT; |
| 66 |
} |
| 67 |
return new EGLContextImpl( eglContextId ); |
| 68 |
} |
| 69 |
|
| 70 |
public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { |
| 71 |
long eglSurfaceId = _eglCreatePbufferSurface(display, config, attrib_list); |
| 72 |
if (eglSurfaceId == 0) { |
| 73 |
return EGL10.EGL_NO_SURFACE; |
| 74 |
} |
| 75 |
return new EGLSurfaceImpl( eglSurfaceId ); |
| 76 |
} |
| 77 |
|
| 78 |
public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { |
| 79 |
EGLSurfaceImpl sur = new EGLSurfaceImpl(); |
| 80 |
_eglCreatePixmapSurface(sur, display, config, native_pixmap, attrib_list); |
| 81 |
if (sur.mEGLSurface == 0) { |
| 82 |
return EGL10.EGL_NO_SURFACE; |
| 83 |
} |
| 84 |
return sur; |
| 85 |
} |
| 86 |
|
| 87 |
public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { |
| 88 |
Surface sur = null; |
| 89 |
if (native_window instanceof SurfaceView) { |
| 90 |
SurfaceView surfaceView = (SurfaceView)native_window; |
| 91 |
sur = surfaceView.getHolder().getSurface(); |
| 92 |
} else if (native_window instanceof SurfaceHolder) { |
| 93 |
SurfaceHolder holder = (SurfaceHolder)native_window; |
| 94 |
sur = holder.getSurface(); |
| 95 |
} else if (native_window instanceof Surface) { |
| 96 |
sur = (Surface) native_window; |
| 97 |
} |
| 98 |
|
| 99 |
long eglSurfaceId; |
| 100 |
if (sur != null) { |
| 101 |
eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list); |
| 102 |
} else if (native_window instanceof SurfaceTexture) { |
| 103 |
eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, |
| 104 |
native_window, attrib_list); |
| 105 |
} else { |
| 106 |
throw new java.lang.UnsupportedOperationException( |
| 107 |
"eglCreateWindowSurface() can only be called with an instance of " + |
| 108 |
"Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment."); |
| 109 |
} |
| 110 |
|
| 111 |
if (eglSurfaceId == 0) { |
| 112 |
return EGL10.EGL_NO_SURFACE; |
| 113 |
} |
| 114 |
return new EGLSurfaceImpl( eglSurfaceId ); |
| 115 |
} |
| 116 |
|
| 117 |
public synchronized EGLDisplay eglGetDisplay(Object native_display) { |
| 118 |
long value = _eglGetDisplay(native_display); |
| 119 |
if (value == 0) { |
| 120 |
return EGL10.EGL_NO_DISPLAY; |
| 121 |
} |
| 122 |
if (mDisplay.mEGLDisplay != value) |
| 123 |
mDisplay = new EGLDisplayImpl(value); |
| 124 |
return mDisplay; |
| 125 |
} |
| 126 |
|
| 127 |
public synchronized EGLContext eglGetCurrentContext() { |
| 128 |
long value = _eglGetCurrentContext(); |
| 129 |
if (value == 0) { |
| 130 |
return EGL10.EGL_NO_CONTEXT; |
| 131 |
} |
| 132 |
if (mContext.mEGLContext != value) |
| 133 |
mContext = new EGLContextImpl(value); |
| 134 |
return mContext; |
| 135 |
} |
| 136 |
|
| 137 |
public synchronized EGLDisplay eglGetCurrentDisplay() { |
| 138 |
long value = _eglGetCurrentDisplay(); |
| 139 |
if (value == 0) { |
| 140 |
return EGL10.EGL_NO_DISPLAY; |
| 141 |
} |
| 142 |
if (mDisplay.mEGLDisplay != value) |
| 143 |
mDisplay = new EGLDisplayImpl(value); |
| 144 |
return mDisplay; |
| 145 |
} |
| 146 |
|
| 147 |
public synchronized EGLSurface eglGetCurrentSurface(int readdraw) { |
| 148 |
long value = _eglGetCurrentSurface(readdraw); |
| 149 |
if (value == 0) { |
| 150 |
return EGL10.EGL_NO_SURFACE; |
| 151 |
} |
| 152 |
if (mSurface.mEGLSurface != value) |
| 153 |
mSurface = new EGLSurfaceImpl(value); |
| 154 |
return mSurface; |
| 155 |
} |
| 156 |
|
| 157 |
private native long _eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list); |
| 158 |
private native long _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list); |
| 159 |
private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list); |
| 160 |
private native long _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); |
| 161 |
private native long _eglCreateWindowSurfaceTexture(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); |
| 162 |
private native long _eglGetDisplay(Object native_display); |
| 163 |
private native long _eglGetCurrentContext(); |
| 164 |
private native long _eglGetCurrentDisplay(); |
| 165 |
private native long _eglGetCurrentSurface(int readdraw); |
| 166 |
|
| 167 |
native private static void _nativeClassInit(); |
| 168 |
static { _nativeClassInit(); } |
| 169 |
} |