| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/tests/gl_test_utils.h" | 5 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 | 10 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, 0); | 202 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, 0); |
| 203 | 203 |
| 204 return vbo; | 204 return vbo; |
| 205 } | 205 } |
| 206 | 206 |
| 207 bool GLTestHelper::CheckPixels(GLint x, | 207 bool GLTestHelper::CheckPixels(GLint x, |
| 208 GLint y, | 208 GLint y, |
| 209 GLsizei width, | 209 GLsizei width, |
| 210 GLsizei height, | 210 GLsizei height, |
| 211 GLint tolerance, | 211 GLint tolerance, |
| 212 const uint8_t* color) { | 212 const uint8_t* color, |
| 213 int channel_count) { |
| 213 GLsizei size = width * height * 4; | 214 GLsizei size = width * height * 4; |
| 214 std::unique_ptr<uint8_t[]> pixels(new uint8_t[size]); | 215 std::unique_ptr<uint8_t[]> pixels(new uint8_t[size]); |
| 215 memset(pixels.get(), kCheckClearValue, size); | 216 memset(pixels.get(), kCheckClearValue, size); |
| 216 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 217 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
| 217 int bad_count = 0; | 218 int bad_count = 0; |
| 219 channel_count = channel_count > 4 ? 4 : channel_count; |
| 218 for (GLint yy = 0; yy < height; ++yy) { | 220 for (GLint yy = 0; yy < height; ++yy) { |
| 219 for (GLint xx = 0; xx < width; ++xx) { | 221 for (GLint xx = 0; xx < width; ++xx) { |
| 220 int offset = yy * width * 4 + xx * 4; | 222 int offset = yy * width * 4 + xx * 4; |
| 221 for (int jj = 0; jj < 4; ++jj) { | 223 for (int jj = 0; jj < channel_count; ++jj) { |
| 222 uint8_t actual = pixels[offset + jj]; | 224 uint8_t actual = pixels[offset + jj]; |
| 223 uint8_t expected = color[jj]; | 225 uint8_t expected = color[jj]; |
| 224 int diff = actual - expected; | 226 int diff = actual - expected; |
| 225 diff = diff < 0 ? -diff: diff; | 227 diff = diff < 0 ? -diff: diff; |
| 226 if (diff > tolerance) { | 228 if (diff > tolerance) { |
| 227 EXPECT_EQ(expected, actual) << " at " << (xx + x) << ", " << (yy + y) | 229 EXPECT_EQ(expected, actual) << " at " << (xx + x) << ", " << (yy + y) |
| 228 << " channel " << jj; | 230 << " channel " << jj; |
| 229 ++bad_count; | 231 ++bad_count; |
| 230 // Exit early just so we don't spam the log but we print enough | 232 // Exit early just so we don't spam the log but we print enough |
| 231 // to hopefully make it easy to diagnose the issue. | 233 // to hopefully make it easy to diagnose the issue. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 ASSERT_NE(vertex_buffer, 0u); | 353 ASSERT_NE(vertex_buffer, 0u); |
| 352 glUniform1i(sampler_location, 0); | 354 glUniform1i(sampler_location, 0); |
| 353 | 355 |
| 354 glDrawArrays(GL_TRIANGLES, 0, 6); | 356 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 355 | 357 |
| 356 glDeleteShader(vertex_shader); | 358 glDeleteShader(vertex_shader); |
| 357 glDeleteShader(fragment_shader); | 359 glDeleteShader(fragment_shader); |
| 358 glDeleteProgram(program); | 360 glDeleteProgram(program); |
| 359 glDeleteBuffers(1, &vertex_buffer); | 361 glDeleteBuffers(1, &vertex_buffer); |
| 360 } | 362 } |
| OLD | NEW |