| Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2019 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 <cinttypes> | 
|  | 20 |  | 
|  | 21 | #include "RefreshRateConfigs.h" | 
|  | 22 | #include "VSyncModulator.h" | 
|  | 23 |  | 
|  | 24 | namespace android { | 
|  | 25 | namespace scheduler { | 
|  | 26 |  | 
|  | 27 | /* | 
|  | 28 | * This class encapsulates offsets for different refresh rates. Depending | 
|  | 29 | * on what refresh rate we are using, and wheter we are composing in GL, | 
|  | 30 | * different offsets will help us with latency. This class keeps track of | 
|  | 31 | * which mode the device is on, and returns approprate offsets when needed. | 
|  | 32 | */ | 
|  | 33 | class PhaseOffsets { | 
|  | 34 | public: | 
|  | 35 | struct Offsets { | 
|  | 36 | VSyncModulator::Offsets early; | 
|  | 37 | VSyncModulator::Offsets earlyGl; | 
|  | 38 | VSyncModulator::Offsets late; | 
|  | 39 | }; | 
|  | 40 |  | 
|  | 41 | virtual ~PhaseOffsets(); | 
|  | 42 |  | 
|  | 43 | virtual nsecs_t getCurrentAppOffset() = 0; | 
|  | 44 | virtual nsecs_t getCurrentSfOffset() = 0; | 
|  | 45 | virtual Offsets getCurrentOffsets() const = 0; | 
|  | 46 | virtual void setRefreshRateType(RefreshRateConfigs::RefreshRateType refreshRateType) = 0; | 
|  | 47 | virtual void dump(std::string& result) const = 0; | 
|  | 48 | }; | 
|  | 49 |  | 
|  | 50 | namespace impl { | 
|  | 51 | class PhaseOffsets : public scheduler::PhaseOffsets { | 
|  | 52 | public: | 
|  | 53 | PhaseOffsets(); | 
|  | 54 |  | 
|  | 55 | nsecs_t getCurrentAppOffset() override; | 
|  | 56 | nsecs_t getCurrentSfOffset() override; | 
|  | 57 |  | 
|  | 58 | // Returns early, early GL, and late offsets for Apps and SF. | 
|  | 59 | Offsets getCurrentOffsets() const override; | 
|  | 60 |  | 
|  | 61 | // This function should be called when the device is switching between different | 
|  | 62 | // refresh rates, to properly update the offsets. | 
|  | 63 | void setRefreshRateType(RefreshRateConfigs::RefreshRateType refreshRateType) override { | 
|  | 64 | mRefreshRateType = refreshRateType; | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | // Returns current offsets in human friendly format. | 
|  | 68 | void dump(std::string& result) const override; | 
|  | 69 |  | 
|  | 70 | private: | 
|  | 71 | Offsets getmDefaultRefreshRateOffsets() { return mDefaultRefreshRateOffsets; } | 
|  | 72 | Offsets getmHighRefreshRateOffsets() { return mHighRefreshRateOffsets; } | 
|  | 73 |  | 
|  | 74 | std::atomic<RefreshRateConfigs::RefreshRateType> mRefreshRateType = | 
|  | 75 | RefreshRateConfigs::RefreshRateType::DEFAULT; | 
|  | 76 |  | 
|  | 77 | Offsets mDefaultRefreshRateOffsets; | 
|  | 78 | Offsets mHighRefreshRateOffsets; | 
|  | 79 | }; | 
|  | 80 | } // namespace impl | 
|  | 81 |  | 
|  | 82 | } // namespace scheduler | 
|  | 83 | } // namespace android |