Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java

Issue 1461083002: Use EGL14 if supported on Android (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Changed VideoRendererGui to return an EglBase.Context. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | talk/app/webrtc/androidtests/src/org/webrtc/MediaCodecVideoEncoderTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
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; 29 import android.graphics.SurfaceTexture;
30 import android.opengl.GLES20; 30 import android.opengl.GLES20;
31 import android.opengl.Matrix;
32 import android.test.ActivityTestCase; 31 import android.test.ActivityTestCase;
33 import android.test.suitebuilder.annotation.MediumTest; 32 import android.test.suitebuilder.annotation.MediumTest;
34 import android.test.suitebuilder.annotation.SmallTest; 33 import android.test.suitebuilder.annotation.SmallTest;
35 34
36 import java.nio.ByteBuffer; 35 import java.nio.ByteBuffer;
37 import java.util.Random; 36 import java.util.Random;
38 37
39 import javax.microedition.khronos.egl.EGL10;
40 import javax.microedition.khronos.egl.EGLContext;
41
42 public final class GlRectDrawerTest extends ActivityTestCase { 38 public final class GlRectDrawerTest extends ActivityTestCase {
43 // Resolution of the test image. 39 // Resolution of the test image.
44 private static final int WIDTH = 16; 40 private static final int WIDTH = 16;
45 private static final int HEIGHT = 16; 41 private static final int HEIGHT = 16;
46 // Seed for random pixel creation. 42 // Seed for random pixel creation.
47 private static final int SEED = 42; 43 private static final int SEED = 42;
48 // When comparing pixels, allow some slack for float arithmetic and integer ro unding. 44 // When comparing pixels, allow some slack for float arithmetic and integer ro unding.
49 private static final float MAX_DIFF = 1.0f; 45 private static final float MAX_DIFF = 1.5f;
50 46
51 private static float normalizedByte(byte b) { 47 private static float normalizedByte(byte b) {
52 return (b & 0xFF) / 255.0f; 48 return (b & 0xFF) / 255.0f;
53 } 49 }
54 50
55 private static float saturatedConvert(float c) { 51 private static float saturatedConvert(float c) {
56 return 255.0f * Math.max(0, Math.min(c, 1)); 52 return 255.0f * Math.max(0, Math.min(c, 1));
57 } 53 }
58 54
59 // Assert RGB ByteBuffers are pixel perfect identical. 55 // Assert RGB ByteBuffers are pixel perfect identical.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 89 }
94 // Drop alpha. 90 // Drop alpha.
95 rgbaBuffer.get(); 91 rgbaBuffer.get();
96 } 92 }
97 return rgbBuffer; 93 return rgbBuffer;
98 } 94 }
99 95
100 @SmallTest 96 @SmallTest
101 public void testRgbRendering() { 97 public void testRgbRendering() {
102 // Create EGL base with a pixel buffer as display output. 98 // Create EGL base with a pixel buffer as display output.
103 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType .PIXEL_BUFFER); 99 final EglBase eglBase = EglBase.create(null, EglBase.ConfigType.PIXEL_BUFFER );
104 eglBase.createPbufferSurface(WIDTH, HEIGHT); 100 eglBase.createPbufferSurface(WIDTH, HEIGHT);
105 eglBase.makeCurrent(); 101 eglBase.makeCurrent();
106 102
107 // Create RGB byte buffer plane with random content. 103 // Create RGB byte buffer plane with random content.
108 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3); 104 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3);
109 final Random random = new Random(SEED); 105 final Random random = new Random(SEED);
110 random.nextBytes(rgbPlane.array()); 106 random.nextBytes(rgbPlane.array());
111 107
112 // Upload the RGB byte buffer data as a texture. 108 // Upload the RGB byte buffer data as a texture.
113 final int rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); 109 final int rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D);
(...skipping 16 matching lines...) Expand all
130 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane); 126 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane);
131 127
132 drawer.release(); 128 drawer.release();
133 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0); 129 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0);
134 eglBase.release(); 130 eglBase.release();
135 } 131 }
136 132
137 @SmallTest 133 @SmallTest
138 public void testYuvRendering() { 134 public void testYuvRendering() {
139 // Create EGL base with a pixel buffer as display output. 135 // Create EGL base with a pixel buffer as display output.
140 EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL _BUFFER); 136 EglBase eglBase = EglBase.create(null, EglBase.ConfigType.PIXEL_BUFFER);
141 eglBase.createPbufferSurface(WIDTH, HEIGHT); 137 eglBase.createPbufferSurface(WIDTH, HEIGHT);
142 eglBase.makeCurrent(); 138 eglBase.makeCurrent();
143 139
144 // Create YUV byte buffer planes with random content. 140 // Create YUV byte buffer planes with random content.
145 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; 141 final ByteBuffer[] yuvPlanes = new ByteBuffer[3];
146 final Random random = new Random(SEED); 142 final Random random = new Random(SEED);
147 for (int i = 0; i < 3; ++i) { 143 for (int i = 0; i < 3; ++i) {
148 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); 144 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT);
149 random.nextBytes(yuvPlanes[i].array()); 145 random.nextBytes(yuvPlanes[i].array());
150 } 146 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 public void testOesRendering() throws InterruptedException { 220 public void testOesRendering() throws InterruptedException {
225 /** 221 /**
226 * Stub class to convert RGB ByteBuffers to OES textures by drawing onto a S urfaceTexture. 222 * Stub class to convert RGB ByteBuffers to OES textures by drawing onto a S urfaceTexture.
227 */ 223 */
228 class StubOesTextureProducer { 224 class StubOesTextureProducer {
229 private final EglBase eglBase; 225 private final EglBase eglBase;
230 private final GlRectDrawer drawer; 226 private final GlRectDrawer drawer;
231 private final int rgbTexture; 227 private final int rgbTexture;
232 228
233 public StubOesTextureProducer( 229 public StubOesTextureProducer(
234 EGLContext sharedContext, SurfaceTexture surfaceTexture, int width, in t height) { 230 EglBase.Context sharedContext, SurfaceTexture surfaceTexture, int widt h,
235 eglBase = new EglBase(sharedContext, EglBase.ConfigType.PLAIN); 231 int height) {
232 eglBase = EglBase.create(sharedContext, EglBase.ConfigType.PLAIN);
236 surfaceTexture.setDefaultBufferSize(width, height); 233 surfaceTexture.setDefaultBufferSize(width, height);
237 eglBase.createSurface(surfaceTexture); 234 eglBase.createSurface(surfaceTexture);
238 assertEquals(eglBase.surfaceWidth(), width); 235 assertEquals(eglBase.surfaceWidth(), width);
239 assertEquals(eglBase.surfaceHeight(), height); 236 assertEquals(eglBase.surfaceHeight(), height);
240 237
241 drawer = new GlRectDrawer(); 238 drawer = new GlRectDrawer();
242 239
243 eglBase.makeCurrent(); 240 eglBase.makeCurrent();
244 rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); 241 rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D);
245 } 242 }
(...skipping 13 matching lines...) Expand all
259 256
260 public void release() { 257 public void release() {
261 eglBase.makeCurrent(); 258 eglBase.makeCurrent();
262 drawer.release(); 259 drawer.release();
263 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0); 260 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0);
264 eglBase.release(); 261 eglBase.release();
265 } 262 }
266 } 263 }
267 264
268 // Create EGL base with a pixel buffer as display output. 265 // Create EGL base with a pixel buffer as display output.
269 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType .PIXEL_BUFFER); 266 final EglBase eglBase = EglBase.create(null, EglBase.ConfigType.PIXEL_BUFFER );
270 eglBase.createPbufferSurface(WIDTH, HEIGHT); 267 eglBase.createPbufferSurface(WIDTH, HEIGHT);
271 268
272 // Create resources for generating OES textures. 269 // Create resources for generating OES textures.
273 final SurfaceTextureHelper surfaceTextureHelper = 270 final SurfaceTextureHelper surfaceTextureHelper =
274 SurfaceTextureHelper.create(eglBase.getContext()); 271 SurfaceTextureHelper.create(eglBase.getEglBaseContext());
275 final StubOesTextureProducer oesProducer = new StubOesTextureProducer( 272 final StubOesTextureProducer oesProducer = new StubOesTextureProducer(
276 eglBase.getContext(), surfaceTextureHelper.getSurfaceTexture(), WIDTH, H EIGHT); 273 eglBase.getEglBaseContext(), surfaceTextureHelper.getSurfaceTexture(), W IDTH, HEIGHT);
277 final SurfaceTextureHelperTest.MockTextureListener listener = 274 final SurfaceTextureHelperTest.MockTextureListener listener =
278 new SurfaceTextureHelperTest.MockTextureListener(); 275 new SurfaceTextureHelperTest.MockTextureListener();
279 surfaceTextureHelper.setListener(listener); 276 surfaceTextureHelper.setListener(listener);
280 277
281 // Create RGB byte buffer plane with random content. 278 // Create RGB byte buffer plane with random content.
282 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3); 279 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3);
283 final Random random = new Random(SEED); 280 final Random random = new Random(SEED);
284 random.nextBytes(rgbPlane.array()); 281 random.nextBytes(rgbPlane.array());
285 282
286 // Draw the frame and block until an OES texture is delivered. 283 // Draw the frame and block until an OES texture is delivered.
(...skipping 14 matching lines...) Expand all
301 // Assert rendered image is pixel perfect to source RGB. 298 // Assert rendered image is pixel perfect to source RGB.
302 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane); 299 assertEquals(WIDTH, HEIGHT, stripAlphaChannel(rgbaData), rgbPlane);
303 300
304 drawer.release(); 301 drawer.release();
305 surfaceTextureHelper.returnTextureFrame(); 302 surfaceTextureHelper.returnTextureFrame();
306 oesProducer.release(); 303 oesProducer.release();
307 surfaceTextureHelper.disconnect(); 304 surfaceTextureHelper.disconnect();
308 eglBase.release(); 305 eglBase.release();
309 } 306 }
310 } 307 }
OLDNEW
« no previous file with comments | « no previous file | talk/app/webrtc/androidtests/src/org/webrtc/MediaCodecVideoEncoderTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698