1 /*
2  * Copyright 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 <compositionengine/Output.h>
20 #include <gmock/gmock.h>
21 
22 // TODO(b/129481165): remove the #pragma below and fix conversion issues
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wconversion"
25 #pragma clang diagnostic ignored "-Wextra"
26 
27 #include "DisplayHardware/HWComposer.h"
28 
29 // TODO(b/129481165): remove the #pragma below and fix conversion issues
30 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
31 
32 namespace android {
33 namespace mock {
34 
35 namespace hal = android::hardware::graphics::composer::hal;
36 
37 class HWComposer : public android::HWComposer {
38 public:
39     HWComposer();
40     ~HWComposer() override;
41 
42     MOCK_METHOD1(setCallback, void(HWC2::ComposerCallback*));
43     MOCK_CONST_METHOD3(getDisplayIdentificationData,
44                        bool(hal::HWDisplayId, uint8_t*, DisplayIdentificationData*));
45     MOCK_CONST_METHOD1(hasCapability, bool(hal::Capability));
46     MOCK_CONST_METHOD2(hasDisplayCapability, bool(HalDisplayId, hal::DisplayCapability));
47 
48     MOCK_CONST_METHOD0(getMaxVirtualDisplayCount, size_t());
49     MOCK_CONST_METHOD0(getMaxVirtualDisplayDimension, size_t());
50     MOCK_METHOD3(allocateVirtualDisplay, bool(HalVirtualDisplayId, ui::Size, ui::PixelFormat*));
51     MOCK_METHOD2(allocatePhysicalDisplay, void(hal::HWDisplayId, PhysicalDisplayId));
52     MOCK_METHOD1(createLayer, std::shared_ptr<HWC2::Layer>(HalDisplayId));
53     MOCK_METHOD5(getDeviceCompositionChanges,
54                  status_t(HalDisplayId, bool, std::chrono::steady_clock::time_point,
55                           const std::shared_ptr<FenceTime>&,
56                           std::optional<android::HWComposer::DeviceRequestedChanges>*));
57     MOCK_METHOD5(setClientTarget,
58                  status_t(HalDisplayId, uint32_t, const sp<Fence>&, const sp<GraphicBuffer>&,
59                           ui::Dataspace));
60     MOCK_METHOD3(presentAndGetReleaseFences,
61                  status_t(HalDisplayId, std::chrono::steady_clock::time_point,
62                           const std::shared_ptr<FenceTime>&));
63     MOCK_METHOD2(setPowerMode, status_t(PhysicalDisplayId, hal::PowerMode));
64     MOCK_METHOD2(setActiveConfig, status_t(HalDisplayId, size_t));
65     MOCK_METHOD2(setColorTransform, status_t(HalDisplayId, const mat4&));
66     MOCK_METHOD1(disconnectDisplay, void(HalDisplayId));
67     MOCK_CONST_METHOD1(hasDeviceComposition, bool(const std::optional<DisplayId>&));
68     MOCK_CONST_METHOD1(getPresentFence, sp<Fence>(HalDisplayId));
69     MOCK_CONST_METHOD2(getLayerReleaseFence, sp<Fence>(HalDisplayId, HWC2::Layer*));
70     MOCK_METHOD3(setOutputBuffer,
71                  status_t(HalVirtualDisplayId, const sp<Fence>&, const sp<GraphicBuffer>&));
72     MOCK_METHOD1(clearReleaseFences, void(HalDisplayId));
73     MOCK_METHOD2(getHdrCapabilities, status_t(HalDisplayId, HdrCapabilities*));
74     MOCK_CONST_METHOD1(getSupportedPerFrameMetadata, int32_t(HalDisplayId));
75     MOCK_CONST_METHOD2(getRenderIntents,
76                        std::vector<ui::RenderIntent>(HalDisplayId, ui::ColorMode));
77     MOCK_METHOD2(getDataspaceSaturationMatrix, mat4(HalDisplayId, ui::Dataspace));
78     MOCK_METHOD4(getDisplayedContentSamplingAttributes,
79                  status_t(HalDisplayId, ui::PixelFormat*, ui::Dataspace*, uint8_t*));
80     MOCK_METHOD4(setDisplayContentSamplingEnabled, status_t(HalDisplayId, bool, uint8_t, uint64_t));
81     MOCK_METHOD4(getDisplayedContentSample,
82                  status_t(HalDisplayId, uint64_t, uint64_t, DisplayedFrameStats*));
83     MOCK_METHOD2(setDisplayBrightness, std::future<status_t>(PhysicalDisplayId, float));
84     MOCK_METHOD2(getDisplayBrightnessSupport, status_t(PhysicalDisplayId, bool*));
85 
86     MOCK_METHOD2(onHotplug,
87                  std::optional<DisplayIdentificationInfo>(hal::HWDisplayId, hal::Connection));
88     MOCK_CONST_METHOD0(updatesDeviceProductInfoOnHotplugReconnect, bool());
89     MOCK_METHOD2(onVsync, bool(hal::HWDisplayId, int64_t));
90     MOCK_METHOD2(setVsyncEnabled, void(PhysicalDisplayId, hal::Vsync));
91     MOCK_CONST_METHOD1(isConnected, bool(PhysicalDisplayId));
92     MOCK_CONST_METHOD1(getModes, std::vector<HWComposer::HWCDisplayMode>(PhysicalDisplayId));
93     MOCK_CONST_METHOD1(getActiveMode, std::optional<hal::HWConfigId>(PhysicalDisplayId));
94     MOCK_CONST_METHOD1(getColorModes, std::vector<ui::ColorMode>(PhysicalDisplayId));
95     MOCK_METHOD3(setActiveColorMode, status_t(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent));
96     MOCK_CONST_METHOD0(isUsingVrComposer, bool());
97     MOCK_CONST_METHOD1(getDisplayConnectionType, ui::DisplayConnectionType(PhysicalDisplayId));
98     MOCK_CONST_METHOD1(isVsyncPeriodSwitchSupported, bool(PhysicalDisplayId));
99     MOCK_CONST_METHOD2(getDisplayVsyncPeriod, status_t(PhysicalDisplayId, nsecs_t*));
100     MOCK_METHOD4(setActiveModeWithConstraints,
101                  status_t(PhysicalDisplayId, hal::HWConfigId,
102                           const hal::VsyncPeriodChangeConstraints&,
103                           hal::VsyncPeriodChangeTimeline*));
104     MOCK_METHOD2(setAutoLowLatencyMode, status_t(PhysicalDisplayId, bool));
105     MOCK_METHOD2(getSupportedContentTypes,
106                  status_t(PhysicalDisplayId, std::vector<hal::ContentType>*));
107     MOCK_METHOD2(setContentType, status_t(PhysicalDisplayId, hal::ContentType));
108     MOCK_CONST_METHOD0(getSupportedLayerGenericMetadata,
109                        const std::unordered_map<std::string, bool>&());
110 
111     MOCK_CONST_METHOD1(dump, void(std::string&));
112     MOCK_CONST_METHOD0(getComposer, android::Hwc2::Composer*());
113     MOCK_CONST_METHOD1(getHwcDisplayId, std::optional<hal::HWDisplayId>(int32_t));
114     MOCK_CONST_METHOD0(getInternalHwcDisplayId, std::optional<hal::HWDisplayId>());
115     MOCK_CONST_METHOD0(getExternalHwcDisplayId, std::optional<hal::HWDisplayId>());
116     MOCK_CONST_METHOD1(toPhysicalDisplayId, std::optional<PhysicalDisplayId>(hal::HWDisplayId));
117     MOCK_CONST_METHOD1(fromPhysicalDisplayId, std::optional<hal::HWDisplayId>(PhysicalDisplayId));
118 };
119 
120 } // namespace mock
121 } // namespace android
122