Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 1 | /* |
| 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 Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 23 | #include <scheduler/Time.h> |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 24 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 25 | namespace android { |
| 26 | class EventThreadTest; |
| 27 | } |
| 28 | |
| 29 | namespace android::fuzz { |
| 30 | class SchedulerFuzzer; |
| 31 | } |
| 32 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 33 | namespace android::scheduler { |
| 34 | |
| 35 | // TODO(b/185535769): Rename classes, and remove aliases. |
| 36 | class VSyncDispatch; |
| 37 | class VSyncTracker; |
| 38 | |
| 39 | class VsyncController; |
| 40 | using VsyncDispatch = VSyncDispatch; |
| 41 | using VsyncTracker = VSyncTracker; |
| 42 | |
| 43 | // Schedule that synchronizes to hardware VSYNC of a physical display. |
| 44 | class VsyncSchedule { |
| 45 | public: |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 46 | explicit VsyncSchedule(FeatureFlags); |
| 47 | VsyncSchedule(VsyncSchedule&&); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 48 | ~VsyncSchedule(); |
| 49 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 50 | Period period() const; |
| 51 | TimePoint vsyncDeadlineAfter(TimePoint) const; |
| 52 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 53 | // TODO(b/185535769): Hide behind API. |
| 54 | const VsyncTracker& getTracker() const { return *mTracker; } |
| 55 | VsyncTracker& getTracker() { return *mTracker; } |
| 56 | VsyncController& getController() { return *mController; } |
| 57 | |
| 58 | // TODO(b/185535769): Remove once VsyncSchedule owns all registrations. |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 59 | VsyncDispatch& getDispatch() { return *mDispatch; } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 60 | |
| 61 | void dump(std::string&) const; |
| 62 | |
| 63 | private: |
| 64 | friend class TestableScheduler; |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 65 | friend class android::EventThreadTest; |
| 66 | friend class android::fuzz::SchedulerFuzzer; |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 67 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 68 | using TrackerPtr = std::unique_ptr<VsyncTracker>; |
| 69 | using DispatchPtr = std::unique_ptr<VsyncDispatch>; |
| 70 | using ControllerPtr = std::unique_ptr<VsyncController>; |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 71 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 72 | // For tests. |
| 73 | VsyncSchedule(TrackerPtr, DispatchPtr, ControllerPtr); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 74 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 75 | static TrackerPtr createTracker(); |
| 76 | static DispatchPtr createDispatch(VsyncTracker&); |
| 77 | static ControllerPtr createController(VsyncTracker&, FeatureFlags); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 78 | |
| 79 | class PredictedVsyncTracer; |
| 80 | using TracerPtr = std::unique_ptr<PredictedVsyncTracer>; |
| 81 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 82 | // Effectively const except in move constructor. |
| 83 | TrackerPtr mTracker; |
| 84 | DispatchPtr mDispatch; |
| 85 | ControllerPtr mController; |
| 86 | TracerPtr mTracer; |
| 87 | }; |
| 88 | |
| 89 | } // namespace android::scheduler |