33
44import android .graphics .SurfaceTexture ;
55import android .opengl .EGL14 ;
6- import android .opengl .EGLConfig ;
76import android .opengl .EGLContext ;
87import android .opengl .EGLDisplay ;
98import android .opengl .EGLSurface ;
@@ -42,22 +41,6 @@ public class OutputSurface implements SurfaceTexture.OnFrameAvailableListener {
4241
4342 private TextureRender mTextureRender ;
4443
45- /**
46- * Creates an OutputSurface backed by a pbuffer with the specifed dimensions. The new
47- * EGL context and surface will be made current. Creates a Surface that can be passed
48- * to MediaCodec.configure().
49- */
50- public OutputSurface (int width , int height ) {
51- if (width <= 0 || height <= 0 ) {
52- throw new IllegalArgumentException ();
53- }
54-
55- eglSetup (width , height );
56- makeCurrent ();
57-
58- setup (this );
59- }
60-
6144 /**
6245 * Creates an OutputSurface using the current EGL context (rather than establishing a
6346 * new one). Creates a Surface that can be passed to MediaCodec.configure().
@@ -66,10 +49,6 @@ public OutputSurface() {
6649 setup (this );
6750 }
6851
69- public OutputSurface (final SurfaceTexture .OnFrameAvailableListener listener ) {
70- setup (listener );
71- }
72-
7352 /**
7453 * Creates instances of TextureRender and SurfaceTexture, and a Surface associated
7554 * with the SurfaceTexture.
@@ -101,63 +80,6 @@ private void setup(SurfaceTexture.OnFrameAvailableListener listener) {
10180 mSurface = new Surface (mSurfaceTexture );
10281 }
10382
104- /**
105- * Prepares EGL. We want a GLES 2.0 context and a surface that supports pbuffer.
106- */
107- private void eglSetup (int width , int height ) {
108- mEGLDisplay = EGL14 .eglGetDisplay (EGL14 .EGL_DEFAULT_DISPLAY );
109- if (mEGLDisplay == EGL14 .EGL_NO_DISPLAY ) {
110- throw new RuntimeException ("unable to get EGL14 display" );
111- }
112- int [] version = new int [2 ];
113- if (!EGL14 .eglInitialize (mEGLDisplay , version , 0 , version , 1 )) {
114- mEGLDisplay = null ;
115- throw new RuntimeException ("unable to initialize EGL14" );
116- }
117-
118- // Configure EGL for pbuffer and OpenGL ES 2.0. We want enough RGB bits
119- // to be able to tell if the frame is reasonable.
120- int [] attribList = {
121- EGL14 .EGL_RED_SIZE , 8 ,
122- EGL14 .EGL_GREEN_SIZE , 8 ,
123- EGL14 .EGL_BLUE_SIZE , 8 ,
124- EGL14 .EGL_RENDERABLE_TYPE , EGL14 .EGL_OPENGL_ES2_BIT ,
125- EGL14 .EGL_SURFACE_TYPE , EGL14 .EGL_PBUFFER_BIT ,
126- EGL14 .EGL_NONE
127- };
128- EGLConfig [] configs = new EGLConfig [1 ];
129- int [] numConfigs = new int [1 ];
130- if (!EGL14 .eglChooseConfig (mEGLDisplay , attribList , 0 , configs , 0 , configs .length ,
131- numConfigs , 0 )) {
132- throw new RuntimeException ("unable to find RGB888+recordable ES2 EGL config" );
133- }
134-
135- // Configure context for OpenGL ES 2.0.
136- int [] attrib_list = {
137- EGL14 .EGL_CONTEXT_CLIENT_VERSION , 2 ,
138- EGL14 .EGL_NONE
139- };
140- mEGLContext = EGL14 .eglCreateContext (mEGLDisplay , configs [0 ], EGL14 .EGL_NO_CONTEXT ,
141- attrib_list , 0 );
142- checkEglError ("eglCreateContext" );
143- if (mEGLContext == null ) {
144- throw new RuntimeException ("null context" );
145- }
146-
147- // Create a pbuffer surface. By using this for output, we can use glReadPixels
148- // to test values in the output.
149- int [] surfaceAttribs = {
150- EGL14 .EGL_WIDTH , width ,
151- EGL14 .EGL_HEIGHT , height ,
152- EGL14 .EGL_NONE
153- };
154- mEGLSurface = EGL14 .eglCreatePbufferSurface (mEGLDisplay , configs [0 ], surfaceAttribs , 0 );
155- checkEglError ("eglCreatePbufferSurface" );
156- if (mEGLSurface == null ) {
157- throw new RuntimeException ("surface was null" );
158- }
159- }
160-
16183 /**
16284 * Discard all resources held by this class, notably the EGL context.
16385 */
0 commit comments