blob: c0f7a57bed754529d5221c0cea642e5107336f08 [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 Buckleye9023cf2022-11-23 22:39:25 +000037
38private:
39 bool useHintSession();
40 bool init();
41 APerformanceHintSession* mHintSession = nullptr;
42
43 nsecs_t mLastFrameNotification = 0;
44 nsecs_t mLastTargetWorkDuration = 0;
45
46 pid_t mUiThreadId;
47 pid_t mRenderThreadId;
48
49 bool mSessionValid = true;
50
51 static constexpr nsecs_t kResetHintTimeout = 100_ms;
52 static constexpr int64_t kSanityCheckLowerBound = 100_us;
53 static constexpr int64_t kSanityCheckUpperBound = 10_s;
54};
55
56} /* namespace renderthread */
57} /* namespace uirenderer */
58} /* namespace android */