Index: talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java |
diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java |
index 71bd5e3561da14888cfea5324d0171a282b7ebdb..8708ffd7f3ff9eb5a0da91be0a1acb224681be9d 100644 |
--- a/talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java |
+++ b/talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java |
@@ -54,9 +54,53 @@ public class GlRectDrawerTest extends ActivityTestCase { |
} |
@SmallTest |
+ public void testRgbRendering() throws Exception { |
+ // Create EGL base with a pixel buffer as display output. |
+ final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL_BUFFER); |
+ eglBase.createPbufferSurface(WIDTH, HEIGHT); |
+ eglBase.makeCurrent(); |
+ |
+ // Create RGB byte buffer plane with random content. |
+ final ByteBuffer rgbaPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3); |
+ final Random random = new Random(SEED); |
+ random.nextBytes(rgbaPlane.array()); |
+ |
+ // Upload the RGB byte buffer data as a texture. |
+ final int rgbaTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); |
+ GLES20.glActiveTexture(GLES20.GL_TEXTURE0); |
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, rgbaTexture); |
+ GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, WIDTH, |
+ HEIGHT, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, rgbaPlane); |
+ |
+ // Draw the RGB frame onto the pixel buffer. |
+ final GlRectDrawer drawer = new GlRectDrawer(); |
+ final float[] identityMatrix = new float[16]; |
+ Matrix.setIdentityM(identityMatrix, 0); |
+ drawer.drawRgb(rgbaTexture, identityMatrix); |
+ |
+ // Download the pixels in the pixel buffer as RGBA. |
+ final ByteBuffer data = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 4); |
+ GLES20.glReadPixels(0, 0, WIDTH, HEIGHT, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data); |
hbos
2015/09/24 11:37:38
Why read RGBA and not just RGB?
magjed_webrtc
2015/09/24 12:15:17
Done. I switched to RGB without alpha.
|
+ |
+ // Assert rendered image is pixel perfect to source RGB. |
+ for (int y = 0; y < HEIGHT; ++y) { |
+ for (int x = 0; x < WIDTH; ++x) { |
+ assertEquals("Red", data.get() & 0xFF, rgbaPlane.get() & 0xFF); |
+ assertEquals("Green", data.get() & 0xFF, rgbaPlane.get() & 0xFF); |
+ assertEquals("Blue", data.get() & 0xFF, rgbaPlane.get() & 0xFF); |
+ assertEquals("Alpha", data.get() & 0xFF, 255); |
+ } |
+ } |
+ |
+ drawer.release(); |
+ GLES20.glDeleteTextures(1, new int[] {rgbaTexture}, 0); |
+ eglBase.release(); |
+ } |
+ |
+ @SmallTest |
public void testYuvRendering() throws Exception { |
// Create EGL base with a pixel buffer as display output. |
- EglBase eglBase = eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL_BUFFER); |
+ EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL_BUFFER); |
eglBase.createPbufferSurface(WIDTH, HEIGHT); |
eglBase.makeCurrent(); |