Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc

Issue 481913005: gpu: glCopyTextureCHROMIUM() checks dest internal format incorrectly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef GL_GLEXT_PROTOTYPES 5 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES 6 #define GL_GLEXT_PROTOTYPES
7 #endif 7 #endif
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 GLint value = 0; 66 GLint value = 0;
67 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); 67 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
68 GLuint fb_id = value; 68 GLuint fb_id = value;
69 EXPECT_EQ(framebuffer_id_, fb_id); 69 EXPECT_EQ(framebuffer_id_, fb_id);
70 70
71 // Check that FB is complete. 71 // Check that FB is complete.
72 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 72 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
73 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 73 glCheckFramebufferStatus(GL_FRAMEBUFFER));
74 74
75 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); 75 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
76 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 76 EXPECT_EQ(glGetError(), GL_NO_ERROR);
no sievers 2014/08/22 18:07:19 nit: EXPECT_EQ(GL_NO_ERROR, glGetError()) here and
dshwang 2014/08/22 19:07:55 Done.
dshwang 2014/08/22 19:11:42 ah... clang preprocessor converts macro to int whi
77 }
78
79 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormat) {
80 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA,
81 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT};
82 GLint dest_formats[] = {GL_RGB, GL_RGBA};
83
84 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) {
85 for (size_t dest_index = 0; dest_index < arraysize(dest_formats);
86 dest_index++) {
87 glBindTexture(GL_TEXTURE_2D, textures_[0]);
88 glTexImage2D(GL_TEXTURE_2D,
89 0,
90 src_formats[src_index],
91 1,
92 1,
93 0,
94 src_formats[src_index],
95 GL_UNSIGNED_BYTE,
96 NULL);
97 EXPECT_EQ(glGetError(), GL_NO_ERROR);
98
99 glCopyTextureCHROMIUM(GL_TEXTURE_2D,
100 textures_[0],
101 textures_[1],
102 0,
103 dest_formats[dest_index],
104 GL_UNSIGNED_BYTE);
105 EXPECT_EQ(glGetError(), GL_NO_ERROR) << "src_index:" << src_index
106 << " dest_index:" << dest_index;
107 }
108 }
109
no sievers 2014/08/22 18:07:19 nit: can you cut this off into a separate test her
dshwang 2014/08/22 19:07:55 Yes. I separated it.
110 glBindTexture(GL_TEXTURE_2D, textures_[0]);
111 glTexImage2D(
112 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
113 EXPECT_EQ(glGetError(), GL_NO_ERROR);
114
115 // Check unsupported format reports error.
116 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE,
117 GL_LUMINANCE_ALPHA, GL_BGRA_EXT};
118 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
119 dest_index++) {
120 glCopyTextureCHROMIUM(GL_TEXTURE_2D,
121 textures_[0],
122 textures_[1],
123 0,
124 unsupported_dest_formats[dest_index],
125 GL_UNSIGNED_BYTE);
126 EXPECT_EQ(glGetError(), GL_INVALID_VALUE) << "dest_index:" << dest_index;
127 }
128 }
129
130 // Test to ensure that the destination texture is redefined if the properties
131 // are different.
132 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) {
133 uint8 pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u,
134 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u};
135
136 glBindTexture(GL_TEXTURE_2D, textures_[0]);
137 glTexImage2D(
138 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
139
140 glBindTexture(GL_TEXTURE_2D, textures_[1]);
141 glTexImage2D(GL_TEXTURE_2D,
142 0,
143 GL_BGRA_EXT,
144 1,
145 1,
146 0,
147 GL_BGRA_EXT,
148 GL_UNSIGNED_BYTE,
149 pixels);
150 EXPECT_EQ(glGetError(), GL_NO_ERROR);
151
152 // GL_INVALID_OPERATION due to "intrinsic format" != "internal format".
153 glTexSubImage2D(
154 GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
155 EXPECT_EQ(glGetError(), GL_INVALID_OPERATION);
156 // GL_INVALID_VALUE due to bad dimensions.
157 glTexSubImage2D(
158 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
159 EXPECT_EQ(glGetError(), GL_INVALID_VALUE);
no sievers 2014/08/22 18:07:19 hmm not sure these tests for TexSubImage2D() behav
dshwang 2014/08/22 19:07:55 Yes, I piggy back TexSubImage2D()'s error check, b
160
161 // If the dest texture has different properties, glCopyTextureCHROMIUM()
162 // redefines them.
163 glCopyTextureCHROMIUM(
164 GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, GL_UNSIGNED_BYTE);
165 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
166
167 // glTexSubImage2D() succeeds because textures_[1] is redefined into 2x2
168 // dimension and GL_RGBA format.
169 glBindTexture(GL_TEXTURE_2D, textures_[1]);
170 glTexSubImage2D(
171 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
172 EXPECT_EQ(glGetError(), GL_NO_ERROR);
173
174 // Check the FB is still bound.
175 GLint value = 0;
176 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
177 GLuint fb_id = value;
178 EXPECT_EQ(framebuffer_id_, fb_id);
179
180 // Check that FB is complete.
181 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
182 glCheckFramebufferStatus(GL_FRAMEBUFFER));
183
184 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, pixels);
no sievers 2014/08/22 18:07:19 Althought you define all pixels to the same value
dshwang 2014/08/22 19:07:55 That's right. Now I compare it with &pixel[12]
185 EXPECT_EQ(glGetError(), GL_NO_ERROR);
77 } 186 }
78 187
79 // Test that the extension respects the flip-y pixel storage setting. 188 // Test that the extension respects the flip-y pixel storage setting.
80 TEST_F(GLCopyTextureCHROMIUMTest, FlipY) { 189 TEST_F(GLCopyTextureCHROMIUMTest, FlipY) {
81 uint8 pixels[2][2][4]; 190 uint8 pixels[2][2][4];
82 for (int x = 0; x < 2; ++x) { 191 for (int x = 0; x < 2; ++x) {
83 for (int y = 0; y < 2; ++y) { 192 for (int y = 0; y < 2; ++y) {
84 pixels[y][x][0] = x + y; 193 pixels[y][x][0] = x + y;
85 pixels[y][x][1] = x + y; 194 pixels[y][x][1] = x + y;
86 pixels[y][x][2] = x + y; 195 pixels[y][x][2] = x + y;
87 pixels[y][x][3] = 255u; 196 pixels[y][x][3] = 255u;
88 } 197 }
89 } 198 }
90 199
91 glBindTexture(GL_TEXTURE_2D, textures_[0]); 200 glBindTexture(GL_TEXTURE_2D, textures_[0]);
92 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 201 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
93 pixels); 202 pixels);
94 203
95 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); 204 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE);
96 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 205 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
97 GL_UNSIGNED_BYTE); 206 GL_UNSIGNED_BYTE);
98 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 207 EXPECT_EQ(glGetError(), GL_NO_ERROR);
99 208
100 uint8 copied_pixels[2][2][4] = {{{0}}}; 209 uint8 copied_pixels[2][2][4] = {{{0}}};
101 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); 210 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels);
102 for (int x = 0; x < 2; ++x) { 211 for (int x = 0; x < 2; ++x) {
103 for (int y = 0; y < 2; ++y) { 212 for (int y = 0; y < 2; ++y) {
104 EXPECT_EQ(pixels[1-y][x][0], copied_pixels[y][x][0]); 213 EXPECT_EQ(pixels[1-y][x][0], copied_pixels[y][x][0]);
105 EXPECT_EQ(pixels[1-y][x][1], copied_pixels[y][x][1]); 214 EXPECT_EQ(pixels[1-y][x][1], copied_pixels[y][x][1]);
106 EXPECT_EQ(pixels[1-y][x][2], copied_pixels[y][x][2]); 215 EXPECT_EQ(pixels[1-y][x][2], copied_pixels[y][x][2]);
107 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); 216 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]);
108 } 217 }
109 } 218 }
110 219
111 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 220 EXPECT_EQ(glGetError(), GL_NO_ERROR);
112 } 221 }
113 222
114 // Test that the extension respects the GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM 223 // Test that the extension respects the GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM
115 // storage setting. 224 // storage setting.
116 TEST_F(GLCopyTextureCHROMIUMTest, PremultiplyAlpha) { 225 TEST_F(GLCopyTextureCHROMIUMTest, PremultiplyAlpha) {
117 uint8 pixels[1 * 4] = { 2, 2, 2, 128 }; 226 uint8 pixels[1 * 4] = { 2, 2, 2, 128 };
118 227
119 glBindTexture(GL_TEXTURE_2D, textures_[0]); 228 glBindTexture(GL_TEXTURE_2D, textures_[0]);
120 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 229 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
121 pixels); 230 pixels);
122 231
123 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); 232 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE);
124 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 233 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
125 GL_UNSIGNED_BYTE); 234 GL_UNSIGNED_BYTE);
126 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 235 EXPECT_EQ(glGetError(), GL_NO_ERROR);
127 236
128 uint8 copied_pixels[1 * 4] = {0}; 237 uint8 copied_pixels[1 * 4] = {0};
129 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); 238 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels);
130 EXPECT_EQ(1u, copied_pixels[0]); 239 EXPECT_EQ(1u, copied_pixels[0]);
131 EXPECT_EQ(1u, copied_pixels[1]); 240 EXPECT_EQ(1u, copied_pixels[1]);
132 EXPECT_EQ(1u, copied_pixels[2]); 241 EXPECT_EQ(1u, copied_pixels[2]);
133 EXPECT_EQ(128u, copied_pixels[3]); 242 EXPECT_EQ(128u, copied_pixels[3]);
134 243
135 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 244 EXPECT_EQ(glGetError(), GL_NO_ERROR);
136 } 245 }
137 246
138 // Test that the extension respects the GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM 247 // Test that the extension respects the GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM
139 // storage setting. 248 // storage setting.
140 TEST_F(GLCopyTextureCHROMIUMTest, UnpremultiplyAlpha) { 249 TEST_F(GLCopyTextureCHROMIUMTest, UnpremultiplyAlpha) {
141 uint8 pixels[1 * 4] = { 16, 16, 16, 128 }; 250 uint8 pixels[1 * 4] = { 16, 16, 16, 128 };
142 251
143 glBindTexture(GL_TEXTURE_2D, textures_[0]); 252 glBindTexture(GL_TEXTURE_2D, textures_[0]);
144 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 253 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
145 pixels); 254 pixels);
146 255
147 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); 256 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE);
148 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 257 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
149 GL_UNSIGNED_BYTE); 258 GL_UNSIGNED_BYTE);
150 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 259 EXPECT_EQ(glGetError(), GL_NO_ERROR);
151 260
152 uint8 copied_pixels[1 * 4] = {0}; 261 uint8 copied_pixels[1 * 4] = {0};
153 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); 262 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels);
154 EXPECT_EQ(32u, copied_pixels[0]); 263 EXPECT_EQ(32u, copied_pixels[0]);
155 EXPECT_EQ(32u, copied_pixels[1]); 264 EXPECT_EQ(32u, copied_pixels[1]);
156 EXPECT_EQ(32u, copied_pixels[2]); 265 EXPECT_EQ(32u, copied_pixels[2]);
157 EXPECT_EQ(128u, copied_pixels[3]); 266 EXPECT_EQ(128u, copied_pixels[3]);
158 267
159 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 268 EXPECT_EQ(glGetError(), GL_NO_ERROR);
160 } 269 }
161 270
162 TEST_F(GLCopyTextureCHROMIUMTest, FlipYAndPremultiplyAlpha) { 271 TEST_F(GLCopyTextureCHROMIUMTest, FlipYAndPremultiplyAlpha) {
163 uint8 pixels[2][2][4]; 272 uint8 pixels[2][2][4];
164 for (int x = 0; x < 2; ++x) { 273 for (int x = 0; x < 2; ++x) {
165 for (int y = 0; y < 2; ++y) { 274 for (int y = 0; y < 2; ++y) {
166 uint8 color = 16 * x + 16 * y; 275 uint8 color = 16 * x + 16 * y;
167 pixels[y][x][0] = color; 276 pixels[y][x][0] = color;
168 pixels[y][x][1] = color; 277 pixels[y][x][1] = color;
169 pixels[y][x][2] = color; 278 pixels[y][x][2] = color;
170 pixels[y][x][3] = 128u; 279 pixels[y][x][3] = 128u;
171 } 280 }
172 } 281 }
173 282
174 glBindTexture(GL_TEXTURE_2D, textures_[0]); 283 glBindTexture(GL_TEXTURE_2D, textures_[0]);
175 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 284 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
176 pixels); 285 pixels);
177 286
178 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); 287 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE);
179 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); 288 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE);
180 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 289 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
181 GL_UNSIGNED_BYTE); 290 GL_UNSIGNED_BYTE);
182 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 291 EXPECT_EQ(glGetError(), GL_NO_ERROR);
183 292
184 uint8 copied_pixels[2][2][4] = {{{0}}}; 293 uint8 copied_pixels[2][2][4] = {{{0}}};
185 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); 294 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels);
186 for (int x = 0; x < 2; ++x) { 295 for (int x = 0; x < 2; ++x) {
187 for (int y = 0; y < 2; ++y) { 296 for (int y = 0; y < 2; ++y) {
188 EXPECT_EQ(pixels[1-y][x][0] / 2, copied_pixels[y][x][0]); 297 EXPECT_EQ(pixels[1-y][x][0] / 2, copied_pixels[y][x][0]);
189 EXPECT_EQ(pixels[1-y][x][1] / 2, copied_pixels[y][x][1]); 298 EXPECT_EQ(pixels[1-y][x][1] / 2, copied_pixels[y][x][1]);
190 EXPECT_EQ(pixels[1-y][x][2] / 2, copied_pixels[y][x][2]); 299 EXPECT_EQ(pixels[1-y][x][2] / 2, copied_pixels[y][x][2]);
191 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); 300 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]);
192 } 301 }
193 } 302 }
194 303
195 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 304 EXPECT_EQ(glGetError(), GL_NO_ERROR);
196 } 305 }
197 306
198 TEST_F(GLCopyTextureCHROMIUMTest, FlipYAndUnpremultiplyAlpha) { 307 TEST_F(GLCopyTextureCHROMIUMTest, FlipYAndUnpremultiplyAlpha) {
199 uint8 pixels[2][2][4]; 308 uint8 pixels[2][2][4];
200 for (int x = 0; x < 2; ++x) { 309 for (int x = 0; x < 2; ++x) {
201 for (int y = 0; y < 2; ++y) { 310 for (int y = 0; y < 2; ++y) {
202 uint8 color = 16 * x + 16 * y; 311 uint8 color = 16 * x + 16 * y;
203 pixels[y][x][0] = color; 312 pixels[y][x][0] = color;
204 pixels[y][x][1] = color; 313 pixels[y][x][1] = color;
205 pixels[y][x][2] = color; 314 pixels[y][x][2] = color;
206 pixels[y][x][3] = 128u; 315 pixels[y][x][3] = 128u;
207 } 316 }
208 } 317 }
209 318
210 glBindTexture(GL_TEXTURE_2D, textures_[0]); 319 glBindTexture(GL_TEXTURE_2D, textures_[0]);
211 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 320 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
212 pixels); 321 pixels);
213 322
214 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE); 323 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, GL_TRUE);
215 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE); 324 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, GL_TRUE);
216 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 325 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
217 GL_UNSIGNED_BYTE); 326 GL_UNSIGNED_BYTE);
218 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 327 EXPECT_EQ(glGetError(), GL_NO_ERROR);
219 328
220 uint8 copied_pixels[2][2][4] = {{{0}}}; 329 uint8 copied_pixels[2][2][4] = {{{0}}};
221 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels); 330 glReadPixels(0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, copied_pixels);
222 for (int x = 0; x < 2; ++x) { 331 for (int x = 0; x < 2; ++x) {
223 for (int y = 0; y < 2; ++y) { 332 for (int y = 0; y < 2; ++y) {
224 EXPECT_EQ(pixels[1-y][x][0] * 2, copied_pixels[y][x][0]); 333 EXPECT_EQ(pixels[1-y][x][0] * 2, copied_pixels[y][x][0]);
225 EXPECT_EQ(pixels[1-y][x][1] * 2, copied_pixels[y][x][1]); 334 EXPECT_EQ(pixels[1-y][x][1] * 2, copied_pixels[y][x][1]);
226 EXPECT_EQ(pixels[1-y][x][2] * 2, copied_pixels[y][x][2]); 335 EXPECT_EQ(pixels[1-y][x][2] * 2, copied_pixels[y][x][2]);
227 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]); 336 EXPECT_EQ(pixels[1-y][x][3], copied_pixels[y][x][3]);
228 } 337 }
229 } 338 }
230 339
231 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 340 EXPECT_EQ(glGetError(), GL_NO_ERROR);
232 } 341 }
233 342
234 namespace { 343 namespace {
235 344
236 void glEnableDisable(GLint param, GLboolean value) { 345 void glEnableDisable(GLint param, GLboolean value) {
237 if (value) 346 if (value)
238 glEnable(param); 347 glEnable(param);
239 else 348 else
240 glDisable(param); 349 glDisable(param);
241 } 350 }
(...skipping 19 matching lines...) Expand all
261 glEnableDisable(GL_STENCIL_TEST, setting); 370 glEnableDisable(GL_STENCIL_TEST, setting);
262 glEnableDisable(GL_CULL_FACE, setting); 371 glEnableDisable(GL_CULL_FACE, setting);
263 glEnableDisable(GL_BLEND, setting); 372 glEnableDisable(GL_BLEND, setting);
264 glColorMask(setting, setting, setting, setting); 373 glColorMask(setting, setting, setting, setting);
265 glDepthMask(setting); 374 glDepthMask(setting);
266 375
267 glActiveTexture(GL_TEXTURE1 + x); 376 glActiveTexture(GL_TEXTURE1 + x);
268 377
269 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 378 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0,
270 GL_RGBA, GL_UNSIGNED_BYTE); 379 GL_RGBA, GL_UNSIGNED_BYTE);
271 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 380 EXPECT_EQ(glGetError(), GL_NO_ERROR);
272 381
273 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST)); 382 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST));
274 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST)); 383 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST));
275 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST)); 384 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST));
276 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE)); 385 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE));
277 EXPECT_EQ(setting, glIsEnabled(GL_BLEND)); 386 EXPECT_EQ(setting, glIsEnabled(GL_BLEND));
278 387
279 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; 388 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
280 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array); 389 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array);
281 EXPECT_EQ(setting, bool_array[0]); 390 EXPECT_EQ(setting, bool_array[0]);
282 391
283 bool_array[0] = GL_FALSE; 392 bool_array[0] = GL_FALSE;
284 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array); 393 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array);
285 EXPECT_EQ(setting, bool_array[0]); 394 EXPECT_EQ(setting, bool_array[0]);
286 EXPECT_EQ(setting, bool_array[1]); 395 EXPECT_EQ(setting, bool_array[1]);
287 EXPECT_EQ(setting, bool_array[2]); 396 EXPECT_EQ(setting, bool_array[2]);
288 EXPECT_EQ(setting, bool_array[3]); 397 EXPECT_EQ(setting, bool_array[3]);
289 398
290 GLint active_texture = 0; 399 GLint active_texture = 0;
291 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); 400 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
292 EXPECT_EQ(GL_TEXTURE1 + x, active_texture); 401 EXPECT_EQ(GL_TEXTURE1 + x, active_texture);
293 } 402 }
294 403
295 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 404 EXPECT_EQ(glGetError(), GL_NO_ERROR);
296 }; 405 };
297 406
298 // Verify that invocation of the extension does not modify the bound 407 // Verify that invocation of the extension does not modify the bound
299 // texture state. 408 // texture state.
300 TEST_F(GLCopyTextureCHROMIUMTest, TextureStatePreserved) { 409 TEST_F(GLCopyTextureCHROMIUMTest, TextureStatePreserved) {
301 // Setup the texture used for the extension invocation. 410 // Setup the texture used for the extension invocation.
302 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 411 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
303 glBindTexture(GL_TEXTURE_2D, textures_[0]); 412 glBindTexture(GL_TEXTURE_2D, textures_[0]);
304 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 413 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
305 pixels); 414 pixels);
306 415
307 GLuint texture_ids[2]; 416 GLuint texture_ids[2];
308 glGenTextures(2, texture_ids); 417 glGenTextures(2, texture_ids);
309 418
310 glActiveTexture(GL_TEXTURE0); 419 glActiveTexture(GL_TEXTURE0);
311 glBindTexture(GL_TEXTURE_2D, texture_ids[0]); 420 glBindTexture(GL_TEXTURE_2D, texture_ids[0]);
312 421
313 glActiveTexture(GL_TEXTURE1); 422 glActiveTexture(GL_TEXTURE1);
314 glBindTexture(GL_TEXTURE_2D, texture_ids[1]); 423 glBindTexture(GL_TEXTURE_2D, texture_ids[1]);
315 424
316 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 425 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0,
317 GL_RGBA, GL_UNSIGNED_BYTE); 426 GL_RGBA, GL_UNSIGNED_BYTE);
318 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 427 EXPECT_EQ(glGetError(), GL_NO_ERROR);
319 428
320 GLint active_texture = 0; 429 GLint active_texture = 0;
321 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); 430 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
322 EXPECT_EQ(GL_TEXTURE1, active_texture); 431 EXPECT_EQ(GL_TEXTURE1, active_texture);
323 432
324 GLint bound_texture = 0; 433 GLint bound_texture = 0;
325 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); 434 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
326 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture)); 435 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture));
327 glBindTexture(GL_TEXTURE_2D, 0); 436 glBindTexture(GL_TEXTURE_2D, 0);
328 437
329 bound_texture = 0; 438 bound_texture = 0;
330 glActiveTexture(GL_TEXTURE0); 439 glActiveTexture(GL_TEXTURE0);
331 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); 440 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
332 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture)); 441 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture));
333 glBindTexture(GL_TEXTURE_2D, 0); 442 glBindTexture(GL_TEXTURE_2D, 0);
334 443
335 glDeleteTextures(2, texture_ids); 444 glDeleteTextures(2, texture_ids);
336 445
337 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 446 EXPECT_EQ(glGetError(), GL_NO_ERROR);
338 } 447 }
339 448
340 // Verify that invocation of the extension does not perturb the currently 449 // Verify that invocation of the extension does not perturb the currently
341 // bound FBO state. 450 // bound FBO state.
342 TEST_F(GLCopyTextureCHROMIUMTest, FBOStatePreserved) { 451 TEST_F(GLCopyTextureCHROMIUMTest, FBOStatePreserved) {
343 // Setup the texture used for the extension invocation. 452 // Setup the texture used for the extension invocation.
344 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 453 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
345 glBindTexture(GL_TEXTURE_2D, textures_[0]); 454 glBindTexture(GL_TEXTURE_2D, textures_[0]);
346 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 455 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
347 pixels); 456 pixels);
(...skipping 20 matching lines...) Expand all
368 GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)); 477 GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER));
369 478
370 // Test that we can write to the bound framebuffer 479 // Test that we can write to the bound framebuffer
371 uint8 expected_color[4] = { 255u, 255u, 0, 255u }; 480 uint8 expected_color[4] = { 255u, 255u, 0, 255u };
372 glClearColor(1.0, 1.0, 0, 1.0); 481 glClearColor(1.0, 1.0, 0, 1.0);
373 glClear(GL_COLOR_BUFFER_BIT); 482 glClear(GL_COLOR_BUFFER_BIT);
374 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); 483 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color);
375 484
376 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, 485 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0,
377 GL_RGBA, GL_UNSIGNED_BYTE); 486 GL_RGBA, GL_UNSIGNED_BYTE);
378 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 487 EXPECT_EQ(glGetError(), GL_NO_ERROR);
379 488
380 EXPECT_TRUE(glIsFramebuffer(framebuffer_id)); 489 EXPECT_TRUE(glIsFramebuffer(framebuffer_id));
381 490
382 // Ensure that reading from the framebuffer produces correct pixels. 491 // Ensure that reading from the framebuffer produces correct pixels.
383 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color); 492 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color);
384 493
385 uint8 expected_color2[4] = { 255u, 0, 255u, 255u }; 494 uint8 expected_color2[4] = { 255u, 0, 255u, 255u };
386 glClearColor(1.0, 0, 1.0, 1.0); 495 glClearColor(1.0, 0, 1.0, 1.0);
387 glClear(GL_COLOR_BUFFER_BIT); 496 glClear(GL_COLOR_BUFFER_BIT);
388 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color2); 497 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color2);
(...skipping 23 matching lines...) Expand all
412 fbo_params = 0; 521 fbo_params = 0;
413 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 522 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
414 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, 523 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
415 &fbo_params); 524 &fbo_params);
416 EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(fbo_params)); 525 EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(fbo_params));
417 526
418 glDeleteRenderbuffers(1, &renderbuffer_id); 527 glDeleteRenderbuffers(1, &renderbuffer_id);
419 glDeleteTextures(1, &texture_id); 528 glDeleteTextures(1, &texture_id);
420 glDeleteFramebuffers(1, &framebuffer_id); 529 glDeleteFramebuffers(1, &framebuffer_id);
421 530
422 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 531 EXPECT_EQ(glGetError(), GL_NO_ERROR);
423 } 532 }
424 533
425 TEST_F(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { 534 TEST_F(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) {
426 // unbind the one created in setup. 535 // unbind the one created in setup.
427 glBindFramebuffer(GL_FRAMEBUFFER, 0); 536 glBindFramebuffer(GL_FRAMEBUFFER, 0);
428 glBindTexture(GL_TEXTURE_2D, 0); 537 glBindTexture(GL_TEXTURE_2D, 0);
429 538
430 GLManager gl2; 539 GLManager gl2;
431 GLManager::Options options; 540 GLManager::Options options;
432 options.size = gfx::Size(16, 16); 541 options.size = gfx::Size(16, 16);
(...skipping 15 matching lines...) Expand all
448 "}\n"; 557 "}\n";
449 558
450 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); 559 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
451 glUseProgram(program); 560 glUseProgram(program);
452 GLuint position_loc = glGetAttribLocation(program, "g_Position"); 561 GLuint position_loc = glGetAttribLocation(program, "g_Position");
453 glFlush(); 562 glFlush();
454 563
455 // Delete program from other context. 564 // Delete program from other context.
456 gl2.MakeCurrent(); 565 gl2.MakeCurrent();
457 glDeleteProgram(program); 566 glDeleteProgram(program);
458 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 567 EXPECT_EQ(glGetError(), GL_NO_ERROR);
459 glFlush(); 568 glFlush();
460 569
461 // Program should still be usable on this context. 570 // Program should still be usable on this context.
462 gl_.MakeCurrent(); 571 gl_.MakeCurrent();
463 572
464 GLTestHelper::SetupUnitQuad(position_loc); 573 GLTestHelper::SetupUnitQuad(position_loc);
465 574
466 // test using program before 575 // test using program before
467 uint8 expected[] = { 0, 255, 0, 255, }; 576 uint8 expected[] = { 0, 255, 0, 255, };
468 uint8 zero[] = { 0, 0, 0, 0, }; 577 uint8 zero[] = { 0, 0, 0, 0, };
469 glClear(GL_COLOR_BUFFER_BIT); 578 glClear(GL_COLOR_BUFFER_BIT);
470 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); 579 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero));
471 glDrawArrays(GL_TRIANGLES, 0, 6); 580 glDrawArrays(GL_TRIANGLES, 0, 6);
472 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); 581 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected));
473 582
474 // Call copyTextureCHROMIUM 583 // Call copyTextureCHROMIUM
475 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; 584 uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u };
476 glBindTexture(GL_TEXTURE_2D, textures_[0]); 585 glBindTexture(GL_TEXTURE_2D, textures_[0]);
477 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 586 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
478 pixels); 587 pixels);
479 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 588 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
480 GL_UNSIGNED_BYTE); 589 GL_UNSIGNED_BYTE);
481 590
482 // test using program after 591 // test using program after
483 glClear(GL_COLOR_BUFFER_BIT); 592 glClear(GL_COLOR_BUFFER_BIT);
484 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); 593 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero));
485 glDrawArrays(GL_TRIANGLES, 0, 6); 594 glDrawArrays(GL_TRIANGLES, 0, 6);
486 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); 595 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected));
487 596
488 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 597 EXPECT_EQ(glGetError(), GL_NO_ERROR);
489 598
490 gl2.MakeCurrent(); 599 gl2.MakeCurrent();
491 gl2.Destroy(); 600 gl2.Destroy();
492 gl_.MakeCurrent(); 601 gl_.MakeCurrent();
493 } 602 }
494 603
495 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures. 604 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures.
496 TEST_F(GLCopyTextureCHROMIUMTest, UninitializedSource) { 605 TEST_F(GLCopyTextureCHROMIUMTest, UninitializedSource) {
497 const GLsizei kWidth = 64, kHeight = 64; 606 const GLsizei kWidth = 64, kHeight = 64;
498 glBindTexture(GL_TEXTURE_2D, textures_[0]); 607 glBindTexture(GL_TEXTURE_2D, textures_[0]);
499 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 608 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight,
500 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 609 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
501 610
502 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, 611 glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA,
503 GL_UNSIGNED_BYTE); 612 GL_UNSIGNED_BYTE);
504 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 613 EXPECT_EQ(glGetError(), GL_NO_ERROR);
505 614
506 uint8 pixels[kHeight][kWidth][4] = {{{1}}}; 615 uint8 pixels[kHeight][kWidth][4] = {{{1}}};
507 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 616 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
508 for (int x = 0; x < kWidth; ++x) { 617 for (int x = 0; x < kWidth; ++x) {
509 for (int y = 0; y < kHeight; ++y) { 618 for (int y = 0; y < kHeight; ++y) {
510 EXPECT_EQ(0, pixels[y][x][0]); 619 EXPECT_EQ(0, pixels[y][x][0]);
511 EXPECT_EQ(0, pixels[y][x][1]); 620 EXPECT_EQ(0, pixels[y][x][1]);
512 EXPECT_EQ(0, pixels[y][x][2]); 621 EXPECT_EQ(0, pixels[y][x][2]);
513 EXPECT_EQ(0, pixels[y][x][3]); 622 EXPECT_EQ(0, pixels[y][x][3]);
514 } 623 }
515 } 624 }
516 625
517 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 626 EXPECT_EQ(glGetError(), GL_NO_ERROR);
518 } 627 }
519 628
520 } // namespace gpu 629 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698