diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
commit | 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch) | |
tree | 988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp | |
parent | dd91e772430dc294e3bf478c119ef8d43c0a3358 (diff) | |
download | qtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz |
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp')
-rw-r--r-- | Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp | 125 |
1 files changed, 79 insertions, 46 deletions
diff --git a/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp index 580f15791..f464dcbbc 100644 --- a/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp @@ -27,13 +27,19 @@ #include "Canvas2DLayerChromium.h" #include "CCSchedulerTestCommon.h" +#include "FakeCCLayerTreeHostClient.h" #include "FakeWebGraphicsContext3D.h" #include "GraphicsContext3DPrivate.h" #include "Region.h" +#include "TextureCopier.h" #include "TextureManager.h" -#include "cc/CCCanvasLayerImpl.h" +#include "WebCompositor.h" +#include "WebKit.h" #include "cc/CCSingleThreadProxy.h" +#include "cc/CCTextureLayerImpl.h" #include "cc/CCTextureUpdater.h" +#include "platform/WebKitPlatformSupport.h" +#include "platform/WebThread.h" #include <gmock/gmock.h> #include <gtest/gtest.h> @@ -48,19 +54,27 @@ using testing::Test; namespace { -class MockCanvasContext : public FakeWebGraphicsContext3D { +class FakeCCLayerTreeHost : public CCLayerTreeHost { public: - MOCK_METHOD0(createFramebuffer, WebGLId()); - MOCK_METHOD0(createTexture, WebGLId()); + static PassOwnPtr<FakeCCLayerTreeHost> create() + { + OwnPtr<FakeCCLayerTreeHost> host(adoptPtr(new FakeCCLayerTreeHost)); + host->initialize(); + return host.release(); + } - MOCK_METHOD2(bindFramebuffer, void(WGC3Denum, WebGLId)); - MOCK_METHOD5(framebufferTexture2D, void(WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)); +private: + FakeCCLayerTreeHost() + : CCLayerTreeHost(&m_client, CCSettings()) + { + } - MOCK_METHOD2(bindTexture, void(WGC3Denum, WebGLId)); - MOCK_METHOD8(copyTexSubImage2D, void(WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)); + FakeCCLayerTreeHostClient m_client; +}; - MOCK_METHOD1(deleteFramebuffer, void(WebGLId)); - MOCK_METHOD1(deleteTexture, void(WebGLId)); +class MockCanvasContext : public FakeWebGraphicsContext3D { +public: + MOCK_METHOD0(flush, void(void)); }; class MockTextureAllocator : public TextureAllocator { @@ -69,13 +83,21 @@ public: MOCK_METHOD3(deleteTexture, void(unsigned, const IntSize&, GC3Denum)); }; -} // namespace +class MockTextureCopier : public TextureCopier { +public: + MOCK_METHOD4(copyTexture, void(GraphicsContext3D*, unsigned, unsigned, const IntSize&)); +}; + +class MockTextureUploader : public TextureUploader { +public: + MOCK_METHOD5(uploadTexture, void(GraphicsContext3D*, LayerTextureUpdater::Texture*, TextureAllocator*, const IntRect, const IntRect)); +}; -namespace WebCore { +} // namespace class Canvas2DLayerChromiumTest : public Test { protected: - void fullLifecycleTest(bool threaded) + void fullLifecycleTest(bool threaded, bool deferred) { GraphicsContext3D::Attributes attrs; @@ -86,84 +108,95 @@ protected: MockCanvasContext& implMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(implContext.get())); MockTextureAllocator allocatorMock; - CCTextureUpdater updater(&allocatorMock); + MockTextureCopier copierMock; + MockTextureUploader uploaderMock; + CCTextureUpdater updater; const IntSize size(300, 150); - const size_t maxTextureSize = size.width() * size.height() * 4; - OwnPtr<TextureManager> textureManager = TextureManager::create(maxTextureSize, maxTextureSize, maxTextureSize); + OwnPtr<WebThread> thread; if (threaded) - CCProxy::setImplThread(new FakeCCThread); + thread = adoptPtr(WebKit::Platform::current()->createThread("Canvas2DLayerChromiumTest")); + WebCompositor::initialize(thread.get()); + + OwnPtr<FakeCCLayerTreeHost> layerTreeHost(FakeCCLayerTreeHost::create()); + // Force an update, so that we get a valid TextureManager. + layerTreeHost->updateLayers(updater); const WebGLId backTextureId = 1; const WebGLId frontTextureId = 2; - const WebGLId fboId = 3; { InSequence sequence; - // Note that the canvas backing texture is doublebuffered only when using the threaded - // compositor. - if (threaded) { - // Setup Canvas2DLayerChromium (on the main thread). - EXPECT_CALL(mainMock, createFramebuffer()) - .WillOnce(Return(fboId)); + // Paint canvas contents on the main thread. + EXPECT_CALL(mainMock, flush()); + // Note that the canvas backing texture is doublebuffered only when using the threaded + // compositor and not using deferred canvas rendering + if (threaded && !deferred) { // Create texture and do the copy (on the impl thread). EXPECT_CALL(allocatorMock, createTexture(size, GraphicsContext3D::RGBA)) .WillOnce(Return(frontTextureId)); - EXPECT_CALL(implMock, bindTexture(GraphicsContext3D::TEXTURE_2D, frontTextureId)); - EXPECT_CALL(implMock, bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, fboId)); - EXPECT_CALL(implMock, framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, backTextureId, 0)); - EXPECT_CALL(implMock, copyTexSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, 0, 0, 300, 150)); - EXPECT_CALL(implMock, bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)); - - // Teardown Canvas2DLayerChromium. - EXPECT_CALL(mainMock, deleteFramebuffer(fboId)); + EXPECT_CALL(copierMock, copyTexture(implContext.get(), backTextureId, frontTextureId, size)); + EXPECT_CALL(implMock, flush()); // Teardown TextureManager. EXPECT_CALL(allocatorMock, deleteTexture(frontTextureId, size, GraphicsContext3D::RGBA)); } } - RefPtr<Canvas2DLayerChromium> canvas = Canvas2DLayerChromium::create(mainContext.get(), size); + RefPtr<Canvas2DLayerChromium> canvas = Canvas2DLayerChromium::create(mainContext.get(), size, deferred ? Deferred : NonDeferred); canvas->setIsDrawable(true); - canvas->setTextureManager(textureManager.get()); + canvas->setLayerTreeHost(layerTreeHost.get()); canvas->setBounds(IntSize(600, 300)); canvas->setTextureId(backTextureId); canvas->setNeedsDisplay(); EXPECT_TRUE(canvas->needsDisplay()); - Region occludedScreenSpace; - canvas->paintContentsIfDirty(occludedScreenSpace); + canvas->update(updater, 0); EXPECT_FALSE(canvas->needsDisplay()); { DebugScopedSetImplThread scopedImplThread; OwnPtr<CCLayerImpl> layerImpl = canvas->createCCLayerImpl(); - EXPECT_EQ(0u, static_cast<CCCanvasLayerImpl*>(layerImpl.get())->textureId()); + EXPECT_EQ(0u, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId()); - canvas->updateCompositorResources(implContext.get(), updater); + updater.update(implContext.get(), &allocatorMock, &copierMock, &uploaderMock, 1); canvas->pushPropertiesTo(layerImpl.get()); - if (threaded) - EXPECT_EQ(frontTextureId, static_cast<CCCanvasLayerImpl*>(layerImpl.get())->textureId()); + if (threaded && !deferred) + EXPECT_EQ(frontTextureId, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId()); else - EXPECT_EQ(backTextureId, static_cast<CCCanvasLayerImpl*>(layerImpl.get())->textureId()); + EXPECT_EQ(backTextureId, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId()); } canvas.clear(); - textureManager->reduceMemoryToLimit(0); - textureManager->deleteEvictedTextures(&allocatorMock); + layerTreeHost->contentsTextureManager()->reduceMemoryToLimit(0); + layerTreeHost->contentsTextureManager()->deleteEvictedTextures(&allocatorMock); + layerTreeHost.clear(); + WebCompositor::shutdown(); } }; +namespace { + TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleSingleThread) { - fullLifecycleTest(false); + fullLifecycleTest(false, false); } TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleThreaded) { - fullLifecycleTest(true); + fullLifecycleTest(true, false); } -} // namespace webcore +TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleSingleThreadDeferred) +{ + fullLifecycleTest(false, true); +} + +TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleThreadedDeferred) +{ + fullLifecycleTest(true, true); +} + +} // namespace |