OLD | NEW |
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 #include "gpu/command_buffer/service/test_helper.h" | 5 #include "gpu/command_buffer/service/test_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 .RetiresOnSaturation(); | 337 .RetiresOnSaturation(); |
338 EXPECT_CALL(*gl, GetString(GL_VERSION)) | 338 EXPECT_CALL(*gl, GetString(GL_VERSION)) |
339 .WillOnce(Return(reinterpret_cast<const uint8*>(gl_version))) | 339 .WillOnce(Return(reinterpret_cast<const uint8*>(gl_version))) |
340 .RetiresOnSaturation(); | 340 .RetiresOnSaturation(); |
341 | 341 |
342 std::string l_version(base::StringToLowerASCII(std::string(gl_version))); | 342 std::string l_version(base::StringToLowerASCII(std::string(gl_version))); |
343 bool is_es3 = (l_version.substr(0, 12) == "opengl es 3."); | 343 bool is_es3 = (l_version.substr(0, 12) == "opengl es 3."); |
344 | 344 |
345 if (strstr(extensions, "GL_ARB_texture_float") || | 345 if (strstr(extensions, "GL_ARB_texture_float") || |
346 (is_es3 && strstr(extensions, "GL_EXT_color_buffer_float"))) { | 346 (is_es3 && strstr(extensions, "GL_EXT_color_buffer_float"))) { |
347 static const GLuint gl_ids[] = {101, 102}; | 347 static const GLuint tx_ids[] = {101, 102}; |
| 348 static const GLuint fb_ids[] = {103, 104}; |
348 const GLsizei width = 16; | 349 const GLsizei width = 16; |
349 EXPECT_CALL(*gl, GetIntegerv(GL_FRAMEBUFFER_BINDING, _)) | 350 EXPECT_CALL(*gl, GetIntegerv(GL_FRAMEBUFFER_BINDING, _)) |
350 .WillOnce(SetArgumentPointee<1>(gl_ids[0])) | 351 .WillOnce(SetArgumentPointee<1>(fb_ids[0])) |
351 .RetiresOnSaturation(); | 352 .RetiresOnSaturation(); |
352 EXPECT_CALL(*gl, GetIntegerv(GL_TEXTURE_BINDING_2D, _)) | 353 EXPECT_CALL(*gl, GetIntegerv(GL_TEXTURE_BINDING_2D, _)) |
353 .WillOnce(SetArgumentPointee<1>(gl_ids[0])) | 354 .WillOnce(SetArgumentPointee<1>(tx_ids[0])) |
354 .RetiresOnSaturation(); | 355 .RetiresOnSaturation(); |
355 EXPECT_CALL(*gl, GenTextures(1, _)) | 356 EXPECT_CALL(*gl, GenTextures(1, _)) |
356 .WillOnce(SetArrayArgument<1>(gl_ids + 1, gl_ids + 2)) | 357 .WillOnce(SetArrayArgument<1>(tx_ids + 1, tx_ids + 2)) |
357 .RetiresOnSaturation(); | 358 .RetiresOnSaturation(); |
358 EXPECT_CALL(*gl, GenFramebuffersEXT(1, _)) | 359 EXPECT_CALL(*gl, GenFramebuffersEXT(1, _)) |
359 .WillOnce(SetArrayArgument<1>(gl_ids + 1, gl_ids + 2)) | 360 .WillOnce(SetArrayArgument<1>(fb_ids + 1, fb_ids + 2)) |
360 .RetiresOnSaturation(); | 361 .RetiresOnSaturation(); |
361 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, gl_ids[1])) | 362 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[1])) |
362 .Times(1) | 363 .Times(1) |
363 .RetiresOnSaturation(); | 364 .RetiresOnSaturation(); |
364 EXPECT_CALL(*gl, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | 365 EXPECT_CALL(*gl, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
365 GL_NEAREST)) | 366 GL_NEAREST)) |
366 .Times(1) | 367 .Times(1) |
367 .RetiresOnSaturation(); | 368 .RetiresOnSaturation(); |
368 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0, | 369 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0, |
369 GL_RGBA, GL_FLOAT, _)) | 370 GL_RGBA, GL_FLOAT, _)) |
370 .Times(1) | 371 .Times(1) |
371 .RetiresOnSaturation(); | 372 .RetiresOnSaturation(); |
372 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, gl_ids[1])) | 373 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[1])) |
373 .Times(1) | 374 .Times(1) |
374 .RetiresOnSaturation(); | 375 .RetiresOnSaturation(); |
375 EXPECT_CALL(*gl, FramebufferTexture2DEXT(GL_FRAMEBUFFER, | 376 EXPECT_CALL(*gl, FramebufferTexture2DEXT(GL_FRAMEBUFFER, |
376 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl_ids[1], 0)) | 377 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tx_ids[1], 0)) |
377 .Times(1) | 378 .Times(1) |
378 .RetiresOnSaturation(); | 379 .RetiresOnSaturation(); |
379 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) | 380 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) |
380 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) | 381 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) |
381 .RetiresOnSaturation(); | 382 .RetiresOnSaturation(); |
382 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, | 383 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, |
383 GL_RGB, GL_FLOAT, _)) | 384 GL_RGB, GL_FLOAT, _)) |
384 .Times(1) | 385 .Times(1) |
385 .RetiresOnSaturation(); | 386 .RetiresOnSaturation(); |
386 if (is_es3) { | 387 if (is_es3) { |
387 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) | 388 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) |
388 .WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)) | 389 .WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)) |
389 .RetiresOnSaturation(); | 390 .RetiresOnSaturation(); |
390 } else { | 391 } else { |
391 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) | 392 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) |
392 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) | 393 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) |
393 .RetiresOnSaturation(); | 394 .RetiresOnSaturation(); |
394 } | 395 } |
395 EXPECT_CALL(*gl, DeleteFramebuffersEXT(1, _)) | 396 EXPECT_CALL(*gl, DeleteFramebuffersEXT(1, _)) |
396 .Times(1) | 397 .Times(1) |
397 .RetiresOnSaturation(); | 398 .RetiresOnSaturation(); |
398 EXPECT_CALL(*gl, DeleteTextures(1, _)) | 399 EXPECT_CALL(*gl, DeleteTextures(1, _)) |
399 .Times(1) | 400 .Times(1) |
400 .RetiresOnSaturation(); | 401 .RetiresOnSaturation(); |
401 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, gl_ids[0])) | 402 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[0])) |
402 .Times(1) | 403 .Times(1) |
403 .RetiresOnSaturation(); | 404 .RetiresOnSaturation(); |
404 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, gl_ids[0])) | 405 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[0])) |
405 .Times(1) | 406 .Times(1) |
406 .RetiresOnSaturation(); | 407 .RetiresOnSaturation(); |
407 #if DCHECK_IS_ON | 408 #if DCHECK_IS_ON |
408 EXPECT_CALL(*gl, GetError()) | 409 EXPECT_CALL(*gl, GetError()) |
409 .WillOnce(Return(GL_NO_ERROR)) | 410 .WillOnce(Return(GL_NO_ERROR)) |
410 .RetiresOnSaturation(); | 411 .RetiresOnSaturation(); |
411 #endif | 412 #endif |
412 } | 413 } |
413 | 414 |
414 if (strstr(extensions, "GL_EXT_draw_buffers") || | 415 if (strstr(extensions, "GL_EXT_draw_buffers") || |
415 strstr(extensions, "GL_ARB_draw_buffers") || | 416 strstr(extensions, "GL_ARB_draw_buffers") || |
416 (is_es3 && strstr(extensions, "GL_NV_draw_buffers"))) { | 417 (is_es3 && strstr(extensions, "GL_NV_draw_buffers"))) { |
417 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, _)) | 418 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, _)) |
418 .WillOnce(SetArgumentPointee<1>(8)) | 419 .WillOnce(SetArgumentPointee<1>(8)) |
419 .RetiresOnSaturation(); | 420 .RetiresOnSaturation(); |
420 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, _)) | 421 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, _)) |
421 .WillOnce(SetArgumentPointee<1>(8)) | 422 .WillOnce(SetArgumentPointee<1>(8)) |
422 .RetiresOnSaturation(); | 423 .RetiresOnSaturation(); |
423 } | 424 } |
| 425 |
| 426 if (is_es3 || strstr(extensions, "GL_EXT_texture_rg") || |
| 427 (strstr(extensions, "GL_ARB_texture_rg"))) { |
| 428 static const GLuint tx_ids[] = {101, 102}; |
| 429 static const GLuint fb_ids[] = {103, 104}; |
| 430 const GLsizei width = 1; |
| 431 EXPECT_CALL(*gl, GetIntegerv(GL_FRAMEBUFFER_BINDING, _)) |
| 432 .WillOnce(SetArgumentPointee<1>(fb_ids[0])) |
| 433 .RetiresOnSaturation(); |
| 434 EXPECT_CALL(*gl, GetIntegerv(GL_TEXTURE_BINDING_2D, _)) |
| 435 .WillOnce(SetArgumentPointee<1>(tx_ids[0])) |
| 436 .RetiresOnSaturation(); |
| 437 EXPECT_CALL(*gl, GenTextures(1, _)) |
| 438 .WillOnce(SetArrayArgument<1>(tx_ids + 1, tx_ids + 2)) |
| 439 .RetiresOnSaturation(); |
| 440 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[1])) |
| 441 .Times(1) |
| 442 .RetiresOnSaturation(); |
| 443 EXPECT_CALL(*gl, TexImage2D(GL_TEXTURE_2D, 0, GL_RED_EXT, width, width, 0, |
| 444 GL_RED_EXT, GL_UNSIGNED_BYTE, _)) |
| 445 .Times(1) |
| 446 .RetiresOnSaturation(); |
| 447 EXPECT_CALL(*gl, GenFramebuffersEXT(1, _)) |
| 448 .WillOnce(SetArrayArgument<1>(fb_ids + 1, fb_ids + 2)) |
| 449 .RetiresOnSaturation(); |
| 450 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[1])) |
| 451 .Times(1) |
| 452 .RetiresOnSaturation(); |
| 453 EXPECT_CALL(*gl, FramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 454 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tx_ids[1], 0)) |
| 455 .Times(1) |
| 456 .RetiresOnSaturation(); |
| 457 EXPECT_CALL(*gl, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) |
| 458 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) |
| 459 .RetiresOnSaturation(); |
| 460 EXPECT_CALL(*gl, DeleteFramebuffersEXT(1, _)) |
| 461 .Times(1) |
| 462 .RetiresOnSaturation(); |
| 463 EXPECT_CALL(*gl, DeleteTextures(1, _)) |
| 464 .Times(1) |
| 465 .RetiresOnSaturation(); |
| 466 EXPECT_CALL(*gl, BindFramebufferEXT(GL_FRAMEBUFFER, fb_ids[0])) |
| 467 .Times(1) |
| 468 .RetiresOnSaturation(); |
| 469 EXPECT_CALL(*gl, BindTexture(GL_TEXTURE_2D, tx_ids[0])) |
| 470 .Times(1) |
| 471 .RetiresOnSaturation(); |
| 472 #if DCHECK_IS_ON |
| 473 EXPECT_CALL(*gl, GetError()) |
| 474 .WillOnce(Return(GL_NO_ERROR)) |
| 475 .RetiresOnSaturation(); |
| 476 #endif |
| 477 } |
424 } | 478 } |
425 | 479 |
426 void TestHelper::SetupExpectationsForClearingUniforms( | 480 void TestHelper::SetupExpectationsForClearingUniforms( |
427 ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms) { | 481 ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms) { |
428 for (size_t ii = 0; ii < num_uniforms; ++ii) { | 482 for (size_t ii = 0; ii < num_uniforms; ++ii) { |
429 const UniformInfo& info = uniforms[ii]; | 483 const UniformInfo& info = uniforms[ii]; |
430 switch (info.type) { | 484 switch (info.type) { |
431 case GL_FLOAT: | 485 case GL_FLOAT: |
432 EXPECT_CALL(*gl, Uniform1fv(info.real_location, info.size, _)) | 486 EXPECT_CALL(*gl, Uniform1fv(info.real_location, info.size, _)) |
433 .Times(1) | 487 .Times(1) |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 gfx::SetGLImplementation(implementation); | 823 gfx::SetGLImplementation(implementation); |
770 } | 824 } |
771 | 825 |
772 ScopedGLImplementationSetter::~ScopedGLImplementationSetter() { | 826 ScopedGLImplementationSetter::~ScopedGLImplementationSetter() { |
773 gfx::SetGLImplementation(old_implementation_); | 827 gfx::SetGLImplementation(old_implementation_); |
774 } | 828 } |
775 | 829 |
776 } // namespace gles2 | 830 } // namespace gles2 |
777 } // namespace gpu | 831 } // namespace gpu |
778 | 832 |
OLD | NEW |