Commit 298590fe authored by simonhong's avatar simonhong Committed by Commit bot

cc: Add support for handling authoritative vsync interval

This is partial cl from https://codereview.chromium.org/775143003/
for easy reviewing.
For now, authoritative vsync interval is handled by CompositorVsyncManager.
It will not be used when BeginFrame scheduling is enabled on aura.
Instead, it will be handled by scheduler.
In the next cl, BeginFrame sheduling on aura(and ash) will be turned on.

R=brianderson@chromium.org, mithro@mithis.com
BUG=372086
TEST=cc_unittests

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

Cr-Commit-Position: refs/heads/master@{#322125}
parent 0ad7e334
......@@ -87,6 +87,8 @@ Scheduler::Scheduler(
primary_frame_source_internal_(external_begin_frame_source.Pass()),
background_frame_source_internal_(),
vsync_observer_(NULL),
authoritative_vsync_interval_(base::TimeDelta()),
last_vsync_timebase_(base::TimeTicks()),
throttle_frame_production_(scheduler_settings.throttle_frame_production),
settings_(scheduler_settings),
client_(client),
......@@ -148,9 +150,14 @@ base::TimeTicks Scheduler::Now() const {
void Scheduler::CommitVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) {
// TODO(brianderson): We should not be receiving 0 intervals.
if (interval == base::TimeDelta())
if (authoritative_vsync_interval_ != base::TimeDelta()) {
interval = authoritative_vsync_interval_;
} else if (interval == base::TimeDelta()) {
// TODO(brianderson): We should not be receiving 0 intervals.
interval = BeginFrameArgs::DefaultInterval();
}
last_vsync_timebase_ = timebase;
if (vsync_observer_)
vsync_observer_->OnUpdateVSyncParameters(timebase, interval);
......@@ -431,6 +438,12 @@ void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) {
ProcessScheduledActions();
}
void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) {
authoritative_vsync_interval_ = interval;
if (vsync_observer_)
vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval);
}
// BeginRetroFrame is called for BeginFrames that we've deferred because
// the scheduler was in the middle of processing a previous BeginFrame.
void Scheduler::BeginRetroFrame() {
......
......@@ -166,6 +166,8 @@ class CC_EXPORT Scheduler : public BeginFrameObserverMixIn {
void SetChildrenNeedBeginFrames(bool children_need_begin_frames);
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval);
protected:
Scheduler(SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
......@@ -189,6 +191,9 @@ class CC_EXPORT Scheduler : public BeginFrameObserverMixIn {
scoped_ptr<BeginFrameSource> unthrottled_frame_source_internal_;
VSyncParameterObserver* vsync_observer_;
base::TimeDelta authoritative_vsync_interval_;
base::TimeTicks last_vsync_timebase_;
bool throttle_frame_production_;
const SchedulerSettings settings_;
......
......@@ -2272,5 +2272,33 @@ TEST_F(SchedulerTest, SendBeginMainFrameNotExpectedSoon) {
client_->Reset();
}
TEST_F(SchedulerTest, AuthoritativeVSyncInterval) {
SetUpScheduler(true);
base::TimeDelta initial_interval =
scheduler_->begin_impl_frame_args().interval;
base::TimeDelta authoritative_interval =
base::TimeDelta::FromMilliseconds(33);
scheduler_->SetNeedsCommit();
EXPECT_SCOPED(AdvanceFrame());
EXPECT_EQ(initial_interval, scheduler_->begin_impl_frame_args().interval);
scheduler_->NotifyBeginMainFrameStarted();
scheduler_->NotifyReadyToCommit();
task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
scheduler_->SetAuthoritativeVSyncInterval(authoritative_interval);
EXPECT_SCOPED(AdvanceFrame());
// At the next BeginFrame, authoritative interval is used instead of previous
// interval.
EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval);
EXPECT_EQ(authoritative_interval,
scheduler_->begin_impl_frame_args().interval);
}
} // namespace
} // namespace cc
......@@ -47,6 +47,8 @@ class FakeProxy : public Proxy {
void SetDebugState(const LayerTreeDebugState& debug_state) override {}
bool MainFrameWillHappenForTesting() override;
void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override {}
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override {
}
virtual RendererCapabilities& GetRendererCapabilities();
void SetMaxPartialTextureUpdates(size_t max);
......
......@@ -186,6 +186,7 @@ class TestScheduler : public Scheduler {
BeginFrameSource& frame_source() { return *frame_source_; }
bool FrameProductionThrottled() { return throttle_frame_production_; }
BeginFrameArgs begin_impl_frame_args() { return begin_impl_frame_args_; }
~TestScheduler() override;
......
......@@ -1273,4 +1273,9 @@ void LayerTreeHost::SendBeginFramesToChildren(
client_->SendBeginFramesToChildren(args);
}
void LayerTreeHost::SetAuthoritativeVSyncInterval(
const base::TimeDelta& interval) {
proxy_->SetAuthoritativeVSyncInterval(interval);
}
} // namespace cc
......@@ -306,6 +306,8 @@ class CC_EXPORT LayerTreeHost {
void SetChildrenNeedBeginFrames(bool children_need_begin_frames) const;
void SendBeginFramesToChildren(const BeginFrameArgs& args) const;
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval);
protected:
LayerTreeHost(LayerTreeHostClient* client,
SharedBitmapManager* shared_bitmap_manager,
......
......@@ -106,6 +106,9 @@ class CC_EXPORT Proxy {
virtual void SetChildrenNeedBeginFrames(bool children_need_begin_frames) = 0;
virtual void SetAuthoritativeVSyncInterval(
const base::TimeDelta& interval) = 0;
// Testing hooks
virtual bool MainFrameWillHappenForTesting() = 0;
......
......@@ -753,6 +753,11 @@ void SingleThreadProxy::SetChildrenNeedBeginFrames(
children_need_begin_frames);
}
void SingleThreadProxy::SetAuthoritativeVSyncInterval(
const base::TimeDelta& interval) {
scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval);
}
void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
layer_tree_host_impl_->WillBeginImplFrame(args);
}
......
......@@ -62,6 +62,7 @@ class CC_EXPORT SingleThreadProxy : public Proxy,
bool SupportsImplScrolling() const override;
bool MainFrameWillHappenForTesting() override;
void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override;
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override;
// SchedulerClient implementation
void WillBeginImplFrame(const BeginFrameArgs& args) override;
......
......@@ -1139,6 +1139,11 @@ void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) {
NOTREACHED() << "Only used by SingleThreadProxy";
}
void ThreadProxy::SetAuthoritativeVSyncInterval(
const base::TimeDelta& interval) {
NOTREACHED() << "Only used by SingleThreadProxy";
}
void ThreadProxy::ReadyToFinalizeTextureUpdates() {
DCHECK(IsImplThread());
impl().scheduler->NotifyReadyToCommit();
......
......@@ -178,6 +178,7 @@ class CC_EXPORT ThreadProxy : public Proxy,
void SetDebugState(const LayerTreeDebugState& debug_state) override;
bool MainFrameWillHappenForTesting() override;
void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override;
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override;
// LayerTreeHostImplClient implementation
void UpdateRendererCapabilitiesOnImplThread() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment