• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 
17 #pragma once
18 
19 #include <utils/Condition.h>
20 #include <chrono>
21 #include <vector>
22 
23 #include <android/hardware/graphics/composer/2.4/IComposer.h>
24 #include <composer-hal/2.1/ComposerClient.h>
25 #include <composer-hal/2.2/ComposerClient.h>
26 #include <composer-hal/2.3/ComposerClient.h>
27 #include <composer-hal/2.4/ComposerClient.h>
28 
29 #include "DisplayHardware/HWC2.h"
30 #include "surfaceflinger_fuzzers_utils.h"
31 
32 namespace {
33 class LayerImpl;
34 class Frame;
35 class DelayedEventGenerator;
36 } // namespace
37 
38 namespace android {
39 class SurfaceComposerClient;
40 } // namespace android
41 
42 namespace android::hardware::graphics::composer::hal {
43 
44 using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData;
45 using ::android::hardware::Return;
46 using ::android::hardware::Void;
47 using ::android::HWC2::ComposerCallback;
48 
49 class ComposerCallbackBridge : public IComposerCallback {
50 public:
ComposerCallbackBridge(ComposerCallback * callback,bool vsyncSwitchingSupported)51     ComposerCallbackBridge(ComposerCallback* callback, bool vsyncSwitchingSupported)
52           : mCallback(callback), mVsyncSwitchingSupported(vsyncSwitchingSupported) {}
53 
onHotplug(HWDisplayId display,Connection connection)54     Return<void> onHotplug(HWDisplayId display, Connection connection) override {
55         mCallback->onComposerHalHotplug(display, connection);
56         return Void();
57     }
58 
onRefresh(HWDisplayId display)59     Return<void> onRefresh(HWDisplayId display) override {
60         mCallback->onComposerHalRefresh(display);
61         return Void();
62     }
63 
onVsync(HWDisplayId display,int64_t timestamp)64     Return<void> onVsync(HWDisplayId display, int64_t timestamp) override {
65         if (!mVsyncSwitchingSupported) {
66             mCallback->onComposerHalVsync(display, timestamp, std::nullopt);
67         }
68         return Void();
69     }
70 
onVsync_2_4(HWDisplayId display,int64_t timestamp,VsyncPeriodNanos vsyncPeriodNanos)71     Return<void> onVsync_2_4(HWDisplayId display, int64_t timestamp,
72                              VsyncPeriodNanos vsyncPeriodNanos) override {
73         if (mVsyncSwitchingSupported) {
74             mCallback->onComposerHalVsync(display, timestamp, vsyncPeriodNanos);
75         }
76         return Void();
77     }
78 
onVsyncPeriodTimingChanged(HWDisplayId display,const VsyncPeriodChangeTimeline & timeline)79     Return<void> onVsyncPeriodTimingChanged(HWDisplayId display,
80                                             const VsyncPeriodChangeTimeline& timeline) override {
81         mCallback->onComposerHalVsyncPeriodTimingChanged(display, timeline);
82         return Void();
83     }
84 
onSeamlessPossible(HWDisplayId display)85     Return<void> onSeamlessPossible(HWDisplayId display) override {
86         mCallback->onComposerHalSeamlessPossible(display);
87         return Void();
88     }
89 
90 private:
91     ComposerCallback* const mCallback;
92     const bool mVsyncSwitchingSupported;
93 };
94 
95 struct TestHWC2ComposerCallback : public HWC2::ComposerCallback {
96     virtual ~TestHWC2ComposerCallback() = default;
onComposerHalHotplugTestHWC2ComposerCallback97     void onComposerHalHotplug(HWDisplayId, Connection){};
onComposerHalRefreshTestHWC2ComposerCallback98     void onComposerHalRefresh(HWDisplayId) {}
onComposerHalVsyncTestHWC2ComposerCallback99     void onComposerHalVsync(HWDisplayId, int64_t, std::optional<VsyncPeriodNanos>) {}
onComposerHalVsyncPeriodTimingChangedTestHWC2ComposerCallback100     void onComposerHalVsyncPeriodTimingChanged(HWDisplayId, const VsyncPeriodChangeTimeline&) {}
onComposerHalSeamlessPossibleTestHWC2ComposerCallback101     void onComposerHalSeamlessPossible(HWDisplayId) {}
onComposerHalVsyncIdleTestHWC2ComposerCallback102     void onComposerHalVsyncIdle(HWDisplayId) {}
onRefreshRateChangedDebugTestHWC2ComposerCallback103     void onRefreshRateChangedDebug(const RefreshRateChangedDebugData&) {}
104 };
105 
106 } // namespace android::hardware::graphics::composer::hal
107