blob: 16f67298ad2a1dd448c8df884aeedba88fb4e650 [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#include "PhaseOffsets.h"
18
19#include <cutils/properties.h>
20
21#include "SurfaceFlingerProperties.h"
22
23namespace android {
24using namespace android::sysprop;
25
26namespace scheduler {
27
28PhaseOffsets::~PhaseOffsets() = default;
29
30namespace impl {
31PhaseOffsets::PhaseOffsets() {
32 int64_t vsyncPhaseOffsetNs = vsync_event_phase_offset_ns(1000000);
33
34 int64_t sfVsyncPhaseOffsetNs = vsync_sf_event_phase_offset_ns(1000000);
35
36 char value[PROPERTY_VALUE_MAX];
37 property_get("debug.sf.early_phase_offset_ns", value, "-1");
38 const int earlySfOffsetNs = atoi(value);
39
40 property_get("debug.sf.early_gl_phase_offset_ns", value, "-1");
41 const int earlyGlSfOffsetNs = atoi(value);
42
43 property_get("debug.sf.early_app_phase_offset_ns", value, "-1");
44 const int earlyAppOffsetNs = atoi(value);
45
46 property_get("debug.sf.early_gl_app_phase_offset_ns", value, "-1");
47 const int earlyGlAppOffsetNs = atoi(value);
48
49 property_get("debug.sf.high_fps_early_phase_offset_ns", value, "-1");
50 const int highFpsEarlySfOffsetNs = atoi(value);
51
52 property_get("debug.sf.high_fps_early_gl_phase_offset_ns", value, "-1");
53 const int highFpsEarlyGlSfOffsetNs = atoi(value);
54
55 property_get("debug.sf.high_fps_early_app_phase_offset_ns", value, "-1");
56 const int highFpsEarlyAppOffsetNs = atoi(value);
57
58 property_get("debug.sf.high_fps_early_gl_app_phase_offset_ns", value, "-1");
59 const int highFpsEarlyGlAppOffsetNs = atoi(value);
60
61 // TODO(b/122905996): Define these in device.mk.
Ady Abraham482b4b12019-02-07 19:01:25 -080062 property_get("debug.sf.high_fps_late_app_phase_offset_ns", value, "2000000");
Ana Krulec757f63a2019-01-25 10:46:18 -080063 const int highFpsLateAppOffsetNs = atoi(value);
64
Ady Abraham482b4b12019-02-07 19:01:25 -080065 property_get("debug.sf.high_fps_late_sf_phase_offset_ns", value, "1000000");
Ana Krulec757f63a2019-01-25 10:46:18 -080066 const int highFpsLateSfOffsetNs = atoi(value);
67
68 mDefaultRefreshRateOffsets.early = {earlySfOffsetNs != -1 ? earlySfOffsetNs
69 : sfVsyncPhaseOffsetNs,
70 earlyAppOffsetNs != -1 ? earlyAppOffsetNs
71 : vsyncPhaseOffsetNs};
72 mDefaultRefreshRateOffsets.earlyGl = {earlyGlSfOffsetNs != -1 ? earlyGlSfOffsetNs
73 : sfVsyncPhaseOffsetNs,
74 earlyGlAppOffsetNs != -1 ? earlyGlAppOffsetNs
75 : vsyncPhaseOffsetNs};
76 mDefaultRefreshRateOffsets.late = {sfVsyncPhaseOffsetNs, vsyncPhaseOffsetNs};
77
78 mHighRefreshRateOffsets.early = {highFpsEarlySfOffsetNs != -1 ? highFpsEarlySfOffsetNs
Midas Chienccd3a952019-02-26 18:59:41 +080079 : highFpsLateSfOffsetNs,
Ana Krulec757f63a2019-01-25 10:46:18 -080080 highFpsEarlyAppOffsetNs != -1 ? highFpsEarlyAppOffsetNs
Midas Chienccd3a952019-02-26 18:59:41 +080081 : highFpsLateAppOffsetNs};
Ana Krulec757f63a2019-01-25 10:46:18 -080082 mHighRefreshRateOffsets.earlyGl = {highFpsEarlyGlSfOffsetNs != -1 ? highFpsEarlyGlSfOffsetNs
Midas Chienccd3a952019-02-26 18:59:41 +080083 : highFpsLateSfOffsetNs,
Ana Krulec757f63a2019-01-25 10:46:18 -080084 highFpsEarlyGlAppOffsetNs != -1 ? highFpsEarlyGlAppOffsetNs
Midas Chienccd3a952019-02-26 18:59:41 +080085 : highFpsLateAppOffsetNs};
Ady Abraham482b4b12019-02-07 19:01:25 -080086 mHighRefreshRateOffsets.late = {highFpsLateSfOffsetNs, highFpsLateAppOffsetNs};
Ana Krulec757f63a2019-01-25 10:46:18 -080087}
88
Ady Abraham796beb02019-04-11 15:23:07 -070089PhaseOffsets::Offsets PhaseOffsets::getOffsetsForRefreshRate(
90 android::scheduler::RefreshRateConfigs::RefreshRateType refreshRateType) const {
91 switch (refreshRateType) {
Ana Krulec757f63a2019-01-25 10:46:18 -080092 case RefreshRateConfigs::RefreshRateType::PERFORMANCE:
93 return mHighRefreshRateOffsets;
94 default:
95 return mDefaultRefreshRateOffsets;
96 }
97}
98
99void PhaseOffsets::dump(std::string& result) const {
100 const auto [early, earlyGl, late] = getCurrentOffsets();
101 base::StringAppendF(&result,
102 " app phase: %9" PRId64 " ns\t SF phase: %9" PRId64 " ns\n"
103 " early app phase: %9" PRId64 " ns\t early SF phase: %9" PRId64 " ns\n"
104 "GL early app phase: %9" PRId64 " ns\tGL early SF phase: %9" PRId64 " ns\n",
105 late.app, late.sf, early.app, early.sf, earlyGl.app, earlyGl.sf);
106}
107
108nsecs_t PhaseOffsets::getCurrentAppOffset() {
109 return getCurrentOffsets().late.app;
110}
111
112nsecs_t PhaseOffsets::getCurrentSfOffset() {
113 return getCurrentOffsets().late.sf;
114}
115
116} // namespace impl
117} // namespace scheduler
118} // namespace android