summaryrefslogtreecommitdiffstats
path: root/components/mus/surfaces/surfaces_scheduler.cc
blob: f3752f83ee23b96d9f9c8bf2e737f261e8c6e30a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2014 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 "components/mus/surfaces/surfaces_scheduler.h"

#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/scheduler/compositor_timing_history.h"
#include "cc/surfaces/display.h"

namespace mus {

SurfacesScheduler::SurfacesScheduler()
    : rendering_stats_instrumentation_(
          cc::RenderingStatsInstrumentation::Create()) {
  cc::SchedulerSettings settings;
  scoped_ptr<cc::CompositorTimingHistory> compositor_timing_history(
      new cc::CompositorTimingHistory(cc::CompositorTimingHistory::NULL_UMA,
                                      rendering_stats_instrumentation_.get()));
  scheduler_ = cc::Scheduler::Create(
      this, settings, 0, base::MessageLoop::current()->task_runner().get(),
      nullptr, compositor_timing_history.Pass());
  scheduler_->SetCanStart();
  scheduler_->SetVisible(true);
  scheduler_->SetCanDraw(true);
  scheduler_->SetNeedsBeginMainFrame();
}

SurfacesScheduler::~SurfacesScheduler() {}

void SurfacesScheduler::SetNeedsDraw() {
  // Don't tell the scheduler we need to draw if we have no active displays
  // which can happen if we haven't initialized displays yet or if all active
  // displays have lost their context.
  if (!displays_.empty())
    scheduler_->SetNeedsRedraw();
}

void SurfacesScheduler::OnVSyncParametersUpdated(base::TimeTicks timebase,
                                                 base::TimeDelta interval) {
  scheduler_->CommitVSyncParameters(timebase, interval);
}

void SurfacesScheduler::AddDisplay(cc::Display* display) {
  DCHECK(displays_.find(display) == displays_.end());
  displays_.insert(display);

  // A draw might be necessary (e.g., this display might be getting added on
  // resumption from the app being in the background as happens on android).
  SetNeedsDraw();
}

void SurfacesScheduler::RemoveDisplay(cc::Display* display) {
  auto it = displays_.find(display);
  DCHECK(it != displays_.end());
  displays_.erase(it);
}

void SurfacesScheduler::WillBeginImplFrame(const cc::BeginFrameArgs& args) {}

void SurfacesScheduler::DidFinishImplFrame() {}

void SurfacesScheduler::ScheduledActionSendBeginMainFrame() {
  scheduler_->NotifyBeginMainFrameStarted();
  scheduler_->NotifyReadyToCommit();
}

cc::DrawResult SurfacesScheduler::ScheduledActionDrawAndSwapIfPossible() {
  for (const auto& it : displays_) {
    it->DrawAndSwap();
  }
  return cc::DRAW_SUCCESS;
}

cc::DrawResult SurfacesScheduler::ScheduledActionDrawAndSwapForced() {
  NOTREACHED() << "ScheduledActionDrawAndSwapIfPossible always succeeds.";
  return cc::DRAW_SUCCESS;
}

void SurfacesScheduler::ScheduledActionAnimate() {}

void SurfacesScheduler::ScheduledActionCommit() {
  scheduler_->NotifyReadyToActivate();
}

void SurfacesScheduler::ScheduledActionActivateSyncTree() {}

void SurfacesScheduler::ScheduledActionBeginOutputSurfaceCreation() {
  scheduler_->DidCreateAndInitializeOutputSurface();
}

void SurfacesScheduler::ScheduledActionPrepareTiles() {}

void SurfacesScheduler::ScheduledActionInvalidateOutputSurface() {}

void SurfacesScheduler::SendBeginFramesToChildren(
    const cc::BeginFrameArgs& args) {}

void SurfacesScheduler::SendBeginMainFrameNotExpectedSoon() {}

}  // namespace mus