xref: /aosp_15_r20/hardware/interfaces/graphics/composer/aidl/vts/GraphicsComposerCallback.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /**
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 
18 #include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>
19 #include <android-base/thread_annotations.h>
20 #include <mutex>
21 #include <vector>
22 
23 namespace aidl::android::hardware::graphics::composer3::vts {
24 
25 class GraphicsComposerCallback : public BnComposerCallback {
26   public:
27     void setVsyncAllowed(bool allowed);
28 
29     void setRefreshRateChangedDebugDataEnabledCallbackAllowed(bool allowed);
30 
31     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 
43     int32_t getVsyncIdleCount() const;
44 
45     int64_t getVsyncIdleTime() const;
46 
47     std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline();
48 
49     std::vector<RefreshRateChangedDebugData> takeListOfRefreshRateChangedDebugData();
50 
51     int32_t getInvalidRefreshRateDebugEnabledCallbackCount() const;
52 
53   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;
63     virtual ::ndk::ScopedAStatus onVsyncIdle(int64_t in_display) override;
64     virtual ::ndk::ScopedAStatus onRefreshRateChangedDebug(
65             const RefreshRateChangedDebugData&) override;
66     virtual ::ndk::ScopedAStatus onHotplugEvent(int64_t in_display,
67                                                 common::DisplayHotplugEvent) override;
68     virtual ::ndk::ScopedAStatus onHdcpLevelsChanged(
69             int64_t in_display, const ::aidl::android::hardware::drm::HdcpLevels&) override;
70 
71     mutable std::mutex mMutex;
72     // the set of all currently connected displays
73     std::vector<int64_t> mDisplays GUARDED_BY(mMutex);
74     // true only when vsync is enabled
75     bool mVsyncAllowed GUARDED_BY(mMutex) = true;
76     // true only when RefreshRateChangedCallbackDebugEnabled is set to true.
77     bool mRefreshRateChangedDebugDataEnabledCallbackAllowed GUARDED_BY(mMutex) = false;
78 
79     std::optional<VsyncPeriodChangeTimeline> mTimeline GUARDED_BY(mMutex);
80 
81     std::vector<RefreshRateChangedDebugData> mRefreshRateChangedDebugData GUARDED_BY(mMutex);
82 
83     int32_t mVsyncIdleCount GUARDED_BY(mMutex) = 0;
84     int64_t mVsyncIdleTime GUARDED_BY(mMutex) = 0;
85 
86     // track invalid callbacks
87     int32_t mInvalidHotplugCount GUARDED_BY(mMutex) = 0;
88     int32_t mInvalidRefreshCount GUARDED_BY(mMutex) = 0;
89     int32_t mInvalidVsyncCount GUARDED_BY(mMutex) = 0;
90     int32_t mInvalidVsyncPeriodChangeCount GUARDED_BY(mMutex) = 0;
91     int32_t mInvalidSeamlessPossibleCount GUARDED_BY(mMutex) = 0;
92     int32_t mInvalidRefreshRateDebugEnabledCallbackCount GUARDED_BY(mMutex) = 0;
93     int32_t mHdcpLevelChangedCount GUARDED_BY(mMutex) = 0;
94 };
95 
96 }  // namespace aidl::android::hardware::graphics::composer3::vts
97