| 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId4)).Times(1); | 554 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId4)).Times(1); |
| 555 m_drawingBuffer->beginDestruction(); | 555 m_drawingBuffer->beginDestruction(); |
| 556 testing::Mock::VerifyAndClearExpectations(webContext()); | 556 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 557 } | 557 } |
| 558 | 558 |
| 559 class DepthStencilTrackingContext : public MockWebGraphicsContext3D { | 559 class DepthStencilTrackingContext : public MockWebGraphicsContext3D { |
| 560 public: | 560 public: |
| 561 DepthStencilTrackingContext() | 561 DepthStencilTrackingContext() |
| 562 : m_nextRenderBufferId(1) | 562 : m_nextRenderBufferId(1) |
| 563 , m_stencilAttachment(0) | 563 , m_stencilAttachment(0) |
| 564 , m_depthAttachment(0) {} | 564 , m_depthAttachment(0) |
| 565 , m_depthStencilAttachment(0) {} |
| 565 ~DepthStencilTrackingContext() override {} | 566 ~DepthStencilTrackingContext() override {} |
| 566 | 567 |
| 567 int numAllocatedRenderBuffer() const { return m_nextRenderBufferId - 1; } | 568 int numAllocatedRenderBuffer() const { return m_nextRenderBufferId - 1; } |
| 568 WebGLId stencilAttachment() const { return m_stencilAttachment; } | 569 WebGLId stencilAttachment() const { return m_stencilAttachment; } |
| 569 WebGLId depthAttachment() const { return m_depthAttachment; } | 570 WebGLId depthAttachment() const { return m_depthAttachment; } |
| 571 WebGLId depthStencilAttachment() const { return m_depthStencilAttachment; } |
| 570 | 572 |
| 571 WebString getString(WGC3Denum type) override | 573 WebString getString(WGC3Denum type) override |
| 572 { | 574 { |
| 573 if (type == GL_EXTENSIONS) { | 575 if (type == GL_EXTENSIONS) { |
| 574 return WebString::fromUTF8("GL_OES_packed_depth_stencil"); | 576 return WebString::fromUTF8("GL_OES_packed_depth_stencil"); |
| 575 } | 577 } |
| 576 return WebString(); | 578 return WebString(); |
| 577 } | 579 } |
| 578 | 580 |
| 579 WebGLId createRenderbuffer() override | 581 WebGLId createRenderbuffer() override |
| 580 { | 582 { |
| 581 return ++m_nextRenderBufferId; | 583 return ++m_nextRenderBufferId; |
| 582 } | 584 } |
| 583 | 585 |
| 584 void framebufferRenderbuffer(WGC3Denum target, WGC3Denum attachment, WGC3Den
um renderbuffertarget, WebGLId renderbuffer) override | 586 void framebufferRenderbuffer(WGC3Denum target, WGC3Denum attachment, WGC3Den
um renderbuffertarget, WebGLId renderbuffer) override |
| 585 { | 587 { |
| 586 if (attachment == GL_STENCIL_ATTACHMENT) { | 588 switch (attachment) { |
| 589 case GL_DEPTH_ATTACHMENT: |
| 590 m_depthAttachment = renderbuffer; |
| 591 break; |
| 592 case GL_STENCIL_ATTACHMENT: |
| 587 m_stencilAttachment = renderbuffer; | 593 m_stencilAttachment = renderbuffer; |
| 588 } else { | 594 break; |
| 589 m_depthAttachment = renderbuffer; | 595 case GL_DEPTH_STENCIL_ATTACHMENT: |
| 596 m_depthStencilAttachment = renderbuffer; |
| 597 break; |
| 598 default: |
| 599 ASSERT_NOT_REACHED(); |
| 600 break; |
| 590 } | 601 } |
| 591 } | 602 } |
| 592 | 603 |
| 593 void getIntegerv(WGC3Denum ptype, WGC3Dint* value) override | 604 void getIntegerv(WGC3Denum ptype, WGC3Dint* value) override |
| 594 { | 605 { |
| 595 switch (ptype) { | 606 switch (ptype) { |
| 596 case GL_DEPTH_BITS: | 607 case GL_DEPTH_BITS: |
| 597 *value = m_depthAttachment ? 24 : 0; | 608 *value = (m_depthAttachment || m_depthStencilAttachment) ? 24 : 0; |
| 598 return; | 609 return; |
| 599 case GL_STENCIL_BITS: | 610 case GL_STENCIL_BITS: |
| 600 *value = m_stencilAttachment ? 8 : 0; | 611 *value = (m_stencilAttachment || m_depthStencilAttachment) ? 8 : 0; |
| 601 return; | 612 return; |
| 602 } | 613 } |
| 603 MockWebGraphicsContext3D::getIntegerv(ptype, value); | 614 MockWebGraphicsContext3D::getIntegerv(ptype, value); |
| 604 } | 615 } |
| 605 | 616 |
| 606 private: | 617 private: |
| 607 WebGLId m_nextRenderBufferId; | 618 WebGLId m_nextRenderBufferId; |
| 608 WebGLId m_stencilAttachment; | 619 WebGLId m_stencilAttachment; |
| 609 WebGLId m_depthAttachment; | 620 WebGLId m_depthAttachment; |
| 621 WebGLId m_depthStencilAttachment; |
| 610 }; | 622 }; |
| 611 | 623 |
| 612 struct DepthStencilTestCase { | 624 struct DepthStencilTestCase { |
| 613 DepthStencilTestCase(bool requestStencil, bool requestDepth, int expectedRen
derBuffers, bool expectDepthStencil, const char* const testCaseName) | 625 DepthStencilTestCase(bool requestStencil, bool requestDepth, int expectedRen
derBuffers, const char* const testCaseName) |
| 614 : requestStencil(requestStencil) | 626 : requestStencil(requestStencil) |
| 615 , requestDepth(requestDepth) | 627 , requestDepth(requestDepth) |
| 616 , expectDepthStencil(expectDepthStencil) | |
| 617 , expectedRenderBuffers(expectedRenderBuffers) | 628 , expectedRenderBuffers(expectedRenderBuffers) |
| 618 , testCaseName(testCaseName) { } | 629 , testCaseName(testCaseName) { } |
| 619 | 630 |
| 620 bool requestStencil; | 631 bool requestStencil; |
| 621 bool requestDepth; | 632 bool requestDepth; |
| 622 bool expectDepthStencil; | |
| 623 int expectedRenderBuffers; | 633 int expectedRenderBuffers; |
| 624 const char* const testCaseName; | 634 const char* const testCaseName; |
| 625 }; | 635 }; |
| 626 | 636 |
| 627 // This tests that when the packed depth+stencil extension is supported DrawingB
uffer always allocates | 637 // This tests that when the packed depth+stencil extension is supported DrawingB
uffer always allocates |
| 628 // a single packed renderbuffer if either is requested and properly computes the
actual context attributes | 638 // a single packed renderbuffer if either is requested and properly computes the
actual context attributes |
| 629 // as defined by WebGL. We always allocate a packed buffer in this case since ma
ny desktop OpenGL drivers | 639 // as defined by WebGL. We always allocate a packed buffer in this case since ma
ny desktop OpenGL drivers |
| 630 // that support this extension do not consider a framebuffer with only a depth o
r a stencil buffer attached | 640 // that support this extension do not consider a framebuffer with only a depth o
r a stencil buffer attached |
| 631 // to be complete. | 641 // to be complete. |
| 632 TEST(DrawingBufferDepthStencilTest, packedDepthStencilSupported) | 642 TEST(DrawingBufferDepthStencilTest, packedDepthStencilSupported) |
| 633 { | 643 { |
| 634 DepthStencilTestCase cases[] = { | 644 DepthStencilTestCase cases[] = { |
| 635 DepthStencilTestCase(false, false, false, 0, "neither"), | 645 DepthStencilTestCase(false, false, 0, "neither"), |
| 636 DepthStencilTestCase(true, false, true, 1, "stencil only"), | 646 DepthStencilTestCase(true, false, 1, "stencil only"), |
| 637 DepthStencilTestCase(false, true, true, 1, "depth only"), | 647 DepthStencilTestCase(false, true, 1, "depth only"), |
| 638 DepthStencilTestCase(true, true, true, 1, "both"), | 648 DepthStencilTestCase(true, true, 1, "both"), |
| 639 }; | 649 }; |
| 640 | 650 |
| 641 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); i++) { | 651 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); i++) { |
| 642 SCOPED_TRACE(cases[i].testCaseName); | 652 SCOPED_TRACE(cases[i].testCaseName); |
| 643 OwnPtr<DepthStencilTrackingContext> context = adoptPtr(new DepthStencilT
rackingContext); | 653 OwnPtr<DepthStencilTrackingContext> context = adoptPtr(new DepthStencilT
rackingContext); |
| 644 DepthStencilTrackingContext* trackingContext = context.get(); | 654 DepthStencilTrackingContext* trackingContext = context.get(); |
| 645 DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; | 655 DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; |
| 646 | 656 |
| 647 WebGraphicsContext3D::Attributes requestedAttributes; | 657 WebGraphicsContext3D::Attributes requestedAttributes; |
| 648 requestedAttributes.stencil = cases[i].requestStencil; | 658 requestedAttributes.stencil = cases[i].requestStencil; |
| 649 requestedAttributes.depth = cases[i].requestDepth; | 659 requestedAttributes.depth = cases[i].requestDepth; |
| 650 RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create(context.rele
ase(), IntSize(10, 10), preserve, requestedAttributes); | 660 RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create(context.rele
ase(), IntSize(10, 10), preserve, requestedAttributes); |
| 651 | 661 |
| 652 EXPECT_EQ(cases[i].requestDepth, drawingBuffer->getActualAttributes().de
pth); | 662 EXPECT_EQ(cases[i].requestDepth, drawingBuffer->getActualAttributes().de
pth); |
| 653 EXPECT_EQ(cases[i].requestStencil, drawingBuffer->getActualAttributes().
stencil); | 663 EXPECT_EQ(cases[i].requestStencil, drawingBuffer->getActualAttributes().
stencil); |
| 654 EXPECT_EQ(cases[i].expectedRenderBuffers, trackingContext->numAllocatedR
enderBuffer()); | 664 EXPECT_EQ(cases[i].expectedRenderBuffers, trackingContext->numAllocatedR
enderBuffer()); |
| 655 if (cases[i].expectDepthStencil) { | 665 if (cases[i].requestDepth || cases[i].requestStencil) { |
| 656 EXPECT_EQ(trackingContext->stencilAttachment(), trackingContext->dep
thAttachment()); | 666 EXPECT_NE(0u, trackingContext->depthStencilAttachment()); |
| 657 } else if (cases[i].requestStencil || cases[i].requestDepth) { | 667 EXPECT_EQ(0u, trackingContext->depthAttachment()); |
| 658 EXPECT_NE(trackingContext->stencilAttachment(), trackingContext->dep
thAttachment()); | 668 EXPECT_EQ(0u, trackingContext->stencilAttachment()); |
| 659 } else { | 669 } else { |
| 670 EXPECT_EQ(0u, trackingContext->depthStencilAttachment()); |
| 671 EXPECT_EQ(0u, trackingContext->depthAttachment()); |
| 660 EXPECT_EQ(0u, trackingContext->stencilAttachment()); | 672 EXPECT_EQ(0u, trackingContext->stencilAttachment()); |
| 661 EXPECT_EQ(0u, trackingContext->depthAttachment()); | |
| 662 } | 673 } |
| 663 | 674 |
| 664 drawingBuffer->reset(IntSize(10, 20)); | 675 drawingBuffer->reset(IntSize(10, 20)); |
| 665 EXPECT_EQ(cases[i].requestDepth, drawingBuffer->getActualAttributes().de
pth); | 676 EXPECT_EQ(cases[i].requestDepth, drawingBuffer->getActualAttributes().de
pth); |
| 666 EXPECT_EQ(cases[i].requestStencil, drawingBuffer->getActualAttributes().
stencil); | 677 EXPECT_EQ(cases[i].requestStencil, drawingBuffer->getActualAttributes().
stencil); |
| 667 EXPECT_EQ(cases[i].expectedRenderBuffers, trackingContext->numAllocatedR
enderBuffer()); | 678 EXPECT_EQ(cases[i].expectedRenderBuffers, trackingContext->numAllocatedR
enderBuffer()); |
| 668 if (cases[i].expectDepthStencil) { | 679 if (cases[i].requestDepth || cases[i].requestStencil) { |
| 669 EXPECT_EQ(trackingContext->stencilAttachment(), trackingContext->dep
thAttachment()); | 680 EXPECT_NE(0u, trackingContext->depthStencilAttachment()); |
| 670 } else if (cases[i].requestStencil || cases[i].requestDepth) { | 681 EXPECT_EQ(0u, trackingContext->depthAttachment()); |
| 671 EXPECT_NE(trackingContext->stencilAttachment(), trackingContext->dep
thAttachment()); | 682 EXPECT_EQ(0u, trackingContext->stencilAttachment()); |
| 672 } else { | 683 } else { |
| 684 EXPECT_EQ(0u, trackingContext->depthStencilAttachment()); |
| 685 EXPECT_EQ(0u, trackingContext->depthAttachment()); |
| 673 EXPECT_EQ(0u, trackingContext->stencilAttachment()); | 686 EXPECT_EQ(0u, trackingContext->stencilAttachment()); |
| 674 EXPECT_EQ(0u, trackingContext->depthAttachment()); | |
| 675 } | 687 } |
| 676 | 688 |
| 677 drawingBuffer->beginDestruction(); | 689 drawingBuffer->beginDestruction(); |
| 678 } | 690 } |
| 679 } | 691 } |
| 680 | 692 |
| 681 TEST_F(DrawingBufferTest, verifySetIsHiddenProperlyAffectsMailboxes) | 693 TEST_F(DrawingBufferTest, verifySetIsHiddenProperlyAffectsMailboxes) |
| 682 { | 694 { |
| 683 blink::WebExternalTextureMailbox mailbox; | 695 blink::WebExternalTextureMailbox mailbox; |
| 684 | 696 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 m_drawingBuffer->markContentsChanged(); | 736 m_drawingBuffer->markContentsChanged(); |
| 725 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | 737 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 726 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); | 738 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 727 EXPECT_FALSE(mailbox.allowOverlay); | 739 EXPECT_FALSE(mailbox.allowOverlay); |
| 728 | 740 |
| 729 m_drawingBuffer->mailboxReleased(mailbox, false); | 741 m_drawingBuffer->mailboxReleased(mailbox, false); |
| 730 m_drawingBuffer->beginDestruction(); | 742 m_drawingBuffer->beginDestruction(); |
| 731 } | 743 } |
| 732 | 744 |
| 733 } // namespace blink | 745 } // namespace blink |
| OLD | NEW |