From aa568a64edab7adf8369c4905dcb7afbdba84cca Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Mon, 18 Sep 2017 11:26:30 +0200 Subject: [PATCH] Android: Add interface for getting native EGL context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL also implements support for getting the native context on EGL 1.4. It's a bit tricker to get the native handle for EGL 1.0 so it will be done in a separate CL. Bug: webrtc:8257 Change-Id: I269e75c357f19507098180077fa9d1b1ac4dce23 Reviewed-on: https://webrtc-review.googlesource.com/1880 Reviewed-by: Sami Kalliomäki Commit-Queue: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#19890} --- sdk/android/api/org/webrtc/EglBase.java | 2 +- sdk/android/src/java/org/webrtc/EglBase10.java | 11 ++++++++++- sdk/android/src/java/org/webrtc/EglBase14.java | 10 +++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sdk/android/api/org/webrtc/EglBase.java b/sdk/android/api/org/webrtc/EglBase.java index 1f905885cf..23acdefc8d 100644 --- a/sdk/android/api/org/webrtc/EglBase.java +++ b/sdk/android/api/org/webrtc/EglBase.java @@ -21,7 +21,7 @@ import javax.microedition.khronos.egl.EGL10; */ public abstract class EglBase { // EGL wrapper for an actual EGLContext. - public static class Context {} + public interface Context { long getNativeEglContext(); } // According to the documentation, EGL can be used from multiple threads at the same time if each // thread has its own EGLContext, but in practice it deadlocks on some devices when doing this. diff --git a/sdk/android/src/java/org/webrtc/EglBase10.java b/sdk/android/src/java/org/webrtc/EglBase10.java index 8f1c5c6815..d1d543973b 100644 --- a/sdk/android/src/java/org/webrtc/EglBase10.java +++ b/sdk/android/src/java/org/webrtc/EglBase10.java @@ -37,9 +37,18 @@ class EglBase10 extends EglBase { private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE; // EGL wrapper for an actual EGLContext. - public static class Context extends EglBase.Context { + public static class Context implements EglBase.Context { private final EGLContext eglContext; + @Override + public long getNativeEglContext() { + // TODO(magjed): Implement. There is no easy way of getting the native context for EGL 1.0. We + // need to make sure to have an EglSurface, then make the context current using that surface, + // and then call into JNI and call the native version of eglGetCurrentContext. Then we need to + // restore the state and return the native context. + throw new RuntimeException("getNativeEglContext is not implemented for EGL 1.0"); + } + public Context(EGLContext eglContext) { this.eglContext = eglContext; } diff --git a/sdk/android/src/java/org/webrtc/EglBase14.java b/sdk/android/src/java/org/webrtc/EglBase14.java index 92f0958219..8c33056648 100644 --- a/sdk/android/src/java/org/webrtc/EglBase14.java +++ b/sdk/android/src/java/org/webrtc/EglBase14.java @@ -43,9 +43,17 @@ class EglBase14 extends EglBase { return (CURRENT_SDK_VERSION >= EGLExt_SDK_VERSION); } - public static class Context extends EglBase.Context { + public static class Context implements EglBase.Context { private final android.opengl.EGLContext egl14Context; + @Override + @SuppressWarnings("deprecation") + public long getNativeEglContext() { + return CURRENT_SDK_VERSION >= android.os.Build.VERSION_CODES.LOLLIPOP + ? egl14Context.getNativeHandle() + : egl14Context.getHandle(); + } + public Context(android.opengl.EGLContext eglContext) { this.egl14Context = eglContext; }