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

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: rebased Created 7 years, 12 months 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
« no previous file with comments | « 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 b7e0e7c405e9c5518d600b6b875f37ab72fbabca..257b62da2d83d60583a83a7e255285d5734b9386 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)
@@ -368,7 +367,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), wallClockTime));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::setAnimationEvents, m_mainThreadWeakPtr, base::Passed(&events), wallClockTime));
}
bool ThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff)
@@ -423,7 +422,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)));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::beginFrame, m_mainThreadWeakPtr, base::Passed(&m_pendingDeferredCommit)));
}
bool ThreadProxy::commitRequested() const
@@ -456,6 +455,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;
}
@@ -474,7 +475,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;
@@ -528,7 +529,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)));
+ Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::beginFrame, m_mainThreadWeakPtr, base::Passed(&beginFrameState)));
if (m_beginFrameCompletionEventOnImplThread) {
m_beginFrameCompletionEventOnImplThread->signal();
@@ -727,7 +728,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)
@@ -785,7 +786,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;
« no previous file with comments | « cc/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698