Index: third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp |
index 52c84affb32bc36dde23354e9214a1cdf11d3716..3781a9e2c6e067c26205d80f513c19f6b8c1748b 100644 |
--- a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp |
@@ -33,17 +33,13 @@ |
#include "cc/resources/single_release_callback.h" |
#include "cc/resources/texture_mailbox.h" |
#include "gpu/command_buffer/client/gles2_interface_stub.h" |
-#include "gpu/command_buffer/common/capabilities.h" |
#include "gpu/command_buffer/common/mailbox.h" |
#include "gpu/command_buffer/common/sync_token.h" |
-#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/graphics/ImageBuffer.h" |
#include "platform/graphics/UnacceleratedImageBufferSurface.h" |
-#include "platform/graphics/gpu/Extensions3DUtil.h" |
+#include "platform/graphics/gpu/DrawingBufferTestHelpers.h" |
#include "public/platform/Platform.h" |
-#include "public/platform/WebGraphicsContext3DProvider.h" |
#include "public/platform/functional/WebFunction.h" |
-#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "wtf/PtrUtil.h" |
#include "wtf/RefPtr.h" |
@@ -54,222 +50,15 @@ using testing::_; |
namespace blink { |
-namespace { |
- |
-// The target to use when binding a texture to a Chromium image. |
-GLenum imageCHROMIUMTextureTarget() |
-{ |
-#if OS(MACOSX) |
- return GC3D_TEXTURE_RECTANGLE_ARB; |
-#else |
- return GL_TEXTURE_2D; |
-#endif |
-} |
- |
-// The target to use when preparing a mailbox texture. |
-GLenum drawingBufferTextureTarget() |
-{ |
- if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
- return imageCHROMIUMTextureTarget(); |
- return GL_TEXTURE_2D; |
-} |
- |
-} // namespace |
- |
-class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub { |
-public: |
- void BindTexture(GLenum target, GLuint texture) override |
- { |
- if (target != m_boundTextureTarget && texture == 0) |
- return; |
- |
- // For simplicity, only allow one target to ever be bound. |
- ASSERT_TRUE(m_boundTextureTarget == 0 || target == m_boundTextureTarget); |
- m_boundTextureTarget = target; |
- m_boundTexture = texture; |
- } |
- |
- GLuint64 InsertFenceSyncCHROMIUM() override |
- { |
- static GLuint64 syncPointGenerator = 0; |
- return ++syncPointGenerator; |
- } |
- |
- void WaitSyncTokenCHROMIUM(const GLbyte* syncToken) override |
- { |
- memcpy(&m_mostRecentlyWaitedSyncToken, syncToken, sizeof(m_mostRecentlyWaitedSyncToken)); |
- } |
- |
- GLenum CheckFramebufferStatus(GLenum target) override |
- { |
- return GL_FRAMEBUFFER_COMPLETE; |
- } |
- |
- void GetIntegerv(GLenum pname, GLint* value) override |
- { |
- if (pname == GL_MAX_TEXTURE_SIZE) |
- *value = 1024; |
- } |
- |
- void GenMailboxCHROMIUM(GLbyte* mailbox) override |
- { |
- ++m_currentMailboxByte; |
- memset(mailbox, m_currentMailboxByte, GL_MAILBOX_SIZE_CHROMIUM); |
- } |
- |
- void ProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, const GLbyte* mailbox) override |
- { |
- ASSERT_EQ(target, drawingBufferTextureTarget()); |
- |
- if (!m_createImageChromiumFail) { |
- ASSERT_TRUE(m_textureSizes.contains(texture)); |
- m_mostRecentlyProducedSize = m_textureSizes.get(texture); |
- } |
- } |
- |
- void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels) override |
- { |
- if (target == GL_TEXTURE_2D && !level) { |
- m_textureSizes.set(m_boundTexture, IntSize(width, height)); |
- } |
- } |
- |
- GLuint CreateGpuMemoryBufferImageCHROMIUM(GLsizei width, GLsizei height, GLenum internalformat, GLenum usage) override |
- { |
- if (m_createImageChromiumFail) |
- return 0; |
- m_imageSizes.set(m_currentImageId, IntSize(width, height)); |
- return m_currentImageId++; |
- } |
- |
- MOCK_METHOD1(DestroyImageMock, void(GLuint imageId)); |
- void DestroyImageCHROMIUM(GLuint imageId) |
- { |
- m_imageSizes.remove(imageId); |
- // No textures should be bound to this. |
- ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end()); |
- m_imageSizes.remove(imageId); |
- DestroyImageMock(imageId); |
- } |
- |
- MOCK_METHOD1(BindTexImage2DMock, void(GLint imageId)); |
- void BindTexImage2DCHROMIUM(GLenum target, GLint imageId) |
- { |
- if (target == imageCHROMIUMTextureTarget()) { |
- m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value); |
- m_imageToTextureMap.set(imageId, m_boundTexture); |
- BindTexImage2DMock(imageId); |
- } |
- } |
- |
- MOCK_METHOD1(ReleaseTexImage2DMock, void(GLint imageId)); |
- void ReleaseTexImage2DCHROMIUM(GLenum target, GLint imageId) |
- { |
- if (target == imageCHROMIUMTextureTarget()) { |
- m_imageSizes.set(m_currentImageId, IntSize()); |
- m_imageToTextureMap.remove(imageId); |
- ReleaseTexImage2DMock(imageId); |
- } |
- } |
- |
- void GenSyncTokenCHROMIUM(GLuint64 fenceSync, GLbyte* syncToken) override |
- { |
- static uint64_t uniqueId = 1; |
- gpu::SyncToken source(gpu::GPU_IO, 1, gpu::CommandBufferId::FromUnsafeValue(uniqueId++), 2); |
- memcpy(syncToken, &source, sizeof(source)); |
- } |
- |
- void GenTextures(GLsizei n, GLuint* textures) override |
- { |
- static GLuint id = 1; |
- for (GLsizei i = 0; i < n; ++i) |
- textures[i] = id++; |
- } |
- |
- GLuint boundTexture() const { return m_boundTexture; } |
- GLuint boundTextureTarget() const { return m_boundTextureTarget; } |
- gpu::SyncToken mostRecentlyWaitedSyncToken() const { return m_mostRecentlyWaitedSyncToken; } |
- GLuint nextImageIdToBeCreated() const { return m_currentImageId; } |
- IntSize mostRecentlyProducedSize() const { return m_mostRecentlyProducedSize; } |
- |
- void setCreateImageChromiumFail(bool fail) { m_createImageChromiumFail = fail; } |
- |
-private: |
- GLuint m_boundTexture = 0; |
- GLuint m_boundTextureTarget = 0; |
- gpu::SyncToken m_mostRecentlyWaitedSyncToken; |
- GLbyte m_currentMailboxByte = 0; |
- IntSize m_mostRecentlyProducedSize; |
- bool m_createImageChromiumFail = false; |
- GLuint m_currentImageId = 1; |
- HashMap<GLuint, IntSize> m_textureSizes; |
- HashMap<GLuint, IntSize> m_imageSizes; |
- HashMap<GLuint, GLuint> m_imageToTextureMap; |
-}; |
- |
-static const int initialWidth = 100; |
-static const int initialHeight = 100; |
-static const int alternateHeight = 50; |
- |
-class DrawingBufferForTests : public DrawingBuffer { |
-public: |
- static PassRefPtr<DrawingBufferForTests> create(std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, const IntSize& size, PreserveDrawingBuffer preserve) |
- { |
- std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(contextProvider->contextGL()); |
- RefPtr<DrawingBufferForTests> drawingBuffer = adoptRef(new DrawingBufferForTests(std::move(contextProvider), std::move(extensionsUtil), preserve)); |
- bool multisampleExtensionSupported = false; |
- if (!drawingBuffer->initialize(size, multisampleExtensionSupported)) { |
- drawingBuffer->beginDestruction(); |
- return nullptr; |
- } |
- return drawingBuffer.release(); |
- } |
- |
- DrawingBufferForTests(std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, std::unique_ptr<Extensions3DUtil> extensionsUtil, PreserveDrawingBuffer preserve) |
- : DrawingBuffer(std::move(contextProvider), std::move(extensionsUtil), false /* discardFramebufferSupported */, |
- true /* wantAlphaChannel */, false /* premultipliedAlpha */, preserve, WebGL1, |
- false /* wantDepth */, false /* wantStencil */) |
- , m_live(0) |
- { } |
- |
- ~DrawingBufferForTests() override |
- { |
- if (m_live) |
- *m_live = false; |
- } |
- |
- bool* m_live; |
-}; |
- |
-class WebGraphicsContext3DProviderForTests : public WebGraphicsContext3DProvider { |
-public: |
- WebGraphicsContext3DProviderForTests(std::unique_ptr<gpu::gles2::GLES2Interface> gl) |
- : m_gl(std::move(gl)) |
- { |
- } |
- |
- gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); } |
- bool isSoftwareRendering() const override { return false; } |
- |
- // Not used by WebGL code. |
- GrContext* grContext() override { return nullptr; } |
- bool bindToCurrentThread() override { return false; } |
- gpu::Capabilities getCapabilities() override { return gpu::Capabilities(); } |
- void setLostContextCallback(WebClosure) {} |
- void setErrorMessageCallback(WebFunction<void(const char*, int32_t id)>) {} |
- |
-private: |
- std::unique_ptr<gpu::gles2::GLES2Interface> m_gl; |
-}; |
- |
class DrawingBufferTest : public Test { |
protected: |
void SetUp() override |
{ |
+ IntSize initialSize(InitialWidth, InitialHeight); |
std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2InterfaceForTests); |
m_gl = gl.get(); |
std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
- m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); |
+ m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), initialSize, DrawingBuffer::Preserve); |
CHECK(m_drawingBuffer); |
} |
@@ -282,8 +71,8 @@ TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
cc::TextureMailbox textureMailbox; |
std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
- IntSize initialSize(initialWidth, initialHeight); |
- IntSize alternateSize(initialWidth, alternateHeight); |
+ IntSize initialSize(InitialWidth, InitialHeight); |
+ IntSize alternateSize(InitialWidth, AlternateHeight); |
// Produce one mailbox at size 100x100. |
m_drawingBuffer->markContentsChanged(); |
@@ -291,7 +80,7 @@ TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
// Resize to 100x50. |
- m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); |
+ m_drawingBuffer->reset(alternateSize); |
releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
// Produce a mailbox at this size. |
@@ -300,7 +89,7 @@ TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); |
// Reset to initial size. |
- m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); |
+ m_drawingBuffer->reset(initialSize); |
releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
// Prepare another mailbox and verify that it's the correct size. |
@@ -329,7 +118,7 @@ TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) |
cc::TextureMailbox textureMailbox3; |
std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; |
- IntSize initialSize(initialWidth, initialHeight); |
+ IntSize initialSize(InitialWidth, InitialHeight); |
// Produce mailboxes. |
m_drawingBuffer->markContentsChanged(); |
@@ -478,6 +267,7 @@ class DrawingBufferImageChromiumTest : public DrawingBufferTest { |
protected: |
void SetUp() override |
{ |
+ IntSize initialSize(InitialWidth, InitialHeight); |
std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2InterfaceForTests); |
m_gl = gl.get(); |
std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
@@ -485,7 +275,7 @@ protected: |
m_imageId0 = m_gl->nextImageIdToBeCreated(); |
EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); |
m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), |
- IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); |
+ initialSize, DrawingBuffer::Preserve); |
CHECK(m_drawingBuffer); |
testing::Mock::VerifyAndClearExpectations(m_gl); |
} |
@@ -503,8 +293,8 @@ TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) |
cc::TextureMailbox textureMailbox; |
std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
- IntSize initialSize(initialWidth, initialHeight); |
- IntSize alternateSize(initialWidth, alternateHeight); |
+ IntSize initialSize(InitialWidth, InitialHeight); |
+ IntSize alternateSize(InitialWidth, AlternateHeight); |
GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); |
EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); |
@@ -520,7 +310,7 @@ TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) |
EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); |
EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); |
// Resize to 100x50. |
- m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); |
+ m_drawingBuffer->reset(alternateSize); |
releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
testing::Mock::VerifyAndClearExpectations(m_gl); |
@@ -540,7 +330,7 @@ TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) |
EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); |
EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); |
// Reset to initial size. |
- m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); |
+ m_drawingBuffer->reset(initialSize); |
releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
testing::Mock::VerifyAndClearExpectations(m_gl); |
@@ -583,7 +373,7 @@ TEST_F(DrawingBufferImageChromiumTest, allocationFailure) |
// Request a mailbox. An image should already be created. Everything works |
// as expected. |
EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); |
- IntSize initialSize(initialWidth, initialHeight); |
+ IntSize initialSize(InitialWidth, InitialHeight); |
m_drawingBuffer->markContentsChanged(); |
EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releaseCallback1)); |
EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); |