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 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
18 | 18 |
19 // GCC requires these declarations, but MSVC requires they not be present. | 19 // GCC requires these declarations, but MSVC requires they not be present. |
20 #ifndef COMPILER_MSVC | 20 #ifndef COMPILER_MSVC |
21 const uint8_t GLTestHelper::kCheckClearValue; | 21 const uint8_t GLTestHelper::kCheckClearValue; |
22 #endif | 22 #endif |
23 | 23 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 return vbo; | 194 return vbo; |
195 } | 195 } |
196 | 196 |
197 bool GLTestHelper::CheckPixels(GLint x, | 197 bool GLTestHelper::CheckPixels(GLint x, |
198 GLint y, | 198 GLint y, |
199 GLsizei width, | 199 GLsizei width, |
200 GLsizei height, | 200 GLsizei height, |
201 GLint tolerance, | 201 GLint tolerance, |
202 const uint8_t* color) { | 202 const uint8_t* color) { |
203 GLsizei size = width * height * 4; | 203 GLsizei size = width * height * 4; |
204 scoped_ptr<uint8_t[]> pixels(new uint8_t[size]); | 204 std::unique_ptr<uint8_t[]> pixels(new uint8_t[size]); |
205 memset(pixels.get(), kCheckClearValue, size); | 205 memset(pixels.get(), kCheckClearValue, size); |
206 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 206 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
207 int bad_count = 0; | 207 int bad_count = 0; |
208 for (GLint yy = 0; yy < height; ++yy) { | 208 for (GLint yy = 0; yy < height; ++yy) { |
209 for (GLint xx = 0; xx < width; ++xx) { | 209 for (GLint xx = 0; xx < width; ++xx) { |
210 int offset = yy * width * 4 + xx * 4; | 210 int offset = yy * width * 4 + xx * 4; |
211 for (int jj = 0; jj < 4; ++jj) { | 211 for (int jj = 0; jj < 4; ++jj) { |
212 uint8_t actual = pixels[offset + jj]; | 212 uint8_t actual = pixels[offset + jj]; |
213 uint8_t expected = color[jj]; | 213 uint8_t expected = color[jj]; |
214 int diff = actual - expected; | 214 int diff = actual - expected; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 266 |
267 } | 267 } |
268 | 268 |
269 bool GLTestHelper::SaveBackbufferAsBMP( | 269 bool GLTestHelper::SaveBackbufferAsBMP( |
270 const char* filename, int width, int height) { | 270 const char* filename, int width, int height) { |
271 FILE* fp = fopen(filename, "wb"); | 271 FILE* fp = fopen(filename, "wb"); |
272 EXPECT_TRUE(fp != NULL); | 272 EXPECT_TRUE(fp != NULL); |
273 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 273 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
274 int num_pixels = width * height; | 274 int num_pixels = width * height; |
275 int size = num_pixels * 4; | 275 int size = num_pixels * 4; |
276 scoped_ptr<uint8_t[]> data(new uint8_t[size]); | 276 std::unique_ptr<uint8_t[]> data(new uint8_t[size]); |
277 uint8_t* pixels = data.get(); | 277 uint8_t* pixels = data.get(); |
278 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 278 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
279 | 279 |
280 // RGBA to BGRA | 280 // RGBA to BGRA |
281 for (int ii = 0; ii < num_pixels; ++ii) { | 281 for (int ii = 0; ii < num_pixels; ++ii) { |
282 int offset = ii * 4; | 282 int offset = ii * 4; |
283 uint8_t t = pixels[offset + 0]; | 283 uint8_t t = pixels[offset + 0]; |
284 pixels[offset + 0] = pixels[offset + 2]; | 284 pixels[offset + 0] = pixels[offset + 2]; |
285 pixels[offset + 2] = t; | 285 pixels[offset + 2] = t; |
286 } | 286 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 ASSERT_NE(sampler_location, -1); | 336 ASSERT_NE(sampler_location, -1); |
337 | 337 |
338 GLuint vertex_buffer = GLTestHelper::SetupUnitQuad(sampler_location); | 338 GLuint vertex_buffer = GLTestHelper::SetupUnitQuad(sampler_location); |
339 glDrawArrays(GL_TRIANGLES, 0, 6); | 339 glDrawArrays(GL_TRIANGLES, 0, 6); |
340 | 340 |
341 glDeleteShader(vertex_shader); | 341 glDeleteShader(vertex_shader); |
342 glDeleteShader(fragment_shader); | 342 glDeleteShader(fragment_shader); |
343 glDeleteProgram(program); | 343 glDeleteProgram(program); |
344 glDeleteBuffers(1, &vertex_buffer); | 344 glDeleteBuffers(1, &vertex_buffer); |
345 } | 345 } |
OLD | NEW |