OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 19 matching lines...) Expand all Loading... |
30 import android.opengl.GLES20; | 30 import android.opengl.GLES20; |
31 import android.os.Handler; | 31 import android.os.Handler; |
32 import android.os.HandlerThread; | 32 import android.os.HandlerThread; |
33 import android.os.SystemClock; | 33 import android.os.SystemClock; |
34 import android.test.ActivityTestCase; | 34 import android.test.ActivityTestCase; |
35 import android.test.suitebuilder.annotation.MediumTest; | 35 import android.test.suitebuilder.annotation.MediumTest; |
36 import android.test.suitebuilder.annotation.SmallTest; | 36 import android.test.suitebuilder.annotation.SmallTest; |
37 | 37 |
38 import java.nio.ByteBuffer; | 38 import java.nio.ByteBuffer; |
39 | 39 |
40 import javax.microedition.khronos.egl.EGL10; | |
41 | |
42 public final class SurfaceTextureHelperTest extends ActivityTestCase { | 40 public final class SurfaceTextureHelperTest extends ActivityTestCase { |
43 /** | 41 /** |
44 * Mock texture listener with blocking wait functionality. | 42 * Mock texture listener with blocking wait functionality. |
45 */ | 43 */ |
46 public static final class MockTextureListener | 44 public static final class MockTextureListener |
47 implements SurfaceTextureHelper.OnTextureFrameAvailableListener { | 45 implements SurfaceTextureHelper.OnTextureFrameAvailableListener { |
48 public int oesTextureId; | 46 public int oesTextureId; |
49 public float[] transformMatrix; | 47 public float[] transformMatrix; |
50 private boolean hasNewFrame = false; | 48 private boolean hasNewFrame = false; |
51 // Thread where frames are expected to be received on. | 49 // Thread where frames are expected to be received on. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 /** | 100 /** |
103 * Test normal use by receiving three uniform texture frames. Texture frames a
re returned as early | 101 * Test normal use by receiving three uniform texture frames. Texture frames a
re returned as early |
104 * as possible. The texture pixel values are inspected by drawing the texture
frame to a pixel | 102 * as possible. The texture pixel values are inspected by drawing the texture
frame to a pixel |
105 * buffer and reading it back with glReadPixels(). | 103 * buffer and reading it back with glReadPixels(). |
106 */ | 104 */ |
107 @MediumTest | 105 @MediumTest |
108 public static void testThreeConstantColorFrames() throws InterruptedException
{ | 106 public static void testThreeConstantColorFrames() throws InterruptedException
{ |
109 final int width = 16; | 107 final int width = 16; |
110 final int height = 16; | 108 final int height = 16; |
111 // Create EGL base with a pixel buffer as display output. | 109 // Create EGL base with a pixel buffer as display output. |
112 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); | 110 final EglBase eglBase = EglBase.create(null, EglBase.ConfigType.PIXEL_BUFFER
); |
113 eglBase.createPbufferSurface(width, height); | 111 eglBase.createPbufferSurface(width, height); |
114 final GlRectDrawer drawer = new GlRectDrawer(); | 112 final GlRectDrawer drawer = new GlRectDrawer(); |
115 | 113 |
116 // Create SurfaceTextureHelper and listener. | 114 // Create SurfaceTextureHelper and listener. |
117 final SurfaceTextureHelper surfaceTextureHelper = | 115 final SurfaceTextureHelper surfaceTextureHelper = |
118 SurfaceTextureHelper.create(eglBase.getContext()); | 116 SurfaceTextureHelper.create(eglBase.getEglBaseContext()); |
119 final MockTextureListener listener = new MockTextureListener(); | 117 final MockTextureListener listener = new MockTextureListener(); |
120 surfaceTextureHelper.setListener(listener); | 118 surfaceTextureHelper.setListener(listener); |
121 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; | 119 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; |
122 | 120 |
123 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he SurfaceTexture in | 121 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he SurfaceTexture in |
124 // |surfaceTextureHelper| as the target EGLSurface. | 122 // |surfaceTextureHelper| as the target EGLSurface. |
125 final EglBase eglOesBase = new EglBase(eglBase.getContext(), EglBase.ConfigT
ype.PLAIN); | 123 final EglBase eglOesBase = |
| 124 EglBase.create(eglBase.getEglBaseContext(), EglBase.ConfigType.PLAIN); |
126 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 125 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
127 assertEquals(eglOesBase.surfaceWidth(), width); | 126 assertEquals(eglOesBase.surfaceWidth(), width); |
128 assertEquals(eglOesBase.surfaceHeight(), height); | 127 assertEquals(eglOesBase.surfaceHeight(), height); |
129 | 128 |
130 final int red[] = new int[] {79, 144, 185}; | 129 final int red[] = new int[] {79, 144, 185}; |
131 final int green[] = new int[] {66, 210, 162}; | 130 final int green[] = new int[] {66, 210, 162}; |
132 final int blue[] = new int[] {161, 117, 158}; | 131 final int blue[] = new int[] {161, 117, 158}; |
133 // Draw three frames. | 132 // Draw three frames. |
134 for (int i = 0; i < 3; ++i) { | 133 for (int i = 0; i < 3; ++i) { |
135 // Draw a constant color frame onto the SurfaceTexture. | 134 // Draw a constant color frame onto the SurfaceTexture. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 /** | 168 /** |
170 * Test disconnecting the SurfaceTextureHelper while holding a pending texture
frame. The pending | 169 * Test disconnecting the SurfaceTextureHelper while holding a pending texture
frame. The pending |
171 * texture frame should still be valid, and this is tested by drawing the text
ure frame to a pixel | 170 * texture frame should still be valid, and this is tested by drawing the text
ure frame to a pixel |
172 * buffer and reading it back with glReadPixels(). | 171 * buffer and reading it back with glReadPixels(). |
173 */ | 172 */ |
174 @MediumTest | 173 @MediumTest |
175 public static void testLateReturnFrame() throws InterruptedException { | 174 public static void testLateReturnFrame() throws InterruptedException { |
176 final int width = 16; | 175 final int width = 16; |
177 final int height = 16; | 176 final int height = 16; |
178 // Create EGL base with a pixel buffer as display output. | 177 // Create EGL base with a pixel buffer as display output. |
179 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); | 178 final EglBase eglBase = EglBase.create(null, EglBase.ConfigType.PIXEL_BUFFER
); |
180 eglBase.createPbufferSurface(width, height); | 179 eglBase.createPbufferSurface(width, height); |
181 | 180 |
182 // Create SurfaceTextureHelper and listener. | 181 // Create SurfaceTextureHelper and listener. |
183 final SurfaceTextureHelper surfaceTextureHelper = | 182 final SurfaceTextureHelper surfaceTextureHelper = |
184 SurfaceTextureHelper.create(eglBase.getContext()); | 183 SurfaceTextureHelper.create(eglBase.getEglBaseContext()); |
185 final MockTextureListener listener = new MockTextureListener(); | 184 final MockTextureListener listener = new MockTextureListener(); |
186 surfaceTextureHelper.setListener(listener); | 185 surfaceTextureHelper.setListener(listener); |
187 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; | 186 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; |
188 | 187 |
189 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he SurfaceTexture in | 188 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he SurfaceTexture in |
190 // |surfaceTextureHelper| as the target EGLSurface. | 189 // |surfaceTextureHelper| as the target EGLSurface. |
191 final EglBase eglOesBase = new EglBase(eglBase.getContext(), EglBase.ConfigT
ype.PLAIN); | 190 final EglBase eglOesBase = |
| 191 EglBase.create(eglBase.getEglBaseContext(), EglBase.ConfigType.PLAIN); |
192 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 192 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
193 assertEquals(eglOesBase.surfaceWidth(), width); | 193 assertEquals(eglOesBase.surfaceWidth(), width); |
194 assertEquals(eglOesBase.surfaceHeight(), height); | 194 assertEquals(eglOesBase.surfaceHeight(), height); |
195 | 195 |
196 final int red = 79; | 196 final int red = 79; |
197 final int green = 66; | 197 final int green = 66; |
198 final int blue = 161; | 198 final int blue = 161; |
199 // Draw a constant color frame onto the SurfaceTexture. | 199 // Draw a constant color frame onto the SurfaceTexture. |
200 eglOesBase.makeCurrent(); | 200 eglOesBase.makeCurrent(); |
201 GLES20.glClearColor(red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); | 201 GLES20.glClearColor(red / 255.0f, green / 255.0f, blue / 255.0f, 1.0f); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 | 234 |
235 /** | 235 /** |
236 * Test disconnecting the SurfaceTextureHelper, but keep trying to produce mor
e texture frames. No | 236 * Test disconnecting the SurfaceTextureHelper, but keep trying to produce mor
e texture frames. No |
237 * frames should be delivered to the listener. | 237 * frames should be delivered to the listener. |
238 */ | 238 */ |
239 @MediumTest | 239 @MediumTest |
240 public static void testDisconnect() throws InterruptedException { | 240 public static void testDisconnect() throws InterruptedException { |
241 // Create SurfaceTextureHelper and listener. | 241 // Create SurfaceTextureHelper and listener. |
242 final SurfaceTextureHelper surfaceTextureHelper = | 242 final SurfaceTextureHelper surfaceTextureHelper = |
243 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT); | 243 SurfaceTextureHelper.create(null); |
244 final MockTextureListener listener = new MockTextureListener(); | 244 final MockTextureListener listener = new MockTextureListener(); |
245 surfaceTextureHelper.setListener(listener); | 245 surfaceTextureHelper.setListener(listener); |
246 // Create EglBase with the SurfaceTexture as target EGLSurface. | 246 // Create EglBase with the SurfaceTexture as target EGLSurface. |
247 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PLAIN); | 247 final EglBase eglBase = EglBase.create(null, EglBase.ConfigType.PLAIN); |
248 eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 248 eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
249 eglBase.makeCurrent(); | 249 eglBase.makeCurrent(); |
250 // Assert no frame has been received yet. | 250 // Assert no frame has been received yet. |
251 assertFalse(listener.waitForNewFrame(1)); | 251 assertFalse(listener.waitForNewFrame(1)); |
252 // Draw and wait for one frame. | 252 // Draw and wait for one frame. |
253 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 253 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
254 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). | 254 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
255 eglBase.swapBuffers(); | 255 eglBase.swapBuffers(); |
256 listener.waitForNewFrame(); | 256 listener.waitForNewFrame(); |
257 surfaceTextureHelper.returnTextureFrame(); | 257 surfaceTextureHelper.returnTextureFrame(); |
(...skipping 11 matching lines...) Expand all Loading... |
269 eglBase.release(); | 269 eglBase.release(); |
270 } | 270 } |
271 | 271 |
272 /** | 272 /** |
273 * Test disconnecting the SurfaceTextureHelper immediately after is has been s
etup to use a | 273 * Test disconnecting the SurfaceTextureHelper immediately after is has been s
etup to use a |
274 * shared context. No frames should be delivered to the listener. | 274 * shared context. No frames should be delivered to the listener. |
275 */ | 275 */ |
276 @SmallTest | 276 @SmallTest |
277 public static void testDisconnectImmediately() { | 277 public static void testDisconnectImmediately() { |
278 final SurfaceTextureHelper surfaceTextureHelper = | 278 final SurfaceTextureHelper surfaceTextureHelper = |
279 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT); | 279 SurfaceTextureHelper.create(null); |
280 surfaceTextureHelper.disconnect(); | 280 surfaceTextureHelper.disconnect(); |
281 } | 281 } |
282 | 282 |
283 /** | 283 /** |
284 * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame
is created and | 284 * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame
is created and |
285 * received on a thread separate from the test thread. | 285 * received on a thread separate from the test thread. |
286 */ | 286 */ |
287 @MediumTest | 287 @MediumTest |
288 public static void testFrameOnSeparateThread() throws InterruptedException { | 288 public static void testFrameOnSeparateThread() throws InterruptedException { |
289 final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThre
ad"); | 289 final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThre
ad"); |
290 thread.start(); | 290 thread.start(); |
291 final Handler handler = new Handler(thread.getLooper()); | 291 final Handler handler = new Handler(thread.getLooper()); |
292 | 292 |
293 // Create SurfaceTextureHelper and listener. | 293 // Create SurfaceTextureHelper and listener. |
294 final SurfaceTextureHelper surfaceTextureHelper = | 294 final SurfaceTextureHelper surfaceTextureHelper = |
295 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT, handler); | 295 SurfaceTextureHelper.create(null, handler); |
296 // Create a mock listener and expect frames to be delivered on |thread|. | 296 // Create a mock listener and expect frames to be delivered on |thread|. |
297 final MockTextureListener listener = new MockTextureListener(thread); | 297 final MockTextureListener listener = new MockTextureListener(thread); |
298 surfaceTextureHelper.setListener(listener); | 298 surfaceTextureHelper.setListener(listener); |
299 | 299 |
300 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he | 300 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he |
301 // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface. | 301 // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface. |
302 final EglBase eglOesBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigT
ype.PLAIN); | 302 final EglBase eglOesBase = EglBase.create(null, EglBase.ConfigType.PLAIN); |
303 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 303 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
304 eglOesBase.makeCurrent(); | 304 eglOesBase.makeCurrent(); |
305 // Draw a frame onto the SurfaceTexture. | 305 // Draw a frame onto the SurfaceTexture. |
306 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 306 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
307 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). | 307 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
308 eglOesBase.swapBuffers(); | 308 eglOesBase.swapBuffers(); |
309 eglOesBase.release(); | 309 eglOesBase.release(); |
310 | 310 |
311 // Wait for an OES texture to arrive. | 311 // Wait for an OES texture to arrive. |
312 listener.waitForNewFrame(); | 312 listener.waitForNewFrame(); |
313 | 313 |
314 // Return the frame from this thread. | 314 // Return the frame from this thread. |
315 surfaceTextureHelper.returnTextureFrame(); | 315 surfaceTextureHelper.returnTextureFrame(); |
316 surfaceTextureHelper.disconnect(handler); | 316 surfaceTextureHelper.disconnect(handler); |
317 } | 317 } |
318 | 318 |
319 /** | 319 /** |
320 * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame
is created and | 320 * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame
is created and |
321 * received on a thread separate from the test thread and returned after disco
nnect. | 321 * received on a thread separate from the test thread and returned after disco
nnect. |
322 */ | 322 */ |
323 @MediumTest | 323 @MediumTest |
324 public static void testLateReturnFrameOnSeparateThread() throws InterruptedExc
eption { | 324 public static void testLateReturnFrameOnSeparateThread() throws InterruptedExc
eption { |
325 final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThre
ad"); | 325 final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThre
ad"); |
326 thread.start(); | 326 thread.start(); |
327 final Handler handler = new Handler(thread.getLooper()); | 327 final Handler handler = new Handler(thread.getLooper()); |
328 | 328 |
329 // Create SurfaceTextureHelper and listener. | 329 // Create SurfaceTextureHelper and listener. |
330 final SurfaceTextureHelper surfaceTextureHelper = | 330 final SurfaceTextureHelper surfaceTextureHelper = |
331 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT, handler); | 331 SurfaceTextureHelper.create(null, handler); |
332 // Create a mock listener and expect frames to be delivered on |thread|. | 332 // Create a mock listener and expect frames to be delivered on |thread|. |
333 final MockTextureListener listener = new MockTextureListener(thread); | 333 final MockTextureListener listener = new MockTextureListener(thread); |
334 surfaceTextureHelper.setListener(listener); | 334 surfaceTextureHelper.setListener(listener); |
335 | 335 |
336 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he | 336 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he |
337 // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface. | 337 // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface. |
338 final EglBase eglOesBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigT
ype.PLAIN); | 338 final EglBase eglOesBase = EglBase.create(null, EglBase.ConfigType.PLAIN); |
339 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 339 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
340 eglOesBase.makeCurrent(); | 340 eglOesBase.makeCurrent(); |
341 // Draw a frame onto the SurfaceTexture. | 341 // Draw a frame onto the SurfaceTexture. |
342 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 342 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
343 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). | 343 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
344 eglOesBase.swapBuffers(); | 344 eglOesBase.swapBuffers(); |
345 eglOesBase.release(); | 345 eglOesBase.release(); |
346 | 346 |
347 // Wait for an OES texture to arrive. | 347 // Wait for an OES texture to arrive. |
348 listener.waitForNewFrame(); | 348 listener.waitForNewFrame(); |
349 | 349 |
350 surfaceTextureHelper.disconnect(handler); | 350 surfaceTextureHelper.disconnect(handler); |
351 | 351 |
352 surfaceTextureHelper.returnTextureFrame(); | 352 surfaceTextureHelper.returnTextureFrame(); |
353 } | 353 } |
354 } | 354 } |
OLD | NEW |