OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "platform/graphics/CanvasColorParams.h" | 40 #include "platform/graphics/CanvasColorParams.h" |
41 #include "platform/graphics/ImageBuffer.h" | 41 #include "platform/graphics/ImageBuffer.h" |
42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
43 #include "platform/graphics/gpu/DrawingBufferTestHelpers.h" | 43 #include "platform/graphics/gpu/DrawingBufferTestHelpers.h" |
44 #include "platform/testing/TestingPlatformSupport.h" | 44 #include "platform/testing/TestingPlatformSupport.h" |
45 #include "platform/wtf/PtrUtil.h" | 45 #include "platform/wtf/PtrUtil.h" |
46 #include "platform/wtf/RefPtr.h" | 46 #include "platform/wtf/RefPtr.h" |
47 #include "public/platform/Platform.h" | 47 #include "public/platform/Platform.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
49 | 49 |
50 using testing::Test; | 50 using ::testing::Test; |
51 using testing::_; | 51 using ::testing::_; |
52 | 52 |
53 namespace blink { | 53 namespace blink { |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 class FakePlatformSupport : public TestingPlatformSupport { | 57 class FakePlatformSupport : public TestingPlatformSupport { |
58 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { | 58 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { |
59 return &test_gpu_memory_buffer_manager_; | 59 return &test_gpu_memory_buffer_manager_; |
60 } | 60 } |
61 | 61 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 RuntimeEnabledFeatures::SetWebGLImageChromiumEnabled(true); | 403 RuntimeEnabledFeatures::SetWebGLImageChromiumEnabled(true); |
404 GLES2InterfaceForTests* gl_ = | 404 GLES2InterfaceForTests* gl_ = |
405 static_cast<GLES2InterfaceForTests*>(provider->ContextGL()); | 405 static_cast<GLES2InterfaceForTests*>(provider->ContextGL()); |
406 image_id0_ = gl_->NextImageIdToBeCreated(); | 406 image_id0_ = gl_->NextImageIdToBeCreated(); |
407 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id0_)).Times(1); | 407 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id0_)).Times(1); |
408 drawing_buffer_ = DrawingBufferForTests::Create( | 408 drawing_buffer_ = DrawingBufferForTests::Create( |
409 std::move(provider), gl_, initial_size, DrawingBuffer::kPreserve, | 409 std::move(provider), gl_, initial_size, DrawingBuffer::kPreserve, |
410 kDisableMultisampling); | 410 kDisableMultisampling); |
411 CHECK(drawing_buffer_); | 411 CHECK(drawing_buffer_); |
412 SetAndSaveRestoreState(true); | 412 SetAndSaveRestoreState(true); |
413 testing::Mock::VerifyAndClearExpectations(gl_); | 413 ::testing::Mock::VerifyAndClearExpectations(gl_); |
414 } | 414 } |
415 | 415 |
416 void TearDown() override { | 416 void TearDown() override { |
417 RuntimeEnabledFeatures::SetWebGLImageChromiumEnabled(false); | 417 RuntimeEnabledFeatures::SetWebGLImageChromiumEnabled(false); |
418 platform_.reset(); | 418 platform_.reset(); |
419 } | 419 } |
420 | 420 |
421 GLuint image_id0_; | 421 GLuint image_id0_; |
422 std::unique_ptr<ScopedTestingPlatformSupport<FakePlatformSupport>> platform_; | 422 std::unique_ptr<ScopedTestingPlatformSupport<FakePlatformSupport>> platform_; |
423 }; | 423 }; |
424 | 424 |
425 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { | 425 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { |
426 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests(); | 426 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests(); |
427 cc::TextureMailbox texture_mailbox; | 427 cc::TextureMailbox texture_mailbox; |
428 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 428 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
429 | 429 |
430 IntSize initial_size(kInitialWidth, kInitialHeight); | 430 IntSize initial_size(kInitialWidth, kInitialHeight); |
431 IntSize alternate_size(kInitialWidth, kAlternateHeight); | 431 IntSize alternate_size(kInitialWidth, kAlternateHeight); |
432 | 432 |
433 GLuint image_id1 = gl_->NextImageIdToBeCreated(); | 433 GLuint image_id1 = gl_->NextImageIdToBeCreated(); |
434 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id1)).Times(1); | 434 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id1)).Times(1); |
435 // Produce one mailbox at size 100x100. | 435 // Produce one mailbox at size 100x100. |
436 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); | 436 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); |
437 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, | 437 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, |
438 &release_callback)); | 438 &release_callback)); |
439 EXPECT_EQ(initial_size, gl_->MostRecentlyProducedSize()); | 439 EXPECT_EQ(initial_size, gl_->MostRecentlyProducedSize()); |
440 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); | 440 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); |
441 testing::Mock::VerifyAndClearExpectations(gl_); | 441 ::testing::Mock::VerifyAndClearExpectations(gl_); |
442 VerifyStateWasRestored(); | 442 VerifyStateWasRestored(); |
443 | 443 |
444 GLuint image_id2 = gl_->NextImageIdToBeCreated(); | 444 GLuint image_id2 = gl_->NextImageIdToBeCreated(); |
445 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id2)).Times(1); | 445 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id2)).Times(1); |
446 EXPECT_CALL(*gl_, DestroyImageMock(image_id0_)).Times(1); | 446 EXPECT_CALL(*gl_, DestroyImageMock(image_id0_)).Times(1); |
447 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id0_)).Times(1); | 447 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id0_)).Times(1); |
448 EXPECT_CALL(*gl_, DestroyImageMock(image_id1)).Times(1); | 448 EXPECT_CALL(*gl_, DestroyImageMock(image_id1)).Times(1); |
449 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id1)).Times(1); | 449 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id1)).Times(1); |
450 // Resize to 100x50. | 450 // Resize to 100x50. |
451 drawing_buffer_->Resize(alternate_size); | 451 drawing_buffer_->Resize(alternate_size); |
452 VerifyStateWasRestored(); | 452 VerifyStateWasRestored(); |
453 release_callback->Run(gpu::SyncToken(), false /* lostResource */); | 453 release_callback->Run(gpu::SyncToken(), false /* lostResource */); |
454 VerifyStateWasRestored(); | 454 VerifyStateWasRestored(); |
455 testing::Mock::VerifyAndClearExpectations(gl_); | 455 ::testing::Mock::VerifyAndClearExpectations(gl_); |
456 | 456 |
457 GLuint image_id3 = gl_->NextImageIdToBeCreated(); | 457 GLuint image_id3 = gl_->NextImageIdToBeCreated(); |
458 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id3)).Times(1); | 458 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id3)).Times(1); |
459 // Produce a mailbox at this size. | 459 // Produce a mailbox at this size. |
460 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); | 460 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); |
461 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, | 461 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, |
462 &release_callback)); | 462 &release_callback)); |
463 EXPECT_EQ(alternate_size, gl_->MostRecentlyProducedSize()); | 463 EXPECT_EQ(alternate_size, gl_->MostRecentlyProducedSize()); |
464 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); | 464 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); |
465 testing::Mock::VerifyAndClearExpectations(gl_); | 465 ::testing::Mock::VerifyAndClearExpectations(gl_); |
466 | 466 |
467 GLuint image_id4 = gl_->NextImageIdToBeCreated(); | 467 GLuint image_id4 = gl_->NextImageIdToBeCreated(); |
468 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id4)).Times(1); | 468 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id4)).Times(1); |
469 EXPECT_CALL(*gl_, DestroyImageMock(image_id2)).Times(1); | 469 EXPECT_CALL(*gl_, DestroyImageMock(image_id2)).Times(1); |
470 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id2)).Times(1); | 470 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id2)).Times(1); |
471 EXPECT_CALL(*gl_, DestroyImageMock(image_id3)).Times(1); | 471 EXPECT_CALL(*gl_, DestroyImageMock(image_id3)).Times(1); |
472 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id3)).Times(1); | 472 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id3)).Times(1); |
473 // Reset to initial size. | 473 // Reset to initial size. |
474 drawing_buffer_->Resize(initial_size); | 474 drawing_buffer_->Resize(initial_size); |
475 VerifyStateWasRestored(); | 475 VerifyStateWasRestored(); |
476 release_callback->Run(gpu::SyncToken(), false /* lostResource */); | 476 release_callback->Run(gpu::SyncToken(), false /* lostResource */); |
477 VerifyStateWasRestored(); | 477 VerifyStateWasRestored(); |
478 testing::Mock::VerifyAndClearExpectations(gl_); | 478 ::testing::Mock::VerifyAndClearExpectations(gl_); |
479 | 479 |
480 GLuint image_id5 = gl_->NextImageIdToBeCreated(); | 480 GLuint image_id5 = gl_->NextImageIdToBeCreated(); |
481 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id5)).Times(1); | 481 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id5)).Times(1); |
482 // Prepare another mailbox and verify that it's the correct size. | 482 // Prepare another mailbox and verify that it's the correct size. |
483 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); | 483 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); |
484 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, | 484 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, |
485 &release_callback)); | 485 &release_callback)); |
486 EXPECT_EQ(initial_size, gl_->MostRecentlyProducedSize()); | 486 EXPECT_EQ(initial_size, gl_->MostRecentlyProducedSize()); |
487 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); | 487 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); |
488 testing::Mock::VerifyAndClearExpectations(gl_); | 488 ::testing::Mock::VerifyAndClearExpectations(gl_); |
489 | 489 |
490 // Prepare one final mailbox and verify that it's the correct size. | 490 // Prepare one final mailbox and verify that it's the correct size. |
491 release_callback->Run(gpu::SyncToken(), false /* lostResource */); | 491 release_callback->Run(gpu::SyncToken(), false /* lostResource */); |
492 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); | 492 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); |
493 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, | 493 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, |
494 &release_callback)); | 494 &release_callback)); |
495 EXPECT_EQ(initial_size, gl_->MostRecentlyProducedSize()); | 495 EXPECT_EQ(initial_size, gl_->MostRecentlyProducedSize()); |
496 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); | 496 EXPECT_TRUE(texture_mailbox.is_overlay_candidate()); |
497 release_callback->Run(gpu::SyncToken(), false /* lostResource */); | 497 release_callback->Run(gpu::SyncToken(), false /* lostResource */); |
498 | 498 |
499 EXPECT_CALL(*gl_, DestroyImageMock(image_id5)).Times(1); | 499 EXPECT_CALL(*gl_, DestroyImageMock(image_id5)).Times(1); |
500 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id5)).Times(1); | 500 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id5)).Times(1); |
501 EXPECT_CALL(*gl_, DestroyImageMock(image_id4)).Times(1); | 501 EXPECT_CALL(*gl_, DestroyImageMock(image_id4)).Times(1); |
502 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id4)).Times(1); | 502 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id4)).Times(1); |
503 drawing_buffer_->BeginDestruction(); | 503 drawing_buffer_->BeginDestruction(); |
504 testing::Mock::VerifyAndClearExpectations(gl_); | 504 ::testing::Mock::VerifyAndClearExpectations(gl_); |
505 } | 505 } |
506 | 506 |
507 TEST_F(DrawingBufferImageChromiumTest, allocationFailure) { | 507 TEST_F(DrawingBufferImageChromiumTest, allocationFailure) { |
508 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests(); | 508 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests(); |
509 cc::TextureMailbox texture_mailbox1; | 509 cc::TextureMailbox texture_mailbox1; |
510 std::unique_ptr<cc::SingleReleaseCallback> release_callback1; | 510 std::unique_ptr<cc::SingleReleaseCallback> release_callback1; |
511 cc::TextureMailbox texture_mailbox2; | 511 cc::TextureMailbox texture_mailbox2; |
512 std::unique_ptr<cc::SingleReleaseCallback> release_callback2; | 512 std::unique_ptr<cc::SingleReleaseCallback> release_callback2; |
513 cc::TextureMailbox texture_mailbox3; | 513 cc::TextureMailbox texture_mailbox3; |
514 std::unique_ptr<cc::SingleReleaseCallback> release_callback3; | 514 std::unique_ptr<cc::SingleReleaseCallback> release_callback3; |
515 | 515 |
516 // Request a mailbox. An image should already be created. Everything works | 516 // Request a mailbox. An image should already be created. Everything works |
517 // as expected. | 517 // as expected. |
518 EXPECT_CALL(*gl_, BindTexImage2DMock(_)).Times(1); | 518 EXPECT_CALL(*gl_, BindTexImage2DMock(_)).Times(1); |
519 IntSize initial_size(kInitialWidth, kInitialHeight); | 519 IntSize initial_size(kInitialWidth, kInitialHeight); |
520 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); | 520 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); |
521 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox1, | 521 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox1, |
522 &release_callback1)); | 522 &release_callback1)); |
523 EXPECT_TRUE(texture_mailbox1.is_overlay_candidate()); | 523 EXPECT_TRUE(texture_mailbox1.is_overlay_candidate()); |
524 testing::Mock::VerifyAndClearExpectations(gl_); | 524 ::testing::Mock::VerifyAndClearExpectations(gl_); |
525 VerifyStateWasRestored(); | 525 VerifyStateWasRestored(); |
526 | 526 |
527 // Force image CHROMIUM creation failure. Request another mailbox. It should | 527 // Force image CHROMIUM creation failure. Request another mailbox. It should |
528 // still be provided, but this time with allowOverlay = false. | 528 // still be provided, but this time with allowOverlay = false. |
529 gl_->SetCreateImageChromiumFail(true); | 529 gl_->SetCreateImageChromiumFail(true); |
530 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); | 530 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); |
531 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox2, | 531 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox2, |
532 &release_callback2)); | 532 &release_callback2)); |
533 EXPECT_FALSE(texture_mailbox2.is_overlay_candidate()); | 533 EXPECT_FALSE(texture_mailbox2.is_overlay_candidate()); |
534 VerifyStateWasRestored(); | 534 VerifyStateWasRestored(); |
535 | 535 |
536 // Check that if image CHROMIUM starts working again, mailboxes are | 536 // Check that if image CHROMIUM starts working again, mailboxes are |
537 // correctly created with allowOverlay = true. | 537 // correctly created with allowOverlay = true. |
538 EXPECT_CALL(*gl_, BindTexImage2DMock(_)).Times(1); | 538 EXPECT_CALL(*gl_, BindTexImage2DMock(_)).Times(1); |
539 gl_->SetCreateImageChromiumFail(false); | 539 gl_->SetCreateImageChromiumFail(false); |
540 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); | 540 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); |
541 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox3, | 541 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox3, |
542 &release_callback3)); | 542 &release_callback3)); |
543 EXPECT_TRUE(texture_mailbox3.is_overlay_candidate()); | 543 EXPECT_TRUE(texture_mailbox3.is_overlay_candidate()); |
544 testing::Mock::VerifyAndClearExpectations(gl_); | 544 ::testing::Mock::VerifyAndClearExpectations(gl_); |
545 VerifyStateWasRestored(); | 545 VerifyStateWasRestored(); |
546 | 546 |
547 release_callback1->Run(gpu::SyncToken(), false /* lostResource */); | 547 release_callback1->Run(gpu::SyncToken(), false /* lostResource */); |
548 release_callback2->Run(gpu::SyncToken(), false /* lostResource */); | 548 release_callback2->Run(gpu::SyncToken(), false /* lostResource */); |
549 release_callback3->Run(gpu::SyncToken(), false /* lostResource */); | 549 release_callback3->Run(gpu::SyncToken(), false /* lostResource */); |
550 | 550 |
551 EXPECT_CALL(*gl_, DestroyImageMock(_)).Times(3); | 551 EXPECT_CALL(*gl_, DestroyImageMock(_)).Times(3); |
552 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(_)).Times(3); | 552 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(_)).Times(3); |
553 drawing_buffer_->BeginDestruction(); | 553 drawing_buffer_->BeginDestruction(); |
554 testing::Mock::VerifyAndClearExpectations(gl_); | 554 ::testing::Mock::VerifyAndClearExpectations(gl_); |
555 } | 555 } |
556 | 556 |
557 class DepthStencilTrackingGLES2Interface | 557 class DepthStencilTrackingGLES2Interface |
558 : public gpu::gles2::GLES2InterfaceStub { | 558 : public gpu::gles2::GLES2InterfaceStub { |
559 public: | 559 public: |
560 void FramebufferRenderbuffer(GLenum target, | 560 void FramebufferRenderbuffer(GLenum target, |
561 GLenum attachment, | 561 GLenum attachment, |
562 GLenum renderbuffertarget, | 562 GLenum renderbuffertarget, |
563 GLuint renderbuffer) override { | 563 GLuint renderbuffer) override { |
564 switch (attachment) { | 564 switch (attachment) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 drawing_buffer_->SetIsHidden(true); | 719 drawing_buffer_->SetIsHidden(true); |
720 release_callback->Run(wait_sync_token, false /* lostResource */); | 720 release_callback->Run(wait_sync_token, false /* lostResource */); |
721 // m_drawingBuffer deletes mailbox immediately when hidden. | 721 // m_drawingBuffer deletes mailbox immediately when hidden. |
722 | 722 |
723 EXPECT_EQ(wait_sync_token, gl_->MostRecentlyWaitedSyncToken()); | 723 EXPECT_EQ(wait_sync_token, gl_->MostRecentlyWaitedSyncToken()); |
724 | 724 |
725 drawing_buffer_->BeginDestruction(); | 725 drawing_buffer_->BeginDestruction(); |
726 } | 726 } |
727 | 727 |
728 } // namespace blink | 728 } // namespace blink |
OLD | NEW |