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

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

Issue 2602563002: Refactor DrawTextureQuad and CheckPixels in gl_tests util (Closed)
Patch Set: git cl format Created 3 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <GLES2/gl2.h> 5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h> 6 #include <GLES2/gl2ext.h>
7 #include <GLES2/gl2extchromium.h> 7 #include <GLES2/gl2extchromium.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "gpu/command_buffer/tests/gl_manager.h" 10 #include "gpu/command_buffer/tests/gl_manager.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 color[2] / 255.0f, 134 color[2] / 255.0f,
135 color[3] / 255.0f); 135 color[3] / 255.0f);
136 } 136 }
137 137
138 void TestDraw(int size) { 138 void TestDraw(int size) {
139 uint8_t expected_clear[] = { 139 uint8_t expected_clear[] = {
140 127, 0, 255, 0, 140 127, 0, 255, 0,
141 }; 141 };
142 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); 142 glClearColor(0.5f, 0.0f, 1.0f, 0.0f);
143 glClear(GL_COLOR_BUFFER_BIT); 143 glClear(GL_COLOR_BUFFER_BIT);
144 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size, size, 1, expected_clear)); 144 EXPECT_TRUE(
145 GLTestHelper::CheckPixels(0, 0, size, size, 1, expected_clear, nullptr));
145 glDrawArrays(GL_TRIANGLES, 0, 6); 146 glDrawArrays(GL_TRIANGLES, 0, 6);
146 } 147 }
147 148
148 } // anonymous namespace 149 } // anonymous namespace
149 150
150 // http://crbug.com/281565 151 // http://crbug.com/281565
151 TEST_F(GLVirtualContextsTest, Basic) { 152 TEST_F(GLVirtualContextsTest, Basic) {
152 struct TestInfo { 153 struct TestInfo {
153 int size; 154 int size;
154 uint8_t color[4]; 155 uint8_t color[4];
(...skipping 17 matching lines...) Expand all
172 const TestInfo& test = tests[ii]; 173 const TestInfo& test = tests[ii];
173 GLManager* gl_manager = test.manager; 174 GLManager* gl_manager = test.manager;
174 gl_manager->MakeCurrent(); 175 gl_manager->MakeCurrent();
175 TestDraw(test.size); 176 TestDraw(test.size);
176 } 177 }
177 178
178 for (int ii = 0; ii < kNumTests; ++ii) { 179 for (int ii = 0; ii < kNumTests; ++ii) {
179 const TestInfo& test = tests[ii]; 180 const TestInfo& test = tests[ii];
180 GLManager* gl_manager = test.manager; 181 GLManager* gl_manager = test.manager;
181 gl_manager->MakeCurrent(); 182 gl_manager->MakeCurrent();
182 EXPECT_TRUE(GLTestHelper::CheckPixels( 183 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, test.size, test.size, 0,
183 0, 0, test.size, test.size, 0, test.color)); 184 test.color, nullptr));
184 } 185 }
185 186
186 for (int ii = 0; ii < kNumTests; ++ii) { 187 for (int ii = 0; ii < kNumTests; ++ii) {
187 const TestInfo& test = tests[ii]; 188 const TestInfo& test = tests[ii];
188 GLManager* gl_manager = test.manager; 189 GLManager* gl_manager = test.manager;
189 gl_manager->MakeCurrent(); 190 gl_manager->MakeCurrent();
190 GLTestHelper::CheckGLError("no errors", __LINE__); 191 GLTestHelper::CheckGLError("no errors", __LINE__);
191 } 192 }
192 } 193 }
193 194
(...skipping 11 matching lines...) Expand all
205 gl2_.MakeCurrent(); 206 gl2_.MakeCurrent();
206 // Set up green quad in vao2. 207 // Set up green quad in vao2.
207 glGenVertexArraysOES(1, &vao2); 208 glGenVertexArraysOES(1, &vao2);
208 glBindVertexArrayOES(vao2); 209 glBindVertexArrayOES(vao2);
209 SetUpColoredUnitQuad(kFloatGreen); 210 SetUpColoredUnitQuad(kFloatGreen);
210 glFinish(); 211 glFinish();
211 212
212 gl1_.MakeCurrent(); 213 gl1_.MakeCurrent();
213 // Test to ensure that vao1 is still the active VAO for this context. 214 // Test to ensure that vao1 is still the active VAO for this context.
214 glDrawArrays(GL_TRIANGLES, 0, 6); 215 glDrawArrays(GL_TRIANGLES, 0, 6);
215 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize1, kSize1, 0, kExpectedRed)); 216 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize1, kSize1, 0, kExpectedRed,
217 nullptr));
216 glFinish(); 218 glFinish();
217 GLTestHelper::CheckGLError("no errors", __LINE__); 219 GLTestHelper::CheckGLError("no errors", __LINE__);
218 220
219 gl2_.MakeCurrent(); 221 gl2_.MakeCurrent();
220 // Test to ensure that vao2 is still the active VAO for this context. 222 // Test to ensure that vao2 is still the active VAO for this context.
221 glDrawArrays(GL_TRIANGLES, 0, 6); 223 glDrawArrays(GL_TRIANGLES, 0, 6);
222 EXPECT_TRUE( 224 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize2, kSize2, 0, kExpectedGreen,
223 GLTestHelper::CheckPixels(0, 0, kSize2, kSize2, 0, kExpectedGreen)); 225 nullptr));
224 glFinish(); 226 glFinish();
225 GLTestHelper::CheckGLError("no errors", __LINE__); 227 GLTestHelper::CheckGLError("no errors", __LINE__);
226 } 228 }
227 229
228 // http://crbug.com/363407 230 // http://crbug.com/363407
229 TEST_F(GLVirtualContextsTest, VertexArrayObjectRestoreRebind) { 231 TEST_F(GLVirtualContextsTest, VertexArrayObjectRestoreRebind) {
230 GLuint vao1 = 0, vao2 = 0; 232 GLuint vao1 = 0, vao2 = 0;
231 233
232 gl1_.MakeCurrent(); 234 gl1_.MakeCurrent();
233 // Set up red quad in vao1. 235 // Set up red quad in vao1.
234 glGenVertexArraysOES(1, &vao1); 236 glGenVertexArraysOES(1, &vao1);
235 glBindVertexArrayOES(vao1); 237 glBindVertexArrayOES(vao1);
236 SetUpColoredUnitQuad(kFloatRed); 238 SetUpColoredUnitQuad(kFloatRed);
237 glFinish(); 239 glFinish();
238 240
239 gl2_.MakeCurrent(); 241 gl2_.MakeCurrent();
240 // Set up green quad in new vao2. 242 // Set up green quad in new vao2.
241 glGenVertexArraysOES(1, &vao2); 243 glGenVertexArraysOES(1, &vao2);
242 glBindVertexArrayOES(vao2); 244 glBindVertexArrayOES(vao2);
243 SetUpColoredUnitQuad(kFloatGreen); 245 SetUpColoredUnitQuad(kFloatGreen);
244 glFinish(); 246 glFinish();
245 247
246 gl1_.MakeCurrent(); 248 gl1_.MakeCurrent();
247 // Test to ensure that vao1 hasn't been corrupted after rebinding. 249 // Test to ensure that vao1 hasn't been corrupted after rebinding.
248 // Bind 0 is required so that bind vao1 is not optimized away in the service. 250 // Bind 0 is required so that bind vao1 is not optimized away in the service.
249 glBindVertexArrayOES(0); 251 glBindVertexArrayOES(0);
250 glBindVertexArrayOES(vao1); 252 glBindVertexArrayOES(vao1);
251 glDrawArrays(GL_TRIANGLES, 0, 6); 253 glDrawArrays(GL_TRIANGLES, 0, 6);
252 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize1, kSize1, 0, kExpectedRed)); 254 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize1, kSize1, 0, kExpectedRed,
255 nullptr));
253 glFinish(); 256 glFinish();
254 GLTestHelper::CheckGLError("no errors", __LINE__); 257 GLTestHelper::CheckGLError("no errors", __LINE__);
255 258
256 gl2_.MakeCurrent(); 259 gl2_.MakeCurrent();
257 // Test to ensure that vao1 hasn't been corrupted after rebinding. 260 // Test to ensure that vao1 hasn't been corrupted after rebinding.
258 // Bind 0 is required so that bind vao2 is not optimized away in the service. 261 // Bind 0 is required so that bind vao2 is not optimized away in the service.
259 glBindVertexArrayOES(0); 262 glBindVertexArrayOES(0);
260 glBindVertexArrayOES(vao2); 263 glBindVertexArrayOES(vao2);
261 glDrawArrays(GL_TRIANGLES, 0, 6); 264 glDrawArrays(GL_TRIANGLES, 0, 6);
262 EXPECT_TRUE( 265 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize2, kSize2, 0, kExpectedGreen,
263 GLTestHelper::CheckPixels(0, 0, kSize2, kSize2, 0, kExpectedGreen)); 266 nullptr));
264 glFinish(); 267 glFinish();
265 268
266 GLTestHelper::CheckGLError("no errors", __LINE__); 269 GLTestHelper::CheckGLError("no errors", __LINE__);
267 } 270 }
268 271
269 // http://crbug.com/363407 272 // http://crbug.com/363407
270 TEST_F(GLVirtualContextsTest, VertexArrayObjectRestoreDefault) { 273 TEST_F(GLVirtualContextsTest, VertexArrayObjectRestoreDefault) {
271 gl1_.MakeCurrent(); 274 gl1_.MakeCurrent();
272 // Set up red quad in default VAO. 275 // Set up red quad in default VAO.
273 SetUpColoredUnitQuad(kFloatRed); 276 SetUpColoredUnitQuad(kFloatRed);
274 glFinish(); 277 glFinish();
275 278
276 gl2_.MakeCurrent(); 279 gl2_.MakeCurrent();
277 // Set up green quad in default VAO. 280 // Set up green quad in default VAO.
278 SetUpColoredUnitQuad(kFloatGreen); 281 SetUpColoredUnitQuad(kFloatGreen);
279 glFinish(); 282 glFinish();
280 283
281 // Gen & bind a non-default VAO. 284 // Gen & bind a non-default VAO.
282 GLuint vao; 285 GLuint vao;
283 glGenVertexArraysOES(1, &vao); 286 glGenVertexArraysOES(1, &vao);
284 glBindVertexArrayOES(vao); 287 glBindVertexArrayOES(vao);
285 glFinish(); 288 glFinish();
286 289
287 gl1_.MakeCurrent(); 290 gl1_.MakeCurrent();
288 // Test to ensure that default VAO on gl1_ is still valid. 291 // Test to ensure that default VAO on gl1_ is still valid.
289 glDrawArrays(GL_TRIANGLES, 0, 6); 292 glDrawArrays(GL_TRIANGLES, 0, 6);
290 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize1, kSize1, 0, kExpectedRed)); 293 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize1, kSize1, 0, kExpectedRed,
294 nullptr));
291 glFinish(); 295 glFinish();
292 296
293 gl2_.MakeCurrent(); 297 gl2_.MakeCurrent();
294 // Test to ensure that default VAO on gl2_ is still valid. 298 // Test to ensure that default VAO on gl2_ is still valid.
295 // This tests that a default VAO is restored even when it's not currently 299 // This tests that a default VAO is restored even when it's not currently
296 // bound during the context switch. 300 // bound during the context switch.
297 glBindVertexArrayOES(0); 301 glBindVertexArrayOES(0);
298 glDrawArrays(GL_TRIANGLES, 0, 6); 302 glDrawArrays(GL_TRIANGLES, 0, 6);
299 EXPECT_TRUE( 303 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize2, kSize2, 0, kExpectedGreen,
300 GLTestHelper::CheckPixels(0, 0, kSize2, kSize2, 0, kExpectedGreen)); 304 nullptr));
301 glFinish(); 305 glFinish();
302 306
303 GLTestHelper::CheckGLError("no errors", __LINE__); 307 GLTestHelper::CheckGLError("no errors", __LINE__);
304 } 308 }
305 309
306 TEST_F(GLVirtualContextsTest, VirtualQueries) { 310 TEST_F(GLVirtualContextsTest, VirtualQueries) {
307 const GLenum query_targets[] = { 311 const GLenum query_targets[] = {
308 GL_ANY_SAMPLES_PASSED_EXT, 312 GL_ANY_SAMPLES_PASSED_EXT,
309 GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, 313 GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
310 GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, 314 GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 &query2_available); 360 &query2_available);
357 EXPECT_TRUE(query2_available); 361 EXPECT_TRUE(query2_available);
358 362
359 glDeleteQueriesEXT(1, &query2); 363 glDeleteQueriesEXT(1, &query2);
360 GLTestHelper::CheckGLError("no errors", __LINE__); 364 GLTestHelper::CheckGLError("no errors", __LINE__);
361 } 365 }
362 } 366 }
363 367
364 } // namespace gpu 368 } // namespace gpu
365 369
OLDNEW
« gpu/command_buffer/tests/gl_test_utils.h ('K') | « gpu/command_buffer/tests/gl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698