Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp (95311 => 95312)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp 2011-09-16 19:29:07 UTC (rev 95311)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp 2011-09-16 20:05:01 UTC (rev 95312)
@@ -148,7 +148,6 @@
, 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))
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp (95311 => 95312)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp 2011-09-16 19:29:07 UTC (rev 95311)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp 2011-09-16 20:05:01 UTC (rev 95312)
@@ -84,6 +84,7 @@
GraphicsContext3D* CCThreadProxy::context()
{
+ ASSERT_NOT_REACHED();
return 0;
}
@@ -185,8 +186,8 @@
{
TRACE_EVENT("CCThreadProxy::beginFrameAndCommitOnCCThread", this, 0);
ASSERT(isImplThread());
- // TEMP HACK so we can exercise this code in unit tests.
- CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0));
+ ASSERT_NOT_REACHED();
+ // FIXME: call beginFrameAndCommit on main thread
}
void CCThreadProxy::beginFrameAndCommit(double frameBeginTime)
@@ -246,15 +247,13 @@
TRACE_EVENT("CCThreadProxy::setNeedsCommitAndRedrawOnCCThread", this, 0);
ASSERT(isImplThread());
ASSERT(m_layerTreeHostImpl);
- // TEMP HACK so we can exercise this code in unit tests.
- CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0));
+ ASSERT_NOT_REACHED();
}
void CCThreadProxy::setNeedsRedrawOnCCThread()
{
TRACE_EVENT("CCThreadProxy::setNeedsRedrawOnCCThread", this, 0);
- // TEMP HACK so we can exercise this code in unit tests.
- drawLayersOnCCThread();
+ ASSERT_NOT_REACHED();
}
void CCThreadProxy::initializeImplOnCCThread(CCCompletionEvent* completion)
@@ -285,4 +284,4 @@
completion->signal();
}
-} // namespace WebCore
+}
Modified: trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp (95311 => 95312)
--- trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp 2011-09-16 19:29:07 UTC (rev 95311)
+++ trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp 2011-09-16 20:05:01 UTC (rev 95312)
@@ -28,12 +28,7 @@
#include "cc/CCLayerTreeHost.h"
-#include "CCThreadImpl.h"
-#include "GraphicsContext3DPrivate.h"
-#include "LayerChromium.h"
-#include "LayerPainterChromium.h"
-#include "MockWebGraphicsContext3D.h"
-#include "TextureManager.h"
+#include "GraphicsContext3D.h"
#include "cc/CCLayerTreeHostImpl.h"
#include "cc/CCMainThreadTask.h"
#include "cc/CCThreadTask.h"
@@ -43,256 +38,247 @@
#include <wtf/PassRefPtr.h>
#include <wtf/Vector.h>
+
using namespace WebCore;
-using namespace WebKit;
using namespace WTF;
namespace {
-// Used by test stubs to notify the test when something interesting happens.
-class TestHooks {
-public:
- virtual void beginCommitOnCCThread(CCLayerTreeHostImpl*) { }
- virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { }
- virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*) { }
-};
+class MockLayerTreeHost;
+class MockLayerTreeHostClient;
+class MockLayerTreeHostImpl;
-// Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks.
-class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
+// 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 {
public:
- static PassOwnPtr<MockLayerTreeHostImpl> create(TestHooks* testHooks, const CCSettings& settings)
+ 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();
+
+ static void onBeginTest(void* self)
{
- return adoptPtr(new MockLayerTreeHostImpl(testHooks, settings));
+ static_cast<CCLayerTreeHostTest*>(self)->doBeginTest();
}
- virtual void beginCommit()
+ void doEndTest()
{
- CCLayerTreeHostImpl::beginCommit();
- m_testHooks->beginCommitOnCCThread(this);
}
- virtual void commitComplete()
+ static void onEndTest(void* self)
{
- CCLayerTreeHostImpl::commitComplete();
- m_testHooks->commitCompleteOnCCThread(this);
+ ASSERT(isMainThread());
+ CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
+ test->m_layerTreeHost.clear();
+ test->m_client.clear();
+ webkit_support::QuitMessageLoop();
}
- virtual void drawLayers()
+ void runTest()
{
- CCLayerTreeHostImpl::drawLayers();
- m_testHooks->drawLayersOnCCThread(this);
+ webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast<void*>(this), 0);
+ webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast<void*>(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();
}
-private:
- MockLayerTreeHostImpl(TestHooks* testHooks, const CCSettings& settings)
- : CCLayerTreeHostImpl(settings)
- , m_testHooks(testHooks)
+ static void testTimeout(void* self)
{
+ CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
+ if (!test->m_running)
+ return;
+ test->m_timedOut = true;
+ test->endTest();
}
- TestHooks* m_testHooks;
+ Mutex m_tracesLock;
+ Vector<std::string> m_traces;
+
+ OwnPtr<MockLayerTreeHostClient> m_client;
+ RefPtr<MockLayerTreeHost> m_layerTreeHost;
+
+private:
+ bool m_beginning;
+ bool m_endWhenBeginReturns;
+ bool m_running;
+ bool m_timedOut;
};
-// Adapts CCLayerTreeHost for test. Injects MockLayerTreeHostImpl.
-class MockLayerTreeHost : public CCLayerTreeHost {
+class MockLayerTreeHostClient : public CCLayerTreeHostClient {
public:
- static PassRefPtr<MockLayerTreeHost> create(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr<LayerChromium> rootLayer, const CCSettings& settings)
+ MockLayerTreeHostClient(CCLayerTreeHostTest* test) : m_test(test) { }
+
+ virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
{
- return adoptRef(new MockLayerTreeHost(testHooks, client, rootLayer, settings));
+ return adoptRef<GraphicsContext3D>(0);
}
- virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
+ virtual void animateAndLayout(double frameBeginTime)
{
- return MockLayerTreeHostImpl::create(m_testHooks, settings());
+ m_test->animateAndLayout(this, frameBeginTime);
}
-private:
- MockLayerTreeHost(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr<LayerChromium> rootLayer, const CCSettings& settings)
- : CCLayerTreeHost(client, rootLayer, settings)
- , m_testHooks(testHooks)
+ virtual void updateLayers()
{
- bool success = initialize();
- ASSERT(success);
}
- TestHooks* m_testHooks;
+private:
+ CCLayerTreeHostTest* m_test;
};
-// Test stub for WebGraphicsContext3D. Returns canned values needed for compositor initialization.
-class CompositorMockWebGraphicsContext3D : public MockWebGraphicsContext3D {
+class MockLayerTreeHostCommitter : public CCLayerTreeHostCommitter {
public:
- static PassOwnPtr<CompositorMockWebGraphicsContext3D> create()
+ static PassOwnPtr<MockLayerTreeHostCommitter> create(CCLayerTreeHostTest* test)
{
- return adoptPtr(new CompositorMockWebGraphicsContext3D());
+ return adoptPtr(new MockLayerTreeHostCommitter(test));
}
- 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; }
+ virtual void commit(CCLayerTreeHost* host, CCLayerTreeHostImpl* hostImpl)
+ {
+ CCLayerTreeHostCommitter::commit(host, hostImpl);
+ m_test->commitOnCCThread(reinterpret_cast<MockLayerTreeHost*>(host), reinterpret_cast<MockLayerTreeHostImpl*>(hostImpl));
+ }
private:
- CompositorMockWebGraphicsContext3D() { }
+ MockLayerTreeHostCommitter(CCLayerTreeHostTest* test) : m_test(test) { }
+ CCLayerTreeHostTest* m_test;
};
-// Implementation of CCLayerTreeHost callback interface.
-class MockLayerTreeHostClient : public CCLayerTreeHostClient {
+class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
public:
- static PassOwnPtr<MockLayerTreeHostClient> create(TestHooks* testHooks)
+ static PassOwnPtr<MockLayerTreeHostImpl> create(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
{
- return adoptPtr(new MockLayerTreeHostClient(testHooks));
+ return adoptPtr(new MockLayerTreeHostImpl(client, test));
}
- virtual void animateAndLayout(double frameBeginTime)
+ virtual void beginCommit()
{
+ CCLayerTreeHostImpl::beginCommit();
+ m_test->beginCommitOnCCThread(this);
}
- virtual PassOwnPtr<CCThread> createCompositorThread()
+ virtual void commitComplete()
{
- return CCThreadImpl::create();
+ CCLayerTreeHostImpl::commitComplete();
+ m_test->commitCompleteOnCCThread(this);
}
- virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
+ virtual void drawLayersAndPresent()
{
- OwnPtr<WebGraphicsContext3D> mock = CompositorMockWebGraphicsContext3D::create();
- GraphicsContext3D::Attributes attrs;
- RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(mock.release(), attrs, 0, GraphicsContext3D::RenderDirectlyToHostWindow, GraphicsContext3DPrivate::ForUseOnAnotherThread);
- return context;
+ m_test->drawLayersAndPresentOnCCThread(this);
}
- virtual PassOwnPtr<LayerPainterChromium> createRootLayerPainter()
+private:
+ MockLayerTreeHostImpl(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
+ : CCLayerTreeHostImpl(client)
+ , m_test(test)
{
- return nullptr;
}
- virtual void didRecreateGraphicsContext(bool)
- {
- }
-
-private:
- explicit MockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks(testHooks) { }
-
- TestHooks* m_testHooks;
+ CCLayerTreeHostTest* m_test;
};
-// 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 {
+class MockLayerTreeHostImplProxy : public CCLayerTreeHostImplProxy {
public:
- virtual void afterTest() = 0;
- virtual void beginTest() = 0;
-
- void endTest();
-
- void postSetNeedsCommitToMainThread()
+ static PassOwnPtr<MockLayerTreeHostImplProxy> create(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
{
- callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsCommit, this);
+ return adoptPtr(new MockLayerTreeHostImplProxy(host, test));
}
- void postSetNeedsRedrawToMainThread()
+ PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
{
- callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsRedraw, this);
+ return MockLayerTreeHostImpl::create(this, m_test);
}
-protected:
- CCLayerTreeHostTest()
- : m_beginning(false)
- , m_endWhenBeginReturns(false)
- , m_running(false)
- , m_timedOut(false) { }
+private:
+ MockLayerTreeHostImplProxy(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
+ : CCLayerTreeHostImplProxy(host)
+ , m_test(test) { }
- void doBeginTest();
+ CCLayerTreeHostTest* m_test;
+};
- static void onBeginTest(void* self)
- {
- static_cast<CCLayerTreeHostTest*>(self)->doBeginTest();
- }
+class MockLayerTreeHost : public CCLayerTreeHost {
+public:
+ MockLayerTreeHost(CCLayerTreeHostClient* client, CCLayerTreeHostTest* test)
+ : CCLayerTreeHost(client)
+ , m_test(test) { }
- static void onEndTest(void* self)
+ virtual PassOwnPtr<CCLayerTreeHostImplProxy> createLayerTreeHostImplProxy()
{
- ASSERT(isMainThread());
- webkit_support::QuitMessageLoop();
- CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
- ASSERT(test);
- test->m_layerTreeHost.clear();
+ OwnPtr<CCLayerTreeHostImplProxy> proxy = MockLayerTreeHostImplProxy::create(this, m_test);
+ proxy->start();
+ return proxy.release();
}
- static void dispatchSetNeedsCommit(void* self)
+ virtual void updateLayers()
{
- ASSERT(isMainThread());
- CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
- ASSERT(test);
- if (test->m_layerTreeHost)
- test->m_layerTreeHost->setNeedsCommitAndRedraw();
+ m_test->updateLayers(this);
}
- static void dispatchSetNeedsRedraw(void* self)
+ virtual PassOwnPtr<CCLayerTreeHostCommitter> createLayerTreeHostCommitter()
{
- ASSERT(isMainThread());
- CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
- ASSERT(test);
- if (test->m_layerTreeHost)
- test->m_layerTreeHost->setNeedsRedraw();
+ return MockLayerTreeHostCommitter::create(m_test);
}
- void runTest()
+ virtual void beginCommit()
{
- webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast<void*>(this), 0);
- webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast<void*>(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();
+ CCLayerTreeHost::beginCommit();
+ m_test->beginCommitOnMainThread(this);
}
- static void testTimeout(void* self)
+ virtual void commitComplete()
{
- CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
- if (!test->m_running)
- return;
- test->m_timedOut = true;
- test->endTest();
+ m_test->commitCompleteOnMainThread(this);
+ CCLayerTreeHost::commitComplete();
}
- OwnPtr<MockLayerTreeHostClient> m_client;
- RefPtr<CCLayerTreeHost> m_layerTreeHost;
-
private:
- bool m_beginning;
- bool m_endWhenBeginReturns;
- bool m_running;
- bool m_timedOut;
+ CCLayerTreeHostTest* m_test;
};
void CCLayerTreeHostTest::doBeginTest()
{
- ASSERT(isMainThread());
ASSERT(!m_running);
m_running = true;
- m_client = MockLayerTreeHostClient::create(this);
-
- CCSettings settings;
- settings.enableCompositorThread = true;
- RefPtr<LayerChromium> rootLayer;
- m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, settings);
- ASSERT(m_layerTreeHost);
-
+ m_client = adoptPtr(new MockLayerTreeHostClient(this));
+ m_layerTreeHost = adoptRef(new MockLayerTreeHost(m_client.get(), this));
+ m_layerTreeHost->init();
m_beginning = true;
beginTest();
m_beginning = false;
@@ -341,7 +327,7 @@
virtual void beginTest()
{
- postSetNeedsCommitToMainThread();
+ m_layerTreeHost->setNeedsCommitAndRedraw();
endTest();
}
@@ -361,7 +347,7 @@
virtual void beginTest()
{
- postSetNeedsRedrawToMainThread();
+ m_layerTreeHost->setNeedsRedraw();
endTest();
}
@@ -385,23 +371,23 @@
virtual void beginTest()
{
- postSetNeedsCommitToMainThread();
+ m_layerTreeHost->setNeedsCommitAndRedraw();
endTest();
}
- virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
+ virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
{
m_numCompleteCommits++;
if (m_numCompleteCommits == 2)
endTest();
}
- virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*)
+ virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
{
if (m_numDraws == 1)
- postSetNeedsCommitToMainThread();
+ layerTreeHostImpl->setNeedsCommitAndRedraw();
m_numDraws++;
- postSetNeedsRedrawToMainThread();
+ layerTreeHostImpl->setNeedsRedraw();
}
virtual void afterTest()
@@ -429,18 +415,18 @@
virtual void beginTest()
{
- postSetNeedsCommitToMainThread();
- postSetNeedsCommitToMainThread();
+ m_layerTreeHost->setNeedsCommitAndRedraw();
+ m_layerTreeHost->setNeedsCommitAndRedraw();
}
- virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
+ virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
{
m_numDraws++;
- if (!impl->sourceFrameNumber())
+ if (!layerTreeHostImpl->sourceFrameNumber())
endTest();
}
- virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
+ virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
{
m_numCommits++;
}
@@ -472,18 +458,18 @@
virtual void beginTest()
{
- postSetNeedsCommitToMainThread();
+ m_layerTreeHost->setNeedsCommitAndRedraw();
}
- virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
+ virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
{
- if (!impl->sourceFrameNumber())
- postSetNeedsCommitToMainThread();
- else if (impl->sourceFrameNumber() == 1)
+ if (!layerTreeHostImpl->sourceFrameNumber())
+ layerTreeHostImpl->setNeedsCommitAndRedraw();
+ else if (layerTreeHostImpl->sourceFrameNumber() == 1)
endTest();
}
- virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
+ virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
{
m_numCommits++;
}
@@ -515,20 +501,19 @@
virtual void beginTest()
{
- postSetNeedsCommitToMainThread();
}
- virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
+ virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* impl)
{
EXPECT_EQ(0, impl->sourceFrameNumber());
if (!m_numDraws)
- postSetNeedsRedrawToMainThread(); // Redraw again to verify that the second redraw doesn't commit.
+ impl->setNeedsRedraw(); // redraw again to verify that the second redraw doesnt commit.
else
endTest();
m_numDraws++;
}
- virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
+ virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
{
m_numCommits++;
}