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