// This tests that when the packed depth+stencil extension is supported DrawingBuffer always allocates // a single packed renderbuffer if either is requested and properly computes the actual context attributes // as defined by WebGL. We always allocate a packed buffer in this case since many desktop OpenGL drivers // that support this extension do not consider a framebuffer with only a depth or a stencil buffer attached // to be complete. TEST(DrawingBufferDepthStencilTest, packedDepthStencilSupported) { DepthStencilTestCase cases[] = { DepthStencilTestCase(false, false, false, 0, "neither"), DepthStencilTestCase(true, false, true, 1, "stencil only"), DepthStencilTestCase(false, true, true, 1, "depth only"), DepthStencilTestCase(true, true, true, 1, "both"), }; for (size_t i = 0; i < arraysize(cases); i++) { SCOPED_TRACE(cases[i].testCaseName); OwnPtr<DepthStencilTrackingContext> context = adoptPtr(new DepthStencilTrackingContext); DepthStencilTrackingContext* trackingContext = context.get(); DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; WebGraphicsContext3D::Attributes requestedAttributes; requestedAttributes.stencil = cases[i].requestStencil; requestedAttributes.depth = cases[i].requestDepth; RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create(context.release(), IntSize(10, 10), preserve, requestedAttributes); EXPECT_EQ(cases[i].requestDepth, drawingBuffer->getActualAttributes().depth); EXPECT_EQ(cases[i].requestStencil, drawingBuffer->getActualAttributes().stencil); EXPECT_EQ(cases[i].expectedRenderBuffers, trackingContext->numAllocatedRenderBuffer()); if (cases[i].expectDepthStencil) { EXPECT_EQ(trackingContext->stencilAttachment(), trackingContext->depthAttachment()); } else if (cases[i].requestStencil || cases[i].requestDepth) { EXPECT_NE(trackingContext->stencilAttachment(), trackingContext->depthAttachment()); } else { EXPECT_EQ(0u, trackingContext->stencilAttachment()); EXPECT_EQ(0u, trackingContext->depthAttachment()); } drawingBuffer->reset(IntSize(10, 20)); EXPECT_EQ(cases[i].requestDepth, drawingBuffer->getActualAttributes().depth); EXPECT_EQ(cases[i].requestStencil, drawingBuffer->getActualAttributes().stencil); EXPECT_EQ(cases[i].expectedRenderBuffers, trackingContext->numAllocatedRenderBuffer()); if (cases[i].expectDepthStencil) { EXPECT_EQ(trackingContext->stencilAttachment(), trackingContext->depthAttachment()); } else if (cases[i].requestStencil || cases[i].requestDepth) { EXPECT_NE(trackingContext->stencilAttachment(), trackingContext->depthAttachment()); } else { EXPECT_EQ(0u, trackingContext->stencilAttachment()); EXPECT_EQ(0u, trackingContext->depthAttachment()); } drawingBuffer->beginDestruction(); } }
// This tests that, when the packed depth+stencil extension is supported, and // either depth or stencil is requested, DrawingBuffer always allocates a single // packed renderbuffer and properly computes the actual context attributes as // defined by WebGL. We always allocate a packed buffer in this case since many // desktop OpenGL drivers that support this extension do not consider a // framebuffer with only a depth or a stencil buffer attached to be complete. TEST(DrawingBufferDepthStencilTest, packedDepthStencilSupported) { DepthStencilTestCase cases[] = { DepthStencilTestCase(false, false, 0, "neither"), DepthStencilTestCase(true, false, 1, "stencil only"), DepthStencilTestCase(false, true, 1, "depth only"), DepthStencilTestCase(true, true, 1, "both"), }; for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); i++) { SCOPED_TRACE(cases[i].testCaseName); std::unique_ptr<DepthStencilTrackingGLES2Interface> gl = WTF::wrapUnique(new DepthStencilTrackingGLES2Interface); DepthStencilTrackingGLES2Interface* trackingGL = gl.get(); std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = WTF::wrapUnique( new WebGraphicsContext3DProviderForTests(std::move(gl))); DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; bool premultipliedAlpha = false; bool wantAlphaChannel = true; bool wantDepthBuffer = cases[i].requestDepth; bool wantStencilBuffer = cases[i].requestStencil; bool wantAntialiasing = false; RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( std::move(provider), nullptr, IntSize(10, 10), premultipliedAlpha, wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing, preserve, DrawingBuffer::WebGL1, DrawingBuffer::AllowChromiumImage); // When we request a depth or a stencil buffer, we will get both. EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, drawingBuffer->hasDepthBuffer()); EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, drawingBuffer->hasStencilBuffer()); EXPECT_EQ(cases[i].expectedRenderBuffers, trackingGL->numAllocatedRenderBuffer()); if (cases[i].requestDepth || cases[i].requestStencil) { EXPECT_NE(0u, trackingGL->depthStencilAttachment()); EXPECT_EQ(0u, trackingGL->depthAttachment()); EXPECT_EQ(0u, trackingGL->stencilAttachment()); } else { EXPECT_EQ(0u, trackingGL->depthStencilAttachment()); EXPECT_EQ(0u, trackingGL->depthAttachment()); EXPECT_EQ(0u, trackingGL->stencilAttachment()); } drawingBuffer->resize(IntSize(10, 20)); EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, drawingBuffer->hasDepthBuffer()); EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, drawingBuffer->hasStencilBuffer()); EXPECT_EQ(cases[i].expectedRenderBuffers, trackingGL->numAllocatedRenderBuffer()); if (cases[i].requestDepth || cases[i].requestStencil) { EXPECT_NE(0u, trackingGL->depthStencilAttachment()); EXPECT_EQ(0u, trackingGL->depthAttachment()); EXPECT_EQ(0u, trackingGL->stencilAttachment()); } else { EXPECT_EQ(0u, trackingGL->depthStencilAttachment()); EXPECT_EQ(0u, trackingGL->depthAttachment()); EXPECT_EQ(0u, trackingGL->stencilAttachment()); } drawingBuffer->beginDestruction(); } }