Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 private static float normalizedByte(byte b) { | 48 private static float normalizedByte(byte b) { |
| 49 return (b & 0xFF) / 255.0f; | 49 return (b & 0xFF) / 255.0f; |
| 50 } | 50 } |
| 51 | 51 |
| 52 private static float saturatedConvert(float c) { | 52 private static float saturatedConvert(float c) { |
| 53 return 255.0f * Math.max(0, Math.min(c, 1)); | 53 return 255.0f * Math.max(0, Math.min(c, 1)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 @SmallTest | 56 @SmallTest |
| 57 public void testRgbRendering() throws Exception { | |
| 58 // Create EGL base with a pixel buffer as display output. | |
| 59 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType .PIXEL_BUFFER); | |
| 60 eglBase.createPbufferSurface(WIDTH, HEIGHT); | |
| 61 eglBase.makeCurrent(); | |
| 62 | |
| 63 // Create RGB byte buffer plane with random content. | |
| 64 final ByteBuffer rgbaPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3); | |
| 65 final Random random = new Random(SEED); | |
| 66 random.nextBytes(rgbaPlane.array()); | |
| 67 | |
| 68 // Upload the RGB byte buffer data as a texture. | |
| 69 final int rgbaTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D); | |
| 70 GLES20.glActiveTexture(GLES20.GL_TEXTURE0); | |
| 71 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, rgbaTexture); | |
| 72 GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, WIDTH, | |
| 73 HEIGHT, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, rgbaPlane); | |
| 74 | |
| 75 // Draw the RGB frame onto the pixel buffer. | |
| 76 final GlRectDrawer drawer = new GlRectDrawer(); | |
| 77 final float[] identityMatrix = new float[16]; | |
| 78 Matrix.setIdentityM(identityMatrix, 0); | |
| 79 drawer.drawRgb(rgbaTexture, identityMatrix); | |
| 80 | |
| 81 // Download the pixels in the pixel buffer as RGBA. | |
| 82 final ByteBuffer data = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 4); | |
| 83 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.
| |
| 84 | |
| 85 // Assert rendered image is pixel perfect to source RGB. | |
| 86 for (int y = 0; y < HEIGHT; ++y) { | |
| 87 for (int x = 0; x < WIDTH; ++x) { | |
| 88 assertEquals("Red", data.get() & 0xFF, rgbaPlane.get() & 0xFF); | |
| 89 assertEquals("Green", data.get() & 0xFF, rgbaPlane.get() & 0xFF); | |
| 90 assertEquals("Blue", data.get() & 0xFF, rgbaPlane.get() & 0xFF); | |
| 91 assertEquals("Alpha", data.get() & 0xFF, 255); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 drawer.release(); | |
| 96 GLES20.glDeleteTextures(1, new int[] {rgbaTexture}, 0); | |
| 97 eglBase.release(); | |
| 98 } | |
| 99 | |
| 100 @SmallTest | |
| 57 public void testYuvRendering() throws Exception { | 101 public void testYuvRendering() throws Exception { |
| 58 // Create EGL base with a pixel buffer as display output. | 102 // Create EGL base with a pixel buffer as display output. |
| 59 EglBase eglBase = eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.Config Type.PIXEL_BUFFER); | 103 EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL _BUFFER); |
| 60 eglBase.createPbufferSurface(WIDTH, HEIGHT); | 104 eglBase.createPbufferSurface(WIDTH, HEIGHT); |
| 61 eglBase.makeCurrent(); | 105 eglBase.makeCurrent(); |
| 62 | 106 |
| 63 // Create YUV byte buffer planes with random content. | 107 // Create YUV byte buffer planes with random content. |
| 64 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; | 108 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; |
| 65 final Random random = new Random(SEED); | 109 final Random random = new Random(SEED); |
| 66 for (int i = 0; i < 3; ++i) { | 110 for (int i = 0; i < 3; ++i) { |
| 67 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); | 111 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); |
| 68 random.nextBytes(yuvPlanes[i].array()); | 112 random.nextBytes(yuvPlanes[i].array()); |
| 69 } | 113 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 assertTrue(Math.abs(actualBlue - expectedBlue) < MAX_DIFF); | 162 assertTrue(Math.abs(actualBlue - expectedBlue) < MAX_DIFF); |
| 119 assertEquals(actualAlpha, 255); | 163 assertEquals(actualAlpha, 255); |
| 120 } | 164 } |
| 121 } | 165 } |
| 122 | 166 |
| 123 drawer.release(); | 167 drawer.release(); |
| 124 GLES20.glDeleteTextures(3, yuvTextures, 0); | 168 GLES20.glDeleteTextures(3, yuvTextures, 0); |
| 125 eglBase.release(); | 169 eglBase.release(); |
| 126 } | 170 } |
| 127 } | 171 } |
| OLD | NEW |