mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-28 01:52:26 -06:00
331 lines
13 KiB
Java
331 lines
13 KiB
Java
package org.webrtc;
|
|
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Rect;
|
|
import android.graphics.SurfaceTexture;
|
|
import android.view.Surface;
|
|
import android.view.SurfaceHolder;
|
|
import io.sentry.protocol.ViewHierarchyNode;
|
|
import javax.microedition.khronos.egl.EGL10;
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
|
import javax.microedition.khronos.egl.EGLContext;
|
|
import javax.microedition.khronos.egl.EGLDisplay;
|
|
import javax.microedition.khronos.egl.EGLSurface;
|
|
import org.webrtc.EglBase;
|
|
import org.webrtc.EglBase10;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes3.dex */
|
|
public class EglBase10Impl implements EglBase10 {
|
|
private static final int EGL_CONTEXT_CLIENT_VERSION = 12440;
|
|
private static final String TAG = "EglBase10Impl";
|
|
private final EGL10 egl;
|
|
private EGLConfig eglConfig;
|
|
private EGLContext eglContext;
|
|
private EGLDisplay eglDisplay;
|
|
private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
|
|
|
|
private static native long nativeGetCurrentNativeEGLContext();
|
|
|
|
static /* synthetic */ long access$000() {
|
|
return nativeGetCurrentNativeEGLContext();
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private static class Context implements EglBase10.Context {
|
|
private final EGL10 egl;
|
|
private final EGLContext eglContext;
|
|
private final EGLConfig eglContextConfig;
|
|
|
|
@Override // org.webrtc.EglBase10.Context
|
|
public EGLContext getRawContext() {
|
|
return this.eglContext;
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase.Context
|
|
public long getNativeEglContext() {
|
|
EGLContext eglGetCurrentContext = this.egl.eglGetCurrentContext();
|
|
EGLDisplay eglGetCurrentDisplay = this.egl.eglGetCurrentDisplay();
|
|
EGLSurface eglGetCurrentSurface = this.egl.eglGetCurrentSurface(12377);
|
|
EGLSurface eglGetCurrentSurface2 = this.egl.eglGetCurrentSurface(12378);
|
|
if (eglGetCurrentDisplay == EGL10.EGL_NO_DISPLAY) {
|
|
eglGetCurrentDisplay = this.egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
|
}
|
|
EGLSurface eGLSurface = null;
|
|
try {
|
|
if (eglGetCurrentContext != this.eglContext) {
|
|
eGLSurface = this.egl.eglCreatePbufferSurface(eglGetCurrentDisplay, this.eglContextConfig, new int[]{12375, 1, 12374, 1, 12344});
|
|
if (!this.egl.eglMakeCurrent(eglGetCurrentDisplay, eGLSurface, eGLSurface, this.eglContext)) {
|
|
throw new RuntimeException("Failed to make temporary EGL surface active: " + this.egl.eglGetError());
|
|
}
|
|
}
|
|
return EglBase10Impl.access$000();
|
|
} finally {
|
|
if (0 != 0) {
|
|
this.egl.eglMakeCurrent(eglGetCurrentDisplay, eglGetCurrentSurface, eglGetCurrentSurface2, eglGetCurrentContext);
|
|
this.egl.eglDestroySurface(eglGetCurrentDisplay, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Context(EGL10 egl10, EGLContext eGLContext, EGLConfig eGLConfig) {
|
|
this.egl = egl10;
|
|
this.eglContext = eGLContext;
|
|
this.eglContextConfig = eGLConfig;
|
|
}
|
|
}
|
|
|
|
public EglBase10Impl(EGLContext eGLContext, int[] iArr) {
|
|
EGL10 egl10 = (EGL10) EGLContext.getEGL();
|
|
this.egl = egl10;
|
|
EGLDisplay eglDisplay = getEglDisplay();
|
|
this.eglDisplay = eglDisplay;
|
|
this.eglConfig = getEglConfig(egl10, eglDisplay, iArr);
|
|
int openGlesVersionFromConfig = EglBase.getOpenGlesVersionFromConfig(iArr);
|
|
Logging.d(TAG, "Using OpenGL ES version " + openGlesVersionFromConfig);
|
|
this.eglContext = createEglContext(eGLContext, this.eglDisplay, this.eglConfig, openGlesVersionFromConfig);
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void createSurface(Surface surface) {
|
|
createSurfaceInternal(new SurfaceHolder(surface) { // from class: org.webrtc.EglBase10Impl.1FakeSurfaceHolder
|
|
private final Surface surface;
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void addCallback(SurfaceHolder.Callback callback) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public Surface getSurface() {
|
|
return this.surface;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public Rect getSurfaceFrame() {
|
|
return null;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public boolean isCreating() {
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public Canvas lockCanvas() {
|
|
return null;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public Canvas lockCanvas(Rect rect) {
|
|
return null;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void removeCallback(SurfaceHolder.Callback callback) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void setFixedSize(int i, int i2) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void setFormat(int i) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void setKeepScreenOn(boolean z) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void setSizeFromLayout() {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
@Deprecated
|
|
public void setType(int i) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public void unlockCanvasAndPost(Canvas canvas) {
|
|
}
|
|
|
|
{
|
|
this.surface = surface;
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void createSurface(SurfaceTexture surfaceTexture) {
|
|
createSurfaceInternal(surfaceTexture);
|
|
}
|
|
|
|
private void createSurfaceInternal(Object obj) {
|
|
if (!(obj instanceof SurfaceHolder) && !(obj instanceof SurfaceTexture)) {
|
|
throw new IllegalStateException("Input must be either a SurfaceHolder or SurfaceTexture");
|
|
}
|
|
checkIsNotReleased();
|
|
if (this.eglSurface != EGL10.EGL_NO_SURFACE) {
|
|
throw new RuntimeException("Already has an EGLSurface");
|
|
}
|
|
EGLSurface eglCreateWindowSurface = this.egl.eglCreateWindowSurface(this.eglDisplay, this.eglConfig, obj, new int[]{12344});
|
|
this.eglSurface = eglCreateWindowSurface;
|
|
if (eglCreateWindowSurface == EGL10.EGL_NO_SURFACE) {
|
|
throw new RuntimeException("Failed to create window surface: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void createDummyPbufferSurface() {
|
|
createPbufferSurface(1, 1);
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void createPbufferSurface(int i, int i2) {
|
|
checkIsNotReleased();
|
|
if (this.eglSurface != EGL10.EGL_NO_SURFACE) {
|
|
throw new RuntimeException("Already has an EGLSurface");
|
|
}
|
|
EGLSurface eglCreatePbufferSurface = this.egl.eglCreatePbufferSurface(this.eglDisplay, this.eglConfig, new int[]{12375, i, 12374, i2, 12344});
|
|
this.eglSurface = eglCreatePbufferSurface;
|
|
if (eglCreatePbufferSurface == EGL10.EGL_NO_SURFACE) {
|
|
throw new RuntimeException("Failed to create pixel buffer surface with size " + i + ViewHierarchyNode.JsonKeys.X + i2 + ": 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public EglBase.Context getEglBaseContext() {
|
|
return new Context(this.egl, this.eglContext, this.eglConfig);
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public boolean hasSurface() {
|
|
return this.eglSurface != EGL10.EGL_NO_SURFACE;
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public int surfaceWidth() {
|
|
int[] iArr = new int[1];
|
|
this.egl.eglQuerySurface(this.eglDisplay, this.eglSurface, 12375, iArr);
|
|
return iArr[0];
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public int surfaceHeight() {
|
|
int[] iArr = new int[1];
|
|
this.egl.eglQuerySurface(this.eglDisplay, this.eglSurface, 12374, iArr);
|
|
return iArr[0];
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void releaseSurface() {
|
|
if (this.eglSurface != EGL10.EGL_NO_SURFACE) {
|
|
this.egl.eglDestroySurface(this.eglDisplay, this.eglSurface);
|
|
this.eglSurface = EGL10.EGL_NO_SURFACE;
|
|
}
|
|
}
|
|
|
|
private void checkIsNotReleased() {
|
|
if (this.eglDisplay == EGL10.EGL_NO_DISPLAY || this.eglContext == EGL10.EGL_NO_CONTEXT || this.eglConfig == null) {
|
|
throw new RuntimeException("This object has been released");
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void release() {
|
|
checkIsNotReleased();
|
|
releaseSurface();
|
|
detachCurrent();
|
|
this.egl.eglDestroyContext(this.eglDisplay, this.eglContext);
|
|
this.egl.eglTerminate(this.eglDisplay);
|
|
this.eglContext = EGL10.EGL_NO_CONTEXT;
|
|
this.eglDisplay = EGL10.EGL_NO_DISPLAY;
|
|
this.eglConfig = null;
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void makeCurrent() {
|
|
checkIsNotReleased();
|
|
if (this.eglSurface == EGL10.EGL_NO_SURFACE) {
|
|
throw new RuntimeException("No EGLSurface - can't make current");
|
|
}
|
|
synchronized (EglBase.lock) {
|
|
EGL10 egl10 = this.egl;
|
|
EGLDisplay eGLDisplay = this.eglDisplay;
|
|
EGLSurface eGLSurface = this.eglSurface;
|
|
if (!egl10.eglMakeCurrent(eGLDisplay, eGLSurface, eGLSurface, this.eglContext)) {
|
|
throw new RuntimeException("eglMakeCurrent failed: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void detachCurrent() {
|
|
synchronized (EglBase.lock) {
|
|
if (!this.egl.eglMakeCurrent(this.eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) {
|
|
throw new RuntimeException("eglDetachCurrent failed: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void swapBuffers() {
|
|
checkIsNotReleased();
|
|
if (this.eglSurface == EGL10.EGL_NO_SURFACE) {
|
|
throw new RuntimeException("No EGLSurface - can't swap buffers");
|
|
}
|
|
synchronized (EglBase.lock) {
|
|
this.egl.eglSwapBuffers(this.eglDisplay, this.eglSurface);
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void swapBuffers(long j) {
|
|
swapBuffers();
|
|
}
|
|
|
|
private EGLDisplay getEglDisplay() {
|
|
EGLDisplay eglGetDisplay = this.egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
|
if (eglGetDisplay == EGL10.EGL_NO_DISPLAY) {
|
|
throw new RuntimeException("Unable to get EGL10 display: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
if (this.egl.eglInitialize(eglGetDisplay, new int[2])) {
|
|
return eglGetDisplay;
|
|
}
|
|
throw new RuntimeException("Unable to initialize EGL10: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
|
|
private static EGLConfig getEglConfig(EGL10 egl10, EGLDisplay eGLDisplay, int[] iArr) {
|
|
EGLConfig[] eGLConfigArr = new EGLConfig[1];
|
|
int[] iArr2 = new int[1];
|
|
if (!egl10.eglChooseConfig(eGLDisplay, iArr, eGLConfigArr, 1, iArr2)) {
|
|
throw new RuntimeException("eglChooseConfig failed: 0x" + Integer.toHexString(egl10.eglGetError()));
|
|
}
|
|
if (iArr2[0] <= 0) {
|
|
throw new RuntimeException("Unable to find any matching EGL config");
|
|
}
|
|
EGLConfig eGLConfig = eGLConfigArr[0];
|
|
if (eGLConfig != null) {
|
|
return eGLConfig;
|
|
}
|
|
throw new RuntimeException("eglChooseConfig returned null");
|
|
}
|
|
|
|
private EGLContext createEglContext(EGLContext eGLContext, EGLDisplay eGLDisplay, EGLConfig eGLConfig, int i) {
|
|
EGLContext eglCreateContext;
|
|
if (eGLContext != null && eGLContext == EGL10.EGL_NO_CONTEXT) {
|
|
throw new RuntimeException("Invalid sharedContext");
|
|
}
|
|
int[] iArr = {EGL_CONTEXT_CLIENT_VERSION, i, 12344};
|
|
if (eGLContext == null) {
|
|
eGLContext = EGL10.EGL_NO_CONTEXT;
|
|
}
|
|
synchronized (EglBase.lock) {
|
|
eglCreateContext = this.egl.eglCreateContext(eGLDisplay, eGLConfig, eGLContext, iArr);
|
|
}
|
|
if (eglCreateContext != EGL10.EGL_NO_CONTEXT) {
|
|
return eglCreateContext;
|
|
}
|
|
throw new RuntimeException("Failed to create EGL context: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
}
|