diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 22:59:56 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 22:59:56 +0000 |
commit | e5e9c02081e6b37f49febeba87863a1dac598949 (patch) | |
tree | 3e2c4fcd2926cc064fd7937e3cdee49e9ef62fd6 /cc/test | |
parent | 760d9886b9d56182f6c91944e06f250df6677d33 (diff) | |
download | chromium_src-e5e9c02081e6b37f49febeba87863a1dac598949.zip chromium_src-e5e9c02081e6b37f49febeba87863a1dac598949.tar.gz chromium_src-e5e9c02081e6b37f49febeba87863a1dac598949.tar.bz2 |
Remove WebKit::Platform dependencies from cc
This removes all dependencies on the static WebKit::Platform pointer from cc.
The biggest change is implementing cc::Thread on top of base::MessageLoopProxy
instead of WebKit::WebThread. For the main thread cc::Thread simply binds to
the current thread's MessageLoopProxy. For the impl thread, the bindings layer
(specifically webkit/compositor_bindings/web_compositor_impl) extracts the
MessageLoopProxy out of the passed in WebThread.
BUG=144539
Review URL: https://codereview.chromium.org/11344004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test')
-rw-r--r-- | cc/test/layer_tree_test_common.cc | 100 | ||||
-rw-r--r-- | cc/test/layer_tree_test_common.h | 15 | ||||
-rw-r--r-- | cc/test/run_all_unittests.cc | 9 | ||||
-rw-r--r-- | cc/test/scheduler_test_common.cc | 21 | ||||
-rw-r--r-- | cc/test/scheduler_test_common.h | 20 | ||||
-rw-r--r-- | cc/test/test_webkit_platform.cc | 53 | ||||
-rw-r--r-- | cc/test/test_webkit_platform.h | 44 | ||||
-rw-r--r-- | cc/test/web_compositor_initializer.h | 36 |
8 files changed, 59 insertions, 239 deletions
diff --git a/cc/test/layer_tree_test_common.cc b/cc/test/layer_tree_test_common.cc index 0d77c67..da3f430 100644 --- a/cc/test/layer_tree_test_common.cc +++ b/cc/test/layer_tree_test_common.cc @@ -17,17 +17,15 @@ #include "cc/scoped_thread_proxy.h" #include "cc/settings.h" #include "cc/single_thread_proxy.h" +#include "cc/thread_impl.h" #include "cc/test/animation_test_common.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/occlusion_tracker_test_common.h" #include "cc/test/test_common.h" #include "cc/test/tiled_layer_test_common.h" -#include "cc/thread_task.h" #include "cc/timing_function.h" #include "testing/gmock/include/gmock/gmock.h" -#include <public/Platform.h> -#include <public/WebCompositorSupport.h> #include <public/WebFilterOperation.h> #include <public/WebFilterOperations.h> #include <public/WebThread.h> @@ -270,50 +268,6 @@ private: TestHooks* m_testHooks; }; -class TimeoutTask : public WebThread::Task { -public: - explicit TimeoutTask(ThreadedTest* test) - : m_test(test) - { - } - - void clearTest() - { - m_test = 0; - } - - virtual ~TimeoutTask() - { - if (m_test) - m_test->clearTimeout(); - } - - virtual void run() - { - if (m_test) - m_test->timeout(); - } - -private: - ThreadedTest* m_test; -}; - -class BeginTask : public WebThread::Task { -public: - explicit BeginTask(ThreadedTest* test) - : m_test(test) - { - } - - virtual ~BeginTask() { } - virtual void run() - { - m_test->doBeginTest(); - } -private: - ThreadedTest* m_test; -}; - ThreadedTest::ThreadedTest() : m_beginning(false) , m_endWhenBeginReturns(false) @@ -337,57 +291,57 @@ void ThreadedTest::endTest() if (m_beginning) m_endWhenBeginReturns = true; else - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::realEndTest)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::realEndTest, base::Unretained(this))); } void ThreadedTest::endTestAfterDelay(int delayMilliseconds) { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::endTest)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::endTest, base::Unretained(this))); } void ThreadedTest::postSetNeedsAnimateToMainThread() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSetNeedsAnimate)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSetNeedsAnimate, base::Unretained(this))); } void ThreadedTest::postAddAnimationToMainThread(Layer* layerToReceiveAnimation) { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchAddAnimation, layerToReceiveAnimation)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAddAnimation, base::Unretained(this), base::Unretained(layerToReceiveAnimation))); } void ThreadedTest::postAddInstantAnimationToMainThread() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchAddInstantAnimation)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAddInstantAnimation, base::Unretained(this))); } void ThreadedTest::postSetNeedsCommitToMainThread() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSetNeedsCommit)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSetNeedsCommit, base::Unretained(this))); } void ThreadedTest::postAcquireLayerTextures() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchAcquireLayerTextures)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAcquireLayerTextures, base::Unretained(this))); } void ThreadedTest::postSetNeedsRedrawToMainThread() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSetNeedsRedraw)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSetNeedsRedraw, base::Unretained(this))); } void ThreadedTest::postSetNeedsAnimateAndCommitToMainThread() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSetNeedsAnimateAndCommit)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSetNeedsAnimateAndCommit, base::Unretained(this))); } void ThreadedTest::postSetVisibleToMainThread(bool visible) { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSetVisible, visible)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSetVisible, base::Unretained(this), visible)); } void ThreadedTest::postDidAddAnimationToMainThread() { - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchDidAddAnimation)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchDidAddAnimation, base::Unretained(this))); } void ThreadedTest::doBeginTest() @@ -425,13 +379,13 @@ void ThreadedTest::scheduleComposite() if (!m_started || m_scheduled || m_finished) return; m_scheduled = true; - m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchComposite)); + m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchComposite, base::Unretained(this))); } void ThreadedTest::realEndTest() { DCHECK(Proxy::isMainThread()); - WebKit::Platform::current()->currentThread()->exitRunLoop(); + MessageLoop::current()->Quit(); } void ThreadedTest::dispatchSetNeedsAnimate() @@ -549,38 +503,36 @@ void ThreadedTest::runTest(bool threaded) Settings::setAcceleratedAnimationEnabled(true); if (threaded) { - m_webThread.reset(WebKit::Platform::current()->createThread("ThreadedTest")); - Platform::current()->compositorSupport()->initialize(m_webThread.get()); - } else - Platform::current()->compositorSupport()->initialize(0); + 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()); + } DCHECK(Proxy::isMainThread()); m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread()); initializeSettings(m_settings); - m_beginTask = new BeginTask(this); - WebKit::Platform::current()->currentThread()->postDelayedTask(m_beginTask, 0); // postDelayedTask takes ownership of the task - m_timeoutTask = new TimeoutTask(this); - WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask, 5000); - WebKit::Platform::current()->currentThread()->enterRunLoop(); - + cc::Proxy::mainThread()->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unretained(this))); + m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); + 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(); - if (m_timeoutTask) - m_timeoutTask->clearTest(); + cc::Proxy::setImplThread(0); + + m_timeout.Cancel(); ASSERT_FALSE(m_layerTreeHost.get()); m_client.reset(); if (m_timedOut) { FAIL() << "Test timed out"; - Platform::current()->compositorSupport()->shutdown(); return; } afterTest(); - Platform::current()->compositorSupport()->shutdown(); } } // namespace WebKitTests diff --git a/cc/test/layer_tree_test_common.h b/cc/test/layer_tree_test_common.h index c8d1c36..962764a 100644 --- a/cc/test/layer_tree_test_common.h +++ b/cc/test/layer_tree_test_common.h @@ -7,19 +7,20 @@ #include "base/hash_tables.h" #include "base/memory/ref_counted.h" +#include "base/threading/thread.h" #include "cc/layer_tree_host.h" #include "cc/layer_tree_host_impl.h" #include "cc/scoped_thread_proxy.h" #include "cc/test/compositor_fake_web_graphics_context_3d.h" #include "testing/gtest/include/gtest/gtest.h" #include <public/WebAnimationDelegate.h> -#include <public/WebThread.h> namespace cc { class LayerImpl; class LayerTreeHost; class LayerTreeHostClient; class LayerTreeHostImpl; +class Thread; } namespace WebKitTests { @@ -89,8 +90,6 @@ public: void doBeginTest(); void timeout(); - void clearTimeout() { m_timeoutTask = 0; } - cc::LayerTreeHost* layerTreeHost() { return m_layerTreeHost.get(); } protected: @@ -114,7 +113,8 @@ protected: void dispatchDidAddAnimation(); virtual void runTest(bool threaded); - WebKit::WebThread* webThread() const { return m_webThread.get(); } + + cc::Thread* implThread() { return m_implCCThread.get(); } cc::LayerTreeSettings m_settings; scoped_ptr<MockLayerImplTreeHostClient> m_client; @@ -131,9 +131,10 @@ private: bool m_scheduled; bool m_started; - scoped_ptr<WebKit::WebThread> m_webThread; - TimeoutTask* m_timeoutTask; - BeginTask* m_beginTask; + scoped_ptr<cc::Thread> m_mainCCThread; + scoped_ptr<cc::Thread> m_implCCThread; + scoped_ptr<base::Thread> m_implThread; + base::CancelableClosure m_timeout; }; class ThreadedTestThreadOnly : public ThreadedTest { diff --git a/cc/test/run_all_unittests.cc b/cc/test/run_all_unittests.cc index 9132bab..d0fddbc 100644 --- a/cc/test/run_all_unittests.cc +++ b/cc/test/run_all_unittests.cc @@ -4,18 +4,17 @@ #include "base/message_loop.h" #include "base/test/test_suite.h" -#include "cc/test/test_webkit_platform.h" +#include "cc/thread_impl.h" +#include "cc/proxy.h" #include "testing/gmock/include/gmock/gmock.h" -#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" int main(int argc, char** argv) { ::testing::InitGoogleMock(&argc, argv); TestSuite test_suite(argc, argv); - cc::TestWebKitPlatform platform; MessageLoop message_loop; - WebKit::Platform::initialize(&platform); + scoped_ptr<cc::Thread> mainCCThread = cc::ThreadImpl::createForCurrentThread(); + cc::Proxy::setMainThread(mainCCThread.get()); int result = test_suite.Run(); - WebKit::Platform::shutdown(); return result; } diff --git a/cc/test/scheduler_test_common.cc b/cc/test/scheduler_test_common.cc index b2bedd8..4d2c13c 100644 --- a/cc/test/scheduler_test_common.cc +++ b/cc/test/scheduler_test_common.cc @@ -24,24 +24,31 @@ FakeThread::~FakeThread() { } -void FakeThread::postTask(PassOwnPtr<Task>) +void FakeThread::runPendingTask() { - NOTREACHED(); + ASSERT_TRUE(m_pendingTask); + scoped_ptr<base::Closure> task = m_pendingTask.Pass(); + task->Run(); } -void FakeThread::postDelayedTask(PassOwnPtr<Task> task, long long delay) +void FakeThread::postTask(base::Closure cb) +{ + postDelayedTask(cb, 0); +} + +void FakeThread::postDelayedTask(base::Closure cb, long long delay) { if (m_runPendingTaskOnOverwrite && hasPendingTask()) runPendingTask(); - EXPECT_TRUE(!hasPendingTask()); - m_pendingTask = task; + ASSERT_FALSE(hasPendingTask()); + m_pendingTask.reset(new base::Closure(cb)); m_pendingTaskDelay = delay; } -base::PlatformThreadId FakeThread::threadID() const +bool FakeThread::belongsToCurrentThread() const { - return 0; + return true; } void FakeTimeSource::setClient(cc::TimeSourceClient* client) diff --git a/cc/test/scheduler_test_common.h b/cc/test/scheduler_test_common.h index a586150..e43e4b8 100644 --- a/cc/test/scheduler_test_common.h +++ b/cc/test/scheduler_test_common.h @@ -5,12 +5,11 @@ #ifndef CCSchedulerTestCommon_h #define CCSchedulerTestCommon_h -#include "base/threading/platform_thread.h" +#include "base/memory/scoped_ptr.h" #include "cc/delay_based_time_source.h" #include "cc/frame_rate_controller.h" #include "cc/thread.h" #include "testing/gtest/include/gtest/gtest.h" -#include <wtf/OwnPtr.h> namespace WebKitTests { @@ -34,7 +33,7 @@ public: void reset() { m_pendingTaskDelay = 0; - m_pendingTask.clear(); + m_pendingTask.reset(); m_runPendingTaskOnOverwrite = false; } @@ -44,12 +43,7 @@ public: } bool hasPendingTask() const { return m_pendingTask; } - void runPendingTask() - { - ASSERT_TRUE(m_pendingTask); - OwnPtr<Task> task = m_pendingTask.release(); - task->performTask(); - } + void runPendingTask(); long long pendingDelayMs() const { @@ -57,12 +51,12 @@ public: return m_pendingTaskDelay; } - virtual void postTask(PassOwnPtr<Task>) OVERRIDE; - virtual void postDelayedTask(PassOwnPtr<Task> task, long long delay) OVERRIDE; - virtual base::PlatformThreadId threadID() const OVERRIDE; + virtual void postTask(base::Closure cb) OVERRIDE; + virtual void postDelayedTask(base::Closure cb, long long delay) OVERRIDE; + virtual bool belongsToCurrentThread() const OVERRIDE; protected: - OwnPtr<Task> m_pendingTask; + scoped_ptr<base::Closure> m_pendingTask; long long m_pendingTaskDelay; bool m_runPendingTaskOnOverwrite; }; diff --git a/cc/test/test_webkit_platform.cc b/cc/test/test_webkit_platform.cc deleted file mode 100644 index 403ba61..0000000 --- a/cc/test/test_webkit_platform.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 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 "cc/test/test_webkit_platform.h" - -namespace cc { - -TestWebKitPlatform::TestWebKitPlatform() { -} - -TestWebKitPlatform::~TestWebKitPlatform() { -} - -WebKit::WebCompositorSupport* TestWebKitPlatform::compositorSupport() { - return &compositor_support_; -} - -void TestWebKitPlatform::cryptographicallyRandomValues( - unsigned char* buffer, size_t length) { - base::RandBytes(buffer, length); -} - -WebKit::WebThread* TestWebKitPlatform::createThread(const char* name) { - return new webkit_glue::WebThreadImpl(name); -} - -WebKit::WebThread* TestWebKitPlatform::currentThread() { - webkit_glue::WebThreadImplForMessageLoop* thread = - static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); - if (thread) - return (thread); - - scoped_refptr<base::MessageLoopProxy> message_loop = - base::MessageLoopProxy::current(); - if (!message_loop) - return NULL; - - thread = new WebThreadImplForMessageLoop(message_loop); - current_thread_slot_.Set(thread); - return thread; -} - -double TestWebKitPlatform::currentTime() { - return base::Time::Now().ToDoubleT(); -} - -double TestWebKitPlatform::monotonicallyIncreasingTime() { - return base::TimeTicks::Now().ToInternalValue() / - static_cast<double>(base::Time::kMicrosecondsPerSecond); -} - -} diff --git a/cc/test/test_webkit_platform.h b/cc/test/test_webkit_platform.h deleted file mode 100644 index ee7cfa6..0000000 --- a/cc/test/test_webkit_platform.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 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 CC_TEST_TEST_WEBKIT_PLATFORM_H_ -#define CC_TEST_TEST_WEBKIT_PLATFORM_H_ - -#include "base/rand_util.h" -#include "base/threading/thread_local_storage.h" -#include "cc/test/test_webkit_platform.h" -#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" -#include "webkit/compositor_bindings/web_compositor_support_impl.h" -#include "webkit/glue/webthread_impl.h" - -using webkit_glue::WebThreadImplForMessageLoop; - -namespace cc { - -class TestWebKitPlatform : public WebKit::Platform { - public: - TestWebKitPlatform(); - virtual ~TestWebKitPlatform(); - - virtual WebKit::WebCompositorSupport* compositorSupport(); - - virtual void cryptographicallyRandomValues( - unsigned char* buffer, size_t length); - - virtual WebKit::WebThread* createThread(const char* name); - - virtual WebKit::WebThread* currentThread(); - - virtual double currentTime(); - - virtual double monotonicallyIncreasingTime(); - - private: - base::ThreadLocalStorage::Slot current_thread_slot_; - webkit::WebCompositorSupportImpl compositor_support_; -}; - -} // namespace cc - -#endif // CC_TEST_TEST_WEBKIT_PLATFORM_H_ diff --git a/cc/test/web_compositor_initializer.h b/cc/test/web_compositor_initializer.h deleted file mode 100644 index f6203b1..0000000 --- a/cc/test/web_compositor_initializer.h +++ /dev/null @@ -1,36 +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 WebCompositorInitializer_h -#define WebCompositorInitializer_h - -#include "base/basictypes.h" -#include <public/Platform.h> -#include <public/WebCompositorSupport.h> - -namespace WebKit { -class WebThread; -} - -namespace WebKitTests { - -class WebCompositorInitializer { -public: - explicit WebCompositorInitializer(WebKit::WebThread* thread) - { - WebKit::Platform::current()->compositorSupport()->initialize(thread); - } - - ~WebCompositorInitializer() - { - WebKit::Platform::current()->compositorSupport()->shutdown(); - } - -private: - DISALLOW_COPY_AND_ASSIGN(WebCompositorInitializer); -}; - -} - -#endif // WebCompositorInitializer_h |