blob: 278f87c30f2bfd6cc39adc5258744115dd29d1ce [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);
35 std::vector<FrameRateOverride> getAllFrameRateOverrides() EXCLUDES(mFrameRateOverridesLock);
36 void dump(std::string& result) const;
37 bool updateFrameRateOverridesByContent(const UidToFrameRateOverride& frameRateOverrides)
38 EXCLUDES(mFrameRateOverridesLock);
39 void setGameModeRefreshRateForUid(FrameRateOverride frameRateOverride)
40 EXCLUDES(mFrameRateOverridesLock);
41 void setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride)
42 EXCLUDES(mFrameRateOverridesLock);
43
44private:
45 // The frame rate override lists need their own mutex as they are being read
46 // by SurfaceFlinger, Scheduler and EventThread (as a callback) to prevent deadlocks
47 mutable std::mutex mFrameRateOverridesLock;
48
49 // mappings between a UID and a preferred refresh rate that this app would
50 // run at.
51 UidToFrameRateOverride mFrameRateOverridesByContent GUARDED_BY(mFrameRateOverridesLock);
52 UidToFrameRateOverride mFrameRateOverridesFromBackdoor GUARDED_BY(mFrameRateOverridesLock);
53 UidToFrameRateOverride mFrameRateOverridesFromGameManager GUARDED_BY(mFrameRateOverridesLock);
54};
55} // namespace android::scheduler