1 /* 2 * Copyright 2023 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 <chrono> 20 21 #include <utils/Timers.h> 22 23 namespace android::scheduler { 24 25 using namespace std::chrono_literals; 26 27 // Phase offsets and work durations for SF and app deadlines from VSYNC. 28 struct VsyncConfig { 29 nsecs_t sfOffset; 30 nsecs_t appOffset; 31 std::chrono::nanoseconds sfWorkDuration; 32 std::chrono::nanoseconds appWorkDuration; 33 34 bool operator==(const VsyncConfig& other) const { 35 return sfOffset == other.sfOffset && appOffset == other.appOffset && 36 sfWorkDuration == other.sfWorkDuration && appWorkDuration == other.appWorkDuration; 37 } 38 39 bool operator!=(const VsyncConfig& other) const { return !(*this == other); } 40 41 // The duration for which SF can delay a frame if it is considered early based on the 42 // VsyncConfig::appWorkDuration. 43 static constexpr std::chrono::nanoseconds kEarlyLatchMaxThreshold = 100ms; 44 }; 45 46 struct VsyncConfigSet { 47 VsyncConfig early; // Used for early transactions, and during refresh rate change. 48 VsyncConfig earlyGpu; // Used during GPU composition. 49 VsyncConfig late; // Default. 50 std::chrono::nanoseconds hwcMinWorkDuration; // Used for calculating the earliest present time. 51 52 bool operator==(const VsyncConfigSet& other) const { 53 return early == other.early && earlyGpu == other.earlyGpu && late == other.late && 54 hwcMinWorkDuration == other.hwcMinWorkDuration; 55 } 56 57 bool operator!=(const VsyncConfigSet& other) const { return !(*this == other); } 58 }; 59 60 } // namespace android::scheduler 61