| 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 |  | 
|  | 25 | namespace android::scheduler { | 
|  | 26 |  | 
|  | 27 | // TODO(b/185535769): Rename classes, and remove aliases. | 
|  | 28 | class VSyncDispatch; | 
|  | 29 | class VSyncTracker; | 
|  | 30 |  | 
|  | 31 | class VsyncController; | 
|  | 32 | using VsyncDispatch = VSyncDispatch; | 
|  | 33 | using VsyncTracker = VSyncTracker; | 
|  | 34 |  | 
|  | 35 | // Schedule that synchronizes to hardware VSYNC of a physical display. | 
|  | 36 | class VsyncSchedule { | 
|  | 37 | public: | 
|  | 38 | explicit VsyncSchedule(FeatureFlags); | 
|  | 39 | VsyncSchedule(VsyncSchedule&&); | 
|  | 40 | ~VsyncSchedule(); | 
|  | 41 |  | 
| Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 42 | Period period() const; | 
|  | 43 | TimePoint vsyncDeadlineAfter(TimePoint) const; | 
|  | 44 |  | 
| Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 45 | // 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 |  | 
|  | 55 | private: | 
|  | 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 |