blob: bdb9959b1ca7e54d03d7e70fc984858820ef04db [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
Matt Buckley191f5cc2023-03-30 20:58:22 +000021#include <future>
22
Matt Buckleye9023cf2022-11-23 22:39:25 +000023#include "utils/TimeUtils.h"
24
25namespace android {
26namespace uirenderer {
27
28namespace renderthread {
29
30class HintSessionWrapper {
31public:
32 HintSessionWrapper(pid_t uiThreadId, pid_t renderThreadId);
33 ~HintSessionWrapper();
34
35 void updateTargetWorkDuration(long targetDurationNanos);
36 void reportActualWorkDuration(long actualDurationNanos);
37 void sendLoadResetHint();
Matt Buckleyac5f7552022-12-19 22:03:27 +000038 void sendLoadIncreaseHint();
Matt Buckley124d0c672023-01-19 03:04:19 +000039 bool init();
Matt Buckleyac620f62023-08-24 15:56:46 +000040 void destroy();
Matt Buckleye9023cf2022-11-23 22:39:25 +000041
42private:
Matt Buckleye9023cf2022-11-23 22:39:25 +000043 APerformanceHintSession* mHintSession = nullptr;
Matt Buckley191f5cc2023-03-30 20:58:22 +000044 std::future<APerformanceHintSession*> mHintSessionFuture;
Matt Buckleye9023cf2022-11-23 22:39:25 +000045
Matt Buckley814f9fc2023-05-03 14:32:11 +000046 int mResetsSinceLastReport = 0;
Matt Buckleye9023cf2022-11-23 22:39:25 +000047 nsecs_t mLastFrameNotification = 0;
48 nsecs_t mLastTargetWorkDuration = 0;
49
50 pid_t mUiThreadId;
51 pid_t mRenderThreadId;
52
53 bool mSessionValid = true;
54
55 static constexpr nsecs_t kResetHintTimeout = 100_ms;
56 static constexpr int64_t kSanityCheckLowerBound = 100_us;
57 static constexpr int64_t kSanityCheckUpperBound = 10_s;
58};
59
60} /* namespace renderthread */
61} /* namespace uirenderer */
62} /* namespace android */