blob: fcbc10185255bad8c77c270a684731084eb0f7f4 [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();
36
37private:
38 bool useHintSession();
39 bool init();
40 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 */