Android: Expose underlying EGL context in API
This CL adds a way to extract the underlying android.opengl.EGLContext
and javax.microedition.khronos.egl.EGLContext for EglBase14 and
EglBase10 respectively. The reason is that clients can't be expected to
use only WebRTC's OpenGL code and might need to integrate with their
own GL code.
Bug: None
Change-Id: Ie00a564de45a090683542a52005da7e43c586ced
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127888
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27205}
diff --git a/sdk/android/api/org/webrtc/EglBase.java b/sdk/android/api/org/webrtc/EglBase.java
index 43baee7..3d0238d 100644
--- a/sdk/android/api/org/webrtc/EglBase.java
+++ b/sdk/android/api/org/webrtc/EglBase.java
@@ -96,10 +96,15 @@
* 1.4 context if possible, and an EGL 1.0 context otherwise.
*/
public static EglBase create(@Nullable Context sharedContext, int[] configAttributes) {
- return (EglBase14.isEGL14Supported()
- && (sharedContext == null || sharedContext instanceof EglBase14.Context))
- ? new EglBase14((EglBase14.Context) sharedContext, configAttributes)
- : new EglBase10((EglBase10.Context) sharedContext, configAttributes);
+ if (sharedContext == null) {
+ return EglBase14Impl.isEGL14Supported() ? createEgl14(configAttributes)
+ : createEgl10(configAttributes);
+ } else if (sharedContext instanceof EglBase14.Context) {
+ return createEgl14((EglBase14.Context) sharedContext, configAttributes);
+ } else if (sharedContext instanceof EglBase10.Context) {
+ return createEgl10((EglBase10.Context) sharedContext, configAttributes);
+ }
+ throw new IllegalArgumentException("Unrecognized Context");
}
/**
@@ -118,36 +123,50 @@
return create(sharedContext, CONFIG_PLAIN);
}
+ /** Explicitly create a root EGl 1.0 context with the specified config attributes. */
+ public static EglBase10 createEgl10(int[] configAttributes) {
+ return new EglBase10Impl(/* sharedContext= */ null, configAttributes);
+ }
+
/**
- * Explicitly create a root EGl 1.0 context with the specified config attributes.
+ * Explicitly create a root EGl 1.0 context with the specified config attributes and shared
+ * context.
*/
- public static EglBase createEgl10(int[] configAttributes) {
- return new EglBase10(null /* shaderContext */, configAttributes);
+ public static EglBase10 createEgl10(EglBase10.Context sharedContext, int[] configAttributes) {
+ return new EglBase10Impl(
+ sharedContext == null ? null : sharedContext.getRawContext(), configAttributes);
}
/**
* Explicitly create a root EGl 1.0 context with the specified config attributes
* and shared context.
*/
- public static EglBase createEgl10(
+ public static EglBase10 createEgl10(
javax.microedition.khronos.egl.EGLContext sharedContext, int[] configAttributes) {
- return new EglBase10(new EglBase10.Context(sharedContext), configAttributes);
+ return new EglBase10Impl(sharedContext, configAttributes);
+ }
+
+ /** Explicitly create a root EGl 1.4 context with the specified config attributes. */
+ public static EglBase14 createEgl14(int[] configAttributes) {
+ return new EglBase14Impl(/* sharedContext= */ null, configAttributes);
}
/**
- * Explicitly create a root EGl 1.4 context with the specified config attributes.
+ * Explicitly create a root EGl 1.4 context with the specified config attributes and shared
+ * context.
*/
- public static EglBase createEgl14(int[] configAttributes) {
- return new EglBase14(null /* shaderContext */, configAttributes);
+ public static EglBase14 createEgl14(EglBase14.Context sharedContext, int[] configAttributes) {
+ return new EglBase14Impl(
+ sharedContext == null ? null : sharedContext.getRawContext(), configAttributes);
}
/**
* Explicitly create a root EGl 1.4 context with the specified config attributes
* and shared context.
*/
- public static EglBase createEgl14(
+ public static EglBase14 createEgl14(
android.opengl.EGLContext sharedContext, int[] configAttributes) {
- return new EglBase14(new EglBase14.Context(sharedContext), configAttributes);
+ return new EglBase14Impl(sharedContext, configAttributes);
}
void createSurface(Surface surface);
diff --git a/sdk/android/api/org/webrtc/EglBase10.java b/sdk/android/api/org/webrtc/EglBase10.java
new file mode 100644
index 0000000..f8b0a3c
--- /dev/null
+++ b/sdk/android/api/org/webrtc/EglBase10.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+package org.webrtc;
+
+import javax.microedition.khronos.egl.EGLContext;
+
+/** EGL 1.0 implementation of EglBase. */
+public interface EglBase10 extends EglBase {
+ interface Context extends EglBase.Context {
+ EGLContext getRawContext();
+ }
+}
diff --git a/sdk/android/api/org/webrtc/EglBase14.java b/sdk/android/api/org/webrtc/EglBase14.java
new file mode 100644
index 0000000..69c89c4
--- /dev/null
+++ b/sdk/android/api/org/webrtc/EglBase14.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+package org.webrtc;
+
+import android.opengl.EGLContext;
+
+/** EGL 1.4 implementation of EglBase. */
+public interface EglBase14 extends EglBase {
+ interface Context extends EglBase.Context {
+ EGLContext getRawContext();
+ }
+}
diff --git a/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java b/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java
index 8ffe1e2..773ed16 100644
--- a/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java
+++ b/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java
@@ -660,7 +660,8 @@
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
if (useSurface) {
- eglBase = new EglBase14((EglBase14.Context) getEglContext(), EglBase.CONFIG_RECORDABLE);
+ eglBase =
+ EglBase.createEgl14((EglBase14.Context) getEglContext(), EglBase.CONFIG_RECORDABLE);
// Create an input surface and keep a reference since we must release the surface when done.
inputSurface = mediaCodec.createInputSurface();
eglBase.createSurface(inputSurface);