blob: 8c17409b0223d51fce6fad4d4daf8997d38572ac [file] [log] [blame]
Dominik Laskowski068173d2021-08-11 17:22:59 -07001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <memory>
20#include <string>
21
22#include <scheduler/Features.h>
Dominik Laskowski5d164f22022-07-07 07:56:07 -070023#include <scheduler/Time.h>
Dominik Laskowski068173d2021-08-11 17:22:59 -070024
25namespace android::scheduler {
26
27// TODO(b/185535769): Rename classes, and remove aliases.
28class VSyncDispatch;
29class VSyncTracker;
30
31class VsyncController;
32using VsyncDispatch = VSyncDispatch;
33using VsyncTracker = VSyncTracker;
34
35// Schedule that synchronizes to hardware VSYNC of a physical display.
36class VsyncSchedule {
37public:
38 explicit VsyncSchedule(FeatureFlags);
39 VsyncSchedule(VsyncSchedule&&);
40 ~VsyncSchedule();
41
Dominik Laskowski5d164f22022-07-07 07:56:07 -070042 Period period() const;
43 TimePoint vsyncDeadlineAfter(TimePoint) const;
44
Dominik Laskowski068173d2021-08-11 17:22:59 -070045 // TODO(b/185535769): Hide behind API.
46 const VsyncTracker& getTracker() const { return *mTracker; }
47 VsyncTracker& getTracker() { return *mTracker; }
48 VsyncController& getController() { return *mController; }
49
50 // TODO(b/185535769): Remove once VsyncSchedule owns all registrations.
51 VsyncDispatch& getDispatch() { return *mDispatch; }
52
53 void dump(std::string&) const;
54
55private:
56 friend class TestableScheduler;
57
58 using TrackerPtr = std::unique_ptr<VsyncTracker>;
59 using DispatchPtr = std::unique_ptr<VsyncDispatch>;
60 using ControllerPtr = std::unique_ptr<VsyncController>;
61
62 // For tests.
63 VsyncSchedule(TrackerPtr, DispatchPtr, ControllerPtr);
64
65 static TrackerPtr createTracker();
66 static DispatchPtr createDispatch(VsyncTracker&);
67 static ControllerPtr createController(VsyncTracker&, FeatureFlags);
68
69 class PredictedVsyncTracer;
70 using TracerPtr = std::unique_ptr<PredictedVsyncTracer>;
71
72 // Effectively const except in move constructor.
73 TrackerPtr mTracker;
74 DispatchPtr mDispatch;
75 ControllerPtr mController;
76 TracerPtr mTracer;
77};
78
79} // namespace android::scheduler