| Index: Source/web/tests/DrawingBufferTest.cpp
|
| diff --git a/Source/web/tests/DrawingBufferTest.cpp b/Source/web/tests/DrawingBufferTest.cpp
|
| index 2b72d40ff993e5c954ab0daa6ba6519ee2636e43..dc8bd6971d0d2d6359001fb7fd4296ba5db5082a 100644
|
| --- a/Source/web/tests/DrawingBufferTest.cpp
|
| +++ b/Source/web/tests/DrawingBufferTest.cpp
|
| @@ -34,6 +34,7 @@
|
|
|
| #include "platform/graphics/GraphicsContext3D.h"
|
| #include "public/platform/Platform.h"
|
| +#include "public/platform/WebExternalTextureMailbox.h"
|
| #include "web/tests/MockWebGraphicsContext3D.h"
|
| #include "wtf/RefPtr.h"
|
|
|
| @@ -53,6 +54,56 @@ public:
|
| IntSize oldestContextSize() { return IntSize(); }
|
| };
|
|
|
| +class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D {
|
| +public:
|
| + WebGraphicsContext3DForTests()
|
| + : MockWebGraphicsContext3D()
|
| + , m_boundTexture(0)
|
| + , m_currentMailboxByte(0) { }
|
| +
|
| + virtual void bindTexture(WGC3Denum target, WebGLId texture)
|
| + {
|
| + if (target == GraphicsContext3D::TEXTURE_2D) {
|
| + m_boundTexture = texture;
|
| + }
|
| + }
|
| +
|
| + virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels)
|
| + {
|
| + if (target == GraphicsContext3D::TEXTURE_2D && !level) {
|
| + m_textureSizes.set(m_boundTexture, IntSize(width, height));
|
| + }
|
| + }
|
| +
|
| + virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox)
|
| + {
|
| + ++m_currentMailboxByte;
|
| + WebExternalTextureMailbox temp;
|
| + memset(mailbox, m_currentMailboxByte, sizeof(temp.name));
|
| + }
|
| +
|
| + virtual void produceTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailbox)
|
| + {
|
| + ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
|
| + m_mostRecentlyProducedSize = m_textureSizes.get(m_boundTexture);
|
| + }
|
| +
|
| + IntSize mostRecentlyProducedSize()
|
| + {
|
| + return m_mostRecentlyProducedSize;
|
| + }
|
| +
|
| +private:
|
| + WebGLId m_boundTexture;
|
| + HashMap<WebGLId, IntSize> m_textureSizes;
|
| + WGC3Dbyte m_currentMailboxByte;
|
| + IntSize m_mostRecentlyProducedSize;
|
| +};
|
| +
|
| +static const int initialWidth = 100;
|
| +static const int initialHeight = 100;
|
| +static const int alternateHeight = 50;
|
| +
|
| } // namespace
|
|
|
| class DrawingBufferTest : public Test {
|
| @@ -60,9 +111,13 @@ protected:
|
| virtual void SetUp()
|
| {
|
| RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager());
|
| - RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new MockWebGraphicsContext3D));
|
| - const IntSize size(100, 100);
|
| - m_drawingBuffer = DrawingBuffer::create(context.get(), size, DrawingBuffer::Discard, contextEvictionManager.release());
|
| + RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new WebGraphicsContext3DForTests));
|
| + m_drawingBuffer = DrawingBuffer::create(context.get(), IntSize(initialWidth, initialHeight), DrawingBuffer::Discard, contextEvictionManager.release());
|
| + }
|
| +
|
| + WebGraphicsContext3DForTests* webContext()
|
| + {
|
| + return static_cast<WebGraphicsContext3DForTests*>(m_drawingBuffer->context());
|
| }
|
|
|
| RefPtr<DrawingBuffer> m_drawingBuffer;
|
| @@ -80,4 +135,41 @@ TEST_F(DrawingBufferTest, verifyNoNewBuffersAfterContextLostWithMailboxes)
|
| EXPECT_FALSE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
|
| }
|
|
|
| +TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes)
|
| +{
|
| + blink::WebExternalTextureMailbox mailbox;
|
| +
|
| + IntSize initialSize(initialWidth, initialHeight);
|
| + IntSize alternateSize(initialWidth, alternateHeight);
|
| +
|
| + // Produce one mailbox at size 100x100.
|
| + m_drawingBuffer->markContentsChanged();
|
| + EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
|
| + EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
|
| +
|
| + // Resize to 100x50.
|
| + m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight));
|
| + m_drawingBuffer->mailboxReleased(mailbox);
|
| +
|
| + // Produce a mailbox at this size.
|
| + m_drawingBuffer->markContentsChanged();
|
| + EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
|
| + EXPECT_EQ(alternateSize, webContext()->mostRecentlyProducedSize());
|
| +
|
| + // Reset to initial size.
|
| + m_drawingBuffer->reset(IntSize(initialWidth, initialHeight));
|
| + m_drawingBuffer->mailboxReleased(mailbox);
|
| +
|
| + // Prepare another mailbox and verify that it's the correct size.
|
| + m_drawingBuffer->markContentsChanged();
|
| + EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
|
| + EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
|
| +
|
| + // Prepare one final mailbox and verify that it's the correct size.
|
| + m_drawingBuffer->mailboxReleased(mailbox);
|
| + m_drawingBuffer->markContentsChanged();
|
| + EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
|
| + EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
|
| +}
|
| +
|
| } // namespace
|
|
|