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 <gmock/gmock.h>
20 
21 #include "DisplayHardware/HWC2.h"
22 
23 namespace android::HWC2::mock {
24 
25 class Display : public HWC2::Display {
26 public:
27     Display();
28     ~Display() override;
29 
30     MOCK_METHOD(hal::HWDisplayId, getId, (), (const, override));
31     MOCK_METHOD(bool, isConnected, (), (const, override));
32     MOCK_METHOD(void, setConnected, (bool), (override));
33     MOCK_METHOD(bool, hasCapability,
34                 (aidl::android::hardware::graphics::composer3::DisplayCapability),
35                 (const, override));
36     MOCK_METHOD(bool, isVsyncPeriodSwitchSupported, (), (const, override));
37     MOCK_METHOD(void, onLayerDestroyed, (hal::HWLayerId), (override));
38 
39     MOCK_METHOD(hal::Error, acceptChanges, (), (override));
40     MOCK_METHOD((base::expected<std::shared_ptr<HWC2::Layer>, hal::Error>), createLayer, (),
41                 (override));
42     MOCK_METHOD(hal::Error, getChangedCompositionTypes,
43                 ((std::unordered_map<Layer *,
44                                      aidl::android::hardware::graphics::composer3::Composition> *)),
45                 (override));
46     MOCK_METHOD(hal::Error, getColorModes, (std::vector<hal::ColorMode> *), (const, override));
47     MOCK_METHOD(int32_t, getSupportedPerFrameMetadata, (), (const, override));
48     MOCK_METHOD(hal::Error, getRenderIntents, (hal::ColorMode, std::vector<hal::RenderIntent> *),
49                 (const, override));
50     MOCK_METHOD(hal::Error, getDataspaceSaturationMatrix, (hal::Dataspace, android::mat4 *),
51                 (override));
52     MOCK_METHOD(hal::Error, getName, (std::string *), (const, override));
53     MOCK_METHOD(hal::Error, getRequests,
54                 (hal::DisplayRequest *, (std::unordered_map<Layer *, hal::LayerRequest> *)),
55                 (override));
56     MOCK_METHOD((ftl::Expected<ui::DisplayConnectionType, hal::Error>), getConnectionType, (),
57                 (const, override));
58     MOCK_METHOD(hal::Error, supportsDoze, (bool *), (const, override));
59     MOCK_METHOD(hal::Error, getHdrCapabilities, (android::HdrCapabilities *), (const, override));
60     MOCK_METHOD(hal::Error, getDisplayedContentSamplingAttributes,
61                 (hal::PixelFormat *, hal::Dataspace *, uint8_t *), (const, override));
62     MOCK_METHOD(hal::Error, setDisplayContentSamplingEnabled, (bool, uint8_t, uint64_t),
63                 (const, override));
64     MOCK_METHOD(hal::Error, getDisplayedContentSample,
65                 (uint64_t, uint64_t, android::DisplayedFrameStats *), (const, override));
66     MOCK_METHOD(hal::Error, getReleaseFences,
67                 ((std::unordered_map<Layer *, android::sp<android::Fence>> *)), (const, override));
68     MOCK_METHOD(hal::Error, present, (android::sp<android::Fence> *), (override));
69     MOCK_METHOD(hal::Error, setClientTarget,
70                 (uint32_t, const android::sp<android::GraphicBuffer>&,
71                  const android::sp<android::Fence>&, hal::Dataspace, float),
72                 (override));
73     MOCK_METHOD(hal::Error, setColorMode, (hal::ColorMode, hal::RenderIntent), (override));
74     MOCK_METHOD(hal::Error, setColorTransform, (const android::mat4 &), (override));
75     MOCK_METHOD(hal::Error, setOutputBuffer,
76                 (const android::sp<android::GraphicBuffer> &, const android::sp<android::Fence> &),
77                 (override));
78     MOCK_METHOD(hal::Error, setPowerMode, (hal::PowerMode), (override));
79     MOCK_METHOD(hal::Error, setVsyncEnabled, (hal::Vsync), (override));
80     MOCK_METHOD(hal::Error, validate, (nsecs_t, int32_t, uint32_t*, uint32_t*), (override));
81     MOCK_METHOD(hal::Error, presentOrValidate,
82                 (nsecs_t, int32_t, uint32_t*, uint32_t*, android::sp<android::Fence>*, uint32_t*),
83                 (override));
84     MOCK_METHOD(ftl::Future<hal::Error>, setDisplayBrightness,
85                 (float, float, const Hwc2::Composer::DisplayBrightnessOptions &), (override));
86     MOCK_METHOD(hal::Error, setActiveConfigWithConstraints,
87                 (hal::HWConfigId, const hal::VsyncPeriodChangeConstraints &,
88                  hal::VsyncPeriodChangeTimeline *),
89                 (override));
90     MOCK_METHOD(hal::Error, setBootDisplayConfig, (hal::HWConfigId), (override));
91     MOCK_METHOD(hal::Error, clearBootDisplayConfig, (), (override));
92     MOCK_METHOD(hal::Error, getPreferredBootDisplayConfig, (hal::HWConfigId *), (const, override));
93     MOCK_METHOD(hal::Error, setAutoLowLatencyMode, (bool), (override));
94     MOCK_METHOD(hal::Error, getSupportedContentTypes, (std::vector<hal::ContentType> *),
95                 (const, override));
96     MOCK_METHOD(hal::Error, setContentType, (hal::ContentType), (override));
97     MOCK_METHOD(
98             hal::Error, getClientTargetProperty,
99             (aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness *),
100             (override));
101     MOCK_METHOD(
102             hal::Error, getDisplayDecorationSupport,
103             (std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> *),
104             (override));
105     MOCK_METHOD(hal::Error, setIdleTimerEnabled, (std::chrono::milliseconds), (override));
106     MOCK_METHOD(bool, hasDisplayIdleTimerCapability, (), (const override));
107     MOCK_METHOD(hal::Error, getPhysicalDisplayOrientation, (Hwc2::AidlTransform *),
108                 (const override));
109     MOCK_METHOD(hal::Error, getOverlaySupport,
110                 (aidl::android::hardware::graphics::composer3::OverlayProperties *),
111                 (const override));
112 };
113 
114 class Layer : public HWC2::Layer {
115 public:
116     Layer();
117     ~Layer() override;
118 
119     MOCK_METHOD(hal::HWLayerId, getId, (), (const, override));
120     MOCK_METHOD(hal::Error, setCursorPosition, (int32_t, int32_t), (override));
121     MOCK_METHOD(hal::Error, setBuffer,
122                 (uint32_t, const android::sp<android::GraphicBuffer> &,
123                  const android::sp<android::Fence> &),
124                 (override));
125     MOCK_METHOD(hal::Error, setSurfaceDamage, (const android::Region &), (override));
126     MOCK_METHOD(hal::Error, setBlendMode, (hal::BlendMode), (override));
127     MOCK_METHOD(hal::Error, setColor, (aidl::android::hardware::graphics::composer3::Color),
128                 (override));
129     MOCK_METHOD(hal::Error, setCompositionType,
130                 (aidl::android::hardware::graphics::composer3::Composition), (override));
131     MOCK_METHOD(hal::Error, setDataspace, (android::ui::Dataspace), (override));
132     MOCK_METHOD(hal::Error, setPerFrameMetadata, (const int32_t, const android::HdrMetadata &),
133                 (override));
134     MOCK_METHOD(hal::Error, setDisplayFrame, (const android::Rect &), (override));
135     MOCK_METHOD(hal::Error, setPlaneAlpha, (float), (override));
136     MOCK_METHOD(hal::Error, setSidebandStream, (const native_handle_t *), (override));
137     MOCK_METHOD(hal::Error, setSourceCrop, (const android::FloatRect &), (override));
138     MOCK_METHOD(hal::Error, setTransform, (hal::Transform), (override));
139     MOCK_METHOD(hal::Error, setVisibleRegion, (const android::Region &), (override));
140     MOCK_METHOD(hal::Error, setZOrder, (uint32_t), (override));
141     MOCK_METHOD(hal::Error, setColorTransform, (const android::mat4 &), (override));
142     MOCK_METHOD(hal::Error, setLayerGenericMetadata,
143                 (const std::string &, bool, const std::vector<uint8_t> &), (override));
144     MOCK_METHOD(hal::Error, setBrightness, (float), (override));
145     MOCK_METHOD(hal::Error, setBlockingRegion, (const android::Region &), (override));
146 };
147 
148 } // namespace android::HWC2::mock
149