blob: 5c0cb6f66120db94923f9ba66f6f4ae981a1b59c [file] [log] [blame]
// Copyright 2015 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/trees/threaded_channel.h"
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "base/trace_event/trace_event.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));
}
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) {}
void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl,
proxy_impl_->GetImplWeakPtr(), throttle));
}
void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints,
TopControlsState current,
bool animate) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl,
proxy_impl_->GetImplWeakPtr(), constraints, current, animate));
}
void ThreadedChannel::InitializeOutputSurfaceOnImpl(
OutputSurface* output_surface) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl,
proxy_impl_->GetImplWeakPtr(), output_surface));
}
void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl,
proxy_impl_->GetImplWeakPtr()));
}
void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl,
proxy_impl_->GetImplWeakPtr(), is_throttled));
}
void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl,
proxy_impl_->GetImplWeakPtr(), defer_commits));
}
void ThreadedChannel::FinishAllRenderingOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::FinishAllRenderingOnImpl,
proxy_impl_->GetImplWeakPtr(), completion));
}
void ThreadedChannel::SetNeedsCommitOnImpl() {
ImplThreadTaskRunner()->PostTask(FROM_HERE,
base::Bind(&ProxyImpl::SetNeedsCommitOnImpl,
proxy_impl_->GetImplWeakPtr()));
}
void ThreadedChannel::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl,
proxy_impl_->GetImplWeakPtr(), reason));
}
void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl,
proxy_impl_->GetImplWeakPtr(), damage_rect));
}
void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::StartCommitOnImpl,
proxy_impl_->GetImplWeakPtr(), completion));
}
void ThreadedChannel::SetVisibleOnImpl(CompletionEvent* completion,
bool visible) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_->GetImplWeakPtr(),
completion, visible));
}
void ThreadedChannel::ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl,
proxy_impl_->GetImplWeakPtr(), completion));
}
void ThreadedChannel::FinishGLOnImpl(CompletionEvent* completion) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl,
proxy_impl_->GetImplWeakPtr(), completion));
}
void ThreadedChannel::MainFrameWillHappenOnImplForTesting(
CompletionEvent* completion,
bool* main_frame_will_happen) {
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting,
proxy_impl_->GetImplWeakPtr(), completion,
main_frame_will_happen));
}
void ThreadedChannel::DidCompleteSwapBuffers() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers,
proxy_main_->GetMainWeakPtr()));
}
void ThreadedChannel::SetRendererCapabilitiesMainCopy(
const RendererCapabilities& capabilities) {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilitiesMainCopy,
proxy_main_->GetMainWeakPtr(), capabilities));
}
void ThreadedChannel::BeginMainFrameNotExpectedSoon() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon,
proxy_main_->GetMainWeakPtr()));
}
void ThreadedChannel::DidCommitAndDrawFrame() {
MainThreadTaskRunner()->PostTask(FROM_HERE,
base::Bind(&ProxyMain::DidCommitAndDrawFrame,
proxy_main_->GetMainWeakPtr()));
}
void ThreadedChannel::SetAnimationEvents(
scoped_ptr<AnimationEventsVector> queue) {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ProxyMain::SetAnimationEvents, proxy_main_->GetMainWeakPtr(),
base::Passed(&queue)));
}
void ThreadedChannel::DidLoseOutputSurface() {
MainThreadTaskRunner()->PostTask(FROM_HERE,
base::Bind(&ProxyMain::DidLoseOutputSurface,
proxy_main_->GetMainWeakPtr()));
}
void ThreadedChannel::RequestNewOutputSurface() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface,
proxy_main_->GetMainWeakPtr()));
}
void ThreadedChannel::DidInitializeOutputSurface(
bool success,
const RendererCapabilities& capabilities) {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ProxyMain::DidInitializeOutputSurface,
proxy_main_->GetMainWeakPtr(), success, capabilities));
}
void ThreadedChannel::DidCompletePageScaleAnimation() {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation,
proxy_main_->GetMainWeakPtr()));
}
void ThreadedChannel::PostFrameTimingEventsOnMain(
scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain,
proxy_main_->GetMainWeakPtr(),
base::Passed(composite_events.Pass()),
base::Passed(main_frame_events.Pass())));
}
void ThreadedChannel::BeginMainFrame(
scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ProxyMain::BeginMainFrame, proxy_main_->GetMainWeakPtr(),
base::Passed(&begin_main_frame_state)));
}
ThreadedChannel::~ThreadedChannel() {
TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel");
}
base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const {
return main_task_runner_.get();
}
base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const {
return impl_task_runner_.get();
}
} // namespace cc