Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #define LOG_TAG "hwc2-device" |
| 18 | |
| 19 | #include "DrmHwcTwo.h" |
| 20 | #include "backend/Backend.h" |
| 21 | #include "utils/log.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | struct Drmhwc2Device : hwc2_device { |
| 26 | DrmHwcTwo drmhwctwo; |
| 27 | }; |
| 28 | |
| 29 | static DrmHwcTwo *ToDrmHwcTwo(hwc2_device_t *dev) { |
| 30 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast): |
| 31 | return &static_cast<Drmhwc2Device *>(dev)->drmhwctwo; |
| 32 | } |
| 33 | |
| 34 | template <typename PFN, typename T> |
| 35 | static hwc2_function_pointer_t ToHook(T function) { |
| 36 | static_assert(std::is_same<PFN, T>::value, "Incompatible fn pointer"); |
| 37 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): |
| 38 | return reinterpret_cast<hwc2_function_pointer_t>(function); |
| 39 | } |
| 40 | |
| 41 | template <typename T, typename HookType, HookType func, typename... Args> |
| 42 | static T DeviceHook(hwc2_device_t *dev, Args... args) { |
| 43 | DrmHwcTwo *hwc = ToDrmHwcTwo(dev); |
| 44 | return static_cast<T>(((*hwc).*func)(std::forward<Args>(args)...)); |
| 45 | } |
| 46 | |
| 47 | template <typename HookType, HookType func, typename... Args> |
| 48 | static int32_t DisplayHook(hwc2_device_t *dev, hwc2_display_t display_handle, |
| 49 | Args... args) { |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 50 | HwcDisplay *display = DrmHwcTwo::GetDisplay(ToDrmHwcTwo(dev), display_handle); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 51 | if (!display) |
| 52 | return static_cast<int32_t>(HWC2::Error::BadDisplay); |
| 53 | |
| 54 | return static_cast<int32_t>((display->*func)(std::forward<Args>(args)...)); |
| 55 | } |
| 56 | |
| 57 | template <typename HookType, HookType func, typename... Args> |
| 58 | static int32_t LayerHook(hwc2_device_t *dev, hwc2_display_t display_handle, |
| 59 | hwc2_layer_t layer_handle, Args... args) { |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 60 | HwcDisplay *display = DrmHwcTwo::GetDisplay(ToDrmHwcTwo(dev), display_handle); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 61 | if (!display) |
| 62 | return static_cast<int32_t>(HWC2::Error::BadDisplay); |
| 63 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 64 | HwcLayer *layer = display->get_layer(layer_handle); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 65 | if (!layer) |
| 66 | return static_cast<int32_t>(HWC2::Error::BadLayer); |
| 67 | |
| 68 | return static_cast<int32_t>((layer->*func)(std::forward<Args>(args)...)); |
| 69 | } |
| 70 | |
| 71 | static int HookDevClose(hw_device_t *dev) { |
| 72 | // NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast): Safe |
| 73 | auto *hwc2_dev = reinterpret_cast<hwc2_device_t *>(dev); |
| 74 | std::unique_ptr<DrmHwcTwo> ctx(ToDrmHwcTwo(hwc2_dev)); |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static void HookDevGetCapabilities(hwc2_device_t * /*dev*/, uint32_t *out_count, |
| 79 | int32_t * /*out_capabilities*/) { |
| 80 | *out_count = 0; |
| 81 | } |
| 82 | |
| 83 | static hwc2_function_pointer_t HookDevGetFunction(struct hwc2_device * /*dev*/, |
| 84 | int32_t descriptor) { |
| 85 | auto func = static_cast<HWC2::FunctionDescriptor>(descriptor); |
| 86 | switch (func) { |
| 87 | // Device functions |
| 88 | case HWC2::FunctionDescriptor::CreateVirtualDisplay: |
| 89 | return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>( |
| 90 | DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay), |
| 91 | &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t, |
| 92 | int32_t *, hwc2_display_t *>); |
| 93 | case HWC2::FunctionDescriptor::DestroyVirtualDisplay: |
| 94 | return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>( |
| 95 | DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay), |
| 96 | &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>); |
| 97 | case HWC2::FunctionDescriptor::Dump: |
| 98 | return ToHook<HWC2_PFN_DUMP>( |
| 99 | DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump, |
| 100 | uint32_t *, char *>); |
| 101 | case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount: |
| 102 | return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>( |
| 103 | DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount), |
| 104 | &DrmHwcTwo::GetMaxVirtualDisplayCount>); |
| 105 | case HWC2::FunctionDescriptor::RegisterCallback: |
| 106 | return ToHook<HWC2_PFN_REGISTER_CALLBACK>( |
| 107 | DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback), |
| 108 | &DrmHwcTwo::RegisterCallback, int32_t, |
| 109 | hwc2_callback_data_t, hwc2_function_pointer_t>); |
| 110 | |
| 111 | // Display functions |
| 112 | case HWC2::FunctionDescriptor::AcceptDisplayChanges: |
| 113 | return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 114 | DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges), |
| 115 | &HwcDisplay::AcceptDisplayChanges>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 116 | case HWC2::FunctionDescriptor::CreateLayer: |
| 117 | return ToHook<HWC2_PFN_CREATE_LAYER>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 118 | DisplayHook<decltype(&HwcDisplay::CreateLayer), |
| 119 | &HwcDisplay::CreateLayer, hwc2_layer_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 120 | case HWC2::FunctionDescriptor::DestroyLayer: |
| 121 | return ToHook<HWC2_PFN_DESTROY_LAYER>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 122 | DisplayHook<decltype(&HwcDisplay::DestroyLayer), |
| 123 | &HwcDisplay::DestroyLayer, hwc2_layer_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 124 | case HWC2::FunctionDescriptor::GetActiveConfig: |
| 125 | return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 126 | DisplayHook<decltype(&HwcDisplay::GetActiveConfig), |
| 127 | &HwcDisplay::GetActiveConfig, hwc2_config_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 128 | case HWC2::FunctionDescriptor::GetChangedCompositionTypes: |
| 129 | return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 130 | DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes), |
| 131 | &HwcDisplay::GetChangedCompositionTypes, uint32_t *, |
| 132 | hwc2_layer_t *, int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 133 | case HWC2::FunctionDescriptor::GetClientTargetSupport: |
| 134 | return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 135 | DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport), |
| 136 | &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t, |
| 137 | int32_t, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 138 | case HWC2::FunctionDescriptor::GetColorModes: |
| 139 | return ToHook<HWC2_PFN_GET_COLOR_MODES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 140 | DisplayHook<decltype(&HwcDisplay::GetColorModes), |
| 141 | &HwcDisplay::GetColorModes, uint32_t *, int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 142 | case HWC2::FunctionDescriptor::GetDisplayAttribute: |
| 143 | return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 144 | DisplayHook<decltype(&HwcDisplay::GetDisplayAttribute), |
| 145 | &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, |
| 146 | int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 147 | case HWC2::FunctionDescriptor::GetDisplayConfigs: |
| 148 | return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 149 | DisplayHook<decltype(&HwcDisplay::GetDisplayConfigs), |
| 150 | &HwcDisplay::GetDisplayConfigs, uint32_t *, |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 151 | hwc2_config_t *>); |
| 152 | case HWC2::FunctionDescriptor::GetDisplayName: |
| 153 | return ToHook<HWC2_PFN_GET_DISPLAY_NAME>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 154 | DisplayHook<decltype(&HwcDisplay::GetDisplayName), |
| 155 | &HwcDisplay::GetDisplayName, uint32_t *, char *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 156 | case HWC2::FunctionDescriptor::GetDisplayRequests: |
| 157 | return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 158 | DisplayHook<decltype(&HwcDisplay::GetDisplayRequests), |
| 159 | &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *, |
| 160 | hwc2_layer_t *, int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 161 | case HWC2::FunctionDescriptor::GetDisplayType: |
| 162 | return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 163 | DisplayHook<decltype(&HwcDisplay::GetDisplayType), |
| 164 | &HwcDisplay::GetDisplayType, int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 165 | case HWC2::FunctionDescriptor::GetDozeSupport: |
| 166 | return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 167 | DisplayHook<decltype(&HwcDisplay::GetDozeSupport), |
| 168 | &HwcDisplay::GetDozeSupport, int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 169 | case HWC2::FunctionDescriptor::GetHdrCapabilities: |
| 170 | return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 171 | DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities), |
| 172 | &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *, |
| 173 | float *, float *, float *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 174 | case HWC2::FunctionDescriptor::GetReleaseFences: |
| 175 | return ToHook<HWC2_PFN_GET_RELEASE_FENCES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 176 | DisplayHook<decltype(&HwcDisplay::GetReleaseFences), |
| 177 | &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *, |
| 178 | int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 179 | case HWC2::FunctionDescriptor::PresentDisplay: |
| 180 | return ToHook<HWC2_PFN_PRESENT_DISPLAY>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 181 | DisplayHook<decltype(&HwcDisplay::PresentDisplay), |
| 182 | &HwcDisplay::PresentDisplay, int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 183 | case HWC2::FunctionDescriptor::SetActiveConfig: |
| 184 | return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 185 | DisplayHook<decltype(&HwcDisplay::SetActiveConfig), |
| 186 | &HwcDisplay::SetActiveConfig, hwc2_config_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 187 | case HWC2::FunctionDescriptor::SetClientTarget: |
| 188 | return ToHook<HWC2_PFN_SET_CLIENT_TARGET>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 189 | DisplayHook<decltype(&HwcDisplay::SetClientTarget), |
| 190 | &HwcDisplay::SetClientTarget, buffer_handle_t, int32_t, |
| 191 | int32_t, hwc_region_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 192 | case HWC2::FunctionDescriptor::SetColorMode: |
| 193 | return ToHook<HWC2_PFN_SET_COLOR_MODE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 194 | DisplayHook<decltype(&HwcDisplay::SetColorMode), |
| 195 | &HwcDisplay::SetColorMode, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 196 | case HWC2::FunctionDescriptor::SetColorTransform: |
| 197 | return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 198 | DisplayHook<decltype(&HwcDisplay::SetColorTransform), |
| 199 | &HwcDisplay::SetColorTransform, const float *, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 200 | case HWC2::FunctionDescriptor::SetOutputBuffer: |
| 201 | return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 202 | DisplayHook<decltype(&HwcDisplay::SetOutputBuffer), |
| 203 | &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 204 | case HWC2::FunctionDescriptor::SetPowerMode: |
| 205 | return ToHook<HWC2_PFN_SET_POWER_MODE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 206 | DisplayHook<decltype(&HwcDisplay::SetPowerMode), |
| 207 | &HwcDisplay::SetPowerMode, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 208 | case HWC2::FunctionDescriptor::SetVsyncEnabled: |
| 209 | return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 210 | DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled), |
| 211 | &HwcDisplay::SetVsyncEnabled, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 212 | case HWC2::FunctionDescriptor::ValidateDisplay: |
| 213 | return ToHook<HWC2_PFN_VALIDATE_DISPLAY>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 214 | DisplayHook<decltype(&HwcDisplay::ValidateDisplay), |
| 215 | &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 216 | #if PLATFORM_SDK_VERSION > 27 |
| 217 | case HWC2::FunctionDescriptor::GetRenderIntents: |
| 218 | return ToHook<HWC2_PFN_GET_RENDER_INTENTS>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 219 | DisplayHook<decltype(&HwcDisplay::GetRenderIntents), |
| 220 | &HwcDisplay::GetRenderIntents, int32_t, uint32_t *, |
| 221 | int32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 222 | case HWC2::FunctionDescriptor::SetColorModeWithRenderIntent: |
| 223 | return ToHook<HWC2_PFN_SET_COLOR_MODE_WITH_RENDER_INTENT>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 224 | DisplayHook<decltype(&HwcDisplay::SetColorModeWithIntent), |
| 225 | &HwcDisplay::SetColorModeWithIntent, int32_t, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 226 | #endif |
| 227 | #if PLATFORM_SDK_VERSION > 28 |
| 228 | case HWC2::FunctionDescriptor::GetDisplayIdentificationData: |
| 229 | return ToHook<HWC2_PFN_GET_DISPLAY_IDENTIFICATION_DATA>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 230 | DisplayHook<decltype(&HwcDisplay::GetDisplayIdentificationData), |
| 231 | &HwcDisplay::GetDisplayIdentificationData, uint8_t *, |
| 232 | uint32_t *, uint8_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 233 | case HWC2::FunctionDescriptor::GetDisplayCapabilities: |
| 234 | return ToHook<HWC2_PFN_GET_DISPLAY_CAPABILITIES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 235 | DisplayHook<decltype(&HwcDisplay::GetDisplayCapabilities), |
| 236 | &HwcDisplay::GetDisplayCapabilities, uint32_t *, |
| 237 | uint32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 238 | case HWC2::FunctionDescriptor::GetDisplayBrightnessSupport: |
| 239 | return ToHook<HWC2_PFN_GET_DISPLAY_BRIGHTNESS_SUPPORT>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 240 | DisplayHook<decltype(&HwcDisplay::GetDisplayBrightnessSupport), |
| 241 | &HwcDisplay::GetDisplayBrightnessSupport, bool *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 242 | case HWC2::FunctionDescriptor::SetDisplayBrightness: |
| 243 | return ToHook<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 244 | DisplayHook<decltype(&HwcDisplay::SetDisplayBrightness), |
| 245 | &HwcDisplay::SetDisplayBrightness, float>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 246 | #endif /* PLATFORM_SDK_VERSION > 28 */ |
| 247 | #if PLATFORM_SDK_VERSION > 29 |
| 248 | case HWC2::FunctionDescriptor::GetDisplayConnectionType: |
| 249 | return ToHook<HWC2_PFN_GET_DISPLAY_CONNECTION_TYPE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 250 | DisplayHook<decltype(&HwcDisplay::GetDisplayConnectionType), |
| 251 | &HwcDisplay::GetDisplayConnectionType, uint32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 252 | case HWC2::FunctionDescriptor::GetDisplayVsyncPeriod: |
| 253 | return ToHook<HWC2_PFN_GET_DISPLAY_VSYNC_PERIOD>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 254 | DisplayHook<decltype(&HwcDisplay::GetDisplayVsyncPeriod), |
| 255 | &HwcDisplay::GetDisplayVsyncPeriod, |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 256 | hwc2_vsync_period_t *>); |
| 257 | case HWC2::FunctionDescriptor::SetActiveConfigWithConstraints: |
| 258 | return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 259 | DisplayHook<decltype(&HwcDisplay::SetActiveConfigWithConstraints), |
| 260 | &HwcDisplay::SetActiveConfigWithConstraints, |
| 261 | hwc2_config_t, hwc_vsync_period_change_constraints_t *, |
| 262 | hwc_vsync_period_change_timeline_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 263 | case HWC2::FunctionDescriptor::SetAutoLowLatencyMode: |
| 264 | return ToHook<HWC2_PFN_SET_AUTO_LOW_LATENCY_MODE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 265 | DisplayHook<decltype(&HwcDisplay::SetAutoLowLatencyMode), |
| 266 | &HwcDisplay::SetAutoLowLatencyMode, bool>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 267 | case HWC2::FunctionDescriptor::GetSupportedContentTypes: |
| 268 | return ToHook<HWC2_PFN_GET_SUPPORTED_CONTENT_TYPES>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 269 | DisplayHook<decltype(&HwcDisplay::GetSupportedContentTypes), |
| 270 | &HwcDisplay::GetSupportedContentTypes, uint32_t *, |
| 271 | uint32_t *>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 272 | case HWC2::FunctionDescriptor::SetContentType: |
| 273 | return ToHook<HWC2_PFN_SET_CONTENT_TYPE>( |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame^] | 274 | DisplayHook<decltype(&HwcDisplay::SetContentType), |
| 275 | &HwcDisplay::SetContentType, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 276 | #endif |
| 277 | // Layer functions |
| 278 | case HWC2::FunctionDescriptor::SetCursorPosition: |
| 279 | return ToHook<HWC2_PFN_SET_CURSOR_POSITION>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 280 | LayerHook<decltype(&HwcLayer::SetCursorPosition), |
| 281 | &HwcLayer::SetCursorPosition, int32_t, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 282 | case HWC2::FunctionDescriptor::SetLayerBlendMode: |
| 283 | return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 284 | LayerHook<decltype(&HwcLayer::SetLayerBlendMode), |
| 285 | &HwcLayer::SetLayerBlendMode, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 286 | case HWC2::FunctionDescriptor::SetLayerBuffer: |
| 287 | return ToHook<HWC2_PFN_SET_LAYER_BUFFER>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 288 | LayerHook<decltype(&HwcLayer::SetLayerBuffer), |
| 289 | &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 290 | case HWC2::FunctionDescriptor::SetLayerColor: |
| 291 | return ToHook<HWC2_PFN_SET_LAYER_COLOR>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 292 | LayerHook<decltype(&HwcLayer::SetLayerColor), |
| 293 | &HwcLayer::SetLayerColor, hwc_color_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 294 | case HWC2::FunctionDescriptor::SetLayerCompositionType: |
| 295 | return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 296 | LayerHook<decltype(&HwcLayer::SetLayerCompositionType), |
| 297 | &HwcLayer::SetLayerCompositionType, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 298 | case HWC2::FunctionDescriptor::SetLayerDataspace: |
| 299 | return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 300 | LayerHook<decltype(&HwcLayer::SetLayerDataspace), |
| 301 | &HwcLayer::SetLayerDataspace, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 302 | case HWC2::FunctionDescriptor::SetLayerDisplayFrame: |
| 303 | return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 304 | LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame), |
| 305 | &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 306 | case HWC2::FunctionDescriptor::SetLayerPlaneAlpha: |
| 307 | return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 308 | LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha), |
| 309 | &HwcLayer::SetLayerPlaneAlpha, float>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 310 | case HWC2::FunctionDescriptor::SetLayerSidebandStream: |
| 311 | return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 312 | LayerHook<decltype(&HwcLayer::SetLayerSidebandStream), |
| 313 | &HwcLayer::SetLayerSidebandStream, |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 314 | const native_handle_t *>); |
| 315 | case HWC2::FunctionDescriptor::SetLayerSourceCrop: |
| 316 | return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 317 | LayerHook<decltype(&HwcLayer::SetLayerSourceCrop), |
| 318 | &HwcLayer::SetLayerSourceCrop, hwc_frect_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 319 | case HWC2::FunctionDescriptor::SetLayerSurfaceDamage: |
| 320 | return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 321 | LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage), |
| 322 | &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 323 | case HWC2::FunctionDescriptor::SetLayerTransform: |
| 324 | return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 325 | LayerHook<decltype(&HwcLayer::SetLayerTransform), |
| 326 | &HwcLayer::SetLayerTransform, int32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 327 | case HWC2::FunctionDescriptor::SetLayerVisibleRegion: |
| 328 | return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 329 | LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion), |
| 330 | &HwcLayer::SetLayerVisibleRegion, hwc_region_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 331 | case HWC2::FunctionDescriptor::SetLayerZOrder: |
| 332 | return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>( |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 333 | LayerHook<decltype(&HwcLayer::SetLayerZOrder), |
| 334 | &HwcLayer::SetLayerZOrder, uint32_t>); |
Roman Stratiienko | 26fd2b2 | 2022-01-04 12:59:29 +0200 | [diff] [blame] | 335 | case HWC2::FunctionDescriptor::Invalid: |
| 336 | default: |
| 337 | return nullptr; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static int HookDevOpen(const struct hw_module_t *module, const char *name, |
| 342 | struct hw_device_t **dev) { |
| 343 | if (strcmp(name, HWC_HARDWARE_COMPOSER) != 0) { |
| 344 | ALOGE("Invalid module name- %s", name); |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | |
| 348 | auto ctx = std::make_unique<Drmhwc2Device>(); |
| 349 | if (!ctx) { |
| 350 | ALOGE("Failed to allocate DrmHwcTwo"); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | ctx->common.tag = HARDWARE_DEVICE_TAG; |
| 355 | ctx->common.version = HWC_DEVICE_API_VERSION_2_0; |
| 356 | ctx->common.close = HookDevClose; |
| 357 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) |
| 358 | ctx->common.module = (hw_module_t *)module; |
| 359 | ctx->getCapabilities = HookDevGetCapabilities; |
| 360 | ctx->getFunction = HookDevGetFunction; |
| 361 | |
| 362 | HWC2::Error err = ctx->drmhwctwo.Init(); |
| 363 | if (err != HWC2::Error::None) { |
| 364 | ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err); |
| 365 | return -EINVAL; |
| 366 | } |
| 367 | |
| 368 | *dev = &ctx.release()->common; |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | } // namespace android |
| 374 | |
| 375 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
| 376 | static struct hw_module_methods_t hwc2_module_methods = { |
| 377 | .open = android::HookDevOpen, |
| 378 | }; |
| 379 | |
| 380 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
| 381 | hw_module_t HAL_MODULE_INFO_SYM = { |
| 382 | .tag = HARDWARE_MODULE_TAG, |
| 383 | .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0), |
| 384 | .id = HWC_HARDWARE_MODULE_ID, |
| 385 | .name = "DrmHwcTwo module", |
| 386 | .author = "The Android Open Source Project", |
| 387 | .methods = &hwc2_module_methods, |
| 388 | .dso = nullptr, |
| 389 | .reserved = {0}, |
| 390 | }; |