1 /*
2  * Copyright (C) 2018 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/ComposerHal.h"
22 #include "DisplayHardware/HWC2.h"
23 
24 namespace android {
25 
26 class GraphicBuffer;
27 
28 namespace Hwc2::mock {
29 
30 using android::hardware::graphics::common::V1_0::ColorTransform;
31 using android::hardware::graphics::common::V1_0::Transform;
32 using android::hardware::graphics::common::V1_1::RenderIntent;
33 using android::hardware::graphics::common::V1_2::ColorMode;
34 using android::hardware::graphics::common::V1_2::Dataspace;
35 using android::hardware::graphics::common::V1_2::PixelFormat;
36 
37 using android::hardware::graphics::composer::V2_1::Config;
38 using android::hardware::graphics::composer::V2_1::Display;
39 using android::hardware::graphics::composer::V2_1::Error;
40 using android::hardware::graphics::composer::V2_1::IComposer;
41 using android::hardware::graphics::composer::V2_1::Layer;
42 using android::hardware::graphics::composer::V2_4::IComposerCallback;
43 using android::hardware::graphics::composer::V2_4::IComposerClient;
44 
45 using aidl::android::hardware::graphics::common::DisplayDecorationSupport;
46 
47 class Composer : public Hwc2::Composer {
48 public:
49     using Display = android::hardware::graphics::composer::V2_1::Display;
50     Composer();
51     ~Composer() override;
52 
53     MOCK_METHOD(bool, isSupported, (OptionalFeature), (const, override));
54     MOCK_METHOD(bool, isVrrSupported, (), (const, override));
55     MOCK_METHOD0(getCapabilities,
56                  std::vector<aidl::android::hardware::graphics::composer3::Capability>());
57     MOCK_METHOD0(dumpDebugInfo, std::string());
58     MOCK_METHOD1(registerCallback, void(HWC2::ComposerCallback&));
59     MOCK_METHOD1(executeCommands, Error(Display));
60     MOCK_METHOD0(getMaxVirtualDisplayCount, uint32_t());
61     MOCK_METHOD4(createVirtualDisplay, Error(uint32_t, uint32_t, PixelFormat*, Display*));
62     MOCK_METHOD1(destroyVirtualDisplay, Error(Display));
63     MOCK_METHOD1(acceptDisplayChanges, Error(Display));
64     MOCK_METHOD2(createLayer, Error(Display, Layer* outLayer));
65     MOCK_METHOD2(destroyLayer, Error(Display, Layer));
66     MOCK_METHOD2(getActiveConfig, Error(Display, Config*));
67     MOCK_METHOD3(getChangedCompositionTypes,
68                  Error(Display, std::vector<Layer>*,
69                        std::vector<aidl::android::hardware::graphics::composer3::Composition>*));
70     MOCK_METHOD2(getColorModes, Error(Display, std::vector<ColorMode>*));
71     MOCK_METHOD4(getDisplayAttribute,
72                  Error(Display, Config config, IComposerClient::Attribute, int32_t*));
73     MOCK_METHOD2(getDisplayConfigs, Error(Display, std::vector<Config>*));
74     MOCK_METHOD3(getDisplayConfigurations,
75                  Error(Display, int32_t, std::vector<DisplayConfiguration>*));
76     MOCK_METHOD2(getDisplayName, Error(Display, std::string*));
77     MOCK_METHOD4(getDisplayRequests,
78                  Error(Display, uint32_t*, std::vector<Layer>*, std::vector<uint32_t>*));
79     MOCK_METHOD2(getDozeSupport, Error(Display, bool*));
80     MOCK_METHOD2(getKernelIdleTimerSupport, Error(Display, bool*));
81     MOCK_METHOD5(getHdrCapabilities, Error(Display, std::vector<Hdr>*, float*, float*, float*));
82     MOCK_METHOD1(getPerFrameMetadataKeys,
83                  std::vector<IComposerClient::PerFrameMetadataKey>(Display));
84     MOCK_METHOD2(getDataspaceSaturationMatrix, Error(Dataspace, mat4*));
85     MOCK_METHOD3(getDisplayIdentificationData, Error(Display, uint8_t*, std::vector<uint8_t>*));
86     MOCK_METHOD3(getReleaseFences, Error(Display, std::vector<Layer>*, std::vector<int>*));
87     MOCK_METHOD2(presentDisplay, Error(Display, int*));
88     MOCK_METHOD2(setActiveConfig, Error(Display, Config));
89     MOCK_METHOD(Error, setClientTarget,
90                 (Display, uint32_t, const sp<GraphicBuffer>&, int, Dataspace,
91                  const std::vector<IComposerClient::Rect>&, float),
92                 (override));
93     MOCK_METHOD3(setColorMode, Error(Display, ColorMode, RenderIntent));
94     MOCK_METHOD2(setColorTransform, Error(Display, const float*));
95     MOCK_METHOD3(setOutputBuffer, Error(Display, const native_handle_t*, int));
96     MOCK_METHOD2(setPowerMode, Error(Display, IComposerClient::PowerMode));
97     MOCK_METHOD2(setVsyncEnabled, Error(Display, IComposerClient::Vsync));
98     MOCK_METHOD1(setClientTargetSlotCount, Error(Display));
99     MOCK_METHOD(Error, validateDisplay, (Display, nsecs_t, int32_t, uint32_t*, uint32_t*));
100     MOCK_METHOD(Error, presentOrValidateDisplay,
101                 (Display, nsecs_t, int32_t, uint32_t*, uint32_t*, int*, uint32_t*));
102     MOCK_METHOD4(setCursorPosition, Error(Display, Layer, int32_t, int32_t));
103     MOCK_METHOD5(setLayerBuffer, Error(Display, Layer, uint32_t, const sp<GraphicBuffer>&, int));
104     MOCK_METHOD4(setLayerBufferSlotsToClear,
105                  Error(Display, Layer, const std::vector<uint32_t>&, uint32_t));
106     MOCK_METHOD3(setLayerSurfaceDamage,
107                  Error(Display, Layer, const std::vector<IComposerClient::Rect>&));
108     MOCK_METHOD3(setLayerBlendMode, Error(Display, Layer, IComposerClient::BlendMode));
109     MOCK_METHOD3(setLayerColor,
110                  Error(Display, Layer, const aidl::android::hardware::graphics::composer3::Color&));
111     MOCK_METHOD3(setLayerCompositionType,
112                  Error(Display, Layer, aidl::android::hardware::graphics::composer3::Composition));
113     MOCK_METHOD3(setLayerDataspace, Error(Display, Layer, Dataspace));
114     MOCK_METHOD3(setLayerPerFrameMetadata,
115                  Error(Display, Layer, const std::vector<IComposerClient::PerFrameMetadata>&));
116     MOCK_METHOD3(setLayerDisplayFrame, Error(Display, Layer, const IComposerClient::Rect&));
117     MOCK_METHOD3(setLayerPlaneAlpha, Error(Display, Layer, float));
118     MOCK_METHOD3(setLayerSidebandStream, Error(Display, Layer, const native_handle_t*));
119     MOCK_METHOD3(setLayerSourceCrop, Error(Display, Layer, const IComposerClient::FRect&));
120     MOCK_METHOD3(setLayerTransform, Error(Display, Layer, Transform));
121     MOCK_METHOD3(setLayerVisibleRegion,
122                  Error(Display, Layer, const std::vector<IComposerClient::Rect>&));
123     MOCK_METHOD3(setLayerZOrder, Error(Display, Layer, uint32_t));
124     MOCK_METHOD3(getRenderIntents, Error(Display, ColorMode, std::vector<RenderIntent>*));
125     MOCK_METHOD3(setLayerColorTransform, Error(Display, Layer, const float*));
126     MOCK_METHOD4(getDisplayedContentSamplingAttributes,
127                  Error(Display, PixelFormat*, Dataspace*, uint8_t*));
128     MOCK_METHOD4(setDisplayContentSamplingEnabled, Error(Display, bool, uint8_t, uint64_t));
129     MOCK_METHOD4(getDisplayedContentSample,
130                  Error(Display, uint64_t, uint64_t, DisplayedFrameStats*));
131     MOCK_METHOD3(setLayerPerFrameMetadataBlobs,
132                  Error(Display, Layer, const std::vector<IComposerClient::PerFrameMetadataBlob>&));
133     MOCK_METHOD4(setDisplayBrightness,
134                  Error(Display, float, float, const DisplayBrightnessOptions&));
135     MOCK_METHOD2(
136             getDisplayCapabilities,
137             Error(Display,
138                   std::vector<aidl::android::hardware::graphics::composer3::DisplayCapability>*));
139     MOCK_METHOD2(getDisplayConnectionType,
140                  V2_4::Error(Display, IComposerClient::DisplayConnectionType*));
141     MOCK_METHOD3(getSupportedDisplayVsyncPeriods,
142                  V2_4::Error(Display, Config, std::vector<VsyncPeriodNanos>*));
143     MOCK_METHOD2(getDisplayVsyncPeriod, V2_4::Error(Display, VsyncPeriodNanos*));
144     MOCK_METHOD4(setActiveConfigWithConstraints,
145                  V2_4::Error(Display, Config, const IComposerClient::VsyncPeriodChangeConstraints&,
146                              VsyncPeriodChangeTimeline*));
147     MOCK_METHOD2(setAutoLowLatencyMode, V2_4::Error(Display, bool));
148     MOCK_METHOD2(setBootDisplayConfig, Error(Display, Config));
149     MOCK_METHOD1(clearBootDisplayConfig, Error(Display));
150     MOCK_METHOD2(getPreferredBootDisplayConfig, Error(Display, Config*));
151     MOCK_METHOD1(getHdrConversionCapabilities,
152                  Error(std::vector<
153                          aidl::android::hardware::graphics::common::HdrConversionCapability>*));
154     MOCK_METHOD2(setHdrConversionStrategy,
155                  Error(aidl::android::hardware::graphics::common::HdrConversionStrategy,
156                        aidl::android::hardware::graphics::common::Hdr*));
157     MOCK_METHOD2(getSupportedContentTypes,
158                  V2_4::Error(Display, std::vector<IComposerClient::ContentType>*));
159     MOCK_METHOD2(setContentType, V2_4::Error(Display, IComposerClient::ContentType));
160     MOCK_METHOD5(setLayerGenericMetadata,
161                  V2_4::Error(Display, Layer, const std::string&, bool,
162                              const std::vector<uint8_t>&));
163     MOCK_METHOD1(getLayerGenericMetadataKeys,
164                  V2_4::Error(std::vector<IComposerClient::LayerGenericMetadataKey>*));
165     MOCK_METHOD2(getClientTargetProperty,
166                  Error(Display,
167                        aidl::android::hardware::graphics::composer3::
168                                ClientTargetPropertyWithBrightness*));
169     MOCK_METHOD3(setLayerBrightness, Error(Display, Layer, float));
170     MOCK_METHOD3(setLayerBlockingRegion,
171                  Error(Display, Layer, const std::vector<IComposerClient::Rect>&));
172     MOCK_METHOD2(getDisplayDecorationSupport,
173                  Error(Display, std::optional<DisplayDecorationSupport>*));
174     MOCK_METHOD2(setIdleTimerEnabled, Error(Display, std::chrono::milliseconds));
175     MOCK_METHOD2(hasDisplayIdleTimerCapability, Error(Display, bool*));
176     MOCK_METHOD2(getPhysicalDisplayOrientation, Error(Display, AidlTransform*));
177     MOCK_METHOD1(getOverlaySupport,
178                  Error(aidl::android::hardware::graphics::composer3::OverlayProperties*));
179     MOCK_METHOD1(onHotplugConnect, void(Display));
180     MOCK_METHOD1(onHotplugDisconnect, void(Display));
181     MOCK_METHOD(Error, setRefreshRateChangedCallbackDebugEnabled, (Display, bool));
182     MOCK_METHOD(Error, notifyExpectedPresent, (Display, nsecs_t, int32_t));
183 };
184 
185 } // namespace Hwc2::mock
186 } // namespace android
187