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 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=165050 Review URL: https://codereview.chromium.org/11344004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165060 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
cc
cc.gypcc_tests.gypdelay_based_time_source.ccdelay_based_time_source.hframe_rate_controller.ccframe_rate_controller.hgl_renderer_unittest.cclayer_tree_host_impl.cclayer_tree_host_unittest.cclayer_unittest.ccprioritized_texture_unittest.ccproxy.ccrate_limiter.ccresource_update_controller.ccresource_update_controller.hresource_update_controller_unittest.ccscoped_thread_proxy.ccscoped_thread_proxy.hsingle_thread_proxy.cc
test
layer_tree_test_common.cclayer_tree_test_common.hrun_all_unittests.ccscheduler_test_common.ccscheduler_test_common.htest_webkit_platform.cctest_webkit_platform.hweb_compositor_initializer.h
texture_layer_unittest.ccthread.hthread_impl.ccthread_impl.hthread_proxy.ccthread_proxy.hthread_task.hthread_task_unittest.cctiled_layer_unittest.cctimer.cctimer.htimer_unittest.ccwebkit/compositor_bindings
@ -154,16 +154,15 @@
|
||||
'resource_update_queue.cc',
|
||||
'resource_update_queue.h',
|
||||
'thread.h',
|
||||
'thread_impl.h',
|
||||
'thread_impl.cc',
|
||||
'thread_proxy.cc',
|
||||
'thread_proxy.h',
|
||||
'thread_task.h',
|
||||
'tile_draw_quad.cc',
|
||||
'tile_draw_quad.h',
|
||||
'tiled_layer_impl.cc',
|
||||
'tiled_layer_impl.h',
|
||||
'time_source.h',
|
||||
'timer.cc',
|
||||
'timer.h',
|
||||
'timing_function.cc',
|
||||
'timing_function.h',
|
||||
'video_layer_impl.cc',
|
||||
|
@ -39,9 +39,7 @@
|
||||
'scrollbar_animation_controller_linear_fade_unittest.cc',
|
||||
'solid_color_layer_impl_unittest.cc',
|
||||
'resource_update_controller_unittest.cc',
|
||||
'thread_task_unittest.cc',
|
||||
'tiled_layer_impl_unittest.cc',
|
||||
'timer_unittest.cc',
|
||||
'content_layer_unittest.cc',
|
||||
'float_quad_unittest.cc',
|
||||
'layer_unittest.cc',
|
||||
@ -79,7 +77,6 @@
|
||||
'test/test_common.h',
|
||||
'test/tiled_layer_test_common.cc',
|
||||
'test/tiled_layer_test_common.h',
|
||||
'test/web_compositor_initializer.h',
|
||||
],
|
||||
},
|
||||
'targets': [
|
||||
@ -132,13 +129,9 @@
|
||||
'../third_party/WebKit/Source/WTF/WTF.gyp/WTF.gyp:wtf',
|
||||
'../third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit_wtf_support',
|
||||
'../third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
|
||||
'../webkit/compositor_bindings/compositor_bindings.gyp:webkit_compositor_support',
|
||||
'../webkit/support/webkit_support.gyp:glue',
|
||||
],
|
||||
'sources': [
|
||||
'<@(cc_tests_support_files)',
|
||||
'test/test_webkit_platform.cc',
|
||||
'test/test_webkit_platform.h',
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "base/debug/trace_event.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/message_loop.h"
|
||||
#include "cc/thread.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@ -40,7 +42,8 @@ DelayBasedTimeSource::DelayBasedTimeSource(base::TimeDelta interval, Thread* thr
|
||||
, m_currentParameters(interval, base::TimeTicks())
|
||||
, m_nextParameters(interval, base::TimeTicks())
|
||||
, m_state(STATE_INACTIVE)
|
||||
, m_timer(thread, this)
|
||||
, m_thread(thread)
|
||||
, m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
|
||||
{
|
||||
}
|
||||
|
||||
@ -53,7 +56,7 @@ void DelayBasedTimeSource::setActive(bool active)
|
||||
TRACE_EVENT1("cc", "DelayBasedTimeSource::setActive", "active", active);
|
||||
if (!active) {
|
||||
m_state = STATE_INACTIVE;
|
||||
m_timer.stop();
|
||||
m_weakFactory.InvalidateWeakPtrs();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,7 +68,7 @@ void DelayBasedTimeSource::setActive(bool active)
|
||||
// it runs, we use that to establish the timebase, become truly active, and
|
||||
// fire the first tick.
|
||||
m_state = STATE_STARTING;
|
||||
m_timer.startOneShot(0);
|
||||
m_thread->postTask(base::Bind(&DelayBasedTimeSource::onTimerFired, m_weakFactory.GetWeakPtr()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -222,7 +225,9 @@ void DelayBasedTimeSource::postNextTickTask(base::TimeTicks now)
|
||||
base::TimeDelta delay = newTickTarget - now;
|
||||
DCHECK(delay.InMillisecondsF() <=
|
||||
m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThreshold));
|
||||
m_timer.startOneShot(delay.InSecondsF());
|
||||
m_thread->postDelayedTask(base::Bind(&DelayBasedTimeSource::onTimerFired,
|
||||
m_weakFactory.GetWeakPtr()),
|
||||
delay.InMilliseconds());
|
||||
|
||||
m_nextParameters.tickTarget = newTickTarget;
|
||||
m_currentParameters = m_nextParameters;
|
||||
|
@ -5,18 +5,16 @@
|
||||
#ifndef CCDelayBasedTimeSource_h
|
||||
#define CCDelayBasedTimeSource_h
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "cc/time_source.h"
|
||||
#include "cc/timer.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Thread;
|
||||
|
||||
// This timer implements a time source that achieves the specified interval
|
||||
// in face of millisecond-precision delayed callbacks and random queueing delays.
|
||||
class DelayBasedTimeSource : public TimeSource, TimerClient {
|
||||
class DelayBasedTimeSource : public TimeSource {
|
||||
public:
|
||||
static scoped_refptr<DelayBasedTimeSource> create(base::TimeDelta interval, Thread*);
|
||||
static scoped_refptr<DelayBasedTimeSource> create(base::TimeDelta interval, Thread* thread);
|
||||
|
||||
virtual void setClient(TimeSourceClient* client) OVERRIDE;
|
||||
|
||||
@ -31,18 +29,17 @@ public:
|
||||
virtual base::TimeTicks lastTickTime() OVERRIDE;
|
||||
virtual base::TimeTicks nextTickTime() OVERRIDE;
|
||||
|
||||
// TimerClient implementation.
|
||||
virtual void onTimerFired() OVERRIDE;
|
||||
|
||||
// Virtual for testing.
|
||||
virtual base::TimeTicks now() const;
|
||||
|
||||
protected:
|
||||
DelayBasedTimeSource(base::TimeDelta interval, Thread*);
|
||||
DelayBasedTimeSource(base::TimeDelta interval, Thread* thread);
|
||||
virtual ~DelayBasedTimeSource();
|
||||
|
||||
base::TimeTicks nextTickTarget(base::TimeTicks now);
|
||||
void postNextTickTask(base::TimeTicks now);
|
||||
void onTimerFired();
|
||||
|
||||
enum State {
|
||||
STATE_INACTIVE,
|
||||
@ -70,8 +67,10 @@ protected:
|
||||
Parameters m_nextParameters;
|
||||
|
||||
State m_state;
|
||||
|
||||
Thread* m_thread;
|
||||
Timer m_timer;
|
||||
base::WeakPtrFactory<DelayBasedTimeSource> m_weakFactory;
|
||||
DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource);
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "cc/delay_based_time_source.h"
|
||||
#include "cc/time_source.h"
|
||||
#include "cc/thread.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -47,6 +48,8 @@ FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
|
||||
, m_active(false)
|
||||
, m_swapBuffersCompleteSupported(true)
|
||||
, m_isTimeSourceThrottling(true)
|
||||
, m_thread(0)
|
||||
, m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
|
||||
{
|
||||
m_timeSourceClientAdapter = FrameRateControllerTimeSourceAdapter::create(this);
|
||||
m_timeSource->setClient(m_timeSourceClientAdapter.get());
|
||||
@ -59,7 +62,8 @@ FrameRateController::FrameRateController(Thread* thread)
|
||||
, m_active(false)
|
||||
, m_swapBuffersCompleteSupported(true)
|
||||
, m_isTimeSourceThrottling(false)
|
||||
, m_manualTicker(new Timer(thread, this))
|
||||
, m_thread(thread)
|
||||
, m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
|
||||
{
|
||||
}
|
||||
|
||||
@ -82,7 +86,7 @@ void FrameRateController::setActive(bool active)
|
||||
if (active)
|
||||
postManualTick();
|
||||
else
|
||||
m_manualTicker->stop();
|
||||
m_weakFactory.InvalidateWeakPtrs();
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,10 +124,10 @@ void FrameRateController::onTimerTick()
|
||||
void FrameRateController::postManualTick()
|
||||
{
|
||||
if (m_active)
|
||||
m_manualTicker->startOneShot(0);
|
||||
m_thread->postTask(base::Bind(&FrameRateController::manualTick, m_weakFactory.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void FrameRateController::onTimerFired()
|
||||
void FrameRateController::manualTick()
|
||||
{
|
||||
onTimerTick();
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/time.h"
|
||||
#include "cc/timer.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@ -26,7 +26,7 @@ protected:
|
||||
|
||||
class FrameRateControllerTimeSourceAdapter;
|
||||
|
||||
class FrameRateController : public TimerClient {
|
||||
class FrameRateController {
|
||||
public:
|
||||
explicit FrameRateController(scoped_refptr<TimeSource>);
|
||||
// Alternate form of FrameRateController with unthrottled frame-rate.
|
||||
@ -59,9 +59,7 @@ protected:
|
||||
void onTimerTick();
|
||||
|
||||
void postManualTick();
|
||||
|
||||
// TimerClient implementation (used for unthrottled frame-rate).
|
||||
virtual void onTimerFired() OVERRIDE;
|
||||
void manualTick();
|
||||
|
||||
FrameRateControllerClient* m_client;
|
||||
int m_numFramesPending;
|
||||
@ -73,7 +71,10 @@ protected:
|
||||
|
||||
// Members for unthrottled frame-rate.
|
||||
bool m_isTimeSourceThrottling;
|
||||
scoped_ptr<Timer> m_manualTicker;
|
||||
base::WeakPtrFactory<FrameRateController> m_weakFactory;
|
||||
Thread* m_thread;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FrameRateController);
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "cc/test/fake_web_compositor_output_surface.h"
|
||||
#include "cc/test/fake_web_graphics_context_3d.h"
|
||||
#include "cc/test/test_common.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/khronos/GLES2/gl2.h"
|
||||
@ -114,7 +113,6 @@ protected:
|
||||
GLRendererTest()
|
||||
: m_suggestHaveBackbufferYes(1, true)
|
||||
, m_suggestHaveBackbufferNo(1, false)
|
||||
, m_compositorInitializer(0)
|
||||
, m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext())))
|
||||
, m_resourceProvider(ResourceProvider::create(m_context.get()))
|
||||
, m_renderer(&m_mockClient, m_resourceProvider.get())
|
||||
@ -136,7 +134,6 @@ protected:
|
||||
WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes;
|
||||
WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo;
|
||||
|
||||
WebCompositorInitializer m_compositorInitializer;
|
||||
scoped_ptr<GraphicsContext> m_context;
|
||||
FakeRendererClient m_mockClient;
|
||||
scoped_ptr<ResourceProvider> m_resourceProvider;
|
||||
|
@ -169,11 +169,6 @@ public:
|
||||
|
||||
virtual void onTimerTick() OVERRIDE
|
||||
{
|
||||
// FIXME: We require that animate be called on the impl thread. This
|
||||
// avoids asserts in single threaded mode. Ideally background ticking
|
||||
// would be handled by the proxy/scheduler and this could be removed.
|
||||
DebugScopedSetImplThread impl;
|
||||
|
||||
m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now());
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "third_party/khronos/GLES2/gl2.h"
|
||||
#include "third_party/khronos/GLES2/gl2ext.h"
|
||||
#include <public/Platform.h>
|
||||
#include <public/WebLayerScrollClient.h>
|
||||
#include <public/WebSize.h>
|
||||
|
||||
@ -1046,7 +1045,7 @@ public:
|
||||
|
||||
// We request animation only once.
|
||||
if (!m_animationRequested) {
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &LayerTreeHostTestStartPageScaleAnimation::requestStartPageScaleAnimation));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&LayerTreeHostTestStartPageScaleAnimation::requestStartPageScaleAnimation, base::Unretained(this)));
|
||||
m_animationRequested = true;
|
||||
}
|
||||
}
|
||||
@ -2720,24 +2719,17 @@ public:
|
||||
postSetNeedsCommitToMainThread();
|
||||
}
|
||||
|
||||
class EvictTexturesTask : public WebKit::WebThread::Task {
|
||||
public:
|
||||
EvictTexturesTask(LayerTreeHostTestEvictTextures* test) : m_test(test) { }
|
||||
virtual ~EvictTexturesTask() { }
|
||||
virtual void run() OVERRIDE
|
||||
{
|
||||
DCHECK(m_test->m_implForEvictTextures);
|
||||
m_test->m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0));
|
||||
}
|
||||
|
||||
private:
|
||||
LayerTreeHostTestEvictTextures* m_test;
|
||||
};
|
||||
|
||||
void postEvictTextures()
|
||||
{
|
||||
DCHECK(webThread());
|
||||
webThread()->postTask(new EvictTexturesTask(this));
|
||||
DCHECK(implThread());
|
||||
implThread()->postTask(base::Bind(&LayerTreeHostTestEvictTextures::evictTexturesOnImplThread,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
void evictTexturesOnImplThread()
|
||||
{
|
||||
DCHECK(m_implForEvictTextures);
|
||||
m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0));
|
||||
}
|
||||
|
||||
// Commit 1: Just commit and draw normally, then post an eviction at the end
|
||||
@ -2860,24 +2852,12 @@ public:
|
||||
postSetNeedsCommitToMainThread();
|
||||
}
|
||||
|
||||
class EvictTexturesTask : public WebKit::WebThread::Task {
|
||||
public:
|
||||
EvictTexturesTask(LayerTreeHostTestLostContextAfterEvictTextures* test) : m_test(test) { }
|
||||
virtual ~EvictTexturesTask() { }
|
||||
virtual void run() OVERRIDE
|
||||
{
|
||||
m_test->evictTexturesOnImplThread();
|
||||
}
|
||||
|
||||
private:
|
||||
LayerTreeHostTestLostContextAfterEvictTextures* m_test;
|
||||
};
|
||||
|
||||
void postEvictTextures()
|
||||
{
|
||||
if (webThread())
|
||||
webThread()->postTask(new EvictTexturesTask(this));
|
||||
else {
|
||||
if (implThread()) {
|
||||
implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfterEvictTextures::evictTexturesOnImplThread,
|
||||
base::Unretained(this)));
|
||||
} else {
|
||||
DebugScopedSetImplThread impl;
|
||||
evictTexturesOnImplThread();
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "cc/test/fake_layer_tree_host_client.h"
|
||||
#include "cc/test/geometry_test_utils.h"
|
||||
#include "cc/test/test_common.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include <public/WebTransformationMatrix.h>
|
||||
@ -59,7 +58,6 @@ public:
|
||||
class LayerTest : public testing::Test {
|
||||
public:
|
||||
LayerTest()
|
||||
: m_compositorInitializer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -135,7 +133,6 @@ protected:
|
||||
|
||||
scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost;
|
||||
scoped_refptr<Layer> m_parent, m_child1, m_child2, m_child3, m_grandChild1, m_grandChild2, m_grandChild3;
|
||||
WebCompositorInitializer m_compositorInitializer;
|
||||
};
|
||||
|
||||
TEST_F(LayerTest, basicCreateAndDestroy)
|
||||
@ -638,7 +635,6 @@ void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host)
|
||||
|
||||
TEST(LayerLayerTreeHostTest, enteringTree)
|
||||
{
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> parent = Layer::create();
|
||||
scoped_refptr<Layer> child = Layer::create();
|
||||
scoped_refptr<Layer> mask = Layer::create();
|
||||
@ -667,7 +663,6 @@ TEST(LayerLayerTreeHostTest, enteringTree)
|
||||
|
||||
TEST(LayerLayerTreeHostTest, addingLayerSubtree)
|
||||
{
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> parent = Layer::create();
|
||||
scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::create());
|
||||
|
||||
@ -696,7 +691,6 @@ TEST(LayerLayerTreeHostTest, addingLayerSubtree)
|
||||
|
||||
TEST(LayerLayerTreeHostTest, changeHost)
|
||||
{
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> parent = Layer::create();
|
||||
scoped_refptr<Layer> child = Layer::create();
|
||||
scoped_refptr<Layer> mask = Layer::create();
|
||||
@ -726,7 +720,6 @@ TEST(LayerLayerTreeHostTest, changeHost)
|
||||
|
||||
TEST(LayerLayerTreeHostTest, changeHostInSubtree)
|
||||
{
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> firstParent = Layer::create();
|
||||
scoped_refptr<Layer> firstChild = Layer::create();
|
||||
scoped_refptr<Layer> secondParent = Layer::create();
|
||||
@ -760,7 +753,6 @@ TEST(LayerLayerTreeHostTest, changeHostInSubtree)
|
||||
|
||||
TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer)
|
||||
{
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> parent = Layer::create();
|
||||
scoped_refptr<Layer> mask = Layer::create();
|
||||
scoped_refptr<Layer> replica = Layer::create();
|
||||
@ -795,7 +787,6 @@ TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer)
|
||||
|
||||
TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer)
|
||||
{
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> root = Layer::create();
|
||||
scoped_refptr<Layer> child = Layer::create();
|
||||
root->addChild(child);
|
||||
@ -823,7 +814,6 @@ TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost)
|
||||
ScopedSettings scopedSettings;
|
||||
Settings::setAcceleratedAnimationEnabled(true);
|
||||
|
||||
WebCompositorInitializer compositorInitializer(0);
|
||||
scoped_refptr<Layer> layer = Layer::create();
|
||||
|
||||
// Case 1: without a layerTreeHost, the animation should not be accepted.
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread
|
||||
#include "cc/test/fake_graphics_context.h"
|
||||
#include "cc/test/tiled_layer_test_common.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "cc/texture.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -24,7 +23,6 @@ public:
|
||||
PrioritizedTextureTest()
|
||||
: m_textureSize(256, 256)
|
||||
, m_textureFormat(GL_RGBA)
|
||||
, m_compositorInitializer(0)
|
||||
, m_context(WebKit::createFakeGraphicsContext())
|
||||
{
|
||||
DebugScopedSetImplThread implThread;
|
||||
@ -93,7 +91,6 @@ public:
|
||||
protected:
|
||||
const IntSize m_textureSize;
|
||||
const GLenum m_textureFormat;
|
||||
WebCompositorInitializer m_compositorInitializer;
|
||||
scoped_ptr<GraphicsContext> m_context;
|
||||
scoped_ptr<ResourceProvider> m_resourceProvider;
|
||||
};
|
||||
|
19
cc/proxy.cc
19
cc/proxy.cc
@ -6,7 +6,7 @@
|
||||
|
||||
#include "cc/proxy.h"
|
||||
|
||||
#include "cc/thread_task.h"
|
||||
#include "cc/thread.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@ -14,7 +14,6 @@ namespace {
|
||||
#ifndef NDEBUG
|
||||
bool implThreadIsOverridden = false;
|
||||
bool s_isMainThreadBlocked = false;
|
||||
base::PlatformThreadId threadIDOverridenToBeImplThread;
|
||||
#endif
|
||||
Thread* s_mainThread = 0;
|
||||
Thread* s_implThread = 0;
|
||||
@ -47,10 +46,9 @@ Thread* Proxy::implThread()
|
||||
|
||||
Thread* Proxy::currentThread()
|
||||
{
|
||||
base::PlatformThreadId currentThreadIdentifier = base::PlatformThread::CurrentId();
|
||||
if (s_mainThread && s_mainThread->threadID() == currentThreadIdentifier)
|
||||
if (s_mainThread && s_mainThread->belongsToCurrentThread())
|
||||
return s_mainThread;
|
||||
if (s_implThread && s_implThread->threadID() == currentThreadIdentifier)
|
||||
if (s_implThread && s_implThread->belongsToCurrentThread())
|
||||
return s_implThread;
|
||||
return 0;
|
||||
}
|
||||
@ -59,9 +57,9 @@ bool Proxy::isMainThread()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
DCHECK(s_mainThread);
|
||||
if (implThreadIsOverridden && base::PlatformThread::CurrentId() == threadIDOverridenToBeImplThread)
|
||||
if (implThreadIsOverridden)
|
||||
return false;
|
||||
return base::PlatformThread::CurrentId() == s_mainThread->threadID();
|
||||
return s_mainThread->belongsToCurrentThread();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
@ -70,10 +68,9 @@ bool Proxy::isMainThread()
|
||||
bool Proxy::isImplThread()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
base::PlatformThreadId implThreadID = s_implThread ? s_implThread->threadID() : 0;
|
||||
if (implThreadIsOverridden && base::PlatformThread::CurrentId() == threadIDOverridenToBeImplThread)
|
||||
if (implThreadIsOverridden)
|
||||
return true;
|
||||
return base::PlatformThread::CurrentId() == implThreadID;
|
||||
return s_implThread && s_implThread->belongsToCurrentThread();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
@ -83,8 +80,6 @@ bool Proxy::isImplThread()
|
||||
void Proxy::setCurrentThreadIsImplThread(bool isImplThread)
|
||||
{
|
||||
implThreadIsOverridden = isImplThread;
|
||||
if (isImplThread)
|
||||
threadIDOverridenToBeImplThread = base::PlatformThread::CurrentId();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -13,29 +13,6 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
class RateLimiter::Task : public Thread::Task {
|
||||
public:
|
||||
static PassOwnPtr<Task> create(RateLimiter* rateLimiter)
|
||||
{
|
||||
return adoptPtr(new Task(rateLimiter));
|
||||
}
|
||||
virtual ~Task() { }
|
||||
|
||||
private:
|
||||
explicit Task(RateLimiter* rateLimiter)
|
||||
: Thread::Task(this)
|
||||
, m_rateLimiter(rateLimiter)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
m_rateLimiter->rateLimitContext();
|
||||
}
|
||||
|
||||
scoped_refptr<RateLimiter> m_rateLimiter;
|
||||
};
|
||||
|
||||
scoped_refptr<RateLimiter> RateLimiter::create(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client)
|
||||
{
|
||||
return make_scoped_refptr(new RateLimiter(context, client));
|
||||
@ -60,7 +37,7 @@ void RateLimiter::start()
|
||||
|
||||
TRACE_EVENT0("cc", "RateLimiter::start");
|
||||
m_active = true;
|
||||
Proxy::mainThread()->postTask(RateLimiter::Task::create(this));
|
||||
Proxy::mainThread()->postTask(base::Bind(&RateLimiter::rateLimitContext, this));
|
||||
}
|
||||
|
||||
void RateLimiter::stop()
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "cc/proxy.h"
|
||||
#include "cc/resource_provider.h"
|
||||
#include "cc/texture_copier.h"
|
||||
#include "cc/thread.h"
|
||||
#include "third_party/khronos/GLES2/gl2.h"
|
||||
#include "third_party/skia/include/gpu/SkGpuDevice.h"
|
||||
#include <limits>
|
||||
@ -71,11 +72,13 @@ size_t ResourceUpdateController::maxFullUpdatesPerTick(
|
||||
|
||||
ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider)
|
||||
: m_client(client)
|
||||
, m_timer(new Timer(thread, this))
|
||||
, m_queue(queue.Pass())
|
||||
, m_resourceProvider(resourceProvider)
|
||||
, m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider))
|
||||
, m_firstUpdateAttempt(true)
|
||||
, m_thread(thread)
|
||||
, m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
|
||||
, m_taskPosted(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -89,7 +92,7 @@ void ResourceUpdateController::performMoreUpdates(
|
||||
m_timeLimit = timeLimit;
|
||||
|
||||
// Update already in progress.
|
||||
if (m_timer->isActive())
|
||||
if (m_taskPosted)
|
||||
return;
|
||||
|
||||
// Call updateMoreTexturesNow() directly unless it's the first update
|
||||
@ -98,8 +101,11 @@ void ResourceUpdateController::performMoreUpdates(
|
||||
if (m_firstUpdateAttempt) {
|
||||
// Post a 0-delay task when no updates were left. When it runs,
|
||||
// readyToFinalizeTextureUpdates() will be called.
|
||||
if (!updateMoreTexturesIfEnoughTimeRemaining())
|
||||
m_timer->startOneShot(0);
|
||||
if (!updateMoreTexturesIfEnoughTimeRemaining()) {
|
||||
m_taskPosted = true;
|
||||
m_thread->postTask(base::Bind(&ResourceUpdateController::onTimerFired,
|
||||
m_weakFactory.GetWeakPtr()));
|
||||
}
|
||||
|
||||
m_firstUpdateAttempt = false;
|
||||
} else
|
||||
@ -222,6 +228,7 @@ void ResourceUpdateController::finalize()
|
||||
|
||||
void ResourceUpdateController::onTimerFired()
|
||||
{
|
||||
m_taskPosted = false;
|
||||
ResourceProvider::debugNotifyEnterZone(0xB000000);
|
||||
if (!updateMoreTexturesIfEnoughTimeRemaining())
|
||||
m_client->readyToFinalizeTextureUpdates();
|
||||
@ -254,7 +261,10 @@ bool ResourceUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
|
||||
// time estimate. We use a different timeout here to prevent unnecessary
|
||||
// amounts of idle time when blocking uploads have reached the max.
|
||||
if (m_resourceProvider->numBlockingUploads() >= maxBlockingUpdates()) {
|
||||
m_timer->startOneShot(uploaderBusyTickRate);
|
||||
m_taskPosted = true;
|
||||
m_thread->postDelayedTask(base::Bind(&ResourceUpdateController::onTimerFired,
|
||||
m_weakFactory.GetWeakPtr()),
|
||||
uploaderBusyTickRate * 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -273,9 +283,10 @@ void ResourceUpdateController::updateMoreTexturesNow()
|
||||
{
|
||||
size_t uploads = std::min(
|
||||
m_queue->fullUploadSize(), updateMoreTexturesSize());
|
||||
m_timer->startOneShot(
|
||||
updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() *
|
||||
uploads);
|
||||
m_taskPosted = true;
|
||||
m_thread->postDelayedTask(base::Bind(&ResourceUpdateController::onTimerFired,
|
||||
m_weakFactory.GetWeakPtr()),
|
||||
updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() * uploads * 1000);
|
||||
|
||||
if (!uploads)
|
||||
return;
|
||||
|
@ -7,13 +7,14 @@
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/time.h"
|
||||
#include "cc/resource_update_queue.h"
|
||||
#include "cc/timer.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class ResourceProvider;
|
||||
class Thread;
|
||||
|
||||
class ResourceUpdateControllerClient {
|
||||
public:
|
||||
@ -23,7 +24,7 @@ protected:
|
||||
virtual ~ResourceUpdateControllerClient() { }
|
||||
};
|
||||
|
||||
class ResourceUpdateController : public TimerClient {
|
||||
class ResourceUpdateController {
|
||||
public:
|
||||
static scoped_ptr<ResourceUpdateController> create(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider)
|
||||
{
|
||||
@ -39,8 +40,6 @@ public:
|
||||
void performMoreUpdates(base::TimeTicks timeLimit);
|
||||
void finalize();
|
||||
|
||||
// TimerClient implementation.
|
||||
virtual void onTimerFired() OVERRIDE;
|
||||
|
||||
// Virtual for testing.
|
||||
virtual base::TimeTicks now() const;
|
||||
@ -50,6 +49,7 @@ public:
|
||||
protected:
|
||||
ResourceUpdateController(ResourceUpdateControllerClient*, Thread*, scoped_ptr<ResourceUpdateQueue>, ResourceProvider*);
|
||||
|
||||
private:
|
||||
static size_t maxFullUpdatesPerTick(ResourceProvider*);
|
||||
|
||||
size_t maxBlockingUpdates() const;
|
||||
@ -59,17 +59,19 @@ protected:
|
||||
// This returns true when there were textures left to update.
|
||||
bool updateMoreTexturesIfEnoughTimeRemaining();
|
||||
void updateMoreTexturesNow();
|
||||
void onTimerFired();
|
||||
|
||||
ResourceUpdateControllerClient* m_client;
|
||||
scoped_ptr<Timer> m_timer;
|
||||
scoped_ptr<ResourceUpdateQueue> m_queue;
|
||||
bool m_contentsTexturesPurged;
|
||||
ResourceProvider* m_resourceProvider;
|
||||
base::TimeTicks m_timeLimit;
|
||||
size_t m_textureUpdatesPerTick;
|
||||
bool m_firstUpdateAttempt;
|
||||
Thread* m_thread;
|
||||
base::WeakPtrFactory<ResourceUpdateController> m_weakFactory;
|
||||
bool m_taskPosted;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ResourceUpdateController);
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "cc/test/fake_web_graphics_context_3d.h"
|
||||
#include "cc/test/scheduler_test_common.h"
|
||||
#include "cc/test/tiled_layer_test_common.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include <public/WebThread.h>
|
||||
|
||||
@ -66,7 +65,6 @@ public:
|
||||
ResourceUpdateControllerTest()
|
||||
: m_queue(make_scoped_ptr(new ResourceUpdateQueue))
|
||||
, m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool))
|
||||
, m_compositorInitializer(m_thread.get())
|
||||
, m_fullUploadCountExpected(0)
|
||||
, m_partialCountExpected(0)
|
||||
, m_totalUploadCountExpected(0)
|
||||
@ -188,7 +186,6 @@ protected:
|
||||
scoped_ptr<ResourceUpdateQueue> m_queue;
|
||||
scoped_ptr<PrioritizedTexture> m_textures[4];
|
||||
scoped_ptr<WebThread> m_thread;
|
||||
WebCompositorInitializer m_compositorInitializer;
|
||||
scoped_ptr<PrioritizedTextureManager> m_textureManager;
|
||||
SkBitmap m_bitmap;
|
||||
|
||||
|
@ -6,9 +6,11 @@
|
||||
|
||||
#include "cc/scoped_thread_proxy.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
ScopedThreadProxy::ScopedThreadProxy(Thread* targetThread)
|
||||
ScopedThreadProxy::ScopedThreadProxy(cc::Thread* targetThread)
|
||||
: m_targetThread(targetThread)
|
||||
, m_shutdown(false)
|
||||
{
|
||||
@ -18,4 +20,27 @@ ScopedThreadProxy::~ScopedThreadProxy()
|
||||
{
|
||||
}
|
||||
|
||||
void ScopedThreadProxy::postTask(const tracked_objects::Location& location, base::Closure cb)
|
||||
{
|
||||
m_targetThread->postTask(base::Bind(&ScopedThreadProxy::runTaskIfNotShutdown, this, cb));
|
||||
}
|
||||
|
||||
void ScopedThreadProxy::shutdown()
|
||||
{
|
||||
DCHECK(m_targetThread->belongsToCurrentThread());
|
||||
DCHECK(!m_shutdown);
|
||||
m_shutdown = true;
|
||||
}
|
||||
|
||||
void ScopedThreadProxy::runTaskIfNotShutdown(base::Closure cb)
|
||||
{
|
||||
// If our shutdown flag is set, it's possible that m_targetThread has already been destroyed so don't
|
||||
// touch it.
|
||||
if (m_shutdown) {
|
||||
return;
|
||||
}
|
||||
DCHECK(m_targetThread->belongsToCurrentThread());
|
||||
cb.Run();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,11 @@
|
||||
#ifndef CCScopedThreadProxy_h
|
||||
#define CCScopedThreadProxy_h
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "cc/thread_task.h"
|
||||
#include <wtf/OwnPtr.h>
|
||||
#include <wtf/PassOwnPtr.h>
|
||||
#include "base/callback.h"
|
||||
#include "cc/thread.h"
|
||||
#include "base/location.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@ -26,49 +25,26 @@ namespace cc {
|
||||
// list of outstanding tasks.
|
||||
class ScopedThreadProxy : public base::RefCountedThreadSafe<ScopedThreadProxy> {
|
||||
public:
|
||||
static scoped_refptr<ScopedThreadProxy> create(Thread* targetThread)
|
||||
static scoped_refptr<ScopedThreadProxy> create(cc::Thread* targetThread)
|
||||
{
|
||||
DCHECK(base::PlatformThread::CurrentId() == targetThread->threadID());
|
||||
DCHECK(targetThread->belongsToCurrentThread());
|
||||
return make_scoped_refptr(new ScopedThreadProxy(targetThread));
|
||||
}
|
||||
|
||||
|
||||
// Can be called from any thread. Posts a task to the target thread that runs unless
|
||||
// shutdown() is called before it runs.
|
||||
void postTask(PassOwnPtr<Thread::Task> task)
|
||||
{
|
||||
AddRef();
|
||||
m_targetThread->postTask(createThreadTask(this, &ScopedThreadProxy::runTaskIfNotShutdown, task));
|
||||
}
|
||||
void postTask(const tracked_objects::Location& location, base::Closure cb);
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
DCHECK(base::PlatformThread::CurrentId() == m_targetThread->threadID());
|
||||
DCHECK(!m_shutdown);
|
||||
m_shutdown = true;
|
||||
}
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
explicit ScopedThreadProxy(cc::Thread* targetThread);
|
||||
friend class base::RefCountedThreadSafe<ScopedThreadProxy>;
|
||||
~ScopedThreadProxy();
|
||||
|
||||
explicit ScopedThreadProxy(Thread* targetThread);
|
||||
void runTaskIfNotShutdown(base::Closure cb);
|
||||
|
||||
void runTaskIfNotShutdown(PassOwnPtr<Thread::Task> popTask)
|
||||
{
|
||||
OwnPtr<Thread::Task> task = popTask;
|
||||
// If our shutdown flag is set, it's possible that m_targetThread has already been destroyed so don't
|
||||
// touch it.
|
||||
if (m_shutdown) {
|
||||
Release();
|
||||
return;
|
||||
}
|
||||
DCHECK(base::PlatformThread::CurrentId() == m_targetThread->threadID());
|
||||
task->performTask();
|
||||
Release();
|
||||
}
|
||||
|
||||
Thread* m_targetThread;
|
||||
cc::Thread* m_targetThread;
|
||||
bool m_shutdown; // Only accessed on the target thread
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "cc/graphics_context.h"
|
||||
#include "cc/layer_tree_host.h"
|
||||
#include "cc/resource_update_controller.h"
|
||||
#include "cc/timer.h"
|
||||
|
||||
namespace 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
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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_
|
@ -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
|
@ -10,7 +10,6 @@
|
||||
#include "cc/single_thread_proxy.h"
|
||||
#include "cc/texture_layer_impl.h"
|
||||
#include "cc/test/fake_layer_tree_host_client.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -41,7 +40,6 @@ private:
|
||||
class TextureLayerTest : public testing::Test {
|
||||
public:
|
||||
TextureLayerTest()
|
||||
: m_compositorInitializer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -63,7 +61,6 @@ protected:
|
||||
|
||||
scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost;
|
||||
private:
|
||||
WebKitTests::WebCompositorInitializer m_compositorInitializer;
|
||||
};
|
||||
|
||||
TEST_F(TextureLayerTest, syncImplWhenChangingTextureId)
|
||||
|
23
cc/thread.h
23
cc/thread.h
@ -5,9 +5,8 @@
|
||||
#ifndef CCThread_h
|
||||
#define CCThread_h
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include <wtf/PassOwnPtr.h>
|
||||
|
||||
namespace cc {
|
||||
|
||||
@ -17,25 +16,13 @@ class Thread {
|
||||
public:
|
||||
virtual ~Thread() { }
|
||||
|
||||
class Task {
|
||||
public:
|
||||
virtual ~Task() { }
|
||||
virtual void performTask() = 0;
|
||||
void* instance() const { return m_instance; }
|
||||
protected:
|
||||
Task(void* instance) : m_instance(instance) { }
|
||||
void* m_instance;
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Task);
|
||||
};
|
||||
|
||||
// Executes the task on context's thread asynchronously.
|
||||
virtual void postTask(PassOwnPtr<Task>) = 0;
|
||||
// Executes the callback on context's thread asynchronously.
|
||||
virtual void postTask(base::Closure cb) = 0;
|
||||
|
||||
// Executes the task after the specified delay.
|
||||
virtual void postDelayedTask(PassOwnPtr<Task>, long long delayMs) = 0;
|
||||
virtual void postDelayedTask(base::Closure cb, long long delayMs) = 0;
|
||||
|
||||
virtual base::PlatformThreadId threadID() const = 0;
|
||||
virtual bool belongsToCurrentThread() const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
45
cc/thread_impl.cc
Normal file
45
cc/thread_impl.cc
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2011 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/thread_impl.h"
|
||||
|
||||
#include "base/message_loop.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
scoped_ptr<Thread> ThreadImpl::createForCurrentThread()
|
||||
{
|
||||
return scoped_ptr<Thread>(new ThreadImpl(base::MessageLoopProxy::current())).Pass();
|
||||
}
|
||||
|
||||
scoped_ptr<Thread> ThreadImpl::createForDifferentThread(scoped_refptr<base::MessageLoopProxy> thread)
|
||||
{
|
||||
return scoped_ptr<Thread>(new ThreadImpl(thread)).Pass();
|
||||
}
|
||||
|
||||
ThreadImpl::~ThreadImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void ThreadImpl::postTask(base::Closure cb)
|
||||
{
|
||||
m_thread->PostTask(FROM_HERE, cb);
|
||||
}
|
||||
|
||||
void ThreadImpl::postDelayedTask(base::Closure cb, long long delayMs)
|
||||
{
|
||||
m_thread->PostDelayedTask(FROM_HERE, cb, base::TimeDelta::FromMilliseconds(delayMs));
|
||||
}
|
||||
|
||||
bool ThreadImpl::belongsToCurrentThread() const
|
||||
{
|
||||
return m_thread->BelongsToCurrentThread();
|
||||
}
|
||||
|
||||
ThreadImpl::ThreadImpl(scoped_refptr<base::MessageLoopProxy> thread)
|
||||
: m_thread(thread)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace cc
|
39
cc/thread_impl.h
Normal file
39
cc/thread_impl.h
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2011 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_THREAD_IMPL_H_
|
||||
#define CC_THREAD_IMPL_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/message_loop_proxy.h"
|
||||
#include "cc/thread.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
// Implements cc::Thread in terms of base::MessageLoopProxy.
|
||||
class ThreadImpl : public Thread {
|
||||
public:
|
||||
// Creates a ThreadImpl wrapping the current thread.
|
||||
static scoped_ptr<cc::Thread> createForCurrentThread();
|
||||
|
||||
// Creates a Thread wrapping a non-current thread.
|
||||
static scoped_ptr<cc::Thread> createForDifferentThread(scoped_refptr<base::MessageLoopProxy> thread);
|
||||
|
||||
virtual ~ThreadImpl();
|
||||
|
||||
// cc::Thread implementation
|
||||
virtual void postTask(base::Closure cb) OVERRIDE;
|
||||
virtual void postDelayedTask(base::Closure cb, long long delayMs) OVERRIDE;
|
||||
virtual bool belongsToCurrentThread() const OVERRIDE;
|
||||
|
||||
private:
|
||||
explicit ThreadImpl(scoped_refptr<base::MessageLoopProxy> thread);
|
||||
|
||||
scoped_refptr<base::MessageLoopProxy> m_thread;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#endif // CC_THREAD_IMPL_H_
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "cc/thread_proxy.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/debug/trace_event.h"
|
||||
#include "cc/delay_based_time_source.h"
|
||||
#include "cc/draw_quad.h"
|
||||
@ -15,7 +16,6 @@
|
||||
#include "cc/layer_tree_host.h"
|
||||
#include "cc/scheduler.h"
|
||||
#include "cc/scoped_thread_proxy.h"
|
||||
#include "cc/thread_task.h"
|
||||
#include <public/WebSharedGraphicsContext3D.h>
|
||||
|
||||
using WebKit::WebSharedGraphicsContext3D;
|
||||
@ -83,7 +83,7 @@ bool ThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect)
|
||||
{
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent beginFrameCompletion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::forceBeginFrameOnImplThread, &beginFrameCompletion));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::forceBeginFrameOnImplThread, base::Unretained(this), &beginFrameCompletion));
|
||||
beginFrameCompletion.wait();
|
||||
}
|
||||
m_inCompositeAndReadback = true;
|
||||
@ -96,7 +96,7 @@ bool ThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect)
|
||||
request.pixels = pixels;
|
||||
{
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::requestReadbackOnImplThread, &request));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::requestReadbackOnImplThread, base::Unretained(this), &request));
|
||||
request.completion.wait();
|
||||
}
|
||||
return request.success;
|
||||
@ -120,7 +120,7 @@ void ThreadProxy::requestReadbackOnImplThread(ReadbackRequest* request)
|
||||
void ThreadProxy::startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, base::TimeDelta duration)
|
||||
{
|
||||
DCHECK(Proxy::isMainThread());
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::requestStartPageScaleAnimationOnImplThread, targetPosition, useAnchor, scale, duration));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::requestStartPageScaleAnimationOnImplThread, base::Unretained(this), targetPosition, useAnchor, scale, duration));
|
||||
}
|
||||
|
||||
void ThreadProxy::requestStartPageScaleAnimationOnImplThread(IntSize targetPosition, bool useAnchor, float scale, base::TimeDelta duration)
|
||||
@ -138,7 +138,7 @@ void ThreadProxy::finishAllRendering()
|
||||
// Make sure all GL drawing is finished on the impl thread.
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::finishAllRenderingOnImplThread, &completion));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::finishAllRenderingOnImplThread, base::Unretained(this), &completion));
|
||||
completion.wait();
|
||||
}
|
||||
|
||||
@ -155,15 +155,14 @@ bool ThreadProxy::initializeContext()
|
||||
if (!context.get())
|
||||
return false;
|
||||
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::initializeContextOnImplThread,
|
||||
context.release()));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::initializeContextOnImplThread, base::Unretained(this), context.release()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ThreadProxy::setSurfaceReady()
|
||||
{
|
||||
TRACE_EVENT0("cc", "ThreadProxy::setSurfaceReady");
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::setSurfaceReadyOnImplThread));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setSurfaceReadyOnImplThread, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void ThreadProxy::setSurfaceReadyOnImplThread()
|
||||
@ -177,7 +176,7 @@ void ThreadProxy::setVisible(bool visible)
|
||||
TRACE_EVENT0("cc", "ThreadProxy::setVisible");
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::setVisibleOnImplThread, &completion, visible));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setVisibleOnImplThread, base::Unretained(this), &completion, visible));
|
||||
completion.wait();
|
||||
}
|
||||
|
||||
@ -198,10 +197,11 @@ bool ThreadProxy::initializeRenderer()
|
||||
bool initializeSucceeded = false;
|
||||
RendererCapabilities capabilities;
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::initializeRendererOnImplThread,
|
||||
&completion,
|
||||
&initializeSucceeded,
|
||||
&capabilities));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::initializeRendererOnImplThread,
|
||||
base::Unretained(this),
|
||||
&completion,
|
||||
&initializeSucceeded,
|
||||
&capabilities));
|
||||
completion.wait();
|
||||
|
||||
if (initializeSucceeded) {
|
||||
@ -231,11 +231,12 @@ bool ThreadProxy::recreateContext()
|
||||
bool recreateSucceeded = false;
|
||||
RendererCapabilities capabilities;
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::recreateContextOnImplThread,
|
||||
&completion,
|
||||
context.release(),
|
||||
&recreateSucceeded,
|
||||
&capabilities));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateContextOnImplThread,
|
||||
base::Unretained(this),
|
||||
&completion,
|
||||
context.release(),
|
||||
&recreateSucceeded,
|
||||
&capabilities));
|
||||
completion.wait();
|
||||
|
||||
if (recreateSucceeded)
|
||||
@ -249,9 +250,8 @@ void ThreadProxy::renderingStats(RenderingStats* stats)
|
||||
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::renderingStatsOnImplThread,
|
||||
&completion,
|
||||
stats));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::renderingStatsOnImplThread,
|
||||
base::Unretained(this), &completion, stats));
|
||||
stats->totalCommitTimeInSeconds = m_totalCommitTime.InSecondsF();
|
||||
stats->totalCommitCount = m_totalCommitCount;
|
||||
|
||||
@ -266,7 +266,7 @@ const RendererCapabilities& ThreadProxy::rendererCapabilities() const
|
||||
|
||||
void ThreadProxy::loseContext()
|
||||
{
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::didLoseContextOnImplThread));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::didLoseContextOnImplThread, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void ThreadProxy::setNeedsAnimate()
|
||||
@ -281,7 +281,7 @@ void ThreadProxy::setNeedsAnimate()
|
||||
if (m_commitRequestSentToImplThread)
|
||||
return;
|
||||
m_commitRequestSentToImplThread = true;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::setNeedsCommitOnImplThread));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setNeedsCommitOnImplThread, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void ThreadProxy::setNeedsCommit()
|
||||
@ -295,7 +295,7 @@ void ThreadProxy::setNeedsCommit()
|
||||
if (m_commitRequestSentToImplThread)
|
||||
return;
|
||||
m_commitRequestSentToImplThread = true;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::setNeedsCommitOnImplThread));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setNeedsCommitOnImplThread, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void ThreadProxy::didLoseContextOnImplThread()
|
||||
@ -310,7 +310,7 @@ void ThreadProxy::onSwapBuffersCompleteOnImplThread()
|
||||
DCHECK(isImplThread());
|
||||
TRACE_EVENT0("cc", "ThreadProxy::onSwapBuffersCompleteOnImplThread");
|
||||
m_schedulerOnImplThread->didSwapBuffersComplete();
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::didCompleteSwapBuffers));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::didCompleteSwapBuffers, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void ThreadProxy::onVSyncParametersChanged(base::TimeTicks timebase, base::TimeDelta interval)
|
||||
@ -346,7 +346,7 @@ void ThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animati
|
||||
{
|
||||
DCHECK(isImplThread());
|
||||
TRACE_EVENT0("cc", "ThreadProxy::postAnimationEventsToMainThreadOnImplThread");
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::setAnimationEvents, events.release(), wallClockTime));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::setAnimationEvents, base::Unretained(this), events.release(), wallClockTime));
|
||||
}
|
||||
|
||||
bool ThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff)
|
||||
@ -389,8 +389,8 @@ void ThreadProxy::setNeedsRedraw()
|
||||
{
|
||||
DCHECK(isMainThread());
|
||||
TRACE_EVENT0("cc", "ThreadProxy::setNeedsRedraw");
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::setFullRootLayerDamageOnImplThread));
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::setNeedsRedrawOnImplThread));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setFullRootLayerDamageOnImplThread, base::Unretained(this)));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setNeedsRedrawOnImplThread, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void ThreadProxy::setDeferCommits(bool deferCommits)
|
||||
@ -406,7 +406,7 @@ void ThreadProxy::setDeferCommits(bool deferCommits)
|
||||
|
||||
if (!m_deferCommits && m_deferredCommitPending) {
|
||||
m_deferredCommitPending = false;
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginFrame));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::beginFrame, base::Unretained(this)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,7 +431,7 @@ void ThreadProxy::start()
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent completion;
|
||||
scoped_ptr<InputHandler> handler = m_layerTreeHost->createInputHandler();
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::initializeImplOnImplThread, &completion, handler.release()));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::initializeImplOnImplThread, base::Unretained(this), &completion, handler.release()));
|
||||
completion.wait();
|
||||
|
||||
m_started = true;
|
||||
@ -448,7 +448,7 @@ void ThreadProxy::stop()
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::layerTreeHostClosedOnImplThread, &completion));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::layerTreeHostClosedOnImplThread, base::Unretained(this), &completion));
|
||||
completion.wait();
|
||||
}
|
||||
|
||||
@ -463,7 +463,7 @@ void ThreadProxy::forceSerializeOnSwapBuffers()
|
||||
{
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::forceSerializeOnSwapBuffersOnImplThread, &completion));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::forceSerializeOnSwapBuffersOnImplThread, base::Unretained(this), &completion));
|
||||
completion.wait();
|
||||
}
|
||||
|
||||
@ -509,7 +509,7 @@ void ThreadProxy::scheduledActionBeginFrame()
|
||||
if (m_layerTreeHost->contentsTextureManager())
|
||||
m_layerTreeHost->contentsTextureManager()->getEvictedBackings(m_pendingBeginFrameRequest->evictedContentsTexturesBackings);
|
||||
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginFrame));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::beginFrame, base::Unretained(this)));
|
||||
|
||||
if (m_beginFrameCompletionEventOnImplThread) {
|
||||
m_beginFrameCompletionEventOnImplThread->signal();
|
||||
@ -565,7 +565,7 @@ void ThreadProxy::beginFrame()
|
||||
m_forcedCommitRequested = false;
|
||||
|
||||
TRACE_EVENT0("cc", "EarlyOut_NotVisible");
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::beginFrameAbortedOnImplThread));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameAbortedOnImplThread, base::Unretained(this)));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -618,7 +618,7 @@ void ThreadProxy::beginFrame()
|
||||
|
||||
base::TimeTicks startTime = base::TimeTicks::HighResNow();
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::beginFrameCompleteOnImplThread, &completion, queue.release()));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameCompleteOnImplThread, base::Unretained(this), &completion, queue.release()));
|
||||
completion.wait();
|
||||
base::TimeTicks endTime = base::TimeTicks::HighResNow();
|
||||
|
||||
@ -716,7 +716,7 @@ void ThreadProxy::scheduledActionCommit()
|
||||
void ThreadProxy::scheduledActionBeginContextRecreation()
|
||||
{
|
||||
DCHECK(isImplThread());
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginContextRecreation));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::beginContextRecreation, base::Unretained(this)));
|
||||
}
|
||||
|
||||
ScheduledActionDrawAndSwapResult ThreadProxy::scheduledActionDrawAndSwapInternal(bool forcedDraw)
|
||||
@ -776,7 +776,7 @@ ScheduledActionDrawAndSwapResult ThreadProxy::scheduledActionDrawAndSwapInternal
|
||||
// Tell the main thread that the the newly-commited frame was drawn.
|
||||
if (m_nextFrameIsNewlyCommittedFrameOnImplThread) {
|
||||
m_nextFrameIsNewlyCommittedFrameOnImplThread = false;
|
||||
m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::didCommitAndDrawFrame));
|
||||
m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::didCommitAndDrawFrame, base::Unretained(this)));
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -797,7 +797,7 @@ void ThreadProxy::acquireLayerTextures()
|
||||
TRACE_EVENT0("cc", "ThreadProxy::acquireLayerTextures");
|
||||
DebugScopedSetMainThreadBlocked mainThreadBlocked;
|
||||
CompletionEvent completion;
|
||||
Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::acquireLayerTexturesForMainThreadOnImplThread, &completion));
|
||||
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::acquireLayerTexturesForMainThreadOnImplThread, base::Unretained(this), &completion));
|
||||
completion.wait(); // Block until it is safe to write to layer textures from the main thread.
|
||||
|
||||
m_texturesAcquired = true;
|
||||
@ -872,33 +872,13 @@ void ThreadProxy::setAnimationEvents(AnimationEventsVector* passed_events, base:
|
||||
m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime);
|
||||
}
|
||||
|
||||
class ThreadProxyContextRecreationTimer : public Timer, TimerClient {
|
||||
public:
|
||||
static scoped_ptr<ThreadProxyContextRecreationTimer> create(ThreadProxy* proxy) { return make_scoped_ptr(new ThreadProxyContextRecreationTimer(proxy)); }
|
||||
|
||||
virtual void onTimerFired() OVERRIDE
|
||||
{
|
||||
m_proxy->tryToRecreateContext();
|
||||
}
|
||||
|
||||
private:
|
||||
explicit ThreadProxyContextRecreationTimer(ThreadProxy* proxy)
|
||||
: Timer(Proxy::mainThread(), this)
|
||||
, m_proxy(proxy)
|
||||
{
|
||||
}
|
||||
|
||||
ThreadProxy* m_proxy;
|
||||
};
|
||||
|
||||
void ThreadProxy::beginContextRecreation()
|
||||
{
|
||||
TRACE_EVENT0("cc", "ThreadProxy::beginContextRecreation");
|
||||
DCHECK(isMainThread());
|
||||
DCHECK(!m_contextRecreationTimer);
|
||||
m_contextRecreationTimer = ThreadProxyContextRecreationTimer::create(this);
|
||||
m_layerTreeHost->didLoseContext();
|
||||
m_contextRecreationTimer->startOneShot(contextRecreationTickRate);
|
||||
m_contextRecreationCallback.Reset(base::Bind(&ThreadProxy::tryToRecreateContext, base::Unretained(this)));
|
||||
Proxy::mainThread()->postTask(m_contextRecreationCallback.callback());
|
||||
}
|
||||
|
||||
void ThreadProxy::tryToRecreateContext()
|
||||
@ -907,9 +887,9 @@ void ThreadProxy::tryToRecreateContext()
|
||||
DCHECK(m_layerTreeHost);
|
||||
LayerTreeHost::RecreateResult result = m_layerTreeHost->recreateContext();
|
||||
if (result == LayerTreeHost::RecreateFailedButTryAgain)
|
||||
m_contextRecreationTimer->startOneShot(contextRecreationTickRate);
|
||||
Proxy::mainThread()->postTask(m_contextRecreationCallback.callback());
|
||||
else if (result == LayerTreeHost::RecreateSucceeded)
|
||||
m_contextRecreationTimer.reset();
|
||||
m_contextRecreationCallback.Cancel();
|
||||
}
|
||||
|
||||
void ThreadProxy::initializeImplOnImplThread(CompletionEvent* completion, InputHandler* handler)
|
||||
|
@ -21,7 +21,6 @@ class ResourceUpdateQueue;
|
||||
class Scheduler;
|
||||
class ScopedThreadProxy;
|
||||
class Thread;
|
||||
class ThreadProxyContextRecreationTimer;
|
||||
|
||||
class ThreadProxy : public Proxy, LayerTreeHostImplClient, SchedulerClient, ResourceUpdateControllerClient {
|
||||
public:
|
||||
@ -79,7 +78,6 @@ public:
|
||||
|
||||
private:
|
||||
explicit ThreadProxy(LayerTreeHost*);
|
||||
friend class ThreadProxyContextRecreationTimer;
|
||||
|
||||
// Set on impl thread, read on main thread.
|
||||
struct BeginFrameAndCommitState {
|
||||
@ -134,7 +132,7 @@ private:
|
||||
bool m_commitRequested; // Set only when setNeedsCommit is called.
|
||||
bool m_commitRequestSentToImplThread; // Set by setNeedsCommit and setNeedsAnimate.
|
||||
bool m_forcedCommitRequested;
|
||||
scoped_ptr<ThreadProxyContextRecreationTimer> m_contextRecreationTimer;
|
||||
base::CancelableClosure m_contextRecreationCallback;
|
||||
LayerTreeHost* m_layerTreeHost;
|
||||
bool m_rendererInitialized;
|
||||
RendererCapabilities m_RendererCapabilitiesMainThreadCopy;
|
||||
|
305
cc/thread_task.h
305
cc/thread_task.h
@ -1,305 +0,0 @@
|
||||
// Copyright 2011 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 CCThreadTask_h
|
||||
#define CCThreadTask_h
|
||||
|
||||
#include "cc/thread.h"
|
||||
#include <wtf/PassOwnPtr.h>
|
||||
|
||||
namespace cc {
|
||||
|
||||
template<typename T>
|
||||
class ThreadTask0 : public Thread::Task {
|
||||
public:
|
||||
typedef void (T::*Method)();
|
||||
typedef ThreadTask0<T> ThreadTaskImpl;
|
||||
|
||||
static PassOwnPtr<ThreadTaskImpl> create(T* instance, Method method)
|
||||
{
|
||||
return adoptPtr(new ThreadTaskImpl(instance, method));
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadTask0(T* instance, Method method)
|
||||
: Thread::Task(instance)
|
||||
, m_method(method)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
(*static_cast<T*>(instance()).*m_method)();
|
||||
}
|
||||
|
||||
private:
|
||||
Method m_method;
|
||||
};
|
||||
|
||||
template<typename T, typename P1, typename MP1>
|
||||
class ThreadTask1 : public Thread::Task {
|
||||
public:
|
||||
typedef void (T::*Method)(MP1);
|
||||
typedef ThreadTask1<T, P1, MP1> ThreadTaskImpl;
|
||||
|
||||
static PassOwnPtr<ThreadTaskImpl> create(T* instance, Method method, P1 parameter1)
|
||||
{
|
||||
return adoptPtr(new ThreadTaskImpl(instance, method, parameter1));
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadTask1(T* instance, Method method, P1 parameter1)
|
||||
: Thread::Task(instance)
|
||||
, m_method(method)
|
||||
, m_parameter1(parameter1)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
(*static_cast<T*>(instance()).*m_method)(m_parameter1);
|
||||
}
|
||||
|
||||
private:
|
||||
Method m_method;
|
||||
P1 m_parameter1;
|
||||
};
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2>
|
||||
class ThreadTask2 : public Thread::Task {
|
||||
public:
|
||||
typedef void (T::*Method)(MP1, MP2);
|
||||
typedef ThreadTask2<T, P1, MP1, P2, MP2> ThreadTaskImpl;
|
||||
|
||||
static PassOwnPtr<ThreadTaskImpl> create(T* instance, Method method, P1 parameter1, P2 parameter2)
|
||||
{
|
||||
return adoptPtr(new ThreadTaskImpl(instance, method, parameter1, parameter2));
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadTask2(T* instance, Method method, P1 parameter1, P2 parameter2)
|
||||
: Thread::Task(instance)
|
||||
, m_method(method)
|
||||
, m_parameter1(parameter1)
|
||||
, m_parameter2(parameter2)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
(*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2);
|
||||
}
|
||||
|
||||
private:
|
||||
Method m_method;
|
||||
P1 m_parameter1;
|
||||
P2 m_parameter2;
|
||||
};
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
|
||||
class ThreadTask3 : public Thread::Task {
|
||||
public:
|
||||
typedef void (T::*Method)(MP1, MP2, MP3);
|
||||
typedef ThreadTask3<T, P1, MP1, P2, MP2, P3, MP3> ThreadTaskImpl;
|
||||
|
||||
static PassOwnPtr<ThreadTaskImpl> create(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3)
|
||||
{
|
||||
return adoptPtr(new ThreadTaskImpl(instance, method, parameter1, parameter2, parameter3));
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadTask3(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3)
|
||||
: Thread::Task(instance)
|
||||
, m_method(method)
|
||||
, m_parameter1(parameter1)
|
||||
, m_parameter2(parameter2)
|
||||
, m_parameter3(parameter3)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
(*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3);
|
||||
}
|
||||
|
||||
private:
|
||||
Method m_method;
|
||||
P1 m_parameter1;
|
||||
P2 m_parameter2;
|
||||
P3 m_parameter3;
|
||||
};
|
||||
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4>
|
||||
class ThreadTask4 : public Thread::Task {
|
||||
public:
|
||||
typedef void (T::*Method)(MP1, MP2, MP3, MP4);
|
||||
typedef ThreadTask4<T, P1, MP1, P2, MP2, P3, MP3, P4, MP4> ThreadTaskImpl;
|
||||
|
||||
static PassOwnPtr<ThreadTaskImpl> create(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4)
|
||||
{
|
||||
return adoptPtr(new ThreadTaskImpl(instance, method, parameter1, parameter2, parameter3, parameter4));
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadTask4(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4)
|
||||
: Thread::Task(instance)
|
||||
, m_method(method)
|
||||
, m_parameter1(parameter1)
|
||||
, m_parameter2(parameter2)
|
||||
, m_parameter3(parameter3)
|
||||
, m_parameter4(parameter4)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
(*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3, m_parameter4);
|
||||
}
|
||||
|
||||
private:
|
||||
Method m_method;
|
||||
P1 m_parameter1;
|
||||
P2 m_parameter2;
|
||||
P3 m_parameter3;
|
||||
P4 m_parameter4;
|
||||
};
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5>
|
||||
class ThreadTask5 : public Thread::Task {
|
||||
public:
|
||||
typedef void (T::*Method)(MP1, MP2, MP3, MP4, MP5);
|
||||
typedef ThreadTask5<T, P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5> ThreadTaskImpl;
|
||||
|
||||
static PassOwnPtr<ThreadTaskImpl> create(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4, P5 parameter5)
|
||||
{
|
||||
return adoptPtr(new ThreadTaskImpl(instance, method, parameter1, parameter2, parameter3, parameter4, parameter5));
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadTask5(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4, P5 parameter5)
|
||||
: Thread::Task(instance)
|
||||
, m_method(method)
|
||||
, m_parameter1(parameter1)
|
||||
, m_parameter2(parameter2)
|
||||
, m_parameter3(parameter3)
|
||||
, m_parameter4(parameter4)
|
||||
, m_parameter5(parameter5)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
(*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5);
|
||||
}
|
||||
|
||||
private:
|
||||
Method m_method;
|
||||
P1 m_parameter1;
|
||||
P2 m_parameter2;
|
||||
P3 m_parameter3;
|
||||
P4 m_parameter4;
|
||||
P5 m_parameter5;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)());
|
||||
|
||||
template<typename T>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)())
|
||||
{
|
||||
return ThreadTask0<T>::create(
|
||||
callee,
|
||||
method);
|
||||
}
|
||||
|
||||
template<typename T, typename P1, typename MP1>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)(MP1),
|
||||
const P1& parameter1)
|
||||
{
|
||||
return ThreadTask1<T, P1, MP1>::create(
|
||||
callee,
|
||||
method,
|
||||
parameter1);
|
||||
}
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)(MP1, MP2),
|
||||
const P1& parameter1,
|
||||
const P2& parameter2)
|
||||
{
|
||||
return ThreadTask2<T, P1, MP1, P2, MP2>::create(
|
||||
callee,
|
||||
method,
|
||||
parameter1,
|
||||
parameter2);
|
||||
}
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)(MP1, MP2, MP3),
|
||||
const P1& parameter1,
|
||||
const P2& parameter2,
|
||||
const P3& parameter3)
|
||||
{
|
||||
return ThreadTask3<T, P1, MP1, P2, MP2, P3, MP3>::create(
|
||||
callee,
|
||||
method,
|
||||
parameter1,
|
||||
parameter2,
|
||||
parameter3);
|
||||
}
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)(MP1, MP2, MP3, MP4),
|
||||
const P1& parameter1,
|
||||
const P2& parameter2,
|
||||
const P3& parameter3,
|
||||
const P4& parameter4)
|
||||
{
|
||||
return ThreadTask4<T, P1, MP1, P2, MP2, P3, MP3, P4, MP4>::create(
|
||||
callee,
|
||||
method,
|
||||
parameter1,
|
||||
parameter2,
|
||||
parameter3,
|
||||
parameter4);
|
||||
|
||||
}
|
||||
|
||||
template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5>
|
||||
PassOwnPtr<Thread::Task> createThreadTask(
|
||||
T* const callee,
|
||||
void (T::*method)(MP1, MP2, MP3, MP4, MP5),
|
||||
const P1& parameter1,
|
||||
const P2& parameter2,
|
||||
const P3& parameter3,
|
||||
const P4& parameter4,
|
||||
const P5& parameter5)
|
||||
{
|
||||
return ThreadTask5<T, P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5>::create(
|
||||
callee,
|
||||
method,
|
||||
parameter1,
|
||||
parameter2,
|
||||
parameter3,
|
||||
parameter4,
|
||||
parameter5);
|
||||
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#endif // CCThreadTask_h
|
@ -1,42 +0,0 @@
|
||||
// Copyright 2011 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/thread_task.h"
|
||||
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Mock {
|
||||
public:
|
||||
MOCK_METHOD0(method0, void());
|
||||
MOCK_METHOD1(method1, void(int a1));
|
||||
MOCK_METHOD2(method2, void(int a1, int a2));
|
||||
MOCK_METHOD3(method3, void(int a1, int a2, int a3));
|
||||
MOCK_METHOD4(method4, void(int a1, int a2, int a3, int a4));
|
||||
MOCK_METHOD5(method5, void(int a1, int a2, int a3, int a4, int a5));
|
||||
};
|
||||
|
||||
TEST(ThreadTaskTest, runnableMethods)
|
||||
{
|
||||
Mock mock;
|
||||
EXPECT_CALL(mock, method0()).Times(1);
|
||||
EXPECT_CALL(mock, method1(9)).Times(1);
|
||||
EXPECT_CALL(mock, method2(9, 8)).Times(1);
|
||||
EXPECT_CALL(mock, method3(9, 8, 7)).Times(1);
|
||||
EXPECT_CALL(mock, method4(9, 8, 7, 6)).Times(1);
|
||||
EXPECT_CALL(mock, method5(9, 8, 7, 6, 5)).Times(1);
|
||||
|
||||
createThreadTask(&mock, &Mock::method0)->performTask();
|
||||
createThreadTask(&mock, &Mock::method1, 9)->performTask();
|
||||
createThreadTask(&mock, &Mock::method2, 9, 8)->performTask();
|
||||
createThreadTask(&mock, &Mock::method3, 9, 8, 7)->performTask();
|
||||
createThreadTask(&mock, &Mock::method4, 9, 8, 7, 6)->performTask();
|
||||
createThreadTask(&mock, &Mock::method5, 9, 8, 7, 6, 5)->performTask();
|
||||
}
|
||||
|
||||
} // namespace cc
|
@ -17,7 +17,6 @@
|
||||
#include "cc/test/fake_layer_tree_host_client.h"
|
||||
#include "cc/test/geometry_test_utils.h"
|
||||
#include "cc/test/tiled_layer_test_common.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include <public/WebTransformationMatrix.h>
|
||||
|
||||
@ -49,8 +48,7 @@ private:
|
||||
class TiledLayerTest : public testing::Test {
|
||||
public:
|
||||
TiledLayerTest()
|
||||
: m_compositorInitializer(0)
|
||||
, m_context(WebKit::createFakeGraphicsContext())
|
||||
: m_context(WebKit::createFakeGraphicsContext())
|
||||
, m_queue(make_scoped_ptr(new ResourceUpdateQueue))
|
||||
, m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool))
|
||||
, m_occlusion(0)
|
||||
@ -157,7 +155,6 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
WebKitTests::WebCompositorInitializer m_compositorInitializer;
|
||||
scoped_ptr<GraphicsContext> m_context;
|
||||
scoped_ptr<ResourceProvider> m_resourceProvider;
|
||||
scoped_ptr<ResourceUpdateQueue> m_queue;
|
||||
|
81
cc/timer.cc
81
cc/timer.cc
@ -1,81 +0,0 @@
|
||||
// Copyright 2011 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/timer.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/logging.h"
|
||||
#include "cc/thread.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class TimerTask : public Thread::Task {
|
||||
public:
|
||||
explicit TimerTask(Timer* timer)
|
||||
: Thread::Task(0)
|
||||
, m_timer(timer)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~TimerTask()
|
||||
{
|
||||
if (!m_timer)
|
||||
return;
|
||||
|
||||
DCHECK(m_timer->m_task == this);
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
virtual void performTask() OVERRIDE
|
||||
{
|
||||
if (!m_timer)
|
||||
return;
|
||||
|
||||
TimerClient* client = m_timer->m_client;
|
||||
|
||||
m_timer->stop();
|
||||
if (client)
|
||||
client->onTimerFired();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Timer;
|
||||
|
||||
Timer* m_timer; // null if cancelled
|
||||
};
|
||||
|
||||
Timer::Timer(Thread* thread, TimerClient* client)
|
||||
: m_client(client)
|
||||
, m_thread(thread)
|
||||
, m_task(0)
|
||||
{
|
||||
}
|
||||
|
||||
Timer::~Timer()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void Timer::startOneShot(double intervalSeconds)
|
||||
{
|
||||
stop();
|
||||
|
||||
m_task = new TimerTask(this);
|
||||
|
||||
// The thread expects delays in milliseconds.
|
||||
m_thread->postDelayedTask(adoptPtr(m_task), intervalSeconds * 1000.0);
|
||||
}
|
||||
|
||||
void Timer::stop()
|
||||
{
|
||||
if (!m_task)
|
||||
return;
|
||||
|
||||
m_task->m_timer = 0;
|
||||
m_task = 0;
|
||||
}
|
||||
|
||||
} // namespace cc
|
41
cc/timer.h
41
cc/timer.h
@ -1,41 +0,0 @@
|
||||
// Copyright 2011 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 CCTimer_h
|
||||
#define CCTimer_h
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Thread;
|
||||
class TimerTask;
|
||||
|
||||
class TimerClient {
|
||||
public:
|
||||
virtual ~TimerClient() { }
|
||||
|
||||
virtual void onTimerFired() = 0;
|
||||
};
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
Timer(Thread*, TimerClient*);
|
||||
~Timer();
|
||||
|
||||
// If a previous task is pending, it will be replaced with the new one.
|
||||
void startOneShot(double intervalSeconds);
|
||||
void stop();
|
||||
|
||||
bool isActive() const { return m_task; }
|
||||
|
||||
private:
|
||||
friend class TimerTask;
|
||||
|
||||
TimerClient* m_client;
|
||||
Thread* m_thread;
|
||||
TimerTask* m_task; // weak pointer
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#endif
|
@ -1,63 +0,0 @@
|
||||
// Copyright 2011 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/timer.h"
|
||||
|
||||
#include "cc/test/scheduler_test_common.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
using namespace cc;
|
||||
using namespace WebKitTests;
|
||||
|
||||
namespace {
|
||||
|
||||
class TimerTest : public testing::Test, public TimerClient {
|
||||
public:
|
||||
TimerTest() : m_flag(false) { }
|
||||
|
||||
void onTimerFired() { m_flag = true; }
|
||||
|
||||
protected:
|
||||
FakeThread m_thread;
|
||||
bool m_flag;
|
||||
};
|
||||
|
||||
TEST_F(TimerTest, OneShot)
|
||||
{
|
||||
Timer timer(&m_thread, this);
|
||||
timer.startOneShot(0.001);
|
||||
EXPECT_TRUE(timer.isActive());
|
||||
m_thread.runPendingTask();
|
||||
EXPECT_FALSE(timer.isActive());
|
||||
EXPECT_TRUE(m_flag);
|
||||
EXPECT_FALSE(m_thread.hasPendingTask());
|
||||
}
|
||||
|
||||
TEST_F(TimerTest, StopManually)
|
||||
{
|
||||
Timer timer(&m_thread, this);
|
||||
timer.startOneShot(0.001);
|
||||
EXPECT_TRUE(timer.isActive());
|
||||
timer.stop();
|
||||
EXPECT_FALSE(timer.isActive());
|
||||
|
||||
m_thread.runPendingTask();
|
||||
EXPECT_FALSE(m_flag);
|
||||
EXPECT_FALSE(m_thread.hasPendingTask());
|
||||
}
|
||||
|
||||
TEST_F(TimerTest, StopByScope)
|
||||
{
|
||||
{
|
||||
Timer timer(&m_thread, this);
|
||||
timer.startOneShot(0.001);
|
||||
}
|
||||
|
||||
m_thread.runPendingTask();
|
||||
EXPECT_FALSE(m_flag);
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
// Copyright 2011 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 "ccthread_impl.h"
|
||||
|
||||
#include "cc/completion_event.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebThread.h"
|
||||
|
||||
using cc::Thread;
|
||||
using cc::CompletionEvent;
|
||||
|
||||
namespace WebKit {
|
||||
|
||||
// Task that, when runs, places the current thread ID into the provided
|
||||
// pointer and signals a completion event.
|
||||
//
|
||||
// Does not provide a PassOwnPtr<GetThreadIDTask>::create method because
|
||||
// the resulting object is always handed into a WebThread, which does not understand
|
||||
// PassOwnPtrs.
|
||||
class GetThreadIDTask : public WebThread::Task {
|
||||
public:
|
||||
GetThreadIDTask(base::PlatformThreadId* result, CompletionEvent* completion)
|
||||
: m_completion(completion)
|
||||
, m_result(result) { }
|
||||
|
||||
virtual ~GetThreadIDTask() { }
|
||||
|
||||
virtual void run()
|
||||
{
|
||||
*m_result = base::PlatformThread::CurrentId();
|
||||
m_completion->signal();
|
||||
}
|
||||
|
||||
private:
|
||||
CompletionEvent* m_completion;
|
||||
base::PlatformThreadId* m_result;
|
||||
};
|
||||
|
||||
// General adapter from a Thread::Task to a WebThread::Task.
|
||||
class ThreadTaskAdapter : public WebThread::Task {
|
||||
public:
|
||||
explicit ThreadTaskAdapter(PassOwnPtr<Thread::Task> task) : m_task(task) { }
|
||||
|
||||
virtual ~ThreadTaskAdapter() { }
|
||||
|
||||
virtual void run()
|
||||
{
|
||||
m_task->performTask();
|
||||
}
|
||||
|
||||
private:
|
||||
OwnPtr<Thread::Task> m_task;
|
||||
};
|
||||
|
||||
scoped_ptr<Thread> CCThreadImpl::createForCurrentThread()
|
||||
{
|
||||
return scoped_ptr<Thread>(new CCThreadImpl(Platform::current()->currentThread(), true)).Pass();
|
||||
}
|
||||
|
||||
scoped_ptr<Thread> CCThreadImpl::createForDifferentThread(WebThread* thread)
|
||||
{
|
||||
return scoped_ptr<Thread>(new CCThreadImpl(thread, false)).Pass();
|
||||
}
|
||||
|
||||
CCThreadImpl::~CCThreadImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void CCThreadImpl::postTask(PassOwnPtr<Thread::Task> task)
|
||||
{
|
||||
m_thread->postTask(new ThreadTaskAdapter(task));
|
||||
}
|
||||
|
||||
void CCThreadImpl::postDelayedTask(PassOwnPtr<Thread::Task> task, long long delayMs)
|
||||
{
|
||||
m_thread->postDelayedTask(new ThreadTaskAdapter(task), delayMs);
|
||||
}
|
||||
|
||||
base::PlatformThreadId CCThreadImpl::threadID() const
|
||||
{
|
||||
return m_threadID;
|
||||
}
|
||||
|
||||
CCThreadImpl::CCThreadImpl(WebThread* thread, bool currentThread)
|
||||
: m_thread(thread)
|
||||
{
|
||||
if (currentThread) {
|
||||
m_threadID = base::PlatformThread::CurrentId();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the threadId for the newly-created thread by running a task
|
||||
// on that thread, blocking on the result.
|
||||
CompletionEvent completion;
|
||||
m_thread->postTask(new GetThreadIDTask(&m_threadID, &completion));
|
||||
completion.wait();
|
||||
}
|
||||
|
||||
} // namespace WebKit
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2011 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 "base/memory/scoped_ptr.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "cc/thread.h"
|
||||
#include <wtf/OwnPtr.h>
|
||||
#include <wtf/PassOwnPtr.h>
|
||||
|
||||
#ifndef CCThreadImpl_h
|
||||
#define CCThreadImpl_h
|
||||
|
||||
namespace WebKit {
|
||||
|
||||
class WebThread;
|
||||
|
||||
// Implements Thread in terms of WebThread.
|
||||
class CCThreadImpl : public cc::Thread {
|
||||
public:
|
||||
// Creates a CCThreadImpl wrapping the current thread.
|
||||
static scoped_ptr<cc::Thread> createForCurrentThread();
|
||||
|
||||
// Creates a Thread wrapping a non-current WebThread.
|
||||
static scoped_ptr<cc::Thread> createForDifferentThread(WebThread*);
|
||||
|
||||
virtual ~CCThreadImpl();
|
||||
virtual void postTask(PassOwnPtr<cc::Thread::Task>);
|
||||
virtual void postDelayedTask(PassOwnPtr<cc::Thread::Task>, long long delayMs);
|
||||
base::PlatformThreadId threadID() const;
|
||||
|
||||
private:
|
||||
CCThreadImpl(WebThread*, bool currentThread);
|
||||
|
||||
WebThread* m_thread;
|
||||
base::PlatformThreadId m_threadID;
|
||||
};
|
||||
|
||||
} // namespace WebKit
|
||||
|
||||
#endif
|
@ -5,8 +5,6 @@
|
||||
{
|
||||
'variables': {
|
||||
'webkit_compositor_bindings_sources': [
|
||||
'ccthread_impl.cc',
|
||||
'ccthread_impl.h',
|
||||
'web_animation_curve_common.cc',
|
||||
'web_animation_curve_common.h',
|
||||
'web_animation_impl.cc',
|
||||
|
@ -4,16 +4,16 @@
|
||||
|
||||
#include "base/message_loop.h"
|
||||
#include "base/test/test_suite.h"
|
||||
#include "cc/test/test_webkit_platform.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
|
||||
#include "cc/proxy.h"
|
||||
#include "cc/thread_impl.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
TestSuite testSuite(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 = testSuite.Run();
|
||||
|
||||
return result;
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "cc/layer_tree_host.h"
|
||||
#include "cc/proxy.h"
|
||||
#include "cc/settings.h"
|
||||
#include "ccthread_impl.h"
|
||||
#include "cc/thread_impl.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
|
||||
#include "webkit/glue/webthread_impl.h"
|
||||
|
||||
@ -45,10 +45,12 @@ void WebCompositorImpl::initialize(WebThread* implThread)
|
||||
ASSERT(!s_initialized);
|
||||
s_initialized = true;
|
||||
|
||||
s_mainThread = CCThreadImpl::createForCurrentThread().release();
|
||||
s_mainThread = cc::ThreadImpl::createForCurrentThread().release();
|
||||
Proxy::setMainThread(s_mainThread);
|
||||
if (implThread) {
|
||||
s_implThread = CCThreadImpl::createForDifferentThread(implThread).release();
|
||||
webkit_glue::WebThreadImpl* webThreadImpl = static_cast<webkit_glue::WebThreadImpl*>(implThread);
|
||||
MessageLoop* implMessageLoop = webThreadImpl->message_loop();
|
||||
s_implThread = cc::ThreadImpl::createForDifferentThread(implMessageLoop->message_loop_proxy()).release();
|
||||
Proxy::setImplThread(s_implThread);
|
||||
} else
|
||||
Proxy::setImplThread(0);
|
||||
|
@ -4,19 +4,21 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "base/cancelable_callback.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "cc/proxy.h"
|
||||
#include "cc/thread_impl.h"
|
||||
#include "cc/test/compositor_fake_web_graphics_context_3d.h"
|
||||
#include "cc/test/fake_web_compositor_output_surface.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSupport.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewClient.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebThread.h"
|
||||
#include "web_layer_impl.h"
|
||||
#include "web_layer_tree_view_impl.h"
|
||||
#include "web_layer_tree_view_test_common.h"
|
||||
#include "webkit/compositor_bindings/test/web_layer_tree_view_test_common.h"
|
||||
#include "webkit/compositor_bindings/web_layer_impl.h"
|
||||
#include "webkit/compositor_bindings/web_layer_tree_view_impl.h"
|
||||
|
||||
using namespace WebKit;
|
||||
using testing::Mock;
|
||||
@ -28,7 +30,7 @@ class MockWebLayerTreeViewClientForThreadedTests : public MockWebLayerTreeViewCl
|
||||
public:
|
||||
virtual void didBeginFrame() OVERRIDE
|
||||
{
|
||||
WebKit::Platform::current()->currentThread()->exitRunLoop();
|
||||
MessageLoop::current()->Quit();
|
||||
MockWebLayerTreeViewClient::didBeginFrame();
|
||||
}
|
||||
};
|
||||
@ -55,7 +57,6 @@ public:
|
||||
|
||||
m_rootLayer.reset();
|
||||
m_view.reset();
|
||||
WebKit::Platform::current()->compositorSupport()->shutdown();
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -72,7 +73,6 @@ protected:
|
||||
|
||||
virtual void initializeCompositor() OVERRIDE
|
||||
{
|
||||
WebKit::Platform::current()->compositorSupport()->initialize(0);
|
||||
}
|
||||
|
||||
virtual WebLayerTreeViewClient* client() OVERRIDE
|
||||
@ -83,78 +83,30 @@ protected:
|
||||
MockWebLayerTreeViewClient m_client;
|
||||
};
|
||||
|
||||
class CancelableTaskWrapper : public base::RefCounted<CancelableTaskWrapper> {
|
||||
class Task : public WebThread::Task {
|
||||
public:
|
||||
Task(CancelableTaskWrapper* cancelableTask)
|
||||
: m_cancelableTask(cancelableTask)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void run() OVERRIDE
|
||||
{
|
||||
m_cancelableTask->runIfNotCanceled();
|
||||
}
|
||||
|
||||
scoped_refptr<CancelableTaskWrapper> m_cancelableTask;
|
||||
};
|
||||
|
||||
public:
|
||||
CancelableTaskWrapper(scoped_ptr<WebThread::Task> task)
|
||||
: m_task(task.Pass())
|
||||
{
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
m_task.reset();
|
||||
}
|
||||
|
||||
WebThread::Task* createTask()
|
||||
{
|
||||
ASSERT(m_task);
|
||||
return new Task(this);
|
||||
}
|
||||
|
||||
void runIfNotCanceled()
|
||||
{
|
||||
if (!m_task)
|
||||
return;
|
||||
m_task->run();
|
||||
m_task.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class base::RefCounted<CancelableTaskWrapper>;
|
||||
~CancelableTaskWrapper() { }
|
||||
|
||||
scoped_ptr<WebThread::Task> m_task;
|
||||
};
|
||||
|
||||
class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase {
|
||||
protected:
|
||||
class TimeoutTask : public WebThread::Task {
|
||||
virtual void run() OVERRIDE
|
||||
{
|
||||
WebKit::Platform::current()->currentThread()->exitRunLoop();
|
||||
}
|
||||
};
|
||||
virtual ~WebLayerTreeViewThreadedTest()
|
||||
{
|
||||
cc::Proxy::setImplThread(0);
|
||||
}
|
||||
|
||||
void composite()
|
||||
{
|
||||
m_view->setNeedsRedraw();
|
||||
scoped_refptr<CancelableTaskWrapper> timeoutTask(new CancelableTaskWrapper(scoped_ptr<WebThread::Task>(new TimeoutTask())));
|
||||
WebKit::Platform::current()->currentThread()->postDelayedTask(timeoutTask->createTask(), 5000);
|
||||
WebKit::Platform::current()->currentThread()->enterRunLoop();
|
||||
timeoutTask->cancel();
|
||||
base::CancelableClosure timeout(base::Bind(&MessageLoop::Quit, base::Unretained(MessageLoop::current())));
|
||||
MessageLoop::current()->PostDelayedTask(FROM_HERE,
|
||||
timeout.callback(),
|
||||
base::TimeDelta::FromSeconds(5));
|
||||
MessageLoop::current()->Run();
|
||||
m_view->finishAllRendering();
|
||||
}
|
||||
|
||||
virtual void initializeCompositor() OVERRIDE
|
||||
{
|
||||
m_webThread.reset(WebKit::Platform::current()->createThread("WebLayerTreeViewTest"));
|
||||
WebKit::Platform::current()->compositorSupport()->initialize(m_webThread.get());
|
||||
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());
|
||||
}
|
||||
|
||||
virtual WebLayerTreeViewClient* client() OVERRIDE
|
||||
@ -163,7 +115,9 @@ protected:
|
||||
}
|
||||
|
||||
MockWebLayerTreeViewClientForThreadedTests m_client;
|
||||
scoped_ptr<WebThread> m_webThread;
|
||||
scoped_ptr<base::Thread> m_implThread;
|
||||
scoped_ptr<cc::Thread> m_implCCThread;
|
||||
base::CancelableClosure m_timeout;
|
||||
};
|
||||
|
||||
TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <public/WebLayer.h>
|
||||
|
||||
#include "cc/test/compositor_fake_web_graphics_context_3d.h"
|
||||
#include "cc/test/web_compositor_initializer.h"
|
||||
#include "web_layer_impl.h"
|
||||
#include "web_layer_tree_view_test_common.h"
|
||||
#include <public/WebContentLayer.h>
|
||||
@ -40,7 +39,6 @@ public:
|
||||
class WebLayerTest : public Test {
|
||||
public:
|
||||
WebLayerTest()
|
||||
: m_compositorInitializer(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -62,7 +60,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
WebKitTests::WebCompositorInitializer m_compositorInitializer;
|
||||
MockWebLayerTreeViewClient m_client;
|
||||
scoped_ptr<WebLayer> m_rootLayer;
|
||||
scoped_ptr<WebLayerTreeView> m_view;
|
||||
|
Reference in New Issue
Block a user