1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 2022 The Android Open Source Project
3*0a9764feSAndroid Build Coastguard Worker *
4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*0a9764feSAndroid Build Coastguard Worker *
8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*0a9764feSAndroid Build Coastguard Worker *
10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*0a9764feSAndroid Build Coastguard Worker * limitations under the License.
15*0a9764feSAndroid Build Coastguard Worker */
16*0a9764feSAndroid Build Coastguard Worker
17*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
18*0a9764feSAndroid Build Coastguard Worker // #define LOG_NDEBUG 0 // Uncomment to see HWC2 API calls in logcat
19*0a9764feSAndroid Build Coastguard Worker
20*0a9764feSAndroid Build Coastguard Worker #define LOG_TAG "drmhwc"
21*0a9764feSAndroid Build Coastguard Worker
22*0a9764feSAndroid Build Coastguard Worker #include <cinttypes>
23*0a9764feSAndroid Build Coastguard Worker
24*0a9764feSAndroid Build Coastguard Worker #include "DrmHwcTwo.h"
25*0a9764feSAndroid Build Coastguard Worker #include "backend/Backend.h"
26*0a9764feSAndroid Build Coastguard Worker #include "utils/log.h"
27*0a9764feSAndroid Build Coastguard Worker
28*0a9764feSAndroid Build Coastguard Worker namespace android {
29*0a9764feSAndroid Build Coastguard Worker
30*0a9764feSAndroid Build Coastguard Worker /* Converts long __PRETTY_FUNCTION__ result, e.g.:
31*0a9764feSAndroid Build Coastguard Worker * "int32_t android::LayerHook(hwc2_device_t *, hwc2_display_t, hwc2_layer_t,"
32*0a9764feSAndroid Build Coastguard Worker * "Args...) [HookType = HWC2::Error (android::HwcLayer::*)(const native_handle"
33*0a9764feSAndroid Build Coastguard Worker * "*,int), func = &android::HwcLayer::SetLayerBuffer, Args = <const
34*0a9764feSAndroid Build Coastguard Worker * "native_handle, int>"
35*0a9764feSAndroid Build Coastguard Worker * to the short "android::HwcLayer::SetLayerBuffer" for better logs readability
36*0a9764feSAndroid Build Coastguard Worker */
GetFuncName(const char * pretty_function)37*0a9764feSAndroid Build Coastguard Worker static std::string GetFuncName(const char *pretty_function) {
38*0a9764feSAndroid Build Coastguard Worker const std::string str(pretty_function);
39*0a9764feSAndroid Build Coastguard Worker const char *start = "func = &";
40*0a9764feSAndroid Build Coastguard Worker auto p1 = str.find(start);
41*0a9764feSAndroid Build Coastguard Worker p1 += strlen(start);
42*0a9764feSAndroid Build Coastguard Worker auto p2 = str.find(',', p1);
43*0a9764feSAndroid Build Coastguard Worker return str.substr(p1, p2 - p1);
44*0a9764feSAndroid Build Coastguard Worker }
45*0a9764feSAndroid Build Coastguard Worker
46*0a9764feSAndroid Build Coastguard Worker struct Drmhwc2Device : hwc2_device {
47*0a9764feSAndroid Build Coastguard Worker DrmHwcTwo drmhwctwo;
48*0a9764feSAndroid Build Coastguard Worker };
49*0a9764feSAndroid Build Coastguard Worker
ToDrmHwcTwo(hwc2_device_t * dev)50*0a9764feSAndroid Build Coastguard Worker static DrmHwcTwo *ToDrmHwcTwo(hwc2_device_t *dev) {
51*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast):
52*0a9764feSAndroid Build Coastguard Worker return &static_cast<Drmhwc2Device *>(dev)->drmhwctwo;
53*0a9764feSAndroid Build Coastguard Worker }
54*0a9764feSAndroid Build Coastguard Worker
55*0a9764feSAndroid Build Coastguard Worker template <typename PFN, typename T>
ToHook(T function)56*0a9764feSAndroid Build Coastguard Worker static hwc2_function_pointer_t ToHook(T function) {
57*0a9764feSAndroid Build Coastguard Worker static_assert(std::is_same<PFN, T>::value, "Incompatible fn pointer");
58*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast):
59*0a9764feSAndroid Build Coastguard Worker return reinterpret_cast<hwc2_function_pointer_t>(function);
60*0a9764feSAndroid Build Coastguard Worker }
61*0a9764feSAndroid Build Coastguard Worker
62*0a9764feSAndroid Build Coastguard Worker template <typename T, typename HookType, HookType func, typename... Args>
DeviceHook(hwc2_device_t * dev,Args...args)63*0a9764feSAndroid Build Coastguard Worker static T DeviceHook(hwc2_device_t *dev, Args... args) {
64*0a9764feSAndroid Build Coastguard Worker ALOGV("Device hook: %s", GetFuncName(__PRETTY_FUNCTION__).c_str());
65*0a9764feSAndroid Build Coastguard Worker DrmHwcTwo *hwc = ToDrmHwcTwo(dev);
66*0a9764feSAndroid Build Coastguard Worker const std::unique_lock lock(hwc->GetResMan().GetMainLock());
67*0a9764feSAndroid Build Coastguard Worker return static_cast<T>(((*hwc).*func)(std::forward<Args>(args)...));
68*0a9764feSAndroid Build Coastguard Worker }
69*0a9764feSAndroid Build Coastguard Worker
70*0a9764feSAndroid Build Coastguard Worker template <typename HookType, HookType func, typename... Args>
DisplayHook(hwc2_device_t * dev,hwc2_display_t display_handle,Args...args)71*0a9764feSAndroid Build Coastguard Worker static int32_t DisplayHook(hwc2_device_t *dev, hwc2_display_t display_handle,
72*0a9764feSAndroid Build Coastguard Worker Args... args) {
73*0a9764feSAndroid Build Coastguard Worker ALOGV("Display #%" PRIu64 " hook: %s", display_handle,
74*0a9764feSAndroid Build Coastguard Worker GetFuncName(__PRETTY_FUNCTION__).c_str());
75*0a9764feSAndroid Build Coastguard Worker DrmHwcTwo *hwc = ToDrmHwcTwo(dev);
76*0a9764feSAndroid Build Coastguard Worker const std::unique_lock lock(hwc->GetResMan().GetMainLock());
77*0a9764feSAndroid Build Coastguard Worker auto *display = hwc->GetDisplay(display_handle);
78*0a9764feSAndroid Build Coastguard Worker if (display == nullptr)
79*0a9764feSAndroid Build Coastguard Worker return static_cast<int32_t>(HWC2::Error::BadDisplay);
80*0a9764feSAndroid Build Coastguard Worker
81*0a9764feSAndroid Build Coastguard Worker return static_cast<int32_t>((display->*func)(std::forward<Args>(args)...));
82*0a9764feSAndroid Build Coastguard Worker }
83*0a9764feSAndroid Build Coastguard Worker
84*0a9764feSAndroid Build Coastguard Worker template <typename HookType, HookType func, typename... Args>
LayerHook(hwc2_device_t * dev,hwc2_display_t display_handle,hwc2_layer_t layer_handle,Args...args)85*0a9764feSAndroid Build Coastguard Worker static int32_t LayerHook(hwc2_device_t *dev, hwc2_display_t display_handle,
86*0a9764feSAndroid Build Coastguard Worker hwc2_layer_t layer_handle, Args... args) {
87*0a9764feSAndroid Build Coastguard Worker ALOGV("Display #%" PRIu64 " Layer: #%" PRIu64 " hook: %s", display_handle,
88*0a9764feSAndroid Build Coastguard Worker layer_handle, GetFuncName(__PRETTY_FUNCTION__).c_str());
89*0a9764feSAndroid Build Coastguard Worker DrmHwcTwo *hwc = ToDrmHwcTwo(dev);
90*0a9764feSAndroid Build Coastguard Worker const std::unique_lock lock(hwc->GetResMan().GetMainLock());
91*0a9764feSAndroid Build Coastguard Worker auto *display = hwc->GetDisplay(display_handle);
92*0a9764feSAndroid Build Coastguard Worker if (display == nullptr)
93*0a9764feSAndroid Build Coastguard Worker return static_cast<int32_t>(HWC2::Error::BadDisplay);
94*0a9764feSAndroid Build Coastguard Worker
95*0a9764feSAndroid Build Coastguard Worker HwcLayer *layer = display->get_layer(layer_handle);
96*0a9764feSAndroid Build Coastguard Worker if (!layer)
97*0a9764feSAndroid Build Coastguard Worker return static_cast<int32_t>(HWC2::Error::BadLayer);
98*0a9764feSAndroid Build Coastguard Worker
99*0a9764feSAndroid Build Coastguard Worker return static_cast<int32_t>((layer->*func)(std::forward<Args>(args)...));
100*0a9764feSAndroid Build Coastguard Worker }
101*0a9764feSAndroid Build Coastguard Worker
HookDevClose(hw_device_t * dev)102*0a9764feSAndroid Build Coastguard Worker static int HookDevClose(hw_device_t *dev) {
103*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast): Safe
104*0a9764feSAndroid Build Coastguard Worker auto *hwc2_dev = reinterpret_cast<hwc2_device_t *>(dev);
105*0a9764feSAndroid Build Coastguard Worker const std::unique_ptr<DrmHwcTwo> ctx(ToDrmHwcTwo(hwc2_dev));
106*0a9764feSAndroid Build Coastguard Worker return 0;
107*0a9764feSAndroid Build Coastguard Worker }
108*0a9764feSAndroid Build Coastguard Worker
HookDevGetCapabilities(hwc2_device_t *,uint32_t * out_count,int32_t *)109*0a9764feSAndroid Build Coastguard Worker static void HookDevGetCapabilities(hwc2_device_t * /*dev*/, uint32_t *out_count,
110*0a9764feSAndroid Build Coastguard Worker int32_t * /*out_capabilities*/) {
111*0a9764feSAndroid Build Coastguard Worker *out_count = 0;
112*0a9764feSAndroid Build Coastguard Worker }
113*0a9764feSAndroid Build Coastguard Worker
HookDevGetFunction(struct hwc2_device *,int32_t descriptor)114*0a9764feSAndroid Build Coastguard Worker static hwc2_function_pointer_t HookDevGetFunction(struct hwc2_device * /*dev*/,
115*0a9764feSAndroid Build Coastguard Worker int32_t descriptor) {
116*0a9764feSAndroid Build Coastguard Worker auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
117*0a9764feSAndroid Build Coastguard Worker switch (func) {
118*0a9764feSAndroid Build Coastguard Worker // Device functions
119*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::CreateVirtualDisplay:
120*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
121*0a9764feSAndroid Build Coastguard Worker DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
122*0a9764feSAndroid Build Coastguard Worker &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
123*0a9764feSAndroid Build Coastguard Worker int32_t *, hwc2_display_t *>);
124*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
125*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
126*0a9764feSAndroid Build Coastguard Worker DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
127*0a9764feSAndroid Build Coastguard Worker &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
128*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::Dump:
129*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_DUMP>(
130*0a9764feSAndroid Build Coastguard Worker DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump,
131*0a9764feSAndroid Build Coastguard Worker uint32_t *, char *>);
132*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
133*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
134*0a9764feSAndroid Build Coastguard Worker DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
135*0a9764feSAndroid Build Coastguard Worker &DrmHwcTwo::GetMaxVirtualDisplayCount>);
136*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::RegisterCallback:
137*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
138*0a9764feSAndroid Build Coastguard Worker DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
139*0a9764feSAndroid Build Coastguard Worker &DrmHwcTwo::RegisterCallback, int32_t,
140*0a9764feSAndroid Build Coastguard Worker hwc2_callback_data_t, hwc2_function_pointer_t>);
141*0a9764feSAndroid Build Coastguard Worker
142*0a9764feSAndroid Build Coastguard Worker // Display functions
143*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::AcceptDisplayChanges:
144*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
145*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
146*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::AcceptDisplayChanges>);
147*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::CreateLayer:
148*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_CREATE_LAYER>(
149*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::CreateLayer),
150*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::CreateLayer, hwc2_layer_t *>);
151*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::DestroyLayer:
152*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_DESTROY_LAYER>(
153*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::DestroyLayer),
154*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::DestroyLayer, hwc2_layer_t>);
155*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetActiveConfig:
156*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
157*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
158*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
159*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
160*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
161*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
162*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
163*0a9764feSAndroid Build Coastguard Worker hwc2_layer_t *, int32_t *>);
164*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetClientTargetSupport:
165*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
166*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
167*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
168*0a9764feSAndroid Build Coastguard Worker int32_t, int32_t>);
169*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetColorModes:
170*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_COLOR_MODES>(
171*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetColorModes),
172*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
173*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayAttribute:
174*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(
175*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayAttribute),
176*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t,
177*0a9764feSAndroid Build Coastguard Worker int32_t *>);
178*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayConfigs:
179*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(
180*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::LegacyGetDisplayConfigs),
181*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::LegacyGetDisplayConfigs, uint32_t *,
182*0a9764feSAndroid Build Coastguard Worker hwc2_config_t *>);
183*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayName:
184*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
185*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayName),
186*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayName, uint32_t *, char *>);
187*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayRequests:
188*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
189*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
190*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
191*0a9764feSAndroid Build Coastguard Worker hwc2_layer_t *, int32_t *>);
192*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayType:
193*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
194*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayType),
195*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayType, int32_t *>);
196*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDozeSupport:
197*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
198*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
199*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDozeSupport, int32_t *>);
200*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetHdrCapabilities:
201*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
202*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
203*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
204*0a9764feSAndroid Build Coastguard Worker float *, float *, float *>);
205*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetReleaseFences:
206*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
207*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
208*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
209*0a9764feSAndroid Build Coastguard Worker int32_t *>);
210*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::PresentDisplay:
211*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
212*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::PresentDisplay),
213*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::PresentDisplay, int32_t *>);
214*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetActiveConfig:
215*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
216*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
217*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetActiveConfig, hwc2_config_t>);
218*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetClientTarget:
219*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(
220*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetClientTarget),
221*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetClientTarget, buffer_handle_t, int32_t,
222*0a9764feSAndroid Build Coastguard Worker int32_t, hwc_region_t>);
223*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetColorMode:
224*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_COLOR_MODE>(
225*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetColorMode),
226*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetColorMode, int32_t>);
227*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetColorTransform:
228*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
229*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetColorTransform),
230*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetColorTransform, const float *, int32_t>);
231*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetOutputBuffer:
232*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
233*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
234*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
235*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetPowerMode:
236*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_POWER_MODE>(
237*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetPowerMode),
238*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetPowerMode, int32_t>);
239*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetVsyncEnabled:
240*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
241*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
242*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetVsyncEnabled, int32_t>);
243*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::ValidateDisplay:
244*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
245*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
246*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
247*0a9764feSAndroid Build Coastguard Worker #if __ANDROID_API__ > 27
248*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetRenderIntents:
249*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_RENDER_INTENTS>(
250*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetRenderIntents),
251*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetRenderIntents, int32_t, uint32_t *,
252*0a9764feSAndroid Build Coastguard Worker int32_t *>);
253*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetColorModeWithRenderIntent:
254*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_COLOR_MODE_WITH_RENDER_INTENT>(
255*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetColorModeWithIntent),
256*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetColorModeWithIntent, int32_t, int32_t>);
257*0a9764feSAndroid Build Coastguard Worker #endif
258*0a9764feSAndroid Build Coastguard Worker #if __ANDROID_API__ > 28
259*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayIdentificationData:
260*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_IDENTIFICATION_DATA>(
261*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayIdentificationData),
262*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayIdentificationData, uint8_t *,
263*0a9764feSAndroid Build Coastguard Worker uint32_t *, uint8_t *>);
264*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayCapabilities:
265*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_CAPABILITIES>(
266*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayCapabilities),
267*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayCapabilities, uint32_t *,
268*0a9764feSAndroid Build Coastguard Worker uint32_t *>);
269*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayBrightnessSupport:
270*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_BRIGHTNESS_SUPPORT>(
271*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayBrightnessSupport),
272*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayBrightnessSupport, bool *>);
273*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetDisplayBrightness:
274*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>(
275*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetDisplayBrightness),
276*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetDisplayBrightness, float>);
277*0a9764feSAndroid Build Coastguard Worker #endif /* __ANDROID_API__ > 28 */
278*0a9764feSAndroid Build Coastguard Worker #if __ANDROID_API__ > 29
279*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayConnectionType:
280*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_CONNECTION_TYPE>(
281*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayConnectionType),
282*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayConnectionType, uint32_t *>);
283*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetDisplayVsyncPeriod:
284*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_DISPLAY_VSYNC_PERIOD>(
285*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetDisplayVsyncPeriod),
286*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetDisplayVsyncPeriod,
287*0a9764feSAndroid Build Coastguard Worker hwc2_vsync_period_t *>);
288*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetActiveConfigWithConstraints:
289*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS>(
290*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetActiveConfigWithConstraints),
291*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetActiveConfigWithConstraints,
292*0a9764feSAndroid Build Coastguard Worker hwc2_config_t, hwc_vsync_period_change_constraints_t *,
293*0a9764feSAndroid Build Coastguard Worker hwc_vsync_period_change_timeline_t *>);
294*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetAutoLowLatencyMode:
295*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_AUTO_LOW_LATENCY_MODE>(
296*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetAutoLowLatencyMode),
297*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetAutoLowLatencyMode, bool>);
298*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::GetSupportedContentTypes:
299*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_GET_SUPPORTED_CONTENT_TYPES>(
300*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::GetSupportedContentTypes),
301*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::GetSupportedContentTypes, uint32_t *,
302*0a9764feSAndroid Build Coastguard Worker uint32_t *>);
303*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetContentType:
304*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_CONTENT_TYPE>(
305*0a9764feSAndroid Build Coastguard Worker DisplayHook<decltype(&HwcDisplay::SetContentType),
306*0a9764feSAndroid Build Coastguard Worker &HwcDisplay::SetContentType, int32_t>);
307*0a9764feSAndroid Build Coastguard Worker #endif
308*0a9764feSAndroid Build Coastguard Worker // Layer functions
309*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetCursorPosition:
310*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
311*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetCursorPosition),
312*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetCursorPosition, int32_t, int32_t>);
313*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerBlendMode:
314*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
315*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerBlendMode),
316*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerBlendMode, int32_t>);
317*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerBuffer:
318*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
319*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerBuffer),
320*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>);
321*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerColor:
322*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
323*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerColor),
324*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerColor, hwc_color_t>);
325*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerCompositionType:
326*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
327*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerCompositionType),
328*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerCompositionType, int32_t>);
329*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerDataspace:
330*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
331*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerDataspace),
332*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerDataspace, int32_t>);
333*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
334*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
335*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame),
336*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>);
337*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
338*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
339*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha),
340*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerPlaneAlpha, float>);
341*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerSidebandStream:
342*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(
343*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerSidebandStream),
344*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerSidebandStream,
345*0a9764feSAndroid Build Coastguard Worker const native_handle_t *>);
346*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerSourceCrop:
347*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
348*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerSourceCrop),
349*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerSourceCrop, hwc_frect_t>);
350*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
351*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
352*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage),
353*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>);
354*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerTransform:
355*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
356*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerTransform),
357*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerTransform, int32_t>);
358*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
359*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
360*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion),
361*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerVisibleRegion, hwc_region_t>);
362*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::SetLayerZOrder:
363*0a9764feSAndroid Build Coastguard Worker return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
364*0a9764feSAndroid Build Coastguard Worker LayerHook<decltype(&HwcLayer::SetLayerZOrder),
365*0a9764feSAndroid Build Coastguard Worker &HwcLayer::SetLayerZOrder, uint32_t>);
366*0a9764feSAndroid Build Coastguard Worker case HWC2::FunctionDescriptor::Invalid:
367*0a9764feSAndroid Build Coastguard Worker default:
368*0a9764feSAndroid Build Coastguard Worker return nullptr;
369*0a9764feSAndroid Build Coastguard Worker }
370*0a9764feSAndroid Build Coastguard Worker }
371*0a9764feSAndroid Build Coastguard Worker
HookDevOpen(const struct hw_module_t * module,const char * name,struct hw_device_t ** dev)372*0a9764feSAndroid Build Coastguard Worker static int HookDevOpen(const struct hw_module_t *module, const char *name,
373*0a9764feSAndroid Build Coastguard Worker struct hw_device_t **dev) {
374*0a9764feSAndroid Build Coastguard Worker if (strcmp(name, HWC_HARDWARE_COMPOSER) != 0) {
375*0a9764feSAndroid Build Coastguard Worker ALOGE("Invalid module name- %s", name);
376*0a9764feSAndroid Build Coastguard Worker return -EINVAL;
377*0a9764feSAndroid Build Coastguard Worker }
378*0a9764feSAndroid Build Coastguard Worker
379*0a9764feSAndroid Build Coastguard Worker auto ctx = std::make_unique<Drmhwc2Device>();
380*0a9764feSAndroid Build Coastguard Worker if (!ctx) {
381*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to allocate DrmHwcTwo");
382*0a9764feSAndroid Build Coastguard Worker return -ENOMEM;
383*0a9764feSAndroid Build Coastguard Worker }
384*0a9764feSAndroid Build Coastguard Worker
385*0a9764feSAndroid Build Coastguard Worker ctx->common.tag = HARDWARE_DEVICE_TAG;
386*0a9764feSAndroid Build Coastguard Worker ctx->common.version = HWC_DEVICE_API_VERSION_2_0;
387*0a9764feSAndroid Build Coastguard Worker ctx->common.close = HookDevClose;
388*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
389*0a9764feSAndroid Build Coastguard Worker ctx->common.module = (hw_module_t *)module;
390*0a9764feSAndroid Build Coastguard Worker ctx->getCapabilities = HookDevGetCapabilities;
391*0a9764feSAndroid Build Coastguard Worker ctx->getFunction = HookDevGetFunction;
392*0a9764feSAndroid Build Coastguard Worker
393*0a9764feSAndroid Build Coastguard Worker *dev = &ctx.release()->common;
394*0a9764feSAndroid Build Coastguard Worker
395*0a9764feSAndroid Build Coastguard Worker return 0;
396*0a9764feSAndroid Build Coastguard Worker }
397*0a9764feSAndroid Build Coastguard Worker
398*0a9764feSAndroid Build Coastguard Worker } // namespace android
399*0a9764feSAndroid Build Coastguard Worker
400*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
401*0a9764feSAndroid Build Coastguard Worker static struct hw_module_methods_t hwc2_module_methods = {
402*0a9764feSAndroid Build Coastguard Worker .open = android::HookDevOpen,
403*0a9764feSAndroid Build Coastguard Worker };
404*0a9764feSAndroid Build Coastguard Worker
405*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
406*0a9764feSAndroid Build Coastguard Worker hw_module_t HAL_MODULE_INFO_SYM = {
407*0a9764feSAndroid Build Coastguard Worker .tag = HARDWARE_MODULE_TAG,
408*0a9764feSAndroid Build Coastguard Worker .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
409*0a9764feSAndroid Build Coastguard Worker .id = HWC_HARDWARE_MODULE_ID,
410*0a9764feSAndroid Build Coastguard Worker .name = "DrmHwcTwo module",
411*0a9764feSAndroid Build Coastguard Worker .author = "The Android Open Source Project",
412*0a9764feSAndroid Build Coastguard Worker .methods = &hwc2_module_methods,
413*0a9764feSAndroid Build Coastguard Worker .dso = nullptr,
414*0a9764feSAndroid Build Coastguard Worker .reserved = {0},
415*0a9764feSAndroid Build Coastguard Worker };
416