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 // This values are picked so that RGB -> YUV on the CPU converted |
reveman
2015/11/01 14:19:05
nit: "These values.."
Daniele Castagna
2015/11/01 21:55:31
Done.
| |
94 // back to RGB on the GPU produces the original RGB values without | |
95 // any error. | |
96 const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; | |
93 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; | 97 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; |
94 | 98 |
95 GLuint framebuffer = | 99 GLuint framebuffer = |
96 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); | 100 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
97 ASSERT_TRUE(framebuffer); | 101 ASSERT_TRUE(framebuffer); |
98 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); | 102 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
99 glViewport(0, 0, image_size.width(), image_size.height()); | 103 glViewport(0, 0, image_size.width(), image_size.height()); |
100 | 104 |
101 // Create a solid color green image of preferred format. This must succeed | 105 // Create a solid color green image of preferred format. This must succeed |
102 // in order for a GLImage to be conformant. | 106 // in order for a GLImage to be conformant. |
103 scoped_refptr<gl::GLImage> image = | 107 scoped_refptr<gl::GLImage> image = |
104 this->delegate_.CreateSolidColorImage(image_size, image_color); | 108 this->delegate_.CreateSolidColorImage(image_size, image_color); |
105 ASSERT_TRUE(image); | 109 ASSERT_TRUE(image); |
106 | 110 |
107 // Create a solid color blue texture of the same size as |image|. | 111 // Create a solid color blue texture of the same size as |image|. |
108 GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); | 112 GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); |
109 scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( | 113 scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( |
110 image_size, BufferFormat::RGBA_8888)]); | 114 image_size, BufferFormat::RGBA_8888)]); |
111 GLImageTestSupport::SetBufferDataToColor( | 115 GLImageTestSupport::SetBufferDataToColor( |
112 image_size.width(), image_size.height(), | 116 image_size.width(), image_size.height(), |
113 static_cast<int>(RowSizeForBufferFormat(image_size.width(), | 117 static_cast<int>(RowSizeForBufferFormat(image_size.width(), |
114 BufferFormat::RGBA_8888, 0)), | 118 BufferFormat::RGBA_8888, 0)), |
115 BufferFormat::RGBA_8888, texture_color, pixels.get()); | 119 0, BufferFormat::RGBA_8888, texture_color, pixels.get()); |
116 // Note: This test assume that |image| can be used with GL_TEXTURE_2D but | 120 // Note: This test assume that |image| can be used with GL_TEXTURE_2D but |
117 // that might not be the case for some GLImage implementations. | 121 // that might not be the case for some GLImage implementations. |
118 glBindTexture(GL_TEXTURE_2D, texture); | 122 glBindTexture(GL_TEXTURE_2D, texture); |
119 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_size.width(), | 123 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_size.width(), |
120 image_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 124 image_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
121 | 125 |
122 // Copy |image| to |texture|. | 126 // Copy |image| to |texture|. |
123 bool rv = image->CopyTexImage(GL_TEXTURE_2D); | 127 bool rv = image->CopyTexImage(GL_TEXTURE_2D); |
124 EXPECT_TRUE(rv); | 128 EXPECT_TRUE(rv); |
125 | 129 |
(...skipping 12 matching lines...) Expand all Loading... | |
138 varying vec2 v_texCoord; | 142 varying vec2 v_texCoord; |
139 void main() { | 143 void main() { |
140 gl_FragColor = texture2D(a_texture, v_texCoord); | 144 gl_FragColor = texture2D(a_texture, v_texCoord); |
141 } | 145 } |
142 ); | 146 ); |
143 const char kShaderFloatPrecision[] = STRINGIZE( | 147 const char kShaderFloatPrecision[] = STRINGIZE( |
144 precision mediump float; | 148 precision mediump float; |
145 ); | 149 ); |
146 // clang-format on | 150 // clang-format on |
147 | 151 |
148 GLuint vertex_shader = | 152 GLuint vertex_shader = GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); |
149 GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); | |
150 bool is_gles = GetGLImplementation() == kGLImplementationEGLGLES2; | 153 bool is_gles = GetGLImplementation() == kGLImplementationEGLGLES2; |
151 GLuint fragment_shader = GLTestHelper::LoadShader( | 154 GLuint fragment_shader = GLHelper::LoadShader( |
152 GL_FRAGMENT_SHADER, | 155 GL_FRAGMENT_SHADER, |
153 base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "", | 156 base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "", |
154 kFragmentShader) | 157 kFragmentShader) |
155 .c_str()); | 158 .c_str()); |
156 GLuint program = GLTestHelper::SetupProgram(vertex_shader, fragment_shader); | 159 GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader); |
157 EXPECT_NE(program, 0u); | 160 EXPECT_NE(program, 0u); |
158 glUseProgram(program); | 161 glUseProgram(program); |
159 | 162 |
160 GLint sampler_location = glGetUniformLocation(program, "a_texture"); | 163 GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
161 ASSERT_NE(sampler_location, -1); | 164 ASSERT_NE(sampler_location, -1); |
162 glUniform1i(sampler_location, 0); | 165 glUniform1i(sampler_location, 0); |
163 | 166 |
164 // clang-format off | 167 // clang-format off |
165 static GLfloat vertices[] = { | 168 static GLfloat vertices[] = { |
166 -1.f, -1.f, 0.f, 0.f, | 169 -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); | 204 image->Destroy(true); |
202 } | 205 } |
203 | 206 |
204 // The GLImageCopyTest test case verifies that the GLImage implementation | 207 // The GLImageCopyTest test case verifies that the GLImage implementation |
205 // handles CopyTexImage correctly. | 208 // handles CopyTexImage correctly. |
206 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); | 209 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
207 | 210 |
208 } // namespace gfx | 211 } // namespace gfx |
209 | 212 |
210 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 213 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
OLD | NEW |