Support getNativeEglContext in EglBase10Impl.
Bug: webrtc:12471 Change-Id: Iac969b4985b4db02c18f07c4b5ec2a787e312560 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/207434 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Paulina Hensman <phensman@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33271}
This commit is contained in:
committed by
Commit Bot
parent
8623c75cc5
commit
a33f41bf58
@ -39,6 +39,7 @@ class EglBase10Impl implements EglBase10 {
|
||||
|
||||
// EGL wrapper for an actual EGLContext.
|
||||
private static class Context implements EglBase10.Context {
|
||||
private final EGL10 egl;
|
||||
private final EGLContext eglContext;
|
||||
|
||||
@Override
|
||||
@ -48,14 +49,37 @@ class EglBase10Impl implements EglBase10 {
|
||||
|
||||
@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.
|
||||
return 0 /* EGL_NO_CONTEXT */;
|
||||
EGLContext previousContext = egl.eglGetCurrentContext();
|
||||
EGLDisplay previousDisplay = egl.eglGetCurrentDisplay();
|
||||
EGLSurface previousDrawSurface = egl.eglGetCurrentSurface(EGL10.EGL_DRAW);
|
||||
EGLSurface previousReadSurface = egl.eglGetCurrentSurface(EGL10.EGL_READ);
|
||||
EGLSurface tempEglSurface = null;
|
||||
|
||||
EGLDisplay defaultDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
||||
|
||||
try {
|
||||
if (previousContext != eglContext) {
|
||||
int[] surfaceAttribs = {EGL10.EGL_WIDTH, 1, EGL10.EGL_HEIGHT, 1, EGL10.EGL_NONE};
|
||||
EGLConfig eglConfig = getEglConfig(egl, defaultDisplay, EglBase.CONFIG_PIXEL_BUFFER);
|
||||
|
||||
tempEglSurface = egl.eglCreatePbufferSurface(defaultDisplay, eglConfig, surfaceAttribs);
|
||||
if (!egl.eglMakeCurrent(defaultDisplay, tempEglSurface, tempEglSurface, eglContext)) {
|
||||
throw new RuntimeException("Failed to make temporary EGL surface active.");
|
||||
}
|
||||
}
|
||||
|
||||
return nativeGetCurrentNativeEGLContext();
|
||||
} finally {
|
||||
if (tempEglSurface != null) {
|
||||
egl.eglMakeCurrent(
|
||||
previousDisplay, previousDrawSurface, previousReadSurface, previousContext);
|
||||
egl.eglDestroySurface(defaultDisplay, tempEglSurface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Context(EGLContext eglContext) {
|
||||
public Context(EGL10 egl, EGLContext eglContext) {
|
||||
this.egl = egl;
|
||||
this.eglContext = eglContext;
|
||||
}
|
||||
}
|
||||
@ -64,7 +88,7 @@ class EglBase10Impl implements EglBase10 {
|
||||
public EglBase10Impl(EGLContext sharedContext, int[] configAttributes) {
|
||||
this.egl = (EGL10) EGLContext.getEGL();
|
||||
eglDisplay = getEglDisplay();
|
||||
eglConfig = getEglConfig(eglDisplay, configAttributes);
|
||||
eglConfig = getEglConfig(egl, eglDisplay, configAttributes);
|
||||
final int openGlesVersion = EglBase.getOpenGlesVersionFromConfig(configAttributes);
|
||||
Logging.d(TAG, "Using OpenGL ES version " + openGlesVersion);
|
||||
eglContext = createEglContext(sharedContext, eglDisplay, eglConfig, openGlesVersion);
|
||||
@ -186,7 +210,7 @@ class EglBase10Impl implements EglBase10 {
|
||||
|
||||
@Override
|
||||
public org.webrtc.EglBase.Context getEglBaseContext() {
|
||||
return new Context(eglContext);
|
||||
return new Context(egl, eglContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -294,7 +318,7 @@ class EglBase10Impl implements EglBase10 {
|
||||
}
|
||||
|
||||
// Return an EGLConfig, or die trying.
|
||||
private EGLConfig getEglConfig(EGLDisplay eglDisplay, int[] configAttributes) {
|
||||
private static EGLConfig getEglConfig(EGL10 egl, EGLDisplay eglDisplay, int[] configAttributes) {
|
||||
EGLConfig[] configs = new EGLConfig[1];
|
||||
int[] numConfigs = new int[1];
|
||||
if (!egl.eglChooseConfig(eglDisplay, configAttributes, configs, configs.length, numConfigs)) {
|
||||
@ -329,4 +353,6 @@ class EglBase10Impl implements EglBase10 {
|
||||
}
|
||||
return eglContext;
|
||||
}
|
||||
|
||||
private static native long nativeGetCurrentNativeEGLContext();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user