Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3971)

Unified Diff: cc/thread_proxy.cc

Issue 11571068: Use WeakPtr for posting cc tasks to main thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use WeakPtr for tasks posted to main thread in ThreadedTests Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« cc/test/layer_tree_test_common.cc ('K') | « cc/thread_proxy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/thread_proxy.cc
diff --git a/cc/thread_proxy.cc b/cc/thread_proxy.cc
index e759bcf035f3cdfe638c7e4ae2386c929fbaf022..f9ac23ec2055142e5435004c35587f6ca20f0be9 100644
--- a/cc/thread_proxy.cc
+++ b/cc/thread_proxy.cc
@@ -13,7 +13,6 @@
#include "cc/layer_tree_host.h"
#include "cc/output_surface.h"
#include "cc/scheduler.h"
-#include "cc/scoped_thread_proxy.h"
#include "cc/thread.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsContext3D.h"
@@ -45,7 +44,7 @@ ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost, scoped_ptr<Thread> implTh
, m_inCompositeAndReadback(false)
, m_manageTilesPending(false)
, m_weakFactoryOnImplThread(ALLOW_THIS_IN_INITIALIZER_LIST(this))
- , m_mainThreadProxy(ScopedThreadProxy::create(Proxy::mainThread()))
+ , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
, m_beginFrameCompletionEventOnImplThread(0)
, m_readbackRequestOnImplThread(0)
, m_commitCompletionEventOnImplThread(0)
@@ -310,7 +309,7 @@ void ThreadProxy::onSwapBuffersCompleteOnImplThread()
DCHECK(isImplThread());
TRACE_EVENT0("cc", "ThreadProxy::onSwapBuffersCompleteOnImplThread");
m_schedulerOnImplThread->didSwapBuffersComplete();
- m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::didCompleteSwapBuffers, base::Unretained(this)));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::didCompleteSwapBuffers, m_mainThreadWeakPtr));
}
void ThreadProxy::onVSyncParametersChanged(base::TimeTicks timebase, base::TimeDelta interval)
@@ -361,7 +360,7 @@ void ThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animati
{
DCHECK(isImplThread());
TRACE_EVENT0("cc", "ThreadProxy::postAnimationEventsToMainThreadOnImplThread");
- m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::setAnimationEvents, base::Unretained(this), base::Passed(events.Pass()), wallClockTime));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::setAnimationEvents, m_mainThreadWeakPtr, base::Passed(events.Pass()), wallClockTime));
}
bool ThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff)
@@ -416,7 +415,7 @@ void ThreadProxy::setDeferCommits(bool deferCommits)
TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::setDeferCommits", this);
if (!m_deferCommits && m_pendingDeferredCommit)
- m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::beginFrame, base::Unretained(this), base::Passed(m_pendingDeferredCommit.Pass())));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::beginFrame, m_mainThreadWeakPtr, base::Passed(m_pendingDeferredCommit.Pass())));
}
bool ThreadProxy::commitRequested() const
@@ -449,6 +448,8 @@ void ThreadProxy::start()
Proxy::implThread()->postTask(base::Bind(&ThreadProxy::initializeImplOnImplThread, base::Unretained(this), &completion, handler.release()));
completion.wait();
+ m_mainThreadWeakPtr = m_weakFactory.GetWeakPtr();
+
m_started = true;
}
@@ -467,7 +468,7 @@ void ThreadProxy::stop()
completion.wait();
}
- m_mainThreadProxy->shutdown(); // Stop running tasks posted to us.
+ m_weakFactory.InvalidateWeakPtrs();
DCHECK(!m_layerTreeHostImpl.get()); // verify that the impl deleted.
m_layerTreeHost = 0;
@@ -521,7 +522,7 @@ void ThreadProxy::scheduledActionBeginFrame()
beginFrameState->implTransform = m_layerTreeHostImpl->implTransform();
DCHECK_GT(m_layerTreeHostImpl->memoryAllocationLimitBytes(), 0u);
beginFrameState->memoryAllocationLimitBytes = m_layerTreeHostImpl->memoryAllocationLimitBytes();
- m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::beginFrame, base::Unretained(this), base::Passed(beginFrameState.Pass())));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::beginFrame, m_mainThreadWeakPtr, base::Passed(beginFrameState.Pass())));
if (m_beginFrameCompletionEventOnImplThread) {
m_beginFrameCompletionEventOnImplThread->signal();
@@ -720,7 +721,7 @@ void ThreadProxy::scheduledActionCommit()
void ThreadProxy::scheduledActionBeginContextRecreation()
{
DCHECK(isImplThread());
- m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadProxy::beginContextRecreation, base::Unretained(this)));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::beginContextRecreation, m_mainThreadWeakPtr));
}
ScheduledActionDrawAndSwapResult ThreadProxy::scheduledActionDrawAndSwapInternal(bool forcedDraw)
@@ -778,7 +779,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(FROM_HERE, base::Bind(&ThreadProxy::didCommitAndDrawFrame, base::Unretained(this)));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::didCommitAndDrawFrame, m_mainThreadWeakPtr));
}
return result;
« cc/test/layer_tree_test_common.cc ('K') | « cc/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698