blob: 4185a4c0ab494242d430c4dcb87554d030ba2ec8 [file] [log] [blame]
Andy Yu2ae6b6b2021-11-18 14:51:06 -08001/*
2 * Copyright 2022 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 <android-base/thread_annotations.h>
20#include <gui/DisplayEventReceiver.h>
21#include <scheduler/Fps.h>
22#include <sys/types.h>
23#include <map>
24#include <optional>
25
26namespace android::scheduler {
27class FrameRateOverrideMappings {
28 using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;
29 using UidToFrameRateOverride = std::map<uid_t, Fps>;
30
31public:
32 std::optional<Fps> getFrameRateOverrideForUid(uid_t uid,
33 bool supportsFrameRateOverrideByContent) const
34 EXCLUDES(mFrameRateOverridesLock);
Andy Yud6a36202022-01-26 04:08:22 -080035 std::vector<FrameRateOverride> getAllFrameRateOverrides(bool supportsFrameRateOverrideByContent)
36 EXCLUDES(mFrameRateOverridesLock);
Andy Yu2ae6b6b2021-11-18 14:51:06 -080037 void dump(std::string& result) const;
38 bool updateFrameRateOverridesByContent(const UidToFrameRateOverride& frameRateOverrides)
39 EXCLUDES(mFrameRateOverridesLock);
40 void setGameModeRefreshRateForUid(FrameRateOverride frameRateOverride)
41 EXCLUDES(mFrameRateOverridesLock);
42 void setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride)
43 EXCLUDES(mFrameRateOverridesLock);
44
45private:
46 // The frame rate override lists need their own mutex as they are being read
47 // by SurfaceFlinger, Scheduler and EventThread (as a callback) to prevent deadlocks
48 mutable std::mutex mFrameRateOverridesLock;
49
50 // mappings between a UID and a preferred refresh rate that this app would
51 // run at.
52 UidToFrameRateOverride mFrameRateOverridesByContent GUARDED_BY(mFrameRateOverridesLock);
53 UidToFrameRateOverride mFrameRateOverridesFromBackdoor GUARDED_BY(mFrameRateOverridesLock);
54 UidToFrameRateOverride mFrameRateOverridesFromGameManager GUARDED_BY(mFrameRateOverridesLock);
55};
56} // namespace android::scheduler