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 #include <string> | 6 #include <string> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
| 13 // GCC requires these declarations, but MSVC requires they not be present. |
| 14 #ifndef COMPILER_MSVC |
| 15 const uint8 GLTestHelper::kCheckClearValue; |
| 16 #endif |
| 17 |
13 bool GLTestHelper::HasExtension(const char* extension) { | 18 bool GLTestHelper::HasExtension(const char* extension) { |
14 std::string extensions( | 19 std::string extensions( |
15 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); | 20 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
16 return extensions.find(extension) != std::string::npos; | 21 return extensions.find(extension) != std::string::npos; |
17 } | 22 } |
18 | 23 |
19 bool GLTestHelper::CheckGLError(const char* msg, int line) { | 24 bool GLTestHelper::CheckGLError(const char* msg, int line) { |
20 bool success = true; | 25 bool success = true; |
21 GLenum error = GL_NO_ERROR; | 26 GLenum error = GL_NO_ERROR; |
22 while ((error = glGetError()) != GL_NO_ERROR) { | 27 while ((error = glGetError()) != GL_NO_ERROR) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, 0); | 106 glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, 0); |
102 | 107 |
103 return vbo; | 108 return vbo; |
104 } | 109 } |
105 | 110 |
106 bool GLTestHelper::CheckPixels( | 111 bool GLTestHelper::CheckPixels( |
107 GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, | 112 GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, |
108 const uint8* color) { | 113 const uint8* color) { |
109 GLsizei size = width * height * 4; | 114 GLsizei size = width * height * 4; |
110 scoped_array<uint8> pixels(new uint8[size]); | 115 scoped_array<uint8> pixels(new uint8[size]); |
111 memset(pixels.get(), 123, size); | 116 memset(pixels.get(), kCheckClearValue, size); |
112 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 117 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
113 bool same = true; | 118 bool same = true; |
114 for (GLint yy = 0; yy < height; ++yy) { | 119 for (GLint yy = 0; yy < height; ++yy) { |
115 for (GLint xx = 0; xx < width; ++xx) { | 120 for (GLint xx = 0; xx < width; ++xx) { |
116 int offset = yy * width * 4 + xx * 4; | 121 int offset = yy * width * 4 + xx * 4; |
117 for (int jj = 0; jj < 4; ++jj) { | 122 for (int jj = 0; jj < 4; ++jj) { |
118 uint8 actual = pixels[offset + jj]; | 123 uint8 actual = pixels[offset + jj]; |
119 uint8 expected = color[jj]; | 124 uint8 expected = color[jj]; |
120 int diff = actual - expected; | 125 int diff = actual - expected; |
121 diff = diff < 0 ? -diff: diff; | 126 diff = diff < 0 ? -diff: diff; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 fwrite(&bih, sizeof(bih), 1, fp); | 215 fwrite(&bih, sizeof(bih), 1, fp); |
211 fwrite(pixels, size, 1, fp); | 216 fwrite(pixels, size, 1, fp); |
212 fclose(fp); | 217 fclose(fp); |
213 return true; | 218 return true; |
214 } | 219 } |
215 | 220 |
216 int GLTestHelper::RunTests(int argc, char** argv) { | 221 int GLTestHelper::RunTests(int argc, char** argv) { |
217 testing::InitGoogleMock(&argc, argv); | 222 testing::InitGoogleMock(&argc, argv); |
218 return RUN_ALL_TESTS(); | 223 return RUN_ALL_TESTS(); |
219 } | 224 } |
OLD | NEW |