| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
| 7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 8 | 10 |
| 9 #include <cmath> | 11 #include <cmath> |
| 10 | 12 |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "gpu/command_buffer/tests/gl_manager.h" | 18 #include "gpu/command_buffer/tests/gl_manager.h" |
| 18 #include "gpu/command_buffer/tests/gl_test_utils.h" | 19 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 EXPECT_EQ(data[0], 0); // red | 80 EXPECT_EQ(data[0], 0); // red |
| 80 EXPECT_EQ(data[1], 0); // green | 81 EXPECT_EQ(data[1], 0); // green |
| 81 EXPECT_EQ(data[2], 255); // blue | 82 EXPECT_EQ(data[2], 255); // blue |
| 82 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | 83 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); |
| 83 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 84 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 84 glDeleteBuffers(1, &b); | 85 glDeleteBuffers(1, &b); |
| 85 glDeleteQueriesEXT(1, &q); | 86 glDeleteQueriesEXT(1, &q); |
| 86 GLTestHelper::CheckGLError("no errors", __LINE__); | 87 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 87 } | 88 } |
| 88 | 89 |
| 89 static float HalfToFloat32(uint16 value) { | 90 static float HalfToFloat32(uint16_t value) { |
| 90 int32 s = (value >> 15) & 0x00000001; | 91 int32_t s = (value >> 15) & 0x00000001; |
| 91 int32 e = (value >> 10) & 0x0000001f; | 92 int32_t e = (value >> 10) & 0x0000001f; |
| 92 int32 m = value & 0x000003ff; | 93 int32_t m = value & 0x000003ff; |
| 93 | 94 |
| 94 if (e == 0) { | 95 if (e == 0) { |
| 95 if (m == 0) { | 96 if (m == 0) { |
| 96 uint32 result = s << 31; | 97 uint32_t result = s << 31; |
| 97 return bit_cast<float>(result); | 98 return bit_cast<float>(result); |
| 98 } else { | 99 } else { |
| 99 while (!(m & 0x00000400)) { | 100 while (!(m & 0x00000400)) { |
| 100 m <<= 1; | 101 m <<= 1; |
| 101 e -= 1; | 102 e -= 1; |
| 102 } | 103 } |
| 103 | 104 |
| 104 e += 1; | 105 e += 1; |
| 105 m &= ~0x00000400; | 106 m &= ~0x00000400; |
| 106 } | 107 } |
| 107 } else if (e == 31) { | 108 } else if (e == 31) { |
| 108 if (m == 0) { | 109 if (m == 0) { |
| 109 uint32 result = (s << 31) | 0x7f800000; | 110 uint32_t result = (s << 31) | 0x7f800000; |
| 110 return bit_cast<float>(result); | 111 return bit_cast<float>(result); |
| 111 } else { | 112 } else { |
| 112 uint32 result = (s << 31) | 0x7f800000 | (m << 13); | 113 uint32_t result = (s << 31) | 0x7f800000 | (m << 13); |
| 113 return bit_cast<float>(result); | 114 return bit_cast<float>(result); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 e = e + (127 - 15); | 118 e = e + (127 - 15); |
| 118 m = m << 13; | 119 m = m << 13; |
| 119 | 120 |
| 120 uint32 result = (s << 31) | (e << 23) | m; | 121 uint32_t result = (s << 31) | (e << 23) | m; |
| 121 return bit_cast<float>(result); | 122 return bit_cast<float>(result); |
| 122 } | 123 } |
| 123 | 124 |
| 124 static GLuint CompileShader(GLenum type, const char *data) { | 125 static GLuint CompileShader(GLenum type, const char *data) { |
| 125 const char *shaderStrings[1] = { data }; | 126 const char *shaderStrings[1] = { data }; |
| 126 | 127 |
| 127 GLuint shader = glCreateShader(type); | 128 GLuint shader = glCreateShader(type); |
| 128 glShaderSource(shader, 1, shaderStrings, NULL); | 129 glShaderSource(shader, 1, shaderStrings, NULL); |
| 129 glCompileShader(shader); | 130 glCompileShader(shader); |
| 130 | 131 |
| 131 GLint compile_status = 0; | 132 GLint compile_status = 0; |
| 132 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status); | 133 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status); |
| 133 if (compile_status != GL_TRUE) { | 134 if (compile_status != GL_TRUE) { |
| 134 glDeleteShader(shader); | 135 glDeleteShader(shader); |
| 135 shader = 0; | 136 shader = 0; |
| 136 } | 137 } |
| 137 | 138 |
| 138 return shader; | 139 return shader; |
| 139 } | 140 } |
| 140 | 141 |
| 141 TEST_F(GLReadbackTest, ReadPixelsFloat) { | 142 TEST_F(GLReadbackTest, ReadPixelsFloat) { |
| 142 const GLsizei kTextureSize = 4; | 143 const GLsizei kTextureSize = 4; |
| 143 const GLfloat kDrawColor[4] = { -10.9f, 0.5f, 10.5f, 100.12f }; | 144 const GLfloat kDrawColor[4] = { -10.9f, 0.5f, 10.5f, 100.12f }; |
| 144 const GLfloat kEpsilon = 0.01f; | 145 const GLfloat kEpsilon = 0.01f; |
| 145 | 146 |
| 146 struct TestFormat { | 147 struct TestFormat { |
| 147 GLint format; | 148 GLint format; |
| 148 GLint type; | 149 GLint type; |
| 149 uint32 comp_count; | 150 uint32_t comp_count; |
| 150 }; | 151 }; |
| 151 TestFormat test_formats[4]; | 152 TestFormat test_formats[4]; |
| 152 size_t test_count = 0; | 153 size_t test_count = 0; |
| 153 const char *extensions = reinterpret_cast<const char*>( | 154 const char *extensions = reinterpret_cast<const char*>( |
| 154 glGetString(GL_EXTENSIONS)); | 155 glGetString(GL_EXTENSIONS)); |
| 155 if (strstr(extensions, "GL_OES_texture_half_float") != NULL) { | 156 if (strstr(extensions, "GL_OES_texture_half_float") != NULL) { |
| 156 TestFormat rgb16f = { GL_RGB, GL_HALF_FLOAT_OES, 3 }; | 157 TestFormat rgb16f = { GL_RGB, GL_HALF_FLOAT_OES, 3 }; |
| 157 test_formats[test_count++] = rgb16f; | 158 test_formats[test_count++] = rgb16f; |
| 158 | 159 |
| 159 TestFormat rgba16f = { GL_RGBA, GL_HALF_FLOAT_OES, 4 }; | 160 TestFormat rgba16f = { GL_RGBA, GL_HALF_FLOAT_OES, 4 }; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 GLint read_type = 0; | 254 GLint read_type = 0; |
| 254 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &read_type); | 255 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &read_type); |
| 255 | 256 |
| 256 EXPECT_EQ(glGetError(), GLenum(GL_NO_ERROR)); | 257 EXPECT_EQ(glGetError(), GLenum(GL_NO_ERROR)); |
| 257 | 258 |
| 258 if ((read_format == GL_RGB || read_format == GL_RGBA) && | 259 if ((read_format == GL_RGB || read_format == GL_RGBA) && |
| 259 read_type == test_formats[ii].type) { | 260 read_type == test_formats[ii].type) { |
| 260 glClear(GL_COLOR_BUFFER_BIT); | 261 glClear(GL_COLOR_BUFFER_BIT); |
| 261 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 262 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 262 | 263 |
| 263 uint32 read_comp_count = 0; | 264 uint32_t read_comp_count = 0; |
| 264 switch (read_format) { | 265 switch (read_format) { |
| 265 case GL_RGB: | 266 case GL_RGB: |
| 266 read_comp_count = 3; | 267 read_comp_count = 3; |
| 267 break; | 268 break; |
| 268 case GL_RGBA: | 269 case GL_RGBA: |
| 269 read_comp_count = 4; | 270 read_comp_count = 4; |
| 270 break; | 271 break; |
| 271 } | 272 } |
| 272 | 273 |
| 273 switch (read_type) { | 274 switch (read_type) { |
| 274 case GL_HALF_FLOAT_OES: { | 275 case GL_HALF_FLOAT_OES: { |
| 275 scoped_ptr<GLushort[]> buf( | 276 scoped_ptr<GLushort[]> buf( |
| 276 new GLushort[kTextureSize * kTextureSize * read_comp_count]); | 277 new GLushort[kTextureSize * kTextureSize * read_comp_count]); |
| 277 glReadPixels( | 278 glReadPixels( |
| 278 0, 0, kTextureSize, kTextureSize, read_format, read_type, | 279 0, 0, kTextureSize, kTextureSize, read_format, read_type, |
| 279 buf.get()); | 280 buf.get()); |
| 280 EXPECT_EQ(glGetError(), GLenum(GL_NO_ERROR)); | 281 EXPECT_EQ(glGetError(), GLenum(GL_NO_ERROR)); |
| 281 for (uint32 jj = 0; jj < kTextureSize * kTextureSize; ++jj) { | 282 for (uint32_t jj = 0; jj < kTextureSize * kTextureSize; ++jj) { |
| 282 for (uint32 kk = 0; kk < test_formats[ii].comp_count; ++kk) { | 283 for (uint32_t kk = 0; kk < test_formats[ii].comp_count; ++kk) { |
| 283 EXPECT_LE( | 284 EXPECT_LE( |
| 284 std::abs(HalfToFloat32(buf[jj * read_comp_count + kk]) - | 285 std::abs(HalfToFloat32(buf[jj * read_comp_count + kk]) - |
| 285 kDrawColor[kk]), | 286 kDrawColor[kk]), |
| 286 std::abs(kDrawColor[kk] * kEpsilon)); | 287 std::abs(kDrawColor[kk] * kEpsilon)); |
| 287 } | 288 } |
| 288 } | 289 } |
| 289 break; | 290 break; |
| 290 } | 291 } |
| 291 case GL_FLOAT: { | 292 case GL_FLOAT: { |
| 292 scoped_ptr<GLfloat[]> buf( | 293 scoped_ptr<GLfloat[]> buf( |
| 293 new GLfloat[kTextureSize * kTextureSize * read_comp_count]); | 294 new GLfloat[kTextureSize * kTextureSize * read_comp_count]); |
| 294 glReadPixels( | 295 glReadPixels( |
| 295 0, 0, kTextureSize, kTextureSize, read_format, read_type, | 296 0, 0, kTextureSize, kTextureSize, read_format, read_type, |
| 296 buf.get()); | 297 buf.get()); |
| 297 EXPECT_EQ(glGetError(), GLenum(GL_NO_ERROR)); | 298 EXPECT_EQ(glGetError(), GLenum(GL_NO_ERROR)); |
| 298 for (uint32 jj = 0; jj < kTextureSize * kTextureSize; ++jj) { | 299 for (uint32_t jj = 0; jj < kTextureSize * kTextureSize; ++jj) { |
| 299 for (uint32 kk = 0; kk < test_formats[ii].comp_count; ++kk) { | 300 for (uint32_t kk = 0; kk < test_formats[ii].comp_count; ++kk) { |
| 300 EXPECT_LE( | 301 EXPECT_LE( |
| 301 std::abs(buf[jj * read_comp_count + kk] - kDrawColor[kk]), | 302 std::abs(buf[jj * read_comp_count + kk] - kDrawColor[kk]), |
| 302 std::abs(kDrawColor[kk] * kEpsilon)); | 303 std::abs(kDrawColor[kk] * kEpsilon)); |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 break; | 306 break; |
| 306 } | 307 } |
| 307 } | 308 } |
| 308 } | 309 } |
| 309 } | 310 } |
| 310 | 311 |
| 311 glDeleteFramebuffers(1, &framebuffer); | 312 glDeleteFramebuffers(1, &framebuffer); |
| 312 glDeleteTextures(1, &texture_id); | 313 glDeleteTextures(1, &texture_id); |
| 313 } | 314 } |
| 314 | 315 |
| 315 glDeleteBuffers(1, &vertex_buffer); | 316 glDeleteBuffers(1, &vertex_buffer); |
| 316 glDeleteProgram(program); | 317 glDeleteProgram(program); |
| 317 } | 318 } |
| 318 | 319 |
| 319 } // namespace gpu | 320 } // namespace gpu |
| OLD | NEW |