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 // This file defines tests that implementations of GLImage should pass in order | 5 // This file defines tests that implementations of GLImage should pass in order |
6 // to be conformant. | 6 // to be conformant. |
7 | 7 |
8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/stringize_macros.h" | 13 #include "base/strings/stringize_macros.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/buffer_format_util.h" | 16 #include "ui/gfx/buffer_format_util.h" |
17 #include "ui/gfx/buffer_types.h" | 17 #include "ui/gfx/buffer_types.h" |
18 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
19 #include "ui/gl/gl_context.h" | 19 #include "ui/gl/gl_context.h" |
20 #include "ui/gl/gl_helper.h" | |
20 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
21 #include "ui/gl/gl_implementation.h" | 22 #include "ui/gl/gl_implementation.h" |
22 #include "ui/gl/gl_surface.h" | 23 #include "ui/gl/gl_surface.h" |
23 #include "ui/gl/test/gl_image_test_support.h" | 24 #include "ui/gl/test/gl_image_test_support.h" |
24 #include "ui/gl/test/gl_test_helper.h" | 25 #include "ui/gl/test/gl_test_helper.h" |
25 | 26 |
26 namespace gfx { | 27 namespace gfx { |
27 | 28 |
28 template <typename GLImageTestDelegate> | 29 template <typename GLImageTestDelegate> |
29 class GLImageTest : public testing::Test { | 30 class GLImageTest : public testing::Test { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // GLImage in order to be conformant. | 83 // GLImage in order to be conformant. |
83 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy); | 84 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy); |
84 | 85 |
85 template <typename GLImageTestDelegate> | 86 template <typename GLImageTestDelegate> |
86 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {}; | 87 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {}; |
87 | 88 |
88 TYPED_TEST_CASE_P(GLImageCopyTest); | 89 TYPED_TEST_CASE_P(GLImageCopyTest); |
89 | 90 |
90 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) { | 91 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) { |
91 const Size image_size(256, 256); | 92 const Size image_size(256, 256); |
92 const uint8_t image_color[] = {0xff, 0xff, 0, 0xff}; | 93 const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; |
reveman
2015/10/29 22:08:04
nit: can you add a comment here to explain why the
Daniele Castagna
2015/10/30 23:51:57
Done.
| |
93 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; | 94 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; |
94 | 95 |
95 GLuint framebuffer = | 96 GLuint framebuffer = |
96 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); | 97 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
97 ASSERT_TRUE(framebuffer); | 98 ASSERT_TRUE(framebuffer); |
98 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); | 99 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
99 glViewport(0, 0, image_size.width(), image_size.height()); | 100 glViewport(0, 0, image_size.width(), image_size.height()); |
100 | 101 |
101 // Create a solid color green image of preferred format. This must succeed | 102 // Create a solid color green image of preferred format. This must succeed |
102 // in order for a GLImage to be conformant. | 103 // in order for a GLImage to be conformant. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 varying vec2 v_texCoord; | 139 varying vec2 v_texCoord; |
139 void main() { | 140 void main() { |
140 gl_FragColor = texture2D(a_texture, v_texCoord); | 141 gl_FragColor = texture2D(a_texture, v_texCoord); |
141 } | 142 } |
142 ); | 143 ); |
143 const char kShaderFloatPrecision[] = STRINGIZE( | 144 const char kShaderFloatPrecision[] = STRINGIZE( |
144 precision mediump float; | 145 precision mediump float; |
145 ); | 146 ); |
146 // clang-format on | 147 // clang-format on |
147 | 148 |
148 GLuint vertex_shader = | 149 GLuint vertex_shader = GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); |
149 GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); | |
150 bool is_gles = GetGLImplementation() == kGLImplementationEGLGLES2; | 150 bool is_gles = GetGLImplementation() == kGLImplementationEGLGLES2; |
151 GLuint fragment_shader = GLTestHelper::LoadShader( | 151 GLuint fragment_shader = GLHelper::LoadShader( |
152 GL_FRAGMENT_SHADER, | 152 GL_FRAGMENT_SHADER, |
153 base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "", | 153 base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "", |
154 kFragmentShader) | 154 kFragmentShader) |
155 .c_str()); | 155 .c_str()); |
156 GLuint program = GLTestHelper::SetupProgram(vertex_shader, fragment_shader); | 156 GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader); |
157 EXPECT_NE(program, 0u); | 157 EXPECT_NE(program, 0u); |
158 glUseProgram(program); | 158 glUseProgram(program); |
159 | 159 |
160 GLint sampler_location = glGetUniformLocation(program, "a_texture"); | 160 GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
161 ASSERT_NE(sampler_location, -1); | 161 ASSERT_NE(sampler_location, -1); |
162 glUniform1i(sampler_location, 0); | 162 glUniform1i(sampler_location, 0); |
163 | 163 |
164 // clang-format off | 164 // clang-format off |
165 static GLfloat vertices[] = { | 165 static GLfloat vertices[] = { |
166 -1.f, -1.f, 0.f, 0.f, | 166 -1.f, -1.f, 0.f, 0.f, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 image->Destroy(true); | 201 image->Destroy(true); |
202 } | 202 } |
203 | 203 |
204 // The GLImageCopyTest test case verifies that the GLImage implementation | 204 // The GLImageCopyTest test case verifies that the GLImage implementation |
205 // handles CopyTexImage correctly. | 205 // handles CopyTexImage correctly. |
206 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); | 206 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
207 | 207 |
208 } // namespace gfx | 208 } // namespace gfx |
209 | 209 |
210 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 210 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
OLD | NEW |