Android EglBase: Add support for creating EGLSurface from Surface, not SurfaceHolder
Review URL: https://codereview.webrtc.org/1438223003 Cr-Commit-Position: refs/heads/master@{#10646}
This commit is contained in:
@ -27,7 +27,10 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.view.Surface;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
|
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
@ -86,9 +89,71 @@ public final class EglBase {
|
|||||||
eglContext = createEglContext(sharedContext, eglDisplay, eglConfig);
|
eglContext = createEglContext(sharedContext, eglDisplay, eglConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create EGLSurface from the Android SurfaceHolder.
|
// Create EGLSurface from the Android Surface.
|
||||||
public void createSurface(SurfaceHolder surfaceHolder) {
|
public void createSurface(Surface surface) {
|
||||||
createSurfaceInternal(surfaceHolder);
|
/**
|
||||||
|
* We have to wrap Surface in a SurfaceHolder because for some reason eglCreateWindowSurface
|
||||||
|
* couldn't actually take a Surface object until API 17. Older versions fortunately just call
|
||||||
|
* SurfaceHolder.getSurface(), so we'll do that. No other methods are relevant.
|
||||||
|
*/
|
||||||
|
class FakeSurfaceHolder implements SurfaceHolder {
|
||||||
|
private final Surface surface;
|
||||||
|
|
||||||
|
FakeSurfaceHolder(Surface surface) {
|
||||||
|
this.surface = surface;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCallback(Callback callback) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeCallback(Callback callback) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreating() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(int i) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFixedSize(int i, int i2) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSizeFromLayout() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFormat(int i) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setKeepScreenOn(boolean b) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Canvas lockCanvas() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Canvas lockCanvas(Rect rect) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlockCanvasAndPost(Canvas canvas) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rect getSurfaceFrame() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Surface getSurface() {
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createSurfaceInternal(new FakeSurfaceHolder(surface));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create EGLSurface from the Android SurfaceTexture.
|
// Create EGLSurface from the Android SurfaceTexture.
|
||||||
|
@ -176,7 +176,7 @@ public class SurfaceViewRenderer extends SurfaceView
|
|||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
synchronized (layoutLock) {
|
synchronized (layoutLock) {
|
||||||
if (isSurfaceCreated) {
|
if (isSurfaceCreated) {
|
||||||
eglBase.createSurface(getHolder());
|
eglBase.createSurface(getHolder().getSurface());
|
||||||
eglBase.makeCurrent();
|
eglBase.makeCurrent();
|
||||||
// Necessary for YUV frames with odd width.
|
// Necessary for YUV frames with odd width.
|
||||||
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
|
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
Reference in New Issue
Block a user