blob: 13e992a4e1e743c7aeb97807548d2cad9c65a375 [file] [log] [blame]
ramindani1cb794e2021-10-13 20:45:23 +00001/**
2 * Copyright (c) 2021, 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#pragma once
17
ramindanideb059e2021-11-18 01:57:25 +000018#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
ramindani1cb794e2021-10-13 20:45:23 +000019#include <android-base/thread_annotations.h>
20#include <mutex>
ramindani7ce70fe2022-02-10 18:08:09 +000021#include <vector>
ramindani1cb794e2021-10-13 20:45:23 +000022
ramindani1cb794e2021-10-13 20:45:23 +000023namespace aidl::android::hardware::graphics::composer3::vts {
24
ramindanideb059e2021-11-18 01:57:25 +000025class GraphicsComposerCallback : public BnComposerCallback {
ramindani1cb794e2021-10-13 20:45:23 +000026 public:
27 void setVsyncAllowed(bool allowed);
28
ramindani9dd8c482023-02-21 18:07:56 -080029 void setRefreshRateChangedDebugDataEnabledCallbackAllowed(bool allowed);
30
ramindani1cb794e2021-10-13 20:45:23 +000031 std::vector<int64_t> getDisplays() const;
32
33 int32_t getInvalidHotplugCount() const;
34
35 int32_t getInvalidRefreshCount() const;
36
37 int32_t getInvalidVsyncCount() const;
38
39 int32_t getInvalidVsyncPeriodChangeCount() const;
40
41 int32_t getInvalidSeamlessPossibleCount() const;
42
Midas Chiena0b56bd2022-01-13 23:27:33 +080043 int32_t getVsyncIdleCount() const;
44
45 int64_t getVsyncIdleTime() const;
46
ramindani1cb794e2021-10-13 20:45:23 +000047 std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline();
48
ramindani9dd8c482023-02-21 18:07:56 -080049 std::vector<RefreshRateChangedDebugData> takeListOfRefreshRateChangedDebugData();
50
51 int32_t getInvalidRefreshRateDebugEnabledCallbackCount() const;
52
ramindani1cb794e2021-10-13 20:45:23 +000053 private:
54 virtual ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override;
55 virtual ::ndk::ScopedAStatus onRefresh(int64_t in_display) override;
56 virtual ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override;
57 virtual ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp,
58 int32_t in_vsyncPeriodNanos) override;
59 virtual ::ndk::ScopedAStatus onVsyncPeriodTimingChanged(
60 int64_t in_display,
61 const ::aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline&
62 in_updatedTimeline) override;
Midas Chiena0b56bd2022-01-13 23:27:33 +080063 virtual ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override;
ramindani83450342023-02-03 12:52:08 -080064 virtual ::ndk::ScopedAStatus onRefreshRateChangedDebug(
65 const RefreshRateChangedDebugData&) override;
ramindani1cb794e2021-10-13 20:45:23 +000066
ramindani1cb794e2021-10-13 20:45:23 +000067 mutable std::mutex mMutex;
68 // the set of all currently connected displays
ramindani7ce70fe2022-02-10 18:08:09 +000069 std::vector<int64_t> mDisplays GUARDED_BY(mMutex);
ramindani1cb794e2021-10-13 20:45:23 +000070 // true only when vsync is enabled
71 bool mVsyncAllowed GUARDED_BY(mMutex) = true;
ramindani9dd8c482023-02-21 18:07:56 -080072 // true only when RefreshRateChangedCallbackDebugEnabled is set to true.
73 bool mRefreshRateChangedDebugDataEnabledCallbackAllowed GUARDED_BY(mMutex) = false;
ramindani1cb794e2021-10-13 20:45:23 +000074
75 std::optional<VsyncPeriodChangeTimeline> mTimeline GUARDED_BY(mMutex);
76
ramindani9dd8c482023-02-21 18:07:56 -080077 std::vector<RefreshRateChangedDebugData> mRefreshRateChangedDebugData GUARDED_BY(mMutex);
78
Midas Chiena0b56bd2022-01-13 23:27:33 +080079 int32_t mVsyncIdleCount GUARDED_BY(mMutex) = 0;
80 int64_t mVsyncIdleTime GUARDED_BY(mMutex) = 0;
81
ramindani1cb794e2021-10-13 20:45:23 +000082 // track invalid callbacks
83 int32_t mInvalidHotplugCount GUARDED_BY(mMutex) = 0;
84 int32_t mInvalidRefreshCount GUARDED_BY(mMutex) = 0;
85 int32_t mInvalidVsyncCount GUARDED_BY(mMutex) = 0;
86 int32_t mInvalidVsyncPeriodChangeCount GUARDED_BY(mMutex) = 0;
87 int32_t mInvalidSeamlessPossibleCount GUARDED_BY(mMutex) = 0;
ramindani9dd8c482023-02-21 18:07:56 -080088 int32_t mInvalidRefreshRateDebugEnabledCallbackCount GUARDED_BY(mMutex) = 0;
ramindani1cb794e2021-10-13 20:45:23 +000089};
90
Midas Chiena0b56bd2022-01-13 23:27:33 +080091} // namespace aidl::android::hardware::graphics::composer3::vts