blob: 08747a5615119eec2282166c0716e3dbe857f672 [file] [log] [blame]
Ana Krulec757f63a2019-01-25 10:46:18 -08001/*
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
24namespace android {
25namespace 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 */
33class PhaseOffsets {
34public:
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;
Ady Abraham796beb02019-04-11 15:23:07 -070045 virtual Offsets getOffsetsForRefreshRate(
46 RefreshRateConfigs::RefreshRateType refreshRateType) const = 0;
Ana Krulec757f63a2019-01-25 10:46:18 -080047 virtual Offsets getCurrentOffsets() const = 0;
48 virtual void setRefreshRateType(RefreshRateConfigs::RefreshRateType refreshRateType) = 0;
49 virtual void dump(std::string& result) const = 0;
50};
51
52namespace impl {
53class PhaseOffsets : public scheduler::PhaseOffsets {
54public:
55 PhaseOffsets();
56
57 nsecs_t getCurrentAppOffset() override;
58 nsecs_t getCurrentSfOffset() override;
59
Ady Abraham796beb02019-04-11 15:23:07 -070060 // Returns early, early GL, and late offsets for Apps and SF for a given refresh rate.
61 Offsets getOffsetsForRefreshRate(
62 RefreshRateConfigs::RefreshRateType refreshRateType) const override;
63
Ana Krulec757f63a2019-01-25 10:46:18 -080064 // Returns early, early GL, and late offsets for Apps and SF.
Ady Abraham796beb02019-04-11 15:23:07 -070065 Offsets getCurrentOffsets() const override {
66 return getOffsetsForRefreshRate(mRefreshRateType);
67 }
Ana Krulec757f63a2019-01-25 10:46:18 -080068
69 // This function should be called when the device is switching between different
70 // refresh rates, to properly update the offsets.
71 void setRefreshRateType(RefreshRateConfigs::RefreshRateType refreshRateType) override {
72 mRefreshRateType = refreshRateType;
73 }
74
75 // Returns current offsets in human friendly format.
76 void dump(std::string& result) const override;
77
78private:
Alec Mouri754c98a2019-03-18 18:53:42 -070079 Offsets getDefaultRefreshRateOffsets() { return mDefaultRefreshRateOffsets; }
80 Offsets getHighRefreshRateOffsets() { return mHighRefreshRateOffsets; }
Ana Krulec757f63a2019-01-25 10:46:18 -080081
82 std::atomic<RefreshRateConfigs::RefreshRateType> mRefreshRateType =
83 RefreshRateConfigs::RefreshRateType::DEFAULT;
84
85 Offsets mDefaultRefreshRateOffsets;
86 Offsets mHighRefreshRateOffsets;
87};
88} // namespace impl
89
90} // namespace scheduler
91} // namespace android