1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/view_manager/surfaces/surfaces_scheduler.h"
7 #include "cc/debug/rendering_stats_instrumentation.h"
8 #include "cc/scheduler/compositor_timing_history.h"
9 #include "cc/surfaces/display.h"
13 SurfacesScheduler::SurfacesScheduler()
14 : rendering_stats_instrumentation_(
15 cc::RenderingStatsInstrumentation::Create()) {
16 cc::SchedulerSettings settings
;
17 scoped_ptr
<cc::CompositorTimingHistory
> compositor_timing_history(
18 new cc::CompositorTimingHistory(cc::CompositorTimingHistory::NULL_UMA
,
19 rendering_stats_instrumentation_
.get()));
20 scheduler_
= cc::Scheduler::Create(
21 this, settings
, 0, base::MessageLoop::current()->task_runner().get(),
22 nullptr, compositor_timing_history
.Pass());
23 scheduler_
->SetCanStart();
24 scheduler_
->SetVisible(true);
25 scheduler_
->SetCanDraw(true);
26 scheduler_
->SetNeedsBeginMainFrame();
29 SurfacesScheduler::~SurfacesScheduler() {
32 void SurfacesScheduler::SetNeedsDraw() {
33 // Don't tell the scheduler we need to draw if we have no active displays
34 // which can happen if we haven't initialized displays yet or if all active
35 // displays have lost their context.
36 if (!displays_
.empty())
37 scheduler_
->SetNeedsRedraw();
40 void SurfacesScheduler::OnVSyncParametersUpdated(base::TimeTicks timebase
,
41 base::TimeDelta interval
) {
42 scheduler_
->CommitVSyncParameters(timebase
, interval
);
45 void SurfacesScheduler::AddDisplay(cc::Display
* display
) {
46 DCHECK(displays_
.find(display
) == displays_
.end());
47 displays_
.insert(display
);
49 // A draw might be necessary (e.g., this display might be getting added on
50 // resumption from the app being in the background as happens on android).
54 void SurfacesScheduler::RemoveDisplay(cc::Display
* display
) {
55 auto it
= displays_
.find(display
);
56 DCHECK(it
!= displays_
.end());
60 void SurfacesScheduler::WillBeginImplFrame(const cc::BeginFrameArgs
& args
) {
63 void SurfacesScheduler::DidFinishImplFrame() {
66 void SurfacesScheduler::ScheduledActionSendBeginMainFrame() {
67 scheduler_
->NotifyBeginMainFrameStarted();
68 scheduler_
->NotifyReadyToCommit();
71 cc::DrawResult
SurfacesScheduler::ScheduledActionDrawAndSwapIfPossible() {
72 for (const auto& it
: displays_
) {
75 return cc::DRAW_SUCCESS
;
78 cc::DrawResult
SurfacesScheduler::ScheduledActionDrawAndSwapForced() {
79 NOTREACHED() << "ScheduledActionDrawAndSwapIfPossible always succeeds.";
80 return cc::DRAW_SUCCESS
;
83 void SurfacesScheduler::ScheduledActionAnimate() {
86 void SurfacesScheduler::ScheduledActionCommit() {
87 scheduler_
->NotifyReadyToActivate();
90 void SurfacesScheduler::ScheduledActionActivateSyncTree() {
93 void SurfacesScheduler::ScheduledActionBeginOutputSurfaceCreation() {
94 scheduler_
->DidCreateAndInitializeOutputSurface();
97 void SurfacesScheduler::ScheduledActionPrepareTiles() {
100 void SurfacesScheduler::ScheduledActionInvalidateOutputSurface() {
103 void SurfacesScheduler::SendBeginFramesToChildren(
104 const cc::BeginFrameArgs
& args
) {
107 void SurfacesScheduler::SendBeginMainFrameNotExpectedSoon() {