blob: f2f1298c1eec7546507ccf4b3346c531fd426a7b [file] [log] [blame]
Matt Buckleye9023cf2022-11-23 22:39:25 +00001/*
2 * Copyright (C) 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/performance_hint.h>
20
21#include "utils/TimeUtils.h"
22
23namespace android {
24namespace uirenderer {
25
26namespace renderthread {
27
28class HintSessionWrapper {
29public:
30 HintSessionWrapper(pid_t uiThreadId, pid_t renderThreadId);
31 ~HintSessionWrapper();
32
33 void updateTargetWorkDuration(long targetDurationNanos);
34 void reportActualWorkDuration(long actualDurationNanos);
35 void sendLoadResetHint();
Matt Buckleyac5f7552022-12-19 22:03:27 +000036 void sendLoadIncreaseHint();
Matt Buckley124d0c672023-01-19 03:04:19 +000037 bool init();
Matt Buckleye9023cf2022-11-23 22:39:25 +000038
39private:
Matt Buckleye9023cf2022-11-23 22:39:25 +000040 APerformanceHintSession* mHintSession = nullptr;
41
42 nsecs_t mLastFrameNotification = 0;
43 nsecs_t mLastTargetWorkDuration = 0;
44
45 pid_t mUiThreadId;
46 pid_t mRenderThreadId;
47
48 bool mSessionValid = true;
49
50 static constexpr nsecs_t kResetHintTimeout = 100_ms;
51 static constexpr int64_t kSanityCheckLowerBound = 100_us;
52 static constexpr int64_t kSanityCheckUpperBound = 10_s;
53};
54
55} /* namespace renderthread */
56} /* namespace uirenderer */
57} /* namespace android */