diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 07:17:46 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 07:17:46 +0000 |
commit | 068d7ef6aed7f5a7bdaf1e8d28b422c547be294d (patch) | |
tree | a66fd6a12e3a9ae7ef16c66043fd4e4bebe4d28c /cc/test | |
parent | 2bddc10a9e71bd3e7d7f010b46ec96c7ab623336 (diff) | |
download | chromium_src-068d7ef6aed7f5a7bdaf1e8d28b422c547be294d.zip chromium_src-068d7ef6aed7f5a7bdaf1e8d28b422c547be294d.tar.gz chromium_src-068d7ef6aed7f5a7bdaf1e8d28b422c547be294d.tar.bz2 |
A speculative Revert for r165872 - Remove static thread pointers from CC, attempt 2
BUG=152904
Review URL: https://chromiumcodereview.appspot.com/11232051
TBR=aelias@chromium.org
Review URL: https://codereview.chromium.org/11369071
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test')
-rw-r--r-- | cc/test/fake_proxy.cc | 52 | ||||
-rw-r--r-- | cc/test/fake_proxy.h | 50 | ||||
-rw-r--r-- | cc/test/layer_tree_test_common.cc | 52 | ||||
-rw-r--r-- | cc/test/layer_tree_test_common.h | 8 | ||||
-rw-r--r-- | cc/test/run_all_unittests.cc | 5 |
5 files changed, 36 insertions, 131 deletions
diff --git a/cc/test/fake_proxy.cc b/cc/test/fake_proxy.cc deleted file mode 100644 index fad6c69..0000000 --- a/cc/test/fake_proxy.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" - -#include "cc/test/fake_proxy.h" - -namespace cc { - -bool FakeProxy::compositeAndReadback(void *pixels, const gfx::Rect&) -{ - return false; -} - -bool FakeProxy::isStarted() const -{ - return false; -} - -bool FakeProxy::initializeContext() -{ - return false; -} - -bool FakeProxy::initializeRenderer() -{ - return false; -} - -bool FakeProxy::recreateContext() -{ - return false; -} - -const RendererCapabilities& FakeProxy::rendererCapabilities() const -{ - return m_capabilities; -} - -bool FakeProxy::commitRequested() const -{ - return false; -} - -size_t FakeProxy::maxPartialTextureUpdates() const -{ - return 0; -} - - -} // namespace cc diff --git a/cc/test/fake_proxy.h b/cc/test/fake_proxy.h deleted file mode 100644 index e432d00..0000000 --- a/cc/test/fake_proxy.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FakeCCProxy_h -#define FakeCCProxy_h - -#include "config.h" - -#include "cc/layer_tree_host.h" -#include "cc/proxy.h" -#include "cc/thread.h" - -namespace cc { - -class FakeProxy : public Proxy { -public: - explicit FakeProxy(scoped_ptr<Thread> implThread) : Proxy(implThread.Pass()) { } - - virtual bool compositeAndReadback(void *pixels, const gfx::Rect&) OVERRIDE; - virtual void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, base::TimeDelta duration) OVERRIDE { } - virtual void finishAllRendering() OVERRIDE { } - virtual bool isStarted() const OVERRIDE; - virtual bool initializeContext() OVERRIDE; - virtual void setSurfaceReady() OVERRIDE { } - virtual void setVisible(bool) OVERRIDE { } - virtual bool initializeRenderer() OVERRIDE; - virtual bool recreateContext() OVERRIDE; - virtual void renderingStats(RenderingStats*) OVERRIDE { } - virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE; - virtual void setNeedsAnimate() OVERRIDE { } - virtual void setNeedsCommit() OVERRIDE { } - virtual void setNeedsRedraw() OVERRIDE { } - virtual void setDeferCommits(bool) OVERRIDE { } - virtual void didAddAnimation() OVERRIDE { } - virtual bool commitRequested() const OVERRIDE; - virtual void start() OVERRIDE { } - virtual void stop() OVERRIDE { } - virtual void forceSerializeOnSwapBuffers() OVERRIDE { } - virtual size_t maxPartialTextureUpdates() const OVERRIDE; - virtual void acquireLayerTextures() OVERRIDE { } - virtual void loseContext() OVERRIDE { } - -private: - RendererCapabilities m_capabilities; -}; - -} - -#endif diff --git a/cc/test/layer_tree_test_common.cc b/cc/test/layer_tree_test_common.cc index 92d8e5e..65a2904 100644 --- a/cc/test/layer_tree_test_common.cc +++ b/cc/test/layer_tree_test_common.cc @@ -89,9 +89,9 @@ scoped_ptr<WebCompositorOutputSurface> TestHooks::createOutputSurface() return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsContext3DWithTextureTracking::create(WebGraphicsContext3D::Attributes()).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<WebKit::WebCompositorOutputSurface>(); } -scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) +scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client) { - return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client, proxy)); + return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client)); } void MockLayerTreeHostImpl::beginCommit() @@ -132,8 +132,8 @@ base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const return base::TimeDelta::FromMilliseconds(16); } -MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) - : LayerTreeHostImpl(settings, client, proxy) +MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client) + : LayerTreeHostImpl(settings, client) , m_testHooks(testHooks) { } @@ -141,10 +141,10 @@ MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl. class MockLayerTreeHost : public cc::LayerTreeHost { public: - static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerTreeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSettings& settings, scoped_ptr<cc::Thread> implThread) + static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerTreeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSettings& settings) { scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHooks, client, settings)); - bool success = layerTreeHost->initialize(implThread.Pass()); + bool success = layerTreeHost->initialize(); EXPECT_TRUE(success); layerTreeHost->setRootLayer(rootLayer); @@ -158,7 +158,7 @@ public: virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerTreeHostImplClient* client) { - return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, proxy()).PassAs<cc::LayerTreeHostImpl>(); + return MockLayerTreeHostImpl::create(m_testHooks, settings(), client).PassAs<cc::LayerTreeHostImpl>(); } virtual void didAddAnimation() OVERRIDE @@ -275,7 +275,6 @@ ThreadedTest::ThreadedTest() , m_finished(false) , m_scheduled(false) , m_started(false) - , m_implThread(0) { } @@ -347,13 +346,11 @@ void ThreadedTest::postDidAddAnimationToMainThread() void ThreadedTest::doBeginTest() { + DCHECK(Proxy::isMainThread()); m_client = ThreadedMockLayerTreeHostClient::create(this); scoped_refptr<Layer> rootLayer = Layer::create(); - scoped_ptr<cc::Thread> implCCThread(NULL); - if (m_implThread) - implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->message_loop_proxy()); - m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings, implCCThread.Pass()); + m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings); ASSERT_TRUE(m_layerTreeHost.get()); rootLayer->setLayerTreeHost(m_layerTreeHost.get()); m_layerTreeHost->setSurfaceReady(); @@ -387,12 +384,13 @@ void ThreadedTest::scheduleComposite() void ThreadedTest::realEndTest() { + DCHECK(Proxy::isMainThread()); MessageLoop::current()->Quit(); } void ThreadedTest::dispatchSetNeedsAnimate() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -403,7 +401,7 @@ void ThreadedTest::dispatchSetNeedsAnimate() void ThreadedTest::dispatchAddInstantAnimation() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -414,7 +412,7 @@ void ThreadedTest::dispatchAddInstantAnimation() void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -425,7 +423,7 @@ void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) void ThreadedTest::dispatchSetNeedsAnimateAndCommit() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -438,7 +436,7 @@ void ThreadedTest::dispatchSetNeedsAnimateAndCommit() void ThreadedTest::dispatchSetNeedsCommit() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -449,7 +447,7 @@ void ThreadedTest::dispatchSetNeedsCommit() void ThreadedTest::dispatchAcquireLayerTextures() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -460,7 +458,7 @@ void ThreadedTest::dispatchAcquireLayerTextures() void ThreadedTest::dispatchSetNeedsRedraw() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -471,7 +469,7 @@ void ThreadedTest::dispatchSetNeedsRedraw() void ThreadedTest::dispatchSetVisible(bool visible) { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -489,7 +487,7 @@ void ThreadedTest::dispatchComposite() void ThreadedTest::dispatchDidAddAnimation() { - DCHECK(!proxy() || proxy()->isMainThread()); + DCHECK(Proxy::isMainThread()); if (m_finished) return; @@ -507,21 +505,25 @@ void ThreadedTest::runTest(bool threaded) if (threaded) { m_implThread.reset(new base::Thread("ThreadedTest")); ASSERT_TRUE(m_implThread->Start()); + m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->message_loop_proxy()); + cc::Proxy::setImplThread(m_implCCThread.get()); } - m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); - m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); + DCHECK(Proxy::isMainThread()); + m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread()); initializeSettings(m_settings); - m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unretained(this))); + cc::Proxy::mainThread()->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unretained(this))); m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); - m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000); + cc::Proxy::mainThread()->postDelayedTask(m_timeout.callback(), 5000); MessageLoop::current()->Run(); if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) m_layerTreeHost->rootLayer()->setLayerTreeHost(0); m_layerTreeHost.reset(); + cc::Proxy::setImplThread(0); + m_timeout.Cancel(); ASSERT_FALSE(m_layerTreeHost.get()); diff --git a/cc/test/layer_tree_test_common.h b/cc/test/layer_tree_test_common.h index e33480f..ad044d5 100644 --- a/cc/test/layer_tree_test_common.h +++ b/cc/test/layer_tree_test_common.h @@ -114,8 +114,7 @@ protected: virtual void runTest(bool threaded); - cc::Thread* implThread() { return proxy() ? proxy()->implThread() : 0; } - cc::Proxy* proxy() const { return m_layerTreeHost ? m_layerTreeHost->proxy() : 0; } + cc::Thread* implThread() { return m_implCCThread.get(); } cc::LayerTreeSettings m_settings; scoped_ptr<MockLayerImplTreeHostClient> m_client; @@ -133,6 +132,7 @@ private: bool m_started; scoped_ptr<cc::Thread> m_mainCCThread; + scoped_ptr<cc::Thread> m_implCCThread; scoped_ptr<base::Thread> m_implThread; base::CancelableClosure m_timeout; }; @@ -148,7 +148,7 @@ public: // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. class MockLayerTreeHostImpl : public cc::LayerTreeHostImpl { public: - static scoped_ptr<MockLayerTreeHostImpl> create(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*, cc::Proxy*); + static scoped_ptr<MockLayerTreeHostImpl> create(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*); virtual void beginCommit() OVERRIDE; virtual void commitComplete() OVERRIDE; @@ -164,7 +164,7 @@ protected: virtual base::TimeDelta lowFrequencyAnimationInterval() const OVERRIDE; private: - MockLayerTreeHostImpl(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*, cc::Proxy*); + MockLayerTreeHostImpl(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*); TestHooks* m_testHooks; }; diff --git a/cc/test/run_all_unittests.cc b/cc/test/run_all_unittests.cc index 4ea8697..d0fddbc 100644 --- a/cc/test/run_all_unittests.cc +++ b/cc/test/run_all_unittests.cc @@ -4,13 +4,18 @@ #include "base/message_loop.h" #include "base/test/test_suite.h" +#include "cc/thread_impl.h" +#include "cc/proxy.h" #include "testing/gmock/include/gmock/gmock.h" int main(int argc, char** argv) { ::testing::InitGoogleMock(&argc, argv); TestSuite test_suite(argc, argv); MessageLoop message_loop; + scoped_ptr<cc::Thread> mainCCThread = cc::ThreadImpl::createForCurrentThread(); + cc::Proxy::setMainThread(mainCCThread.get()); int result = test_suite.Run(); return result; } + |