OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/gl/test/gl_test_helper.h" | 5 #include "ui/gl/test/gl_test_helper.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 | 9 |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace gl { | 12 namespace gl { |
13 // static | 13 // static |
14 GLuint GLTestHelper::CreateTexture(GLenum target) { | 14 GLuint GLTestHelper::CreateTexture(GLenum target) { |
15 // Create the texture object. | 15 // Create the texture object. |
16 GLuint texture = 0; | 16 GLuint texture = 0; |
17 glGenTextures(1, &texture); | 17 glGenTextures(1, &texture); |
18 glBindTexture(target, texture); | 18 glBindTexture(target, texture); |
19 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 19 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
(...skipping 26 matching lines...) Expand all Loading... |
46 return framebuffer; | 46 return framebuffer; |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 bool GLTestHelper::CheckPixels(int x, | 50 bool GLTestHelper::CheckPixels(int x, |
51 int y, | 51 int y, |
52 int width, | 52 int width, |
53 int height, | 53 int height, |
54 const uint8_t expected_color[4]) { | 54 const uint8_t expected_color[4]) { |
55 int size = width * height * 4; | 55 int size = width * height * 4; |
56 scoped_ptr<uint8_t[]> pixels(new uint8_t[size]); | 56 std::unique_ptr<uint8_t[]> pixels(new uint8_t[size]); |
57 const uint8_t kCheckClearValue = 123u; | 57 const uint8_t kCheckClearValue = 123u; |
58 memset(pixels.get(), kCheckClearValue, size); | 58 memset(pixels.get(), kCheckClearValue, size); |
59 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 59 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
60 int bad_count = 0; | 60 int bad_count = 0; |
61 for (int yy = 0; yy < height; ++yy) { | 61 for (int yy = 0; yy < height; ++yy) { |
62 for (int xx = 0; xx < width; ++xx) { | 62 for (int xx = 0; xx < width; ++xx) { |
63 int offset = yy * width * 4 + xx * 4; | 63 int offset = yy * width * 4 + xx * 4; |
64 for (int jj = 0; jj < 4; ++jj) { | 64 for (int jj = 0; jj < 4; ++jj) { |
65 uint8_t actual = pixels[offset + jj]; | 65 uint8_t actual = pixels[offset + jj]; |
66 uint8_t expected = expected_color[jj]; | 66 uint8_t expected = expected_color[jj]; |
67 EXPECT_EQ(expected, actual) << " at " << (xx + x) << ", " << (yy + y) | 67 EXPECT_EQ(expected, actual) << " at " << (xx + x) << ", " << (yy + y) |
68 << " channel " << jj; | 68 << " channel " << jj; |
69 bad_count += actual != expected; | 69 bad_count += actual != expected; |
70 // Exit early just so we don't spam the log but we print enough to | 70 // Exit early just so we don't spam the log but we print enough to |
71 // hopefully make it easy to diagnose the issue. | 71 // hopefully make it easy to diagnose the issue. |
72 if (bad_count > 16) | 72 if (bad_count > 16) |
73 return false; | 73 return false; |
74 } | 74 } |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 return !bad_count; | 78 return !bad_count; |
79 } | 79 } |
80 | 80 |
81 } // namespace gl | 81 } // namespace gl |
OLD | NEW |