Skip to content

Commit

Permalink
Make SingleThreadProxy a SchedulerClient
Browse files Browse the repository at this point in the history
This makes ui::Compositor no longer in charge of
scheduling commits and draws, deferring it to cc::Scheduler.

Other compositors that use SingleThreadProxy are left calling composite
synchronously and now pass a flag to indicate that this is their
intention.  This patch doesn't remove synchronous composite, but now
makes it mutually exclusive with scheduling.

BUG=329552, 287250

Review URL: https://codereview.chromium.org/134623005

Cr-Commit-Position: refs/heads/master@{#288866}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288866 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
enne@chromium.org committed Aug 12, 2014
1 parent f83ef23 commit 174c6d4
Show file tree
Hide file tree
Showing 44 changed files with 695 additions and 503 deletions.
7 changes: 5 additions & 2 deletions android_webview/browser/hardware_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ HardwareRenderer::HardwareRenderer(SharedRendererState* state)
// Webview does not own the surface so should not clear it.
settings.should_clear_root_render_pass = false;

layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
this, this, NULL, settings, NULL);
// TODO(enne): Update this this compositor to use a synchronous scheduler.
settings.single_thread_proxy_scheduler = false;

layer_tree_host_ =
cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings, NULL);
layer_tree_host_->SetRootLayer(root_layer_);
layer_tree_host_->SetLayerTreeHostClientReady();
layer_tree_host_->set_has_transparent_background(true);
Expand Down
2 changes: 0 additions & 2 deletions android_webview/browser/hardware_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class HardwareRenderer : public cc::LayerTreeHostClient,
virtual void DidCompleteSwapBuffers() OVERRIDE {}

// cc::LayerTreeHostSingleThreadClient overrides.
virtual void ScheduleComposite() OVERRIDE {}
virtual void ScheduleAnimation() OVERRIDE {}
virtual void DidPostSwapBuffers() OVERRIDE {}
virtual void DidAbortSwapBuffers() OVERRIDE {}

Expand Down
1 change: 1 addition & 0 deletions cc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ component("cc") {
"trees/proxy.h",
"trees/proxy_timing_history.cc",
"trees/proxy_timing_history.h",
"trees/scoped_abort_remaining_swap_promises.h",
"trees/single_thread_proxy.cc",
"trees/single_thread_proxy.h",
"trees/thread_proxy.cc",
Expand Down
1 change: 1 addition & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@
'trees/proxy.h',
'trees/proxy_timing_history.cc',
'trees/proxy_timing_history.h',
'trees/scoped_abort_remaining_swap_promises.h',
'trees/single_thread_proxy.cc',
'trees/single_thread_proxy.h',
'trees/thread_proxy.cc',
Expand Down
27 changes: 15 additions & 12 deletions cc/scheduler/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ Scheduler::Scheduler(
SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id,
const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner)
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
: settings_(scheduler_settings),
client_(client),
layer_tree_host_id_(layer_tree_host_id),
impl_task_runner_(impl_task_runner),
task_runner_(task_runner),
vsync_interval_(BeginFrameArgs::DefaultInterval()),
last_set_needs_begin_frame_(false),
begin_unthrottled_frame_posted_(false),
Expand Down Expand Up @@ -128,7 +128,7 @@ Scheduler::~Scheduler() {
void Scheduler::SetupSyntheticBeginFrames() {
DCHECK(!synthetic_begin_frame_source_);
synthetic_begin_frame_source_.reset(
new SyntheticBeginFrameSource(this, impl_task_runner_.get()));
new SyntheticBeginFrameSource(this, task_runner_.get()));
}

void Scheduler::CommitVSyncParameters(base::TimeTicks timebase,
Expand Down Expand Up @@ -274,6 +274,9 @@ base::TimeTicks Scheduler::LastBeginImplFrameTime() {
}

void Scheduler::SetupNextBeginFrameIfNeeded() {
if (!task_runner_)
return;

bool needs_begin_frame = state_machine_.BeginFrameNeeded();

if (settings_.throttle_frame_production) {
Expand Down Expand Up @@ -328,7 +331,7 @@ void Scheduler::SetupNextBeginFrameWhenVSyncThrottlingDisabled(
}

begin_unthrottled_frame_posted_ = true;
impl_task_runner_->PostTask(FROM_HERE, begin_unthrottled_frame_closure_);
task_runner_->PostTask(FROM_HERE, begin_unthrottled_frame_closure_);
}

// BeginUnthrottledFrame is used when we aren't throttling frame production.
Expand Down Expand Up @@ -362,7 +365,7 @@ void Scheduler::SetupPollingMechanisms(bool needs_begin_frame) {
base::TimeDelta delay = begin_impl_frame_args_.IsValid()
? begin_impl_frame_args_.interval
: BeginFrameArgs::DefaultInterval();
impl_task_runner_->PostDelayedTask(
task_runner_->PostDelayedTask(
FROM_HERE, poll_for_draw_triggers_task_.callback(), delay);
}
} else {
Expand All @@ -387,9 +390,9 @@ void Scheduler::SetupPollingMechanisms(bool needs_begin_frame) {
// Since we'd rather get a BeginImplFrame by the normal mechanism, we
// set the interval to twice the interval from the previous frame.
advance_commit_state_task_.Reset(advance_commit_state_closure_);
impl_task_runner_->PostDelayedTask(FROM_HERE,
advance_commit_state_task_.callback(),
begin_impl_frame_args_.interval * 2);
task_runner_->PostDelayedTask(FROM_HERE,
advance_commit_state_task_.callback(),
begin_impl_frame_args_.interval * 2);
}
} else {
advance_commit_state_task_.Cancel();
Expand Down Expand Up @@ -491,16 +494,16 @@ void Scheduler::PostBeginRetroFrameIfNeeded() {
return;

begin_retro_frame_posted_ = true;
impl_task_runner_->PostTask(FROM_HERE, begin_retro_frame_closure_);
task_runner_->PostTask(FROM_HERE, begin_retro_frame_closure_);
}

// BeginImplFrame starts a compositor frame that will wait up until a deadline
// for a BeginMainFrame+activation to complete before it times out and draws
// any asynchronous animation and scroll/pinch updates.
void Scheduler::BeginImplFrame(const BeginFrameArgs& args) {
TRACE_EVENT1("cc", "Scheduler::BeginImplFrame", "args", args.AsValue());
DCHECK(state_machine_.begin_impl_frame_state() ==
SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
DCHECK_EQ(state_machine_.begin_impl_frame_state(),
SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
DCHECK(state_machine_.HasInitializedOutputSurface());

advance_commit_state_task_.Cancel();
Expand Down Expand Up @@ -567,7 +570,7 @@ void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) {
base::TimeDelta delta = deadline - gfx::FrameTime::Now();
if (delta <= base::TimeDelta())
delta = base::TimeDelta();
impl_task_runner_->PostDelayedTask(
task_runner_->PostDelayedTask(
FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta);
}

Expand Down
15 changes: 7 additions & 8 deletions cc/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class CC_EXPORT Scheduler {
SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id,
const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) {
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
return make_scoped_ptr(new Scheduler(
client, scheduler_settings, layer_tree_host_id, impl_task_runner));
client, scheduler_settings, layer_tree_host_id, task_runner));
}

virtual ~Scheduler();
Expand Down Expand Up @@ -173,16 +173,15 @@ class CC_EXPORT Scheduler {
scoped_refptr<DelayBasedTimeSource> time_source_;
};

Scheduler(
SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id,
const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner);
Scheduler(SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id,
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);

const SchedulerSettings settings_;
SchedulerClient* client_;
int layer_tree_host_id_;
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;

base::TimeDelta vsync_interval_;
base::TimeDelta estimated_parent_draw_time_;
Expand Down
4 changes: 3 additions & 1 deletion cc/scheduler/scheduler_state_machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,9 @@ void SchedulerStateMachine::DidDrawIfPossibleCompleted(DrawResult result) {
}
}

void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; }
void SchedulerStateMachine::SetNeedsCommit() {
needs_commit_ = true;
}

void SchedulerStateMachine::NotifyReadyToCommit() {
DCHECK(commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED)
Expand Down
2 changes: 0 additions & 2 deletions cc/test/fake_layer_tree_host_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class FakeLayerTreeHostClient : public LayerTreeHostClient,
virtual void DidCompleteSwapBuffers() OVERRIDE {}

// LayerTreeHostSingleThreadClient implementation.
virtual void ScheduleComposite() OVERRIDE {}
virtual void ScheduleAnimation() OVERRIDE {}
virtual void DidPostSwapBuffers() OVERRIDE {}
virtual void DidAbortSwapBuffers() OVERRIDE {}

Expand Down
48 changes: 2 additions & 46 deletions cc/test/layer_tree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,6 @@ class LayerTreeHostClientForTesting : public LayerTreeHostClient,
test_hooks_->DidCompleteSwapBuffers();
}

virtual void ScheduleComposite() OVERRIDE {
test_hooks_->ScheduleComposite();
}

virtual void ScheduleAnimation() OVERRIDE {
test_hooks_->ScheduleAnimation();
}

virtual void DidPostSwapBuffers() OVERRIDE {}
virtual void DidAbortSwapBuffers() OVERRIDE {}

Expand Down Expand Up @@ -394,7 +386,6 @@ LayerTreeTest::LayerTreeTest()
end_when_begin_returns_(false),
timed_out_(false),
scheduled_(false),
schedule_when_set_visible_true_(false),
started_(false),
ended_(false),
delegating_renderer_(false),
Expand Down Expand Up @@ -558,15 +549,6 @@ void LayerTreeTest::Timeout() {
EndTest();
}

void LayerTreeTest::ScheduleComposite() {
if (!started_ || scheduled_)
return;
scheduled_ = true;
main_task_runner_->PostTask(
FROM_HERE,
base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_));
}

void LayerTreeTest::RealEndTest() {
if (layer_tree_host_ && proxy()->CommitPendingForTesting()) {
main_task_runner_->PostTask(
Expand Down Expand Up @@ -618,16 +600,8 @@ void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) {

void LayerTreeTest::DispatchSetVisible(bool visible) {
DCHECK(!proxy() || proxy()->IsMainThread());

if (!layer_tree_host_)
return;

layer_tree_host_->SetVisible(visible);

// If the LTH is being made visible and a previous ScheduleComposite() was
// deferred because the LTH was not visible, re-schedule the composite now.
if (layer_tree_host_->visible() && schedule_when_set_visible_true_)
ScheduleComposite();
if (layer_tree_host_)
layer_tree_host_->SetVisible(visible);
}

void LayerTreeTest::DispatchSetNextCommitForcesRedraw() {
Expand All @@ -637,24 +611,6 @@ void LayerTreeTest::DispatchSetNextCommitForcesRedraw() {
layer_tree_host_->SetNextCommitForcesRedraw();
}

void LayerTreeTest::DispatchComposite() {
scheduled_ = false;

if (!layer_tree_host_)
return;

// If the LTH is not visible, defer the composite until the LTH is made
// visible.
if (!layer_tree_host_->visible()) {
schedule_when_set_visible_true_ = true;
return;
}

schedule_when_set_visible_true_ = false;
base::TimeTicks now = gfx::FrameTime::Now();
layer_tree_host_->Composite(now);
}

void LayerTreeTest::RunTest(bool threaded,
bool delegating_renderer,
bool impl_side_painting) {
Expand Down
6 changes: 0 additions & 6 deletions cc/test/layer_tree_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class TestHooks : public AnimationDelegate {
virtual void DidCommit() {}
virtual void DidCommitAndDrawFrame() {}
virtual void DidCompleteSwapBuffers() {}
virtual void ScheduleComposite() {}
virtual void ScheduleAnimation() {}
virtual void DidDeferCommit() {}
virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
bool visible) {}
Expand Down Expand Up @@ -139,8 +137,6 @@ class LayerTreeTest : public testing::Test, public TestHooks {

virtual void InitializeSettings(LayerTreeSettings* settings) {}

virtual void ScheduleComposite() OVERRIDE;

void RealEndTest();

virtual void DispatchAddAnimation(Layer* layer_to_receive_animation,
Expand All @@ -151,7 +147,6 @@ class LayerTreeTest : public testing::Test, public TestHooks {
void DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect);
void DispatchSetVisible(bool visible);
void DispatchSetNextCommitForcesRedraw();
void DispatchComposite();
void DispatchDidAddAnimation();

virtual void AfterTest() = 0;
Expand Down Expand Up @@ -204,7 +199,6 @@ class LayerTreeTest : public testing::Test, public TestHooks {
bool end_when_begin_returns_;
bool timed_out_;
bool scheduled_;
bool schedule_when_set_visible_true_;
bool started_;
bool ended_;
bool delegating_renderer_;
Expand Down
4 changes: 4 additions & 0 deletions cc/trees/layer_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,12 @@ void LayerTreeHost::NotifyInputThrottledUntilCommit() {

void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) {
DCHECK(!proxy_->HasImplThread());
// This function is only valid when not using the scheduler.
DCHECK(!settings_.single_thread_proxy_scheduler);
SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get());

SetLayerTreeHostClientReady();

if (output_surface_lost_)
proxy->CreateAndInitializeOutputSurface();
if (output_surface_lost_)
Expand Down
2 changes: 2 additions & 0 deletions cc/trees/layer_tree_host_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ class ScrollingLayerTreePerfTest : public LayerTreeHostPerfTestJsonReader {
}

virtual void Layout() OVERRIDE {
if (TestEnded())
return;
static const gfx::Vector2d delta = gfx::Vector2d(0, 10);
scrollable_->SetScrollOffset(scrollable_->scroll_offset() + delta);
}
Expand Down
4 changes: 2 additions & 2 deletions cc/trees/layer_tree_host_single_thread_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace cc {
class LayerTreeHostSingleThreadClient {
public:
// Request that the client schedule a composite.
virtual void ScheduleComposite() = 0;
virtual void ScheduleComposite() {}
// Request that the client schedule a composite now, and calculate appropriate
// delay for potential future frame.
virtual void ScheduleAnimation() = 0;
virtual void ScheduleAnimation() {}

// Called whenever the compositor posts a SwapBuffers (either full or
// partial). After DidPostSwapBuffers(), exactly one of
Expand Down
Loading

0 comments on commit 174c6d4

Please sign in to comment.