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, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 package org.webrtc; | 27 package org.webrtc; |
28 | 28 |
| 29 import android.graphics.SurfaceTexture; |
| 30 import android.opengl.GLES20; |
| 31 import android.opengl.Matrix; |
29 import android.test.ActivityTestCase; | 32 import android.test.ActivityTestCase; |
| 33 import android.test.suitebuilder.annotation.MediumTest; |
30 import android.test.suitebuilder.annotation.SmallTest; | 34 import android.test.suitebuilder.annotation.SmallTest; |
31 import android.test.suitebuilder.annotation.MediumTest; | |
32 | 35 |
33 import java.nio.ByteBuffer; | 36 import java.nio.ByteBuffer; |
34 import java.util.Random; | 37 import java.util.Random; |
35 | 38 |
36 import android.graphics.SurfaceTexture; | 39 import javax.microedition.khronos.egl.EGL10; |
37 import android.opengl.EGL14; | 40 import javax.microedition.khronos.egl.EGLContext; |
38 import android.opengl.EGLContext; | |
39 import android.opengl.GLES20; | |
40 import android.opengl.Matrix; | |
41 | 41 |
42 public final class GlRectDrawerTest extends ActivityTestCase { | 42 public final class GlRectDrawerTest extends ActivityTestCase { |
43 // Resolution of the test image. | 43 // Resolution of the test image. |
44 private static final int WIDTH = 16; | 44 private static final int WIDTH = 16; |
45 private static final int HEIGHT = 16; | 45 private static final int HEIGHT = 16; |
46 // Seed for random pixel creation. | 46 // Seed for random pixel creation. |
47 private static final int SEED = 42; | 47 private static final int SEED = 42; |
48 // When comparing pixels, allow some slack for float arithmetic and integer ro
unding. | 48 // When comparing pixels, allow some slack for float arithmetic and integer ro
unding. |
49 private static final float MAX_DIFF = 1.0f; | 49 private static final float MAX_DIFF = 1.0f; |
50 | 50 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 // Drop alpha. | 94 // Drop alpha. |
95 rgbaBuffer.get(); | 95 rgbaBuffer.get(); |
96 } | 96 } |
97 return rgbBuffer; | 97 return rgbBuffer; |
98 } | 98 } |
99 | 99 |
100 @SmallTest | 100 @SmallTest |
101 public void testRgbRendering() { | 101 public void testRgbRendering() { |
102 // Create EGL base with a pixel buffer as display output. | 102 // Create EGL base with a pixel buffer as display output. |
103 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); | 103 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); |
104 eglBase.createPbufferSurface(WIDTH, HEIGHT); | 104 eglBase.createPbufferSurface(WIDTH, HEIGHT); |
105 eglBase.makeCurrent(); | 105 eglBase.makeCurrent(); |
106 | 106 |
107 // Create RGB byte buffer plane with random content. | 107 // Create RGB byte buffer plane with random content. |
108 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3); | 108 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3); |
109 final Random random = new Random(SEED); | 109 final Random random = new Random(SEED); |
110 random.nextBytes(rgbPlane.array()); | 110 random.nextBytes(rgbPlane.array()); |
111 | 111 |
112 // Upload the RGB byte buffer data as a texture. | 112 // Upload the RGB byte buffer data as a texture. |
113 final int rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); | 113 final int rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); |
(...skipping 16 matching lines...) Expand all Loading... |
130 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane); | 130 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane); |
131 | 131 |
132 drawer.release(); | 132 drawer.release(); |
133 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0); | 133 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0); |
134 eglBase.release(); | 134 eglBase.release(); |
135 } | 135 } |
136 | 136 |
137 @SmallTest | 137 @SmallTest |
138 public void testYuvRendering() { | 138 public void testYuvRendering() { |
139 // Create EGL base with a pixel buffer as display output. | 139 // Create EGL base with a pixel buffer as display output. |
140 EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL
_BUFFER); | 140 EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL
_BUFFER); |
141 eglBase.createPbufferSurface(WIDTH, HEIGHT); | 141 eglBase.createPbufferSurface(WIDTH, HEIGHT); |
142 eglBase.makeCurrent(); | 142 eglBase.makeCurrent(); |
143 | 143 |
144 // Create YUV byte buffer planes with random content. | 144 // Create YUV byte buffer planes with random content. |
145 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; | 145 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; |
146 final Random random = new Random(SEED); | 146 final Random random = new Random(SEED); |
147 for (int i = 0; i < 3; ++i) { | 147 for (int i = 0; i < 3; ++i) { |
148 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); | 148 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); |
149 random.nextBytes(yuvPlanes[i].array()); | 149 random.nextBytes(yuvPlanes[i].array()); |
150 } | 150 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 259 |
260 public void release() { | 260 public void release() { |
261 eglBase.makeCurrent(); | 261 eglBase.makeCurrent(); |
262 drawer.release(); | 262 drawer.release(); |
263 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0); | 263 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0); |
264 eglBase.release(); | 264 eglBase.release(); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 // Create EGL base with a pixel buffer as display output. | 268 // Create EGL base with a pixel buffer as display output. |
269 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); | 269 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); |
270 eglBase.createPbufferSurface(WIDTH, HEIGHT); | 270 eglBase.createPbufferSurface(WIDTH, HEIGHT); |
271 | 271 |
272 // Create resources for generating OES textures. | 272 // Create resources for generating OES textures. |
273 final SurfaceTextureHelper surfaceTextureHelper = | 273 final SurfaceTextureHelper surfaceTextureHelper = |
274 SurfaceTextureHelper.create(eglBase.getContext()); | 274 SurfaceTextureHelper.create(eglBase.getContext()); |
275 final StubOesTextureProducer oesProducer = new StubOesTextureProducer( | 275 final StubOesTextureProducer oesProducer = new StubOesTextureProducer( |
276 eglBase.getContext(), surfaceTextureHelper.getSurfaceTexture(), WIDTH, H
EIGHT); | 276 eglBase.getContext(), surfaceTextureHelper.getSurfaceTexture(), WIDTH, H
EIGHT); |
277 final SurfaceTextureHelperTest.MockTextureListener listener = | 277 final SurfaceTextureHelperTest.MockTextureListener listener = |
278 new SurfaceTextureHelperTest.MockTextureListener(); | 278 new SurfaceTextureHelperTest.MockTextureListener(); |
279 surfaceTextureHelper.setListener(listener); | 279 surfaceTextureHelper.setListener(listener); |
(...skipping 21 matching lines...) Expand all Loading... |
301 // Assert rendered image is pixel perfect to source RGB. | 301 // Assert rendered image is pixel perfect to source RGB. |
302 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane); | 302 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane); |
303 | 303 |
304 drawer.release(); | 304 drawer.release(); |
305 surfaceTextureHelper.returnTextureFrame(); | 305 surfaceTextureHelper.returnTextureFrame(); |
306 oesProducer.release(); | 306 oesProducer.release(); |
307 surfaceTextureHelper.disconnect(); | 307 surfaceTextureHelper.disconnect(); |
308 eglBase.release(); | 308 eglBase.release(); |
309 } | 309 } |
310 } | 310 } |
OLD | NEW |