EGL10.eglCreateWindowSurface(): Replace Surface input with SurfaceHolder

Sending a Surface as input to EGL10.eglCreateWindowSurface() is not supported everywhere. See this code as reference:
ae9610220b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.java (42)

Sending a SurfaceHolder as input instead should hopefully be supported everywhere, and this is also what GlSurfaceView does:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/opengl/GLSurfaceView.java#1076

Review URL: https://codereview.webrtc.org/1416213004

Cr-Commit-Position: refs/heads/master@{#10392}
This commit is contained in:
magjed
2015-10-23 18:13:15 -07:00
committed by Commit bot
parent 90d67ddc1d
commit c3402fc3ef
2 changed files with 10 additions and 10 deletions

View File

@ -28,7 +28,7 @@
package org.webrtc;
import android.graphics.SurfaceTexture;
import android.view.Surface;
import android.view.SurfaceHolder;
import org.webrtc.Logging;
@ -86,9 +86,9 @@ public final class EglBase {
eglContext = createEglContext(sharedContext, eglDisplay, eglConfig);
}
// Create EGLSurface from the Android Surface.
public void createSurface(Surface surface) {
createSurfaceInternal(surface);
// Create EGLSurface from the Android SurfaceHolder.
public void createSurface(SurfaceHolder surfaceHolder) {
createSurfaceInternal(surfaceHolder);
}
// Create EGLSurface from the Android SurfaceTexture.
@ -96,10 +96,10 @@ public final class EglBase {
createSurfaceInternal(surfaceTexture);
}
// Create EGLSurface from either Surface or SurfaceTexture.
private void createSurfaceInternal(Object surface) {
if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture)) {
throw new IllegalStateException("Input must be either a Surface or SurfaceTexture");
// Create EGLSurface from either a SurfaceHolder or a SurfaceTexture.
private void createSurfaceInternal(Object nativeWindow) {
if (!(nativeWindow instanceof SurfaceHolder) && !(nativeWindow instanceof SurfaceTexture)) {
throw new IllegalStateException("Input must be either a SurfaceHolder or SurfaceTexture");
}
checkIsNotReleased();
if (configType == ConfigType.PIXEL_BUFFER) {
@ -109,7 +109,7 @@ public final class EglBase {
throw new RuntimeException("Already has an EGLSurface");
}
int[] surfaceAttribs = {EGL10.EGL_NONE};
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs);
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs);
if (eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException("Failed to create window surface");
}

View File

@ -173,7 +173,7 @@ public class SurfaceViewRenderer extends SurfaceView
@Override public void run() {
synchronized (layoutLock) {
if (isSurfaceCreated) {
eglBase.createSurface(getHolder().getSurface());
eglBase.createSurface(getHolder());
eglBase.makeCurrent();
// Necessary for YUV frames with odd width.
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);