diff options
author | perkj <perkj@webrtc.org> | 2015-12-14 06:43:35 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-14 14:43:39 +0000 |
commit | e22e1cb399748112f308b488e7535754ef6b807d (patch) | |
tree | 5c507f935b9820b103b8a9d320b3f8882d5465ea | |
parent | 40f349fddafd97c3f4cd0e37407bd1968496cb09 (diff) | |
download | webrtc-e22e1cb399748112f308b488e7535754ef6b807d.tar.gz |
Revert of Made EglBase an abstract class and cleaned up. (patchset #4 id:60001 of https://codereview.webrtc.org/1526463002/ )
Reason for revert:
Revert due breaking other clients.
Original issue's description:
> Made EglBase an abstract class and cleaned up.
> Adds EglBase10 that implemenents EglBase for EGL 1.0
>
> BUG=webrtc:4993
> TBR=glaznew@webrtc.org
>
> Committed: https://crrev.com/3207916f35ded33f586774e2c98d4d0089fe3c6e
> Cr-Commit-Position: refs/heads/master@{#11011}
TBR=magjed@webrtc.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4993
Review URL: https://codereview.webrtc.org/1522073002
Cr-Commit-Position: refs/heads/master@{#11013}
10 files changed, 319 insertions, 333 deletions
diff --git a/talk/app/webrtc/java/android/org/webrtc/EglBase.java b/talk/app/webrtc/java/android/org/webrtc/EglBase.java index d50213899d..c45aa29602 100644 --- a/talk/app/webrtc/java/android/org/webrtc/EglBase.java +++ b/talk/app/webrtc/java/android/org/webrtc/EglBase.java @@ -27,29 +27,51 @@ package org.webrtc; +import android.graphics.Canvas; import android.graphics.SurfaceTexture; +import android.graphics.Rect; import android.view.Surface; +import android.view.SurfaceHolder; -import javax.microedition.khronos.egl.EGL10; +import org.webrtc.Logging; +import org.webrtc.EglBase.Context; +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.egl.EGLContext; +import javax.microedition.khronos.egl.EGLDisplay; +import javax.microedition.khronos.egl.EGLSurface; /** * Holds EGL state and utility methods for handling an egl 1.0 EGLContext, an EGLDisplay, * and an EGLSurface. */ -public abstract class EglBase { - // EGL wrapper for an actual EGLContext. - public static class Context { - } - +public class EglBase { + private static final String TAG = "EglBase"; // These constants are taken from EGL14.EGL_OPENGL_ES2_BIT and EGL14.EGL_CONTEXT_CLIENT_VERSION. // https://android.googlesource.com/platform/frameworks/base/+/master/opengl/java/android/opengl/EGL14.java // This is similar to how GlSurfaceView does: // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/opengl/GLSurfaceView.java#760 private static final int EGL_OPENGL_ES2_BIT = 4; + private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; // Android-specific extension. private static final int EGL_RECORDABLE_ANDROID = 0x3142; + private final EGL10 egl; + private EGLContext eglContext; + private EGLConfig eglConfig; + private EGLDisplay eglDisplay; + private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE; + + // EGL wrapper for an actual EGLContext. + public static class Context { + private final EGLContext eglContext; + + public Context(EGLContext eglContext) { + this.eglContext = eglContext; + } + } + public static final int[] CONFIG_PLAIN = { EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8, @@ -89,39 +111,257 @@ public abstract class EglBase { return (EglBase14.isEGL14Supported() && (sharedContext == null || sharedContext instanceof EglBase14.Context)) ? new EglBase14((EglBase14.Context) sharedContext, configAttributes) - : new EglBase10((EglBase10.Context) sharedContext, configAttributes); + : new EglBase(sharedContext, configAttributes); } public static EglBase create() { return create(null, CONFIG_PLAIN); } - public abstract void createSurface(Surface surface); + //Create root context without any EGLSurface or parent EGLContext. This can be used for branching + // new contexts that share data. + @Deprecated + public EglBase() { + this((Context) null, CONFIG_PLAIN); + } + + @Deprecated + public EglBase(EGLContext sharedContext, int[] configAttributes) { + this(new Context(sharedContext), configAttributes); + Logging.d(TAG, "EglBase created"); + } + + @Deprecated + public EGLContext getContext() { + return eglContext; + } + + // Create a new context with the specified config type, sharing data with sharedContext. + EglBase(Context sharedContext, int[] configAttributes) { + this.egl = (EGL10) EGLContext.getEGL(); + eglDisplay = getEglDisplay(); + eglConfig = getEglConfig(eglDisplay, configAttributes); + eglContext = createEglContext(sharedContext, eglDisplay, eglConfig); + } + + // TODO(perkj): This is a hacky ctor used to allow us to create an EGLBase14. Remove this and + // make EglBase an abstract class once all applications have started using the create factory + // method. + protected EglBase(boolean dummy) { + this.egl = null; + } + + public void createSurface(Surface surface) { + /** + * 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; + } + + @Deprecated + @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. - public abstract void createSurface(SurfaceTexture surfaceTexture); + public void createSurface(SurfaceTexture surfaceTexture) { + createSurfaceInternal(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 (eglSurface != EGL10.EGL_NO_SURFACE) { + throw new RuntimeException("Already has an EGLSurface"); + } + int[] surfaceAttribs = {EGL10.EGL_NONE}; + eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs); + if (eglSurface == EGL10.EGL_NO_SURFACE) { + throw new RuntimeException("Failed to create window surface"); + } + } // Create dummy 1x1 pixel buffer surface so the context can be made current. - public abstract void createDummyPbufferSurface(); + public void createDummyPbufferSurface() { + createPbufferSurface(1, 1); + } - public abstract void createPbufferSurface(int width, int height); + public void createPbufferSurface(int width, int height) { + checkIsNotReleased(); + if (eglSurface != EGL10.EGL_NO_SURFACE) { + throw new RuntimeException("Already has an EGLSurface"); + } + int[] surfaceAttribs = {EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EGL10.EGL_NONE}; + eglSurface = egl.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttribs); + if (eglSurface == EGL10.EGL_NO_SURFACE) { + throw new RuntimeException("Failed to create pixel buffer surface"); + } + } + + public Context getEglBaseContext() { + return new Context(eglContext); + } - public abstract Context getEglBaseContext(); + public boolean hasSurface() { + return eglSurface != EGL10.EGL_NO_SURFACE; + } - public abstract boolean hasSurface(); + public int surfaceWidth() { + final int widthArray[] = new int[1]; + egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_WIDTH, widthArray); + return widthArray[0]; + } - public abstract int surfaceWidth(); + public int surfaceHeight() { + final int heightArray[] = new int[1]; + egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_HEIGHT, heightArray); + return heightArray[0]; + } - public abstract int surfaceHeight(); + public void releaseSurface() { + if (eglSurface != EGL10.EGL_NO_SURFACE) { + egl.eglDestroySurface(eglDisplay, eglSurface); + eglSurface = EGL10.EGL_NO_SURFACE; + } + } - public abstract void releaseSurface(); + private void checkIsNotReleased() { + if (eglDisplay == EGL10.EGL_NO_DISPLAY || eglContext == EGL10.EGL_NO_CONTEXT + || eglConfig == null) { + throw new RuntimeException("This object has been released"); + } + } - public abstract void release(); + public void release() { + checkIsNotReleased(); + releaseSurface(); + detachCurrent(); + egl.eglDestroyContext(eglDisplay, eglContext); + egl.eglTerminate(eglDisplay); + eglContext = EGL10.EGL_NO_CONTEXT; + eglDisplay = EGL10.EGL_NO_DISPLAY; + eglConfig = null; + } - public abstract void makeCurrent(); + public void makeCurrent() { + checkIsNotReleased(); + if (eglSurface == EGL10.EGL_NO_SURFACE) { + throw new RuntimeException("No EGLSurface - can't make current"); + } + if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { + throw new RuntimeException("eglMakeCurrent failed"); + } + } // Detach the current EGL context, so that it can be made current on another thread. - public abstract void detachCurrent(); + public void detachCurrent() { + if (!egl.eglMakeCurrent( + eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) { + throw new RuntimeException("eglMakeCurrent failed"); + } + } - public abstract void swapBuffers(); + public void swapBuffers() { + checkIsNotReleased(); + if (eglSurface == EGL10.EGL_NO_SURFACE) { + throw new RuntimeException("No EGLSurface - can't swap buffers"); + } + egl.eglSwapBuffers(eglDisplay, eglSurface); + } + + // Return an EGLDisplay, or die trying. + private EGLDisplay getEglDisplay() { + EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + if (eglDisplay == EGL10.EGL_NO_DISPLAY) { + throw new RuntimeException("Unable to get EGL10 display"); + } + int[] version = new int[2]; + if (!egl.eglInitialize(eglDisplay, version)) { + throw new RuntimeException("Unable to initialize EGL10"); + } + return eglDisplay; + } + + // Return an EGLConfig, or die trying. + private EGLConfig getEglConfig(EGLDisplay eglDisplay, int[] configAttributes) { + EGLConfig[] configs = new EGLConfig[1]; + int[] numConfigs = new int[1]; + if (!egl.eglChooseConfig( + eglDisplay, configAttributes, configs, configs.length, numConfigs)) { + throw new RuntimeException("Unable to find any matching EGL config"); + } + return configs[0]; + } + + // Return an EGLConfig, or die trying. + private EGLContext createEglContext( + Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) { + int[] contextAttributes = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; + EGLContext rootContext = + sharedContext == null ? EGL10.EGL_NO_CONTEXT : sharedContext.eglContext; + EGLContext eglContext = + egl.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes); + if (eglContext == EGL10.EGL_NO_CONTEXT) { + throw new RuntimeException("Failed to create EGL context"); + } + return eglContext; + } } diff --git a/talk/app/webrtc/java/android/org/webrtc/EglBase10.java b/talk/app/webrtc/java/android/org/webrtc/EglBase10.java deleted file mode 100644 index f2aa9857fa..0000000000 --- a/talk/app/webrtc/java/android/org/webrtc/EglBase10.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * libjingle - * Copyright 2015 Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.webrtc; - -import android.graphics.Canvas; -import android.graphics.SurfaceTexture; -import android.graphics.Rect; -import android.view.Surface; -import android.view.SurfaceHolder; - -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLContext; -import javax.microedition.khronos.egl.EGLDisplay; -import javax.microedition.khronos.egl.EGLSurface; - -/** - * Holds EGL state and utility methods for handling an egl 1.0 EGLContext, an EGLDisplay, - * and an EGLSurface. - */ -final class EglBase10 extends EglBase { - // This constant is taken from EGL14.EGL_CONTEXT_CLIENT_VERSION. - private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; - - private final EGL10 egl; - private EGLContext eglContext; - private EGLConfig eglConfig; - private EGLDisplay eglDisplay; - private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE; - - // EGL wrapper for an actual EGLContext. - public static class Context extends EglBase.Context { - private final EGLContext eglContext; - - public Context(EGLContext eglContext) { - this.eglContext = eglContext; - } - } - - // Create a new context with the specified config type, sharing data with sharedContext. - EglBase10(Context sharedContext, int[] configAttributes) { - this.egl = (EGL10) EGLContext.getEGL(); - eglDisplay = getEglDisplay(); - eglConfig = getEglConfig(eglDisplay, configAttributes); - eglContext = createEglContext(sharedContext, eglDisplay, eglConfig); - } - - @Override - public void createSurface(Surface surface) { - /** - * 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; - } - - @Deprecated - @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. - @Override - public void createSurface(SurfaceTexture surfaceTexture) { - createSurfaceInternal(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 (eglSurface != EGL10.EGL_NO_SURFACE) { - throw new RuntimeException("Already has an EGLSurface"); - } - int[] surfaceAttribs = {EGL10.EGL_NONE}; - eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs); - if (eglSurface == EGL10.EGL_NO_SURFACE) { - throw new RuntimeException("Failed to create window surface"); - } - } - - // Create dummy 1x1 pixel buffer surface so the context can be made current. - @Override - public void createDummyPbufferSurface() { - createPbufferSurface(1, 1); - } - - @Override - public void createPbufferSurface(int width, int height) { - checkIsNotReleased(); - if (eglSurface != EGL10.EGL_NO_SURFACE) { - throw new RuntimeException("Already has an EGLSurface"); - } - int[] surfaceAttribs = {EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EGL10.EGL_NONE}; - eglSurface = egl.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttribs); - if (eglSurface == EGL10.EGL_NO_SURFACE) { - throw new RuntimeException("Failed to create pixel buffer surface"); - } - } - - @Override - public org.webrtc.EglBase.Context getEglBaseContext() { - return new EglBase10.Context(eglContext); - } - - @Override - public boolean hasSurface() { - return eglSurface != EGL10.EGL_NO_SURFACE; - } - - @Override - public int surfaceWidth() { - final int widthArray[] = new int[1]; - egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_WIDTH, widthArray); - return widthArray[0]; - } - - @Override - public int surfaceHeight() { - final int heightArray[] = new int[1]; - egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_HEIGHT, heightArray); - return heightArray[0]; - } - - @Override - public void releaseSurface() { - if (eglSurface != EGL10.EGL_NO_SURFACE) { - egl.eglDestroySurface(eglDisplay, eglSurface); - eglSurface = EGL10.EGL_NO_SURFACE; - } - } - - private void checkIsNotReleased() { - if (eglDisplay == EGL10.EGL_NO_DISPLAY || eglContext == EGL10.EGL_NO_CONTEXT - || eglConfig == null) { - throw new RuntimeException("This object has been released"); - } - } - - @Override - public void release() { - checkIsNotReleased(); - releaseSurface(); - detachCurrent(); - egl.eglDestroyContext(eglDisplay, eglContext); - egl.eglTerminate(eglDisplay); - eglContext = EGL10.EGL_NO_CONTEXT; - eglDisplay = EGL10.EGL_NO_DISPLAY; - eglConfig = null; - } - - @Override - public void makeCurrent() { - checkIsNotReleased(); - if (eglSurface == EGL10.EGL_NO_SURFACE) { - throw new RuntimeException("No EGLSurface - can't make current"); - } - if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { - throw new RuntimeException("eglMakeCurrent failed"); - } - } - - // Detach the current EGL context, so that it can be made current on another thread. - @Override - public void detachCurrent() { - if (!egl.eglMakeCurrent( - eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) { - throw new RuntimeException("eglMakeCurrent failed"); - } - } - - @Override - public void swapBuffers() { - checkIsNotReleased(); - if (eglSurface == EGL10.EGL_NO_SURFACE) { - throw new RuntimeException("No EGLSurface - can't swap buffers"); - } - egl.eglSwapBuffers(eglDisplay, eglSurface); - } - - // Return an EGLDisplay, or die trying. - private EGLDisplay getEglDisplay() { - EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); - if (eglDisplay == EGL10.EGL_NO_DISPLAY) { - throw new RuntimeException("Unable to get EGL10 display"); - } - int[] version = new int[2]; - if (!egl.eglInitialize(eglDisplay, version)) { - throw new RuntimeException("Unable to initialize EGL10"); - } - return eglDisplay; - } - - // Return an EGLConfig, or die trying. - private EGLConfig getEglConfig(EGLDisplay eglDisplay, int[] configAttributes) { - EGLConfig[] configs = new EGLConfig[1]; - int[] numConfigs = new int[1]; - if (!egl.eglChooseConfig( - eglDisplay, configAttributes, configs, configs.length, numConfigs)) { - throw new RuntimeException("Unable to find any matching EGL config"); - } - return configs[0]; - } - - // Return an EGLConfig, or die trying. - private EGLContext createEglContext( - Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) { - int[] contextAttributes = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; - EGLContext rootContext = - sharedContext == null ? EGL10.EGL_NO_CONTEXT : sharedContext.eglContext; - EGLContext eglContext = - egl.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes); - if (eglContext == EGL10.EGL_NO_CONTEXT) { - throw new RuntimeException("Failed to create EGL context"); - } - return eglContext; - } -} diff --git a/talk/app/webrtc/java/android/org/webrtc/EglBase14.java b/talk/app/webrtc/java/android/org/webrtc/EglBase14.java index 580a3c6826..dc7a454942 100644 --- a/talk/app/webrtc/java/android/org/webrtc/EglBase14.java +++ b/talk/app/webrtc/java/android/org/webrtc/EglBase14.java @@ -47,6 +47,9 @@ final class EglBase14 extends EglBase { private static final String TAG = "EglBase14"; private static final int EGL14_SDK_VERSION = android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; private static final int CURRENT_SDK_VERSION = android.os.Build.VERSION.SDK_INT; + // Android-specific extension. + private static final int EGL_RECORDABLE_ANDROID = 0x3142; + private EGLContext eglContext; private EGLConfig eglConfig; private EGLDisplay eglDisplay; @@ -62,6 +65,7 @@ final class EglBase14 extends EglBase { private final android.opengl.EGLContext egl14Context; Context(android.opengl.EGLContext eglContext) { + super(null); this.egl14Context = eglContext; } } @@ -69,6 +73,7 @@ final class EglBase14 extends EglBase { // Create a new context with the specified config type, sharing data with sharedContext. // |sharedContext| may be null. EglBase14(EglBase14.Context sharedContext, int[] configAttributes) { + super(true /* dummy */); eglDisplay = getEglDisplay(); eglConfig = getEglConfig(eglDisplay, configAttributes); eglContext = createEglContext(sharedContext, eglDisplay, eglConfig); diff --git a/talk/app/webrtc/java/android/org/webrtc/SurfaceViewRenderer.java b/talk/app/webrtc/java/android/org/webrtc/SurfaceViewRenderer.java index 452b3e3f42..3a5cca958f 100644 --- a/talk/app/webrtc/java/android/org/webrtc/SurfaceViewRenderer.java +++ b/talk/app/webrtc/java/android/org/webrtc/SurfaceViewRenderer.java @@ -169,6 +169,13 @@ public class SurfaceViewRenderer extends SurfaceView tryCreateEglSurface(); } + @Deprecated + // TODO(perkj): Remove when applications has been updated. + public void init( + EGLContext sharedContext, RendererCommon.RendererEvents rendererEvents) { + init(sharedContext != null ? new EglBase.Context(sharedContext) : null, rendererEvents); + } + /** * Create and make an EGLSurface current if both init() and surfaceCreated() have been called. */ diff --git a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java index 93d4c0433c..e9e95abedf 100644 --- a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java +++ b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java @@ -415,8 +415,13 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { eglContextReady = eglContextReadyCallback; } + @Deprecated + public static synchronized EGLContext getEGLContext() { + return eglContext; + } + public static synchronized EglBase.Context getEglBaseContext() { - return new EglBase10.Context(eglContext); + return new EglBase.Context(eglContext); } /** Releases GLSurfaceView video renderer. */ diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index f44498443b..c5de965474 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -1365,12 +1365,40 @@ JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( OwnedFactoryAndThreads* owned_factory = reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); + // TODO(perkj): In order to not break existing applications we need to + // check if |local_egl_context| or |remote_egl_context| is an + // EGL10 context. If so, create an EGLBase10.EGL10Context instead. + // Remove this once existing applications has been updated. + jobject local_eglbase_context = local_egl_context; + jobject remote_eglbase_context = remote_egl_context; + + jclass j_egl10_context_class = + FindClass(jni, "javax/microedition/khronos/egl/EGLContext"); + jclass j_eglbase_context_class = + FindClass(jni, "org/webrtc/EglBase$Context"); + + jmethodID j_eglbase_context_ctor = GetMethodID( + jni, j_eglbase_context_class, + "<init>", "(Ljavax/microedition/khronos/egl/EGLContext;)V"); + if (local_egl_context != nullptr && + jni->IsInstanceOf(local_egl_context, j_egl10_context_class)) { + local_eglbase_context = jni->NewObject( + j_eglbase_context_class, j_eglbase_context_ctor, + local_egl_context); + } + if (remote_egl_context != nullptr && + jni->IsInstanceOf(remote_egl_context, j_egl10_context_class)) { + remote_eglbase_context = jni->NewObject( + j_eglbase_context_class, j_eglbase_context_ctor, + remote_egl_context); + } + MediaCodecVideoEncoderFactory* encoder_factory = static_cast<MediaCodecVideoEncoderFactory*> (owned_factory->encoder_factory()); if (encoder_factory) { LOG(LS_INFO) << "Set EGL context for HW encoding."; - encoder_factory->SetEGLContext(jni, local_egl_context); + encoder_factory->SetEGLContext(jni, local_eglbase_context); } MediaCodecVideoDecoderFactory* decoder_factory = @@ -1378,7 +1406,7 @@ JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( (owned_factory->decoder_factory()); if (decoder_factory) { LOG(LS_INFO) << "Set EGL context for HW decoding."; - decoder_factory->SetEGLContext(jni, remote_egl_context); + decoder_factory->SetEGLContext(jni, remote_eglbase_context); } #endif } diff --git a/talk/libjingle.gyp b/talk/libjingle.gyp index 4ad1e39992..c004aad875 100755 --- a/talk/libjingle.gyp +++ b/talk/libjingle.gyp @@ -149,7 +149,6 @@ 'app/webrtc/java/android/org/webrtc/CameraEnumerationAndroid.java', 'app/webrtc/java/android/org/webrtc/CameraEnumerator.java', 'app/webrtc/java/android/org/webrtc/EglBase.java', - 'app/webrtc/java/android/org/webrtc/EglBase10.java', 'app/webrtc/java/android/org/webrtc/EglBase14.java', 'app/webrtc/java/android/org/webrtc/GlRectDrawer.java', 'app/webrtc/java/android/org/webrtc/GlShader.java', diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java index b9abf11eb3..fdcfa29a6c 100644 --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java @@ -181,9 +181,9 @@ public class CallActivity extends Activity remoteRender.setOnClickListener(listener); // Create video renderers. - rootEglBase = EglBase.create(); - localRender.init(rootEglBase.getEglBaseContext(), null); - remoteRender.init(rootEglBase.getEglBaseContext(), null); + rootEglBase = new EglBase(); + localRender.init(rootEglBase.getContext(), null); + remoteRender.init(rootEglBase.getContext(), null); localRender.setZOrderMediaOverlay(true); updateVideoView(); @@ -254,7 +254,6 @@ public class CallActivity extends Activity // For command line execution run connection for <runTimeMs> and exit. if (commandLineRun && runTimeMs > 0) { (new Handler()).postDelayed(new Runnable() { - @Override public void run() { disconnect(); } @@ -489,7 +488,7 @@ public class CallActivity extends Activity signalingParameters = params; logAndToast("Creating peer connection, delay=" + delta + "ms"); - peerConnectionClient.createPeerConnection(rootEglBase.getEglBaseContext(), + peerConnectionClient.createPeerConnection(rootEglBase.getContext(), localRender, remoteRender, signalingParameters); if (signalingParameters.initiator) { diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java index 523c0e0c85..9d45c702e5 100644 --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java @@ -47,6 +47,8 @@ import java.util.TimerTask; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.microedition.khronos.egl.EGLContext; + /** * Peer connection client implementation. * @@ -257,7 +259,7 @@ public class PeerConnectionClient { } public void createPeerConnection( - final EglBase.Context renderEGLContext, + final EGLContext renderEGLContext, final VideoRenderer.Callbacks localRender, final VideoRenderer.Callbacks remoteRender, final SignalingParameters signalingParameters) { @@ -427,7 +429,7 @@ public class PeerConnectionClient { } } - private void createPeerConnectionInternal(EglBase.Context renderEGLContext) { + private void createPeerConnectionInternal(EGLContext renderEGLContext) { if (factory == null || isError) { Log.e(TAG, "Peerconnection factory is not created"); return; @@ -476,7 +478,7 @@ public class PeerConnectionClient { } Log.d(TAG, "Opening camera: " + cameraDeviceName); videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null, - peerConnectionParameters.captureToTexture ? renderEGLContext : null); + peerConnectionParameters.captureToTexture ? new EglBase.Context(renderEGLContext) : null); if (videoCapturer == null) { reportError("Failed to open camera"); return; diff --git a/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java index 16a9fb3612..92c709ab2b 100644 --- a/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java +++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java @@ -240,7 +240,7 @@ public class PeerConnectionClientTest extends InstrumentationTestCase client.setPeerConnectionFactoryOptions(options); client.createPeerConnectionFactory( getInstrumentation().getContext(), peerConnectionParameters, this); - client.createPeerConnection(useTexures ? eglBase.getEglBaseContext() : null, + client.createPeerConnection(useTexures ? eglBase.getContext() : null, localRenderer, remoteRenderer, signalingParameters); client.createOffer(); return client; @@ -270,7 +270,7 @@ public class PeerConnectionClientTest extends InstrumentationTestCase signalingExecutor = new LooperExecutor(); signalingExecutor.requestStart(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - eglBase = EglBase.create(); + eglBase = new EglBase(); } } |