blob: dc71e6eb60cefa1a42c5a4b28804e34f34868223 [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;
Ady Abrahambe0f9482019-04-24 15:41:53 -070049 virtual nsecs_t getOffsetThresholdForNextVsync() const = 0;
Ana Krulec757f63a2019-01-25 10:46:18 -080050 virtual void dump(std::string& result) const = 0;
51};
52
53namespace impl {
54class PhaseOffsets : public scheduler::PhaseOffsets {
55public:
56 PhaseOffsets();
57
58 nsecs_t getCurrentAppOffset() override;
59 nsecs_t getCurrentSfOffset() override;
60
Ady Abraham796beb02019-04-11 15:23:07 -070061 // Returns early, early GL, and late offsets for Apps and SF for a given refresh rate.
62 Offsets getOffsetsForRefreshRate(
63 RefreshRateConfigs::RefreshRateType refreshRateType) const override;
64
Ana Krulec757f63a2019-01-25 10:46:18 -080065 // Returns early, early GL, and late offsets for Apps and SF.
Ady Abraham796beb02019-04-11 15:23:07 -070066 Offsets getCurrentOffsets() const override {
67 return getOffsetsForRefreshRate(mRefreshRateType);
68 }
Ana Krulec757f63a2019-01-25 10:46:18 -080069
70 // This function should be called when the device is switching between different
71 // refresh rates, to properly update the offsets.
72 void setRefreshRateType(RefreshRateConfigs::RefreshRateType refreshRateType) override {
73 mRefreshRateType = refreshRateType;
74 }
75
Ady Abrahambe0f9482019-04-24 15:41:53 -070076 nsecs_t getOffsetThresholdForNextVsync() const override { return mOffsetThresholdForNextVsync; }
77
Ana Krulec757f63a2019-01-25 10:46:18 -080078 // Returns current offsets in human friendly format.
79 void dump(std::string& result) const override;
80
81private:
Alec Mouri754c98a2019-03-18 18:53:42 -070082 Offsets getDefaultRefreshRateOffsets() { return mDefaultRefreshRateOffsets; }
83 Offsets getHighRefreshRateOffsets() { return mHighRefreshRateOffsets; }
Ana Krulec757f63a2019-01-25 10:46:18 -080084
85 std::atomic<RefreshRateConfigs::RefreshRateType> mRefreshRateType =
86 RefreshRateConfigs::RefreshRateType::DEFAULT;
87
88 Offsets mDefaultRefreshRateOffsets;
89 Offsets mHighRefreshRateOffsets;
Ady Abrahambe0f9482019-04-24 15:41:53 -070090 nsecs_t mOffsetThresholdForNextVsync;
Ana Krulec757f63a2019-01-25 10:46:18 -080091};
92} // namespace impl
93
94} // namespace scheduler
95} // namespace android