323 lines
12 KiB
Java
323 lines
12 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 androidx.annotation.Nullable;
|
|
import c.d.b.a.a;
|
|
import h0.c.n0;
|
|
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;
|
|
public class EglBase10Impl implements EglBase10 {
|
|
private static final int EGL_CONTEXT_CLIENT_VERSION = 12440;
|
|
private static final String TAG = "EglBase10Impl";
|
|
private final EGL10 egl = ((EGL10) EGLContext.getEGL());
|
|
@Nullable
|
|
private EGLConfig eglConfig;
|
|
private EGLContext eglContext;
|
|
private EGLDisplay eglDisplay;
|
|
private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
|
|
|
|
/* renamed from: org.webrtc.EglBase10Impl$1FakeSurfaceHolder reason: invalid class name */
|
|
public class AnonymousClass1FakeSurfaceHolder implements SurfaceHolder {
|
|
private final Surface surface;
|
|
|
|
public AnonymousClass1FakeSurfaceHolder(Surface surface) {
|
|
this.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
|
|
@Nullable
|
|
public Rect getSurfaceFrame() {
|
|
return null;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
public boolean isCreating() {
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
@Nullable
|
|
public Canvas lockCanvas() {
|
|
return null;
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder
|
|
@Nullable
|
|
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 z2) {
|
|
}
|
|
|
|
@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) {
|
|
}
|
|
}
|
|
|
|
public static class Context implements EglBase10.Context {
|
|
private final EGLContext eglContext;
|
|
|
|
public Context(EGLContext eGLContext) {
|
|
this.eglContext = eGLContext;
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase.Context
|
|
public long getNativeEglContext() {
|
|
return 0;
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase10.Context
|
|
public EGLContext getRawContext() {
|
|
return this.eglContext;
|
|
}
|
|
}
|
|
|
|
public EglBase10Impl(EGLContext eGLContext, int[] iArr) {
|
|
EGLDisplay eglDisplay = getEglDisplay();
|
|
this.eglDisplay = eglDisplay;
|
|
this.eglConfig = getEglConfig(eglDisplay, iArr);
|
|
int c2 = n0.c(iArr);
|
|
Logging.d("EglBase10Impl", "Using OpenGL ES version " + c2);
|
|
this.eglContext = createEglContext(eGLContext, this.eglDisplay, this.eglConfig, c2);
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|
|
|
|
private EGLContext createEglContext(@Nullable EGLContext eGLContext, EGLDisplay eGLDisplay, EGLConfig eGLConfig, int i) {
|
|
EGLContext eglCreateContext;
|
|
if (eGLContext == null || eGLContext != EGL10.EGL_NO_CONTEXT) {
|
|
int[] iArr = {12440, 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;
|
|
}
|
|
StringBuilder K = a.K("Failed to create EGL context: 0x");
|
|
K.append(Integer.toHexString(this.egl.eglGetError()));
|
|
throw new RuntimeException(K.toString());
|
|
}
|
|
throw new RuntimeException("Invalid sharedContext");
|
|
}
|
|
|
|
private void createSurfaceInternal(Object obj) {
|
|
if ((obj instanceof SurfaceHolder) || (obj instanceof SurfaceTexture)) {
|
|
checkIsNotReleased();
|
|
if (this.eglSurface == EGL10.EGL_NO_SURFACE) {
|
|
EGLSurface eglCreateWindowSurface = this.egl.eglCreateWindowSurface(this.eglDisplay, this.eglConfig, obj, new int[]{12344});
|
|
this.eglSurface = eglCreateWindowSurface;
|
|
if (eglCreateWindowSurface == EGL10.EGL_NO_SURFACE) {
|
|
StringBuilder K = a.K("Failed to create window surface: 0x");
|
|
K.append(Integer.toHexString(this.egl.eglGetError()));
|
|
throw new RuntimeException(K.toString());
|
|
}
|
|
return;
|
|
}
|
|
throw new RuntimeException("Already has an EGLSurface");
|
|
}
|
|
throw new IllegalStateException("Input must be either a SurfaceHolder or SurfaceTexture");
|
|
}
|
|
|
|
private EGLConfig getEglConfig(EGLDisplay eGLDisplay, int[] iArr) {
|
|
EGLConfig[] eGLConfigArr = new EGLConfig[1];
|
|
int[] iArr2 = new int[1];
|
|
if (!this.egl.eglChooseConfig(eGLDisplay, iArr, eGLConfigArr, 1, iArr2)) {
|
|
StringBuilder K = a.K("eglChooseConfig failed: 0x");
|
|
K.append(Integer.toHexString(this.egl.eglGetError()));
|
|
throw new RuntimeException(K.toString());
|
|
} else if (iArr2[0] > 0) {
|
|
EGLConfig eGLConfig = eGLConfigArr[0];
|
|
if (eGLConfig != null) {
|
|
return eGLConfig;
|
|
}
|
|
throw new RuntimeException("eglChooseConfig returned null");
|
|
} else {
|
|
throw new RuntimeException("Unable to find any matching EGL config");
|
|
}
|
|
}
|
|
|
|
private EGLDisplay getEglDisplay() {
|
|
EGLDisplay eglGetDisplay = this.egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
|
if (eglGetDisplay != EGL10.EGL_NO_DISPLAY) {
|
|
if (this.egl.eglInitialize(eglGetDisplay, new int[2])) {
|
|
return eglGetDisplay;
|
|
}
|
|
StringBuilder K = a.K("Unable to initialize EGL10: 0x");
|
|
K.append(Integer.toHexString(this.egl.eglGetError()));
|
|
throw new RuntimeException(K.toString());
|
|
}
|
|
StringBuilder K2 = a.K("Unable to get EGL10 display: 0x");
|
|
K2.append(Integer.toHexString(this.egl.eglGetError()));
|
|
throw new RuntimeException(K2.toString());
|
|
}
|
|
|
|
@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) {
|
|
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) {
|
|
StringBuilder M = a.M("Failed to create pixel buffer surface with size ", i, "x", i2, ": 0x");
|
|
M.append(Integer.toHexString(this.egl.eglGetError()));
|
|
throw new RuntimeException(M.toString());
|
|
}
|
|
return;
|
|
}
|
|
throw new RuntimeException("Already has an EGLSurface");
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void createSurface(SurfaceTexture surfaceTexture) {
|
|
createSurfaceInternal(surfaceTexture);
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void createSurface(Surface surface) {
|
|
createSurfaceInternal(new AnonymousClass1FakeSurfaceHolder(surface));
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void detachCurrent() {
|
|
synchronized (EglBase.lock) {
|
|
EGL10 egl10 = this.egl;
|
|
EGLDisplay eGLDisplay = this.eglDisplay;
|
|
EGLSurface eGLSurface = EGL10.EGL_NO_SURFACE;
|
|
if (!egl10.eglMakeCurrent(eGLDisplay, eGLSurface, eGLSurface, EGL10.EGL_NO_CONTEXT)) {
|
|
throw new RuntimeException("eglDetachCurrent failed: 0x" + Integer.toHexString(this.egl.eglGetError()));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public EglBase.Context getEglBaseContext() {
|
|
return new Context(this.eglContext);
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public boolean hasSurface() {
|
|
return this.eglSurface != EGL10.EGL_NO_SURFACE;
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void makeCurrent() {
|
|
checkIsNotReleased();
|
|
if (this.eglSurface != EGL10.EGL_NO_SURFACE) {
|
|
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()));
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
throw new RuntimeException("No EGLSurface - can't make current");
|
|
}
|
|
|
|
@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 releaseSurface() {
|
|
EGLSurface eGLSurface = this.eglSurface;
|
|
if (eGLSurface != EGL10.EGL_NO_SURFACE) {
|
|
this.egl.eglDestroySurface(this.eglDisplay, eGLSurface);
|
|
this.eglSurface = EGL10.EGL_NO_SURFACE;
|
|
}
|
|
}
|
|
|
|
@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 int surfaceWidth() {
|
|
int[] iArr = new int[1];
|
|
this.egl.eglQuerySurface(this.eglDisplay, this.eglSurface, 12375, iArr);
|
|
return iArr[0];
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void swapBuffers() {
|
|
checkIsNotReleased();
|
|
if (this.eglSurface != EGL10.EGL_NO_SURFACE) {
|
|
synchronized (EglBase.lock) {
|
|
this.egl.eglSwapBuffers(this.eglDisplay, this.eglSurface);
|
|
}
|
|
return;
|
|
}
|
|
throw new RuntimeException("No EGLSurface - can't swap buffers");
|
|
}
|
|
|
|
@Override // org.webrtc.EglBase
|
|
public void swapBuffers(long j) {
|
|
swapBuffers();
|
|
}
|
|
}
|