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

Unified Diff: cc/trees/threaded_channel.cc

Issue 1417053005: cc: Split ThreadProxy into ProxyMain and ProxyImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
Index: cc/trees/threaded_channel.cc
diff --git a/cc/trees/threaded_channel.cc b/cc/trees/threaded_channel.cc
index b723f8c612a93f880182836b0887bc76bed6d66c..63e228eb3f235c17514a8e7344dbcfccafec5d8d 100644
--- a/cc/trees/threaded_channel.cc
+++ b/cc/trees/threaded_channel.cc
@@ -7,31 +7,21 @@
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
+#include "cc/trees/layer_tree_host.h"
namespace cc {
-scoped_ptr<ThreadedChannel> ThreadedChannel::Create(
- ThreadProxy* thread_proxy,
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
- scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
- return make_scoped_ptr(
- new ThreadedChannel(thread_proxy, main_task_runner, impl_task_runner));
+scoped_ptr<ThreadedChannel> ThreadedChannel::Create(ProxyMain* proxy_main) {
+ return make_scoped_ptr(new ThreadedChannel(proxy_main));
}
-ThreadedChannel::ThreadedChannel(
- ThreadProxy* thread_proxy,
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
- scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
- : proxy_main_(thread_proxy),
- proxy_impl_(thread_proxy),
- proxy_(thread_proxy),
- main_task_runner_(main_task_runner),
- impl_task_runner_(impl_task_runner) {}
+ThreadedChannel::ThreadedChannel(ProxyMain* proxy_main)
+ : proxy_main_(proxy_main) {}
void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl,
- proxy_impl_->GetImplWeakPtr(), throttle));
+ proxy_impl_->GetWeakPtr(), throttle));
}
void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints,
@@ -40,56 +30,56 @@ void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints,
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl,
- proxy_impl_->GetImplWeakPtr(), constraints, current, animate));
+ proxy_impl_->GetWeakPtr(), constraints, current, animate));
}
void ThreadedChannel::InitializeOutputSurfaceOnImpl(
OutputSurface* output_surface) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl,
- proxy_impl_->GetImplWeakPtr(), output_surface));
+ proxy_impl_->GetWeakPtr(), output_surface));
}
void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl,
- proxy_impl_->GetImplWeakPtr()));
+ proxy_impl_->GetWeakPtr()));
}
void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl,
- proxy_impl_->GetImplWeakPtr(), is_throttled));
+ proxy_impl_->GetWeakPtr(), is_throttled));
}
void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl,
- proxy_impl_->GetImplWeakPtr(), defer_commits));
+ proxy_impl_->GetWeakPtr(), defer_commits));
}
void ThreadedChannel::FinishAllRenderingOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::FinishAllRenderingOnImpl,
- proxy_impl_->GetImplWeakPtr(), completion));
+ proxy_impl_->GetWeakPtr(), completion));
}
void ThreadedChannel::SetNeedsCommitOnImpl() {
- ImplThreadTaskRunner()->PostTask(FROM_HERE,
- base::Bind(&ProxyImpl::SetNeedsCommitOnImpl,
- proxy_impl_->GetImplWeakPtr()));
+ ImplThreadTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_->GetWeakPtr()));
}
void ThreadedChannel::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl,
- proxy_impl_->GetImplWeakPtr(), reason));
+ proxy_impl_->GetWeakPtr(), reason));
}
void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl,
- proxy_impl_->GetImplWeakPtr(), damage_rect));
+ proxy_impl_->GetWeakPtr(), damage_rect));
}
void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion,
@@ -97,41 +87,70 @@ void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion,
bool hold_commit_for_activation) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
- base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_->GetImplWeakPtr(),
+ base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_->GetWeakPtr(),
completion, layer_tree_host, hold_commit_for_activation));
}
-void ThreadedChannel::InitializeImplOnImpl(CompletionEvent* completion,
- LayerTreeHost* layer_tree_host) {
+void ThreadedChannel::InitializeImpl(
+ CompletionEvent* completion,
+ LayerTreeHost* layer_tree_host,
+ scoped_ptr<BeginFrameSource> external_begin_frame_source) {
+ TRACE_EVENT0("cc", "ThreadChannel::InitializeImpl");
ImplThreadTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&ProxyImpl::InitializeImplOnImpl,
- base::Unretained(proxy_impl_), completion, layer_tree_host));
+ FROM_HERE, base::Bind(&ThreadedChannel::InitializeImplOnImpl,
+ base::Unretained(this), completion, layer_tree_host,
+ base::Passed(&external_begin_frame_source)));
+}
+
+void ThreadedChannel::InitializeImplOnImpl(
+ CompletionEvent* completion,
+ LayerTreeHost* layer_tree_host,
+ scoped_ptr<BeginFrameSource> external_begin_frame_source) {
+ DCHECK(proxy_main_->IsImplThread());
+ proxy_impl_ = CreateProxyImpl(this, layer_tree_host, proxy_main_,
+ external_begin_frame_source.Pass());
+ completion->Signal();
}
-void ThreadedChannel::LayerTreeHostClosedOnImpl(CompletionEvent* completion) {
+scoped_ptr<ProxyImpl> ThreadedChannel::CreateProxyImpl(
+ ChannelImpl* channel_impl,
+ LayerTreeHost* layer_tree_host,
+ TaskRunnerProvider* task_runner_provider,
+ scoped_ptr<BeginFrameSource> external_begin_frame_source) {
+ return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider,
+ external_begin_frame_source.Pass());
+}
+
+void ThreadedChannel::CloseImpl(CompletionEvent* completion) {
+ TRACE_EVENT0("cc", "ThreadChannel::~CloseImpl");
ImplThreadTaskRunner()->PostTask(
- FROM_HERE, base::Bind(&ProxyImpl::LayerTreeHostClosedOnImpl,
- proxy_impl_->GetImplWeakPtr(), completion));
- proxy_impl_ = nullptr;
+ FROM_HERE, base::Bind(&ThreadedChannel::CloseImplOnImpl,
+ base::Unretained(this), completion));
+}
+
+void ThreadedChannel::CloseImplOnImpl(CompletionEvent* completion) {
+ DCHECK(proxy_main_->IsImplThread());
+ proxy_impl_->LayerTreeHostClosedOnImpl();
+ proxy_impl_.reset();
+ completion->Signal();
}
void ThreadedChannel::SetVisibleOnImpl(bool visible) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetVisibleOnImpl,
- proxy_impl_->GetImplWeakPtr(), visible));
+ proxy_impl_->GetWeakPtr(), visible));
}
void ThreadedChannel::ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl,
- proxy_impl_->GetImplWeakPtr(), completion));
+ proxy_impl_->GetWeakPtr(), completion));
}
void ThreadedChannel::FinishGLOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl,
- proxy_impl_->GetImplWeakPtr(), completion));
+ proxy_impl_->GetWeakPtr(), completion));
}
void ThreadedChannel::MainFrameWillHappenOnImplForTesting(
@@ -139,68 +158,66 @@ void ThreadedChannel::MainFrameWillHappenOnImplForTesting(
bool* main_frame_will_happen) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting,
- proxy_impl_->GetImplWeakPtr(), completion,
+ proxy_impl_->GetWeakPtr(), completion,
main_frame_will_happen));
}
void ThreadedChannel::DidCompleteSwapBuffers() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers,
- proxy_main_->GetMainWeakPtr()));
+ proxy_main_->GetWeakPtr()));
}
void ThreadedChannel::SetRendererCapabilitiesMainCopy(
const RendererCapabilities& capabilities) {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilitiesMainCopy,
- proxy_main_->GetMainWeakPtr(), capabilities));
+ proxy_main_->GetWeakPtr(), capabilities));
}
void ThreadedChannel::BeginMainFrameNotExpectedSoon() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon,
- proxy_main_->GetMainWeakPtr()));
+ proxy_main_->GetWeakPtr()));
}
void ThreadedChannel::DidCommitAndDrawFrame() {
- MainThreadTaskRunner()->PostTask(FROM_HERE,
- base::Bind(&ProxyMain::DidCommitAndDrawFrame,
- proxy_main_->GetMainWeakPtr()));
+ MainThreadTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&ProxyMain::DidCommitAndDrawFrame, proxy_main_->GetWeakPtr()));
}
void ThreadedChannel::SetAnimationEvents(
scoped_ptr<AnimationEventsVector> queue) {
MainThreadTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&ProxyMain::SetAnimationEvents, proxy_main_->GetMainWeakPtr(),
- base::Passed(&queue)));
+ FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents,
+ proxy_main_->GetWeakPtr(), base::Passed(&queue)));
}
void ThreadedChannel::DidLoseOutputSurface() {
- MainThreadTaskRunner()->PostTask(FROM_HERE,
- base::Bind(&ProxyMain::DidLoseOutputSurface,
- proxy_main_->GetMainWeakPtr()));
+ MainThreadTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&ProxyMain::DidLoseOutputSurface, proxy_main_->GetWeakPtr()));
}
void ThreadedChannel::RequestNewOutputSurface() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface,
- proxy_main_->GetMainWeakPtr()));
+ proxy_main_->GetWeakPtr()));
}
void ThreadedChannel::DidInitializeOutputSurface(
bool success,
const RendererCapabilities& capabilities) {
MainThreadTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&ProxyMain::DidInitializeOutputSurface,
- proxy_main_->GetMainWeakPtr(), success, capabilities));
+ FROM_HERE, base::Bind(&ProxyMain::DidInitializeOutputSurface,
+ proxy_main_->GetWeakPtr(), success, capabilities));
}
void ThreadedChannel::DidCompletePageScaleAnimation() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation,
- proxy_main_->GetMainWeakPtr()));
+ proxy_main_->GetWeakPtr()));
}
void ThreadedChannel::PostFrameTimingEventsOnMain(
@@ -208,7 +225,7 @@ void ThreadedChannel::PostFrameTimingEventsOnMain(
scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain,
- proxy_main_->GetMainWeakPtr(),
+ proxy_main_->GetWeakPtr(),
base::Passed(composite_events.Pass()),
base::Passed(main_frame_events.Pass())));
}
@@ -217,7 +234,7 @@ void ThreadedChannel::BeginMainFrame(
scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
- base::Bind(&ProxyMain::BeginMainFrame, proxy_main_->GetMainWeakPtr(),
+ base::Bind(&ProxyMain::BeginMainFrame, proxy_main_->GetWeakPtr(),
base::Passed(&begin_main_frame_state)));
}
@@ -225,12 +242,16 @@ ThreadedChannel::~ThreadedChannel() {
TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel");
}
+bool ThreadedChannel::IsInitialized() const {
+ return !!proxy_impl_.get();
+}
+
base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const {
- return main_task_runner_.get();
+ return proxy_main_->MainThreadTaskRunner();
}
base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const {
- return impl_task_runner_.get();
+ return proxy_main_->ImplThreadTaskRunner();
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698