From f71b264450d3e23c44cef43d6e10811a41c07397 Mon Sep 17 00:00:00 2001 From: "jamesr@google.com" Date: Fri, 16 Sep 2011 18:43:37 +0000 Subject: [PATCH] [chromium] Fix CCLayerTreeHostTest https://bugs.webkit.org/show_bug.cgi?id=67418 Source/WebCore: This is a minimal set of changes to get CCLayerTreeHostTest compiling, running and passing with USE_THREADED_COMPOSITING enabled. Patch by Iain Merrick on 2011-09-16 Reviewed by James Robinson. * platform/graphics/chromium/ContentLayerChromium.cpp: (WebCore::ContentLayerChromium::createTextureUpdater): * platform/graphics/chromium/LayerRendererChromium.cpp: (WebCore::LayerRendererChromium::LayerRendererChromium): * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: (WebCore::CCLayerTreeHost::createLayerTreeHostImpl): * platform/graphics/chromium/cc/CCLayerTreeHost.h: * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h: * platform/graphics/chromium/cc/CCThreadProxy.cpp: (WebCore::CCThreadProxy::context): (WebCore::CCThreadProxy::beginFrameAndCommitOnCCThread): (WebCore::CCThreadProxy::setNeedsCommitAndRedrawOnCCThread): (WebCore::CCThreadProxy::setNeedsRedrawOnCCThread): Source/WebKit/chromium: Fixes needed to compile and link with USE_THREADED_COMPOSITING enabled, and to pass the basic unit test. Patch by Iain Merrick on 2011-09-16 Reviewed by James Robinson. * src/GraphicsContext3DChromium.cpp: (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate): (WebCore::GraphicsContext3DPrivate::platformLayer): * src/GraphicsContext3DPrivate.h: * tests/CCLayerTreeHostTest.cpp: (TestHooks::beginCommitOnCCThread): (TestHooks::commitCompleteOnCCThread): (TestHooks::drawLayersOnCCThread): (MockLayerTreeHostImpl::MockLayerTreeHostImpl): (MockLayerTreeHostImpl::beginCommit): (MockLayerTreeHostImpl::commitComplete): (MockLayerTreeHostImpl::drawLayers): (MockLayerTreeHost::MockLayerTreeHost): (MockLayerTreeHost::createLayerTreeHostImpl): (CompositorMockWebGraphicsContext3D::makeContextCurrent): (CompositorMockWebGraphicsContext3D::createProgram): (CompositorMockWebGraphicsContext3D::createShader): (CompositorMockWebGraphicsContext3D::getShaderiv): (CompositorMockWebGraphicsContext3D::getProgramiv): (MockLayerTreeHostClient::MockLayerTreeHostClient): (MockLayerTreeHostClient::animateAndLayout): (MockLayerTreeHostClient::createCompositorThread): (MockLayerTreeHostClient::createLayerTreeHostContext3D): (MockLayerTreeHostClient::createRootLayerPainter): (MockLayerTreeHostClient::didRecreateGraphicsContext): (CCLayerTreeHostTest::postSetNeedsCommitToMainThread): (CCLayerTreeHostTest::postSetNeedsRedrawToMainThread): (CCLayerTreeHostTest::onEndTest): (CCLayerTreeHostTest::dispatchSetNeedsCommit): (CCLayerTreeHostTest::dispatchSetNeedsRedraw): (CCLayerTreeHostTest::runTest): (CCLayerTreeHostTest::doBeginTest): (CCLayerTreeHostTestShortlived2::beginTest): (CCLayerTreeHostTestShortlived3::beginTest): (CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest): (CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread): (CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersOnCCThread): (CCLayerTreeHostTestSetNeedsCommit1::beginTest): (CCLayerTreeHostTestSetNeedsCommit1::drawLayersOnCCThread): (CCLayerTreeHostTestSetNeedsCommit1::commitCompleteOnCCThread): (CCLayerTreeHostTestSetNeedsCommit2::beginTest): (CCLayerTreeHostTestSetNeedsCommit2::drawLayersOnCCThread): (CCLayerTreeHostTestSetNeedsCommit2::commitCompleteOnCCThread): (CCLayerTreeHostTestSetNeedsRedraw::beginTest): (CCLayerTreeHostTestSetNeedsRedraw::drawLayersOnCCThread): (CCLayerTreeHostTestSetNeedsRedraw::commitCompleteOnCCThread): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95309 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 25 ++ .../graphics/chromium/ContentLayerChromium.cpp | 2 + .../graphics/chromium/LayerRendererChromium.cpp | 1 + .../graphics/chromium/cc/CCLayerTreeHost.h | 5 +- .../graphics/chromium/cc/CCLayerTreeHostImpl.h | 4 +- .../graphics/chromium/cc/CCThreadProxy.cpp | 13 +- Source/WebKit/chromium/ChangeLog | 57 ++++ .../WebKit/chromium/tests/CCLayerTreeHostTest.cpp | 353 +++++++++++---------- 8 files changed, 280 insertions(+), 180 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 57bda4f..333ebae 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,28 @@ +2011-09-16 Iain Merrick + + [chromium] Fix CCLayerTreeHostTest + https://bugs.webkit.org/show_bug.cgi?id=67418 + + This is a minimal set of changes to get CCLayerTreeHostTest + compiling, running and passing with USE_THREADED_COMPOSITING + enabled. + + Reviewed by James Robinson. + + * platform/graphics/chromium/ContentLayerChromium.cpp: + (WebCore::ContentLayerChromium::createTextureUpdater): + * platform/graphics/chromium/LayerRendererChromium.cpp: + (WebCore::LayerRendererChromium::LayerRendererChromium): + * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: + (WebCore::CCLayerTreeHost::createLayerTreeHostImpl): + * platform/graphics/chromium/cc/CCLayerTreeHost.h: + * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h: + * platform/graphics/chromium/cc/CCThreadProxy.cpp: + (WebCore::CCThreadProxy::context): + (WebCore::CCThreadProxy::beginFrameAndCommitOnCCThread): + (WebCore::CCThreadProxy::setNeedsCommitAndRedrawOnCCThread): + (WebCore::CCThreadProxy::setNeedsRedrawOnCCThread): + 2011-09-16 Sheriff Bot Unreviewed, rolling out r95227. diff --git a/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp b/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp index 05e3166..0f42aa9 100644 --- a/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp +++ b/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp @@ -120,6 +120,7 @@ bool ContentLayerChromium::drawsContent() const void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host) { +#if !USE(THREADED_COMPOSITING) #if USE(SKIA) // Note that host->skiaContext() will crash if called while in threaded // mode. This thus depends on CCLayerTreeHost::initialize turning off @@ -129,6 +130,7 @@ void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host) return; } #endif // SKIA +#endif // !THREADED_COMPOSITING m_textureUpdater = LayerTextureUpdaterBitmap::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub); } diff --git a/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp b/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp index f3ba0c5..7afcb73 100644 --- a/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp +++ b/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp @@ -148,6 +148,7 @@ LayerRendererChromium::LayerRendererChromium(CCLayerTreeHostImpl* owner, , m_currentRenderSurface(0) , m_offscreenFramebufferId(0) , m_zoomAnimatorScale(1) + , m_contentsTextureMemoryUseBytes(0) , m_context(context) , m_defaultRenderSurface(0) , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f)) diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h index b523f77..fee2956 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h @@ -99,7 +99,7 @@ public: void commitTo(CCLayerTreeHostImpl*); PassOwnPtr createCompositorThread(); PassRefPtr createLayerTreeHostContext3D(); - PassOwnPtr createLayerTreeHostImpl(); + virtual PassOwnPtr createLayerTreeHostImpl(); void didRecreateGraphicsContext(bool success); #if !USE(THREADED_COMPOSITING) void scheduleComposite(); @@ -154,6 +154,7 @@ public: protected: CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr rootLayer, const CCSettings&); + bool initialize(); private: typedef Vector > LayerList; @@ -164,8 +165,6 @@ private: void updateCompositorResources(LayerChromium*, GraphicsContext3D*); void clearPendingUpdate(); - bool initialize(); - bool m_animating; CCLayerTreeHostClient* m_client; diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h index c752e00..a37e9f3 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h @@ -46,13 +46,13 @@ public: static PassOwnPtr create(const CCSettings&); virtual ~CCLayerTreeHostImpl(); + // Virtual for testing virtual void beginCommit(); virtual void commitComplete(); + virtual void drawLayers(); GraphicsContext3D* context(); - void drawLayers(); - void finishAllRendering(); int frameNumber() const { return m_frameNumber; } diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp index 12b5b36..9a84da6 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp +++ b/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp @@ -84,7 +84,6 @@ bool CCThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect) GraphicsContext3D* CCThreadProxy::context() { - ASSERT_NOT_REACHED(); return 0; } @@ -186,8 +185,8 @@ void CCThreadProxy::beginFrameAndCommitOnCCThread() { TRACE_EVENT("CCThreadProxy::beginFrameAndCommitOnCCThread", this, 0); ASSERT(isImplThread()); - ASSERT_NOT_REACHED(); - // FIXME: call beginFrameAndCommit on main thread + // TEMP HACK so we can exercise this code in unit tests. + CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0)); } void CCThreadProxy::beginFrameAndCommit(double frameBeginTime) @@ -247,13 +246,15 @@ void CCThreadProxy::setNeedsCommitAndRedrawOnCCThread() TRACE_EVENT("CCThreadProxy::setNeedsCommitAndRedrawOnCCThread", this, 0); ASSERT(isImplThread()); ASSERT(m_layerTreeHostImpl); - ASSERT_NOT_REACHED(); + // TEMP HACK so we can exercise this code in unit tests. + CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0)); } void CCThreadProxy::setNeedsRedrawOnCCThread() { TRACE_EVENT("CCThreadProxy::setNeedsRedrawOnCCThread", this, 0); - ASSERT_NOT_REACHED(); + // TEMP HACK so we can exercise this code in unit tests. + drawLayersOnCCThread(); } void CCThreadProxy::initializeImplOnCCThread(CCCompletionEvent* completion) @@ -284,4 +285,4 @@ void CCThreadProxy::layerTreeHostClosedOnCCThread(CCCompletionEvent* completion) completion->signal(); } -} +} // namespace WebCore diff --git a/Source/WebKit/chromium/ChangeLog b/Source/WebKit/chromium/ChangeLog index 649dd3a..a1208e6 100644 --- a/Source/WebKit/chromium/ChangeLog +++ b/Source/WebKit/chromium/ChangeLog @@ -1,3 +1,60 @@ +2011-09-16 Iain Merrick + + [chromium] Fix CCLayerTreeHostTest + https://bugs.webkit.org/show_bug.cgi?id=67418 + + Fixes needed to compile and link with USE_THREADED_COMPOSITING + enabled, and to pass the basic unit test. + + Reviewed by James Robinson. + + * src/GraphicsContext3DChromium.cpp: + (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate): + (WebCore::GraphicsContext3DPrivate::platformLayer): + * src/GraphicsContext3DPrivate.h: + * tests/CCLayerTreeHostTest.cpp: + (TestHooks::beginCommitOnCCThread): + (TestHooks::commitCompleteOnCCThread): + (TestHooks::drawLayersOnCCThread): + (MockLayerTreeHostImpl::MockLayerTreeHostImpl): + (MockLayerTreeHostImpl::beginCommit): + (MockLayerTreeHostImpl::commitComplete): + (MockLayerTreeHostImpl::drawLayers): + (MockLayerTreeHost::MockLayerTreeHost): + (MockLayerTreeHost::createLayerTreeHostImpl): + (CompositorMockWebGraphicsContext3D::makeContextCurrent): + (CompositorMockWebGraphicsContext3D::createProgram): + (CompositorMockWebGraphicsContext3D::createShader): + (CompositorMockWebGraphicsContext3D::getShaderiv): + (CompositorMockWebGraphicsContext3D::getProgramiv): + (MockLayerTreeHostClient::MockLayerTreeHostClient): + (MockLayerTreeHostClient::animateAndLayout): + (MockLayerTreeHostClient::createCompositorThread): + (MockLayerTreeHostClient::createLayerTreeHostContext3D): + (MockLayerTreeHostClient::createRootLayerPainter): + (MockLayerTreeHostClient::didRecreateGraphicsContext): + (CCLayerTreeHostTest::postSetNeedsCommitToMainThread): + (CCLayerTreeHostTest::postSetNeedsRedrawToMainThread): + (CCLayerTreeHostTest::onEndTest): + (CCLayerTreeHostTest::dispatchSetNeedsCommit): + (CCLayerTreeHostTest::dispatchSetNeedsRedraw): + (CCLayerTreeHostTest::runTest): + (CCLayerTreeHostTest::doBeginTest): + (CCLayerTreeHostTestShortlived2::beginTest): + (CCLayerTreeHostTestShortlived3::beginTest): + (CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest): + (CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread): + (CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersOnCCThread): + (CCLayerTreeHostTestSetNeedsCommit1::beginTest): + (CCLayerTreeHostTestSetNeedsCommit1::drawLayersOnCCThread): + (CCLayerTreeHostTestSetNeedsCommit1::commitCompleteOnCCThread): + (CCLayerTreeHostTestSetNeedsCommit2::beginTest): + (CCLayerTreeHostTestSetNeedsCommit2::drawLayersOnCCThread): + (CCLayerTreeHostTestSetNeedsCommit2::commitCompleteOnCCThread): + (CCLayerTreeHostTestSetNeedsRedraw::beginTest): + (CCLayerTreeHostTestSetNeedsRedraw::drawLayersOnCCThread): + (CCLayerTreeHostTestSetNeedsRedraw::commitCompleteOnCCThread): + 2011-09-16 Andrey Kosyakov Web Inspector: [Extensions API] support extensions for remote inspector front-end diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp index d854806..ff4ffbe 100644 --- a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp @@ -28,7 +28,12 @@ #include "cc/CCLayerTreeHost.h" -#include "GraphicsContext3D.h" +#include "CCThreadImpl.h" +#include "GraphicsContext3DPrivate.h" +#include "LayerChromium.h" +#include "LayerPainterChromium.h" +#include "MockWebGraphicsContext3D.h" +#include "TextureManager.h" #include "cc/CCLayerTreeHostImpl.h" #include "cc/CCMainThreadTask.h" #include "cc/CCThreadTask.h" @@ -38,247 +43,256 @@ #include #include - using namespace WebCore; +using namespace WebKit; using namespace WTF; namespace { -class MockLayerTreeHost; -class MockLayerTreeHostClient; -class MockLayerTreeHostImpl; - -// The CCLayerTreeHostTest runs with the main loop running. It instantiates a single MockLayerTreeHost and associated -// MockLayerTreeHostImpl/MockLayerTreeHostClient. -// -// beginTest() is called once the main message loop is running and the layer tree host is initialized. -// -// Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCLayerTreeHostTest methods of similar names. -// To track the commit process, override these functions. -// -// The test continues until someone calls endTest. endTest can be called on any thread, but be aware that -// ending the test is an asynchronous process. -class CCLayerTreeHostTest : public testing::Test { +// Used by test stubs to notify the test when something interesting happens. +class TestHooks { public: - CCLayerTreeHostTest() - : m_beginning(false) - , m_endWhenBeginReturns(false) - , m_running(false) - , m_timedOut(false) { } - - virtual void afterTest() = 0; - - virtual void beginTest() = 0; - virtual void animateAndLayout(MockLayerTreeHostClient* layerTreeHost, double frameBeginTime) { } - virtual void beginCommitOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { } - virtual void beginCommitOnMainThread(MockLayerTreeHost* layerTreeHost) { } - virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* layerTreeHostImpl) { } - virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { } - virtual void commitCompleteOnMainThread(MockLayerTreeHost* layerTreeHost) { } - virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { } - virtual void updateLayers(MockLayerTreeHost* layerTreeHost) { } - - void endTest(); - -protected: - void doBeginTest(); + virtual void beginCommitOnCCThread(CCLayerTreeHostImpl*) { } + virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { } + virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*) { } +}; - static void onBeginTest(void* self) +// Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks. +class MockLayerTreeHostImpl : public CCLayerTreeHostImpl { +public: + static PassOwnPtr create(TestHooks* testHooks, const CCSettings& settings) { - static_cast(self)->doBeginTest(); + return adoptPtr(new MockLayerTreeHostImpl(testHooks, settings)); } - void doEndTest() + virtual void beginCommit() { + CCLayerTreeHostImpl::beginCommit(); + m_testHooks->beginCommitOnCCThread(this); } - static void onEndTest(void* self) + virtual void commitComplete() { - ASSERT(isMainThread()); - CCLayerTreeHostTest* test = static_cast(self); - test->m_layerTreeHost.clear(); - test->m_client.clear(); - webkit_support::QuitMessageLoop(); + CCLayerTreeHostImpl::commitComplete(); + m_testHooks->commitCompleteOnCCThread(this); } - void runTest() + virtual void drawLayers() { - webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast(this), 0); - webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast(this), 5000); - webkit_support::RunMessageLoop(); - m_running = false; - bool timedOut = m_timedOut; // Save whether we're timed out in case RunAllPendingMessages has the timeout. - webkit_support::RunAllPendingMessages(); - if (timedOut) { - printf("Test timed out"); - FAIL() << "Test timed out"; - return; - } - afterTest(); + CCLayerTreeHostImpl::drawLayers(); + m_testHooks->drawLayersOnCCThread(this); } - static void testTimeout(void* self) +private: + MockLayerTreeHostImpl(TestHooks* testHooks, const CCSettings& settings) + : CCLayerTreeHostImpl(settings) + , m_testHooks(testHooks) { - CCLayerTreeHostTest* test = static_cast(self); - if (!test->m_running) - return; - test->m_timedOut = true; - test->endTest(); } - Mutex m_tracesLock; - Vector m_traces; - - OwnPtr m_client; - RefPtr m_layerTreeHost; - -private: - bool m_beginning; - bool m_endWhenBeginReturns; - bool m_running; - bool m_timedOut; + TestHooks* m_testHooks; }; -class MockLayerTreeHostClient : public CCLayerTreeHostClient { +// Adapts CCLayerTreeHost for test. Injects MockLayerTreeHostImpl. +class MockLayerTreeHost : public CCLayerTreeHost { public: - MockLayerTreeHostClient(CCLayerTreeHostTest* test) : m_test(test) { } - - virtual PassRefPtr createLayerTreeHostContext3D() + static PassRefPtr create(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr rootLayer, const CCSettings& settings) { - return adoptRef(0); + return adoptRef(new MockLayerTreeHost(testHooks, client, rootLayer, settings)); } - virtual void animateAndLayout(double frameBeginTime) + virtual PassOwnPtr createLayerTreeHostImpl() { - m_test->animateAndLayout(this, frameBeginTime); + return MockLayerTreeHostImpl::create(m_testHooks, settings()); } - virtual void updateLayers() +private: + MockLayerTreeHost(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr rootLayer, const CCSettings& settings) + : CCLayerTreeHost(client, rootLayer, settings) + , m_testHooks(testHooks) { + bool success = initialize(); + ASSERT(success); } -private: - CCLayerTreeHostTest* m_test; + TestHooks* m_testHooks; }; -class MockLayerTreeHostCommitter : public CCLayerTreeHostCommitter { +// Test stub for WebGraphicsContext3D. Returns canned values needed for compositor initialization. +class CompositorMockWebGraphicsContext3D : public MockWebGraphicsContext3D { public: - static PassOwnPtr create(CCLayerTreeHostTest* test) + static PassOwnPtr create() { - return adoptPtr(new MockLayerTreeHostCommitter(test)); + return adoptPtr(new CompositorMockWebGraphicsContext3D()); } - virtual void commit(CCLayerTreeHost* host, CCLayerTreeHostImpl* hostImpl) - { - CCLayerTreeHostCommitter::commit(host, hostImpl); - m_test->commitOnCCThread(reinterpret_cast(host), reinterpret_cast(hostImpl)); - } + virtual bool makeContextCurrent() { return true; } + virtual WebGLId createProgram() { return 1; } + virtual WebGLId createShader(WGC3Denum) { return 1; } + virtual void getShaderiv(WebGLId, WGC3Denum, WGC3Dint* value) { *value = 1; } + virtual void getProgramiv(WebGLId, WGC3Denum, WGC3Dint* value) { *value = 1; } private: - MockLayerTreeHostCommitter(CCLayerTreeHostTest* test) : m_test(test) { } - CCLayerTreeHostTest* m_test; + CompositorMockWebGraphicsContext3D() { } }; -class MockLayerTreeHostImpl : public CCLayerTreeHostImpl { +// Implementation of CCLayerTreeHost callback interface. +class MockLayerTreeHostClient : public CCLayerTreeHostClient { public: - static PassOwnPtr create(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test) + static PassOwnPtr create(TestHooks* testHooks) { - return adoptPtr(new MockLayerTreeHostImpl(client, test)); + return adoptPtr(new MockLayerTreeHostClient(testHooks)); } - virtual void beginCommit() + virtual void animateAndLayout(double frameBeginTime) { - CCLayerTreeHostImpl::beginCommit(); - m_test->beginCommitOnCCThread(this); } - virtual void commitComplete() + virtual PassOwnPtr createCompositorThread() { - CCLayerTreeHostImpl::commitComplete(); - m_test->commitCompleteOnCCThread(this); + return CCThreadImpl::create(); } - virtual void drawLayersAndPresent() + virtual PassRefPtr createLayerTreeHostContext3D() { - m_test->drawLayersAndPresentOnCCThread(this); + OwnPtr mock = CompositorMockWebGraphicsContext3D::create(); + GraphicsContext3D::Attributes attrs; + RefPtr context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(mock.release(), attrs, 0, GraphicsContext3D::RenderDirectlyToHostWindow, GraphicsContext3DPrivate::ForUseOnAnotherThread); + return context; } -private: - MockLayerTreeHostImpl(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test) - : CCLayerTreeHostImpl(client) - , m_test(test) + virtual PassOwnPtr createRootLayerPainter() { + return nullptr; } - CCLayerTreeHostTest* m_test; + virtual void didRecreateGraphicsContext(bool) + { + } + +private: + explicit MockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks(testHooks) { } + + TestHooks* m_testHooks; }; -class MockLayerTreeHostImplProxy : public CCLayerTreeHostImplProxy { +// The CCLayerTreeHostTest runs with the main loop running. It instantiates a single MockLayerTreeHost and associated +// MockLayerTreeHostImpl/MockLayerTreeHostClient. +// +// beginTest() is called once the main message loop is running and the layer tree host is initialized. +// +// Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCLayerTreeHostTest methods of similar names. +// To track the commit process, override these functions. +// +// The test continues until someone calls endTest. endTest can be called on any thread, but be aware that +// ending the test is an asynchronous process. +class CCLayerTreeHostTest : public testing::Test, TestHooks { public: - static PassOwnPtr create(CCLayerTreeHost* host, CCLayerTreeHostTest* test) + virtual void afterTest() = 0; + virtual void beginTest() = 0; + + void endTest(); + + void postSetNeedsCommitToMainThread() { - return adoptPtr(new MockLayerTreeHostImplProxy(host, test)); + callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsCommit, this); } - PassOwnPtr createLayerTreeHostImpl() + void postSetNeedsRedrawToMainThread() { - return MockLayerTreeHostImpl::create(this, m_test); + callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsRedraw, this); } -private: - MockLayerTreeHostImplProxy(CCLayerTreeHost* host, CCLayerTreeHostTest* test) - : CCLayerTreeHostImplProxy(host) - , m_test(test) { } +protected: + CCLayerTreeHostTest() + : m_beginning(false) + , m_endWhenBeginReturns(false) + , m_running(false) + , m_timedOut(false) { } - CCLayerTreeHostTest* m_test; -}; + void doBeginTest(); -class MockLayerTreeHost : public CCLayerTreeHost { -public: - MockLayerTreeHost(CCLayerTreeHostClient* client, CCLayerTreeHostTest* test) - : CCLayerTreeHost(client) - , m_test(test) { } + static void onBeginTest(void* self) + { + static_cast(self)->doBeginTest(); + } - virtual PassOwnPtr createLayerTreeHostImplProxy() + static void onEndTest(void* self) { - OwnPtr proxy = MockLayerTreeHostImplProxy::create(this, m_test); - proxy->start(); - return proxy.release(); + ASSERT(isMainThread()); + webkit_support::QuitMessageLoop(); + CCLayerTreeHostTest* test = static_cast(self); + ASSERT(test); + test->m_layerTreeHost.clear(); } - virtual void updateLayers() + static void dispatchSetNeedsCommit(void* self) { - m_test->updateLayers(this); + ASSERT(isMainThread()); + CCLayerTreeHostTest* test = static_cast(self); + ASSERT(test); + if (test->m_layerTreeHost) + test->m_layerTreeHost->setNeedsCommitAndRedraw(); } - virtual PassOwnPtr createLayerTreeHostCommitter() + static void dispatchSetNeedsRedraw(void* self) { - return MockLayerTreeHostCommitter::create(m_test); + ASSERT(isMainThread()); + CCLayerTreeHostTest* test = static_cast(self); + ASSERT(test); + if (test->m_layerTreeHost) + test->m_layerTreeHost->setNeedsRedraw(); } - virtual void beginCommit() + void runTest() { - CCLayerTreeHost::beginCommit(); - m_test->beginCommitOnMainThread(this); + webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast(this), 0); + webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast(this), 5000); + webkit_support::RunMessageLoop(); + m_running = false; + bool timedOut = m_timedOut; // Save whether we're timed out in case RunAllPendingMessages has the timeout. + webkit_support::RunAllPendingMessages(); + ASSERT(!m_layerTreeHost.get()); + m_client.clear(); + if (timedOut) { + FAIL() << "Test timed out"; + return; + } + afterTest(); } - virtual void commitComplete() + static void testTimeout(void* self) { - m_test->commitCompleteOnMainThread(this); - CCLayerTreeHost::commitComplete(); + CCLayerTreeHostTest* test = static_cast(self); + if (!test->m_running) + return; + test->m_timedOut = true; + test->endTest(); } + OwnPtr m_client; + RefPtr m_layerTreeHost; + private: - CCLayerTreeHostTest* m_test; + bool m_beginning; + bool m_endWhenBeginReturns; + bool m_running; + bool m_timedOut; }; void CCLayerTreeHostTest::doBeginTest() { + ASSERT(isMainThread()); ASSERT(!m_running); m_running = true; - m_client = adoptPtr(new MockLayerTreeHostClient(this)); - m_layerTreeHost = adoptRef(new MockLayerTreeHost(m_client.get(), this)); - m_layerTreeHost->init(); + m_client = MockLayerTreeHostClient::create(this); + + CCSettings settings; + settings.enableCompositorThread = true; + RefPtr rootLayer; + m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, settings); + ASSERT(m_layerTreeHost); + m_beginning = true; beginTest(); m_beginning = false; @@ -327,7 +341,7 @@ public: virtual void beginTest() { - m_layerTreeHost->setNeedsCommitAndRedraw(); + postSetNeedsCommitToMainThread(); endTest(); } @@ -347,7 +361,7 @@ public: virtual void beginTest() { - m_layerTreeHost->setNeedsRedraw(); + postSetNeedsRedrawToMainThread(); endTest(); } @@ -371,23 +385,23 @@ public: virtual void beginTest() { - m_layerTreeHost->setNeedsCommitAndRedraw(); + postSetNeedsCommitToMainThread(); endTest(); } - virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) + virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { m_numCompleteCommits++; if (m_numCompleteCommits == 2) endTest(); } - virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) + virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*) { if (m_numDraws == 1) - layerTreeHostImpl->setNeedsCommitAndRedraw(); + postSetNeedsCommitToMainThread(); m_numDraws++; - layerTreeHostImpl->setNeedsRedraw(); + postSetNeedsRedrawToMainThread(); } virtual void afterTest() @@ -415,18 +429,18 @@ public: virtual void beginTest() { - m_layerTreeHost->setNeedsCommitAndRedraw(); - m_layerTreeHost->setNeedsCommitAndRedraw(); + postSetNeedsCommitToMainThread(); + postSetNeedsCommitToMainThread(); } - virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) + virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl) { m_numDraws++; - if (!layerTreeHostImpl->sourceFrameNumber()) + if (!impl->sourceFrameNumber()) endTest(); } - virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl) + virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { m_numCommits++; } @@ -458,18 +472,18 @@ public: virtual void beginTest() { - m_layerTreeHost->setNeedsCommitAndRedraw(); + postSetNeedsCommitToMainThread(); } - virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) + virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl) { - if (!layerTreeHostImpl->sourceFrameNumber()) - layerTreeHostImpl->setNeedsCommitAndRedraw(); - else if (layerTreeHostImpl->sourceFrameNumber() == 1) + if (!impl->sourceFrameNumber()) + postSetNeedsCommitToMainThread(); + else if (impl->sourceFrameNumber() == 1) endTest(); } - virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl) + virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { m_numCommits++; } @@ -501,19 +515,20 @@ public: virtual void beginTest() { + postSetNeedsCommitToMainThread(); } - virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* impl) + virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl) { EXPECT_EQ(0, impl->sourceFrameNumber()); if (!m_numDraws) - impl->setNeedsRedraw(); // redraw again to verify that the second redraw doesnt commit. + postSetNeedsRedrawToMainThread(); // Redraw again to verify that the second redraw doesn't commit. else endTest(); m_numDraws++; } - virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl) + virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { m_numCommits++; } -- 2.7.4