aboutsummaryrefslogtreecommitdiff
path: root/sdk/android/src/java/org/webrtc/EglBase10Impl.java
diff options
context:
space:
mode:
Diffstat (limited to 'sdk/android/src/java/org/webrtc/EglBase10Impl.java')
-rw-r--r--sdk/android/src/java/org/webrtc/EglBase10Impl.java45
1 files changed, 29 insertions, 16 deletions
diff --git a/sdk/android/src/java/org/webrtc/EglBase10Impl.java b/sdk/android/src/java/org/webrtc/EglBase10Impl.java
index 5f3cd82e13..caa10e7e51 100644
--- a/sdk/android/src/java/org/webrtc/EglBase10Impl.java
+++ b/sdk/android/src/java/org/webrtc/EglBase10Impl.java
@@ -94,6 +94,7 @@ class EglBase10Impl implements EglBase10 {
private final EGLDisplay eglDisplay;
private final EGLConfig eglConfig;
private final RefCountDelegate refCountDelegate;
+ private EGLSurface currentSurface = EGL10.EGL_NO_SURFACE;
public EglConnection(EGLContext sharedContext, int[] configAttributes) {
egl = (EGL10) EGLContext.getEGL();
@@ -111,6 +112,7 @@ class EglBase10Impl implements EglBase10 {
}
egl.eglDestroyContext(eglDisplay, eglContext);
egl.eglTerminate(eglDisplay);
+ currentSurface = EGL10.EGL_NO_SURFACE;
});
}
@@ -152,6 +154,31 @@ class EglBase10Impl implements EglBase10 {
public EGLConfig getConfig() {
return eglConfig;
}
+
+ public void makeCurrent(EGLSurface eglSurface) {
+ if (egl.eglGetCurrentContext() == eglContext && currentSurface == eglSurface) {
+ return;
+ }
+
+ synchronized (EglBase.lock) {
+ if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
+ throw new GLException(egl.eglGetError(),
+ "eglMakeCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
+ }
+ }
+ currentSurface = eglSurface;
+ }
+
+ public void detachCurrent() {
+ synchronized (EglBase.lock) {
+ if (!egl.eglMakeCurrent(
+ eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) {
+ throw new GLException(egl.eglGetError(),
+ "eglDetachCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
+ }
+ }
+ currentSurface = EGL10.EGL_NO_SURFACE;
+ }
}
// Create a new context with the specified config type, sharing data with sharedContext.
@@ -339,27 +366,13 @@ class EglBase10Impl implements EglBase10 {
if (eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException("No EGLSurface - can't make current");
}
- synchronized (EglBase.lock) {
- EGL10 egl = eglConnection.getEgl();
- if (!egl.eglMakeCurrent(
- eglConnection.getDisplay(), eglSurface, eglSurface, eglConnection.getContext())) {
- throw new GLException(egl.eglGetError(),
- "eglMakeCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
- }
- }
+ eglConnection.makeCurrent(eglSurface);
}
// Detach the current EGL context, so that it can be made current on another thread.
@Override
public void detachCurrent() {
- synchronized (EglBase.lock) {
- EGL10 egl = eglConnection.getEgl();
- if (!egl.eglMakeCurrent(eglConnection.getDisplay(), EGL10.EGL_NO_SURFACE,
- EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) {
- throw new GLException(egl.eglGetError(),
- "eglDetachCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
- }
- }
+ eglConnection.detachCurrent();
}
@Override