| 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" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 glEnableVertexAttribArray(location); | 123 glEnableVertexAttribArray(location); |
| 124 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, 0); | 124 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, 0); |
| 125 | 125 |
| 126 return vbo; | 126 return vbo; |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool GLTestHelper::CheckPixels( | 129 bool GLTestHelper::CheckPixels( |
| 130 GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, | 130 GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, |
| 131 const uint8* color) { | 131 const uint8* color) { |
| 132 GLsizei size = width * height * 4; | 132 GLsizei size = width * height * 4; |
| 133 scoped_array<uint8> pixels(new uint8[size]); | 133 scoped_ptr<uint8[]> pixels(new uint8[size]); |
| 134 memset(pixels.get(), kCheckClearValue, size); | 134 memset(pixels.get(), kCheckClearValue, size); |
| 135 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 135 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
| 136 int bad_count = 0; | 136 int bad_count = 0; |
| 137 for (GLint yy = 0; yy < height; ++yy) { | 137 for (GLint yy = 0; yy < height; ++yy) { |
| 138 for (GLint xx = 0; xx < width; ++xx) { | 138 for (GLint xx = 0; xx < width; ++xx) { |
| 139 int offset = yy * width * 4 + xx * 4; | 139 int offset = yy * width * 4 + xx * 4; |
| 140 for (int jj = 0; jj < 4; ++jj) { | 140 for (int jj = 0; jj < 4; ++jj) { |
| 141 uint8 actual = pixels[offset + jj]; | 141 uint8 actual = pixels[offset + jj]; |
| 142 uint8 expected = color[jj]; | 142 uint8 expected = color[jj]; |
| 143 int diff = actual - expected; | 143 int diff = actual - expected; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool GLTestHelper::SaveBackbufferAsBMP( | 198 bool GLTestHelper::SaveBackbufferAsBMP( |
| 199 const char* filename, int width, int height) { | 199 const char* filename, int width, int height) { |
| 200 FILE* fp = fopen(filename, "wb"); | 200 FILE* fp = fopen(filename, "wb"); |
| 201 EXPECT_TRUE(fp != NULL); | 201 EXPECT_TRUE(fp != NULL); |
| 202 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 202 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 203 int num_pixels = width * height; | 203 int num_pixels = width * height; |
| 204 int size = num_pixels * 4; | 204 int size = num_pixels * 4; |
| 205 scoped_array<uint8> data(new uint8[size]); | 205 scoped_ptr<uint8[]> data(new uint8[size]); |
| 206 uint8* pixels = data.get(); | 206 uint8* pixels = data.get(); |
| 207 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 207 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 208 | 208 |
| 209 // RGBA to BGRA | 209 // RGBA to BGRA |
| 210 for (int ii = 0; ii < num_pixels; ++ii) { | 210 for (int ii = 0; ii < num_pixels; ++ii) { |
| 211 int offset = ii * 4; | 211 int offset = ii * 4; |
| 212 uint8 t = pixels[offset + 0]; | 212 uint8 t = pixels[offset + 0]; |
| 213 pixels[offset + 0] = pixels[offset + 2]; | 213 pixels[offset + 0] = pixels[offset + 2]; |
| 214 pixels[offset + 2] = t; | 214 pixels[offset + 2] = t; |
| 215 } | 215 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 238 fwrite(&bih, sizeof(bih), 1, fp); | 238 fwrite(&bih, sizeof(bih), 1, fp); |
| 239 fwrite(pixels, size, 1, fp); | 239 fwrite(pixels, size, 1, fp); |
| 240 fclose(fp); | 240 fclose(fp); |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 int GLTestHelper::RunTests(int argc, char** argv) { | 244 int GLTestHelper::RunTests(int argc, char** argv) { |
| 245 testing::InitGoogleMock(&argc, argv); | 245 testing::InitGoogleMock(&argc, argv); |
| 246 return RUN_ALL_TESTS(); | 246 return RUN_ALL_TESTS(); |
| 247 } | 247 } |
| OLD | NEW |