1 /*
2  * Copyright 2024 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 <gmock/gmock.h>
20 
21 #include "DisplayHardware/HWComposer.h"
22 
23 namespace android::mock {
24 
25 class HWComposer : public android::HWComposer {
26 public:
27     using HWDisplayId = android::hardware::graphics::composer::hal::HWDisplayId;
28     using PowerMode = android::hardware::graphics::composer::hal::PowerMode;
29 
30     HWComposer();
31     ~HWComposer() override;
32 
33     MOCK_METHOD(void, setCallback, (HWC2::ComposerCallback&), (override));
34     MOCK_METHOD(bool, getDisplayIdentificationData,
35                 (HWDisplayId, uint8_t*, DisplayIdentificationData*), (const, override));
36     MOCK_METHOD(bool, hasCapability, (aidl::android::hardware::graphics::composer3::Capability),
37                 (const, override));
38     MOCK_METHOD(bool, hasDisplayCapability,
39                 (HalDisplayId, aidl::android::hardware::graphics::composer3::DisplayCapability),
40                 (const, override));
41 
42     MOCK_METHOD(size_t, getMaxVirtualDisplayCount, (), (const, override));
43     MOCK_METHOD(size_t, getMaxVirtualDisplayDimension, (), (const, override));
44     MOCK_METHOD(bool, allocateVirtualDisplay, (HalVirtualDisplayId, ui::Size, ui::PixelFormat*),
45                 (override));
46     MOCK_METHOD(void, allocatePhysicalDisplay,
47                 (hal::HWDisplayId, PhysicalDisplayId, std::optional<ui::Size>), (override));
48 
49     MOCK_METHOD(std::shared_ptr<HWC2::Layer>, createLayer, (HalDisplayId), (override));
50     MOCK_METHOD(status_t, getDeviceCompositionChanges,
51                 (HalDisplayId, bool, std::optional<std::chrono::steady_clock::time_point>, nsecs_t,
52                  Fps, std::optional<android::HWComposer::DeviceRequestedChanges>*));
53     MOCK_METHOD(status_t, setClientTarget,
54                 (HalDisplayId, uint32_t, const sp<Fence>&, const sp<GraphicBuffer>&, ui::Dataspace,
55                  float),
56                 (override));
57     MOCK_METHOD(status_t, presentAndGetReleaseFences,
58                 (HalDisplayId, std::optional<std::chrono::steady_clock::time_point>), (override));
59     MOCK_METHOD(status_t, executeCommands, (HalDisplayId));
60     MOCK_METHOD(status_t, setPowerMode, (PhysicalDisplayId, PowerMode), (override));
61     MOCK_METHOD(status_t, setColorTransform, (HalDisplayId, const mat4&), (override));
62     MOCK_METHOD(void, disconnectDisplay, (HalDisplayId), (override));
63     MOCK_METHOD(sp<Fence>, getPresentFence, (HalDisplayId), (const, override));
64     MOCK_METHOD(nsecs_t, getPresentTimestamp, (PhysicalDisplayId), (const, override));
65     MOCK_METHOD(sp<Fence>, getLayerReleaseFence, (HalDisplayId, HWC2::Layer*), (const, override));
66     MOCK_METHOD(status_t, setOutputBuffer,
67                 (HalVirtualDisplayId, const sp<Fence>&, const sp<GraphicBuffer>&), (override));
68     MOCK_METHOD(void, clearReleaseFences, (HalDisplayId), (override));
69     MOCK_METHOD(status_t, getHdrCapabilities, (HalDisplayId, HdrCapabilities*), (override));
70     MOCK_METHOD(int32_t, getSupportedPerFrameMetadata, (HalDisplayId), (const, override));
71     MOCK_METHOD(std::vector<ui::RenderIntent>, getRenderIntents, (HalDisplayId, ui::ColorMode),
72                 (const, override));
73     MOCK_METHOD(mat4, getDataspaceSaturationMatrix, (HalDisplayId, ui::Dataspace), (override));
74     MOCK_METHOD(status_t, getDisplayedContentSamplingAttributes,
75                 (HalDisplayId, ui::PixelFormat*, ui::Dataspace*, uint8_t*), (override));
76     MOCK_METHOD(status_t, setDisplayContentSamplingEnabled, (HalDisplayId, bool, uint8_t, uint64_t),
77                 (override));
78     MOCK_METHOD(status_t, getDisplayedContentSample,
79                 (HalDisplayId, uint64_t, uint64_t, DisplayedFrameStats*), (override));
80     MOCK_METHOD(ftl::Future<status_t>, setDisplayBrightness,
81                 (PhysicalDisplayId, float, float, const Hwc2::Composer::DisplayBrightnessOptions&),
82                 (override));
83     MOCK_METHOD(std::optional<DisplayIdentificationInfo>, onHotplug,
84                 (hal::HWDisplayId, hal::Connection), (override));
85     MOCK_METHOD(bool, updatesDeviceProductInfoOnHotplugReconnect, (), (const, override));
86     MOCK_METHOD(std::optional<PhysicalDisplayId>, onVsync, (hal::HWDisplayId, int64_t));
87     MOCK_METHOD(void, setVsyncEnabled, (PhysicalDisplayId, hal::Vsync), (override));
88     MOCK_METHOD(bool, isConnected, (PhysicalDisplayId), (const, override));
89     MOCK_METHOD(std::vector<HWComposer::HWCDisplayMode>, getModes, (PhysicalDisplayId, int32_t),
90                 (const, override));
91     MOCK_METHOD((ftl::Expected<hal::HWConfigId, status_t>), getActiveMode, (PhysicalDisplayId),
92                 (const, override));
93     MOCK_METHOD(std::vector<ui::ColorMode>, getColorModes, (PhysicalDisplayId), (const, override));
94     MOCK_METHOD(status_t, setActiveColorMode, (PhysicalDisplayId, ui::ColorMode, ui::RenderIntent),
95                 (override));
96     MOCK_METHOD(ui::DisplayConnectionType, getDisplayConnectionType, (PhysicalDisplayId),
97                 (const, override));
98     MOCK_METHOD(bool, isVsyncPeriodSwitchSupported, (PhysicalDisplayId), (const, override));
99     MOCK_METHOD((ftl::Expected<nsecs_t, status_t>), getDisplayVsyncPeriod, (PhysicalDisplayId),
100                 (const, override));
101     MOCK_METHOD(status_t, setActiveModeWithConstraints,
102                 (PhysicalDisplayId, hal::HWConfigId, const hal::VsyncPeriodChangeConstraints&,
103                  hal::VsyncPeriodChangeTimeline*),
104                 (override));
105     MOCK_METHOD(status_t, setBootDisplayMode, (PhysicalDisplayId, hal::HWConfigId), (override));
106     MOCK_METHOD(status_t, clearBootDisplayMode, (PhysicalDisplayId), (override));
107     MOCK_METHOD(std::optional<hal::HWConfigId>, getPreferredBootDisplayMode, (PhysicalDisplayId),
108                 (override));
109 
110     MOCK_METHOD(std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>,
111                 getHdrConversionCapabilities, (), (const, override));
112     MOCK_METHOD(status_t, setHdrConversionStrategy,
113                 (aidl::android::hardware::graphics::common::HdrConversionStrategy,
114                  aidl::android::hardware::graphics::common::Hdr*),
115                 (override));
116     MOCK_METHOD(status_t, setAutoLowLatencyMode, (PhysicalDisplayId, bool), (override));
117     MOCK_METHOD(status_t, getSupportedContentTypes,
118                 (PhysicalDisplayId, std::vector<hal::ContentType>*), (const, override));
119     MOCK_METHOD(status_t, setContentType, (PhysicalDisplayId, hal::ContentType)), (override);
120     MOCK_METHOD((const std::unordered_map<std::string, bool>&), getSupportedLayerGenericMetadata,
121                 (), (const, override));
122     MOCK_METHOD(void, dump, (std::string&), (const, override));
123     MOCK_METHOD(void, dumpOverlayProperties, (std::string&), (const, override));
124     MOCK_METHOD(android::Hwc2::Composer*, getComposer, (), (const, override));
125 
126     MOCK_METHOD(hal::HWDisplayId, getPrimaryHwcDisplayId, (), (const, override));
127     MOCK_METHOD(PhysicalDisplayId, getPrimaryDisplayId, (), (const, override));
128     MOCK_METHOD(bool, isHeadless, (), (const, override));
129 
130     MOCK_METHOD(std::optional<PhysicalDisplayId>, toPhysicalDisplayId, (hal::HWDisplayId),
131                 (const, override));
132     MOCK_METHOD(std::optional<hal::HWDisplayId>, fromPhysicalDisplayId, (PhysicalDisplayId),
133                 (const, override));
134     MOCK_METHOD(status_t, getDisplayDecorationSupport,
135                 (PhysicalDisplayId,
136                  std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
137                          support),
138                 (override));
139     MOCK_METHOD(status_t, setIdleTimerEnabled, (PhysicalDisplayId, std::chrono::milliseconds),
140                 (override));
141     MOCK_METHOD(bool, hasDisplayIdleTimerCapability, (PhysicalDisplayId), (const, override));
142     MOCK_METHOD(Hwc2::AidlTransform, getPhysicalDisplayOrientation, (PhysicalDisplayId),
143                 (const, override));
144     MOCK_METHOD(bool, getValidateSkipped, (HalDisplayId), (const, override));
145     MOCK_METHOD(const aidl::android::hardware::graphics::composer3::OverlayProperties&,
146                 getOverlaySupport, (), (const, override));
147     MOCK_METHOD(status_t, setRefreshRateChangedCallbackDebugEnabled, (PhysicalDisplayId, bool));
148     MOCK_METHOD(status_t, notifyExpectedPresent, (PhysicalDisplayId, TimePoint, Fps));
149     MOCK_METHOD(HWC2::Display::LutFileDescriptorMapper&, getLutFileDescriptorMapper, (),
150                 (override));
151     MOCK_METHOD(int32_t, getMaxLayerPictureProfiles, (PhysicalDisplayId));
152     MOCK_METHOD(status_t, setDisplayPictureProfileHandle,
153                 (PhysicalDisplayId, const PictureProfileHandle&));
154 };
155 
156 } // namespace android::mock
157