Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | #define LOG_TAG "hwc-drm-two" |
| 19 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 20 | #include "DrmHwcTwo.h" |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 21 | |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 22 | #include <fcntl.h> |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 23 | #include <hardware/hardware.h> |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 24 | #include <hardware/hwcomposer2.h> |
Roman Stratiienko | 7477471 | 2021-02-05 16:32:47 +0200 | [diff] [blame] | 25 | #include <sync/sync.h> |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 26 | #include <unistd.h> |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 27 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 28 | #include <cinttypes> |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 29 | #include <iostream> |
| 30 | #include <sstream> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 31 | #include <string> |
| 32 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 33 | #include "backend/BackendManager.h" |
Roman Stratiienko | 33365c2 | 2020-10-10 23:06:36 +0300 | [diff] [blame] | 34 | #include "bufferinfo/BufferInfoGetter.h" |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 35 | #include "compositor/DrmDisplayComposition.h" |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 36 | #include "utils/log.h" |
| 37 | #include "utils/properties.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 38 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 39 | namespace android { |
| 40 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 41 | DrmHwcTwo::DrmHwcTwo() : hwc2_device() { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 42 | common.tag = HARDWARE_DEVICE_TAG; |
| 43 | common.version = HWC_DEVICE_API_VERSION_2_0; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 44 | common.close = HookDevClose; |
| 45 | getCapabilities = HookDevGetCapabilities; |
| 46 | getFunction = HookDevGetFunction; |
| 47 | } |
| 48 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 49 | HWC2::Error DrmHwcTwo::CreateDisplay(hwc2_display_t displ, |
| 50 | HWC2::DisplayType type) { |
| 51 | DrmDevice *drm = resource_manager_.GetDrmDevice(displ); |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 52 | if (!drm) { |
| 53 | ALOGE("Failed to get a valid drmresource"); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 54 | return HWC2::Error::NoResources; |
| 55 | } |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 56 | displays_.emplace(std::piecewise_construct, std::forward_as_tuple(displ), |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 57 | std::forward_as_tuple(&resource_manager_, drm, displ, |
| 58 | type)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 59 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 60 | DrmCrtc *crtc = drm->GetCrtcForDisplay(static_cast<int>(displ)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 61 | if (!crtc) { |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 62 | ALOGE("Failed to get crtc for display %d", static_cast<int>(displ)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 63 | return HWC2::Error::BadDisplay; |
| 64 | } |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 65 | auto display_planes = std::vector<DrmPlane *>(); |
| 66 | for (const auto &plane : drm->planes()) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 67 | if (plane->GetCrtcSupported(*crtc)) |
| 68 | display_planes.push_back(plane.get()); |
| 69 | } |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 70 | displays_.at(displ).Init(&display_planes); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 71 | return HWC2::Error::None; |
| 72 | } |
| 73 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 74 | HWC2::Error DrmHwcTwo::Init() { |
| 75 | int rv = resource_manager_.Init(); |
| 76 | if (rv) { |
| 77 | ALOGE("Can't initialize the resource manager %d", rv); |
| 78 | return HWC2::Error::NoResources; |
| 79 | } |
| 80 | |
| 81 | HWC2::Error ret = HWC2::Error::None; |
| 82 | for (int i = 0; i < resource_manager_.getDisplayCount(); i++) { |
| 83 | ret = CreateDisplay(i, HWC2::DisplayType::Physical); |
| 84 | if (ret != HWC2::Error::None) { |
| 85 | ALOGE("Failed to create display %d with error %d", i, ret); |
| 86 | return ret; |
| 87 | } |
| 88 | } |
| 89 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 90 | const auto &drm_devices = resource_manager_.getDrmDevices(); |
| 91 | for (const auto &device : drm_devices) { |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 92 | // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 93 | device->RegisterHotplugHandler(new DrmHotplugHandler(this, device.get())); |
| 94 | } |
| 95 | return ret; |
| 96 | } |
| 97 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 98 | template <typename... Args> |
| 99 | static inline HWC2::Error unsupported(char const *func, Args... /*args*/) { |
| 100 | ALOGV("Unsupported function: %s", func); |
| 101 | return HWC2::Error::Unsupported; |
| 102 | } |
| 103 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 104 | static inline void supported(char const *func) { |
| 105 | ALOGV("Supported function: %s", func); |
| 106 | } |
| 107 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 108 | HWC2::Error DrmHwcTwo::CreateVirtualDisplay(uint32_t width, uint32_t height, |
| 109 | int32_t *format, |
| 110 | hwc2_display_t *display) { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 111 | // TODO(nobody): Implement virtual display |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 112 | return unsupported(__func__, width, height, format, display); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | HWC2::Error DrmHwcTwo::DestroyVirtualDisplay(hwc2_display_t display) { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 116 | // TODO(nobody): Implement virtual display |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 117 | return unsupported(__func__, display); |
| 118 | } |
| 119 | |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 120 | std::string DrmHwcTwo::HwcDisplay::DumpDelta( |
| 121 | DrmHwcTwo::HwcDisplay::Stats delta) { |
| 122 | if (delta.total_pixops_ == 0) |
| 123 | return "No stats yet"; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 124 | double ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_); |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 125 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 126 | std::stringstream ss; |
| 127 | ss << " Total frames count: " << delta.total_frames_ << "\n" |
| 128 | << " Failed to test commit frames: " << delta.failed_kms_validate_ << "\n" |
| 129 | << " Failed to commit frames: " << delta.failed_kms_present_ << "\n" |
| 130 | << ((delta.failed_kms_present_ > 0) |
| 131 | ? " !!! Internal failure, FIX it please\n" |
| 132 | : "") |
| 133 | << " Flattened frames: " << delta.frames_flattened_ << "\n" |
| 134 | << " Pixel operations (free units)" |
| 135 | << " : [TOTAL: " << delta.total_pixops_ << " / GPU: " << delta.gpu_pixops_ |
| 136 | << "]\n" |
| 137 | << " Composition efficiency: " << ratio; |
| 138 | |
| 139 | return ss.str(); |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | std::string DrmHwcTwo::HwcDisplay::Dump() { |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 143 | std::stringstream ss; |
| 144 | ss << "- Display on: " << connector_->name() << "\n" |
| 145 | << " Flattening state: " << compositor_.GetFlatteningState() << "\n" |
| 146 | << "Statistics since system boot:\n" |
| 147 | << DumpDelta(total_stats_) << "\n\n" |
| 148 | << "Statistics since last dumpsys request:\n" |
| 149 | << DumpDelta(total_stats_.minus(prev_stats_)) << "\n\n"; |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 150 | |
| 151 | memcpy(&prev_stats_, &total_stats_, sizeof(Stats)); |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 152 | return ss.str(); |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void DrmHwcTwo::Dump(uint32_t *outSize, char *outBuffer) { |
| 156 | supported(__func__); |
| 157 | |
| 158 | if (outBuffer != nullptr) { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 159 | auto copied_bytes = mDumpString.copy(outBuffer, *outSize); |
| 160 | *outSize = static_cast<uint32_t>(copied_bytes); |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | |
| 164 | std::stringstream output; |
| 165 | |
| 166 | output << "-- drm_hwcomposer --\n\n"; |
| 167 | |
| 168 | for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &dp : displays_) |
| 169 | output << dp.second.Dump(); |
| 170 | |
| 171 | mDumpString = output.str(); |
| 172 | *outSize = static_cast<uint32_t>(mDumpString.size()); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 176 | // TODO(nobody): Implement virtual display |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 177 | unsupported(__func__); |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 182 | hwc2_callback_data_t data, |
| 183 | hwc2_function_pointer_t function) { |
| 184 | supported(__func__); |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 185 | |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 186 | switch (static_cast<HWC2::Callback>(descriptor)) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 187 | case HWC2::Callback::Hotplug: { |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 188 | SetHotplugCallback(data, function); |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 189 | const auto &drm_devices = resource_manager_.getDrmDevices(); |
| 190 | for (const auto &device : drm_devices) |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 191 | HandleInitialHotplugState(device.get()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 192 | break; |
| 193 | } |
Roman Kovalivskyi | 8fae156 | 2020-01-30 20:20:47 +0200 | [diff] [blame] | 194 | case HWC2::Callback::Refresh: { |
| 195 | for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &d : |
| 196 | displays_) |
| 197 | d.second.RegisterRefreshCallback(data, function); |
| 198 | break; |
| 199 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 200 | case HWC2::Callback::Vsync: { |
| 201 | for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &d : |
| 202 | displays_) |
| 203 | d.second.RegisterVsyncCallback(data, function); |
| 204 | break; |
| 205 | } |
| 206 | default: |
| 207 | break; |
| 208 | } |
| 209 | return HWC2::Error::None; |
| 210 | } |
| 211 | |
Alexandru Gheorghe | 6f0030f | 2018-05-01 17:25:48 +0100 | [diff] [blame] | 212 | DrmHwcTwo::HwcDisplay::HwcDisplay(ResourceManager *resource_manager, |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 213 | DrmDevice *drm, hwc2_display_t handle, |
| 214 | HWC2::DisplayType type) |
Alexandru Gheorghe | 6f0030f | 2018-05-01 17:25:48 +0100 | [diff] [blame] | 215 | : resource_manager_(resource_manager), |
| 216 | drm_(drm), |
Alexandru Gheorghe | 6f0030f | 2018-05-01 17:25:48 +0100 | [diff] [blame] | 217 | handle_(handle), |
Roman Kovalivskyi | 12b91a3 | 2019-12-11 19:09:51 +0200 | [diff] [blame] | 218 | type_(type), |
| 219 | color_transform_hint_(HAL_COLOR_TRANSFORM_IDENTITY) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 220 | supported(__func__); |
Roman Kovalivskyi | 12b91a3 | 2019-12-11 19:09:51 +0200 | [diff] [blame] | 221 | |
| 222 | // clang-format off |
| 223 | color_transform_matrix_ = {1.0, 0.0, 0.0, 0.0, |
| 224 | 0.0, 1.0, 0.0, 0.0, |
| 225 | 0.0, 0.0, 1.0, 0.0, |
| 226 | 0.0, 0.0, 0.0, 1.0}; |
| 227 | // clang-format on |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 228 | } |
| 229 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 230 | void DrmHwcTwo::HwcDisplay::ClearDisplay() { |
| 231 | compositor_.ClearDisplay(); |
| 232 | } |
| 233 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 234 | HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) { |
| 235 | supported(__func__); |
| 236 | planner_ = Planner::CreateInstance(drm_); |
| 237 | if (!planner_) { |
| 238 | ALOGE("Failed to create planner instance for composition"); |
| 239 | return HWC2::Error::NoResources; |
| 240 | } |
| 241 | |
| 242 | int display = static_cast<int>(handle_); |
Alexandru Gheorghe | 62e2d2c | 2018-05-11 11:40:53 +0100 | [diff] [blame] | 243 | int ret = compositor_.Init(resource_manager_, display); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 244 | if (ret) { |
| 245 | ALOGE("Failed display compositor init for display %d (%d)", display, ret); |
| 246 | return HWC2::Error::NoResources; |
| 247 | } |
| 248 | |
| 249 | // Split up the given display planes into primary and overlay to properly |
| 250 | // interface with the composition |
| 251 | char use_overlay_planes_prop[PROPERTY_VALUE_MAX]; |
Jason Macnak | f1af957 | 2020-08-20 11:49:51 -0700 | [diff] [blame] | 252 | property_get("vendor.hwc.drm.use_overlay_planes", use_overlay_planes_prop, |
| 253 | "1"); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 254 | bool use_overlay_planes = strtol(use_overlay_planes_prop, nullptr, 10); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 255 | for (auto &plane : *planes) { |
| 256 | if (plane->type() == DRM_PLANE_TYPE_PRIMARY) |
| 257 | primary_planes_.push_back(plane); |
| 258 | else if (use_overlay_planes && (plane)->type() == DRM_PLANE_TYPE_OVERLAY) |
| 259 | overlay_planes_.push_back(plane); |
| 260 | } |
| 261 | |
| 262 | crtc_ = drm_->GetCrtcForDisplay(display); |
| 263 | if (!crtc_) { |
| 264 | ALOGE("Failed to get crtc for display %d", display); |
| 265 | return HWC2::Error::BadDisplay; |
| 266 | } |
| 267 | |
| 268 | connector_ = drm_->GetConnectorForDisplay(display); |
| 269 | if (!connector_) { |
| 270 | ALOGE("Failed to get connector for display %d", display); |
| 271 | return HWC2::Error::BadDisplay; |
| 272 | } |
| 273 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 274 | ret = vsync_worker_.Init(drm_, display); |
| 275 | if (ret) { |
| 276 | ALOGE("Failed to create event worker for d=%d %d\n", display, ret); |
| 277 | return HWC2::Error::BadDisplay; |
| 278 | } |
| 279 | |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 280 | ret = BackendManager::GetInstance().SetBackendForDisplay(this); |
| 281 | if (ret) { |
| 282 | ALOGE("Failed to set backend for d=%d %d\n", display, ret); |
| 283 | return HWC2::Error::BadDisplay; |
| 284 | } |
| 285 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 286 | return ChosePreferredConfig(); |
| 287 | } |
| 288 | |
| 289 | HWC2::Error DrmHwcTwo::HwcDisplay::ChosePreferredConfig() { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 290 | // Fetch the number of modes from the display |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 291 | uint32_t num_configs = 0; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 292 | HWC2::Error err = GetDisplayConfigs(&num_configs, nullptr); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 293 | if (err != HWC2::Error::None || !num_configs) |
| 294 | return err; |
| 295 | |
Andrii Chepurnyi | 1b1e35e | 2019-02-19 21:38:13 +0200 | [diff] [blame] | 296 | return SetActiveConfig(connector_->get_preferred_mode_id()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 299 | void DrmHwcTwo::HwcDisplay::RegisterVsyncCallback( |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 300 | hwc2_callback_data_t data, hwc2_function_pointer_t func) { |
| 301 | supported(__func__); |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 302 | vsync_worker_.RegisterClientCallback(data, func); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 303 | } |
| 304 | |
Roman Kovalivskyi | 8fae156 | 2020-01-30 20:20:47 +0200 | [diff] [blame] | 305 | void DrmHwcTwo::HwcDisplay::RegisterRefreshCallback( |
| 306 | hwc2_callback_data_t data, hwc2_function_pointer_t func) { |
| 307 | supported(__func__); |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 308 | compositor_.SetRefreshCallback(data, func); |
Roman Kovalivskyi | 8fae156 | 2020-01-30 20:20:47 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 311 | HWC2::Error DrmHwcTwo::HwcDisplay::AcceptDisplayChanges() { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 312 | supported(__func__); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 313 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) |
| 314 | l.second.accept_type_change(); |
| 315 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | HWC2::Error DrmHwcTwo::HwcDisplay::CreateLayer(hwc2_layer_t *layer) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 319 | supported(__func__); |
| 320 | layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer()); |
| 321 | *layer = static_cast<hwc2_layer_t>(layer_idx_); |
| 322 | ++layer_idx_; |
| 323 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | HWC2::Error DrmHwcTwo::HwcDisplay::DestroyLayer(hwc2_layer_t layer) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 327 | supported(__func__); |
Vincent Donnefort | 9abec03 | 2019-10-09 15:43:43 +0100 | [diff] [blame] | 328 | if (!get_layer(layer)) |
| 329 | return HWC2::Error::BadLayer; |
| 330 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 331 | layers_.erase(layer); |
| 332 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | HWC2::Error DrmHwcTwo::HwcDisplay::GetActiveConfig(hwc2_config_t *config) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 336 | supported(__func__); |
| 337 | DrmMode const &mode = connector_->active_mode(); |
| 338 | if (mode.id() == 0) |
| 339 | return HWC2::Error::BadConfig; |
| 340 | |
| 341 | *config = mode.id(); |
| 342 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | HWC2::Error DrmHwcTwo::HwcDisplay::GetChangedCompositionTypes( |
| 346 | uint32_t *num_elements, hwc2_layer_t *layers, int32_t *types) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 347 | supported(__func__); |
| 348 | uint32_t num_changes = 0; |
| 349 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) { |
| 350 | if (l.second.type_changed()) { |
| 351 | if (layers && num_changes < *num_elements) |
| 352 | layers[num_changes] = l.first; |
| 353 | if (types && num_changes < *num_elements) |
| 354 | types[num_changes] = static_cast<int32_t>(l.second.validated_type()); |
| 355 | ++num_changes; |
| 356 | } |
| 357 | } |
| 358 | if (!layers && !types) |
| 359 | *num_elements = num_changes; |
| 360 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | HWC2::Error DrmHwcTwo::HwcDisplay::GetClientTargetSupport(uint32_t width, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 364 | uint32_t height, |
| 365 | int32_t /*format*/, |
| 366 | int32_t dataspace) { |
| 367 | supported(__func__); |
| 368 | std::pair<uint32_t, uint32_t> min = drm_->min_resolution(); |
| 369 | std::pair<uint32_t, uint32_t> max = drm_->max_resolution(); |
| 370 | |
| 371 | if (width < min.first || height < min.second) |
| 372 | return HWC2::Error::Unsupported; |
| 373 | |
| 374 | if (width > max.first || height > max.second) |
| 375 | return HWC2::Error::Unsupported; |
| 376 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 377 | if (dataspace != HAL_DATASPACE_UNKNOWN) |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 378 | return HWC2::Error::Unsupported; |
| 379 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 380 | // TODO(nobody): Validate format can be handled by either GL or planes |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 381 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | HWC2::Error DrmHwcTwo::HwcDisplay::GetColorModes(uint32_t *num_modes, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 385 | int32_t *modes) { |
| 386 | supported(__func__); |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 387 | if (!modes) |
| 388 | *num_modes = 1; |
| 389 | |
| 390 | if (modes) |
| 391 | *modes = HAL_COLOR_MODE_NATIVE; |
| 392 | |
| 393 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 397 | int32_t attribute_in, |
| 398 | int32_t *value) { |
| 399 | supported(__func__); |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 400 | auto mode = std::find_if(connector_->modes().begin(), |
| 401 | connector_->modes().end(), |
| 402 | [config](DrmMode const &m) { |
| 403 | return m.id() == config; |
| 404 | }); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 405 | if (mode == connector_->modes().end()) { |
| 406 | ALOGE("Could not find active mode for %d", config); |
| 407 | return HWC2::Error::BadConfig; |
| 408 | } |
| 409 | |
| 410 | static const int32_t kUmPerInch = 25400; |
| 411 | uint32_t mm_width = connector_->mm_width(); |
| 412 | uint32_t mm_height = connector_->mm_height(); |
| 413 | auto attribute = static_cast<HWC2::Attribute>(attribute_in); |
| 414 | switch (attribute) { |
| 415 | case HWC2::Attribute::Width: |
| 416 | *value = mode->h_display(); |
| 417 | break; |
| 418 | case HWC2::Attribute::Height: |
| 419 | *value = mode->v_display(); |
| 420 | break; |
| 421 | case HWC2::Attribute::VsyncPeriod: |
| 422 | // in nanoseconds |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 423 | *value = 1000.0 * 1000.0 * 1000.0 / mode->v_refresh(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 424 | break; |
| 425 | case HWC2::Attribute::DpiX: |
| 426 | // Dots per 1000 inches |
| 427 | *value = mm_width ? (mode->h_display() * kUmPerInch) / mm_width : -1; |
| 428 | break; |
| 429 | case HWC2::Attribute::DpiY: |
| 430 | // Dots per 1000 inches |
| 431 | *value = mm_height ? (mode->v_display() * kUmPerInch) / mm_height : -1; |
| 432 | break; |
Roman Stratiienko | 6f5df17 | 2020-09-27 22:48:08 +0300 | [diff] [blame] | 433 | #if PLATFORM_SDK_VERSION > 29 |
| 434 | case HWC2::Attribute::ConfigGroup: |
| 435 | *value = 0; /* TODO: Add support for config groups */ |
| 436 | break; |
| 437 | #endif |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 438 | default: |
| 439 | *value = -1; |
| 440 | return HWC2::Error::BadConfig; |
| 441 | } |
| 442 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs, |
| 446 | hwc2_config_t *configs) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 447 | supported(__func__); |
| 448 | // Since this callback is normally invoked twice (once to get the count, and |
| 449 | // once to populate configs), we don't really want to read the edid |
| 450 | // redundantly. Instead, only update the modes on the first invocation. While |
| 451 | // it's possible this will result in stale modes, it'll all come out in the |
| 452 | // wash when we try to set the active config later. |
| 453 | if (!configs) { |
| 454 | int ret = connector_->UpdateModes(); |
| 455 | if (ret) { |
| 456 | ALOGE("Failed to update display modes %d", ret); |
| 457 | return HWC2::Error::BadDisplay; |
| 458 | } |
| 459 | } |
| 460 | |
Neil Armstrong | b67d049 | 2019-06-20 09:00:21 +0000 | [diff] [blame] | 461 | // Since the upper layers only look at vactive/hactive/refresh, height and |
| 462 | // width, it doesn't differentiate interlaced from progressive and other |
| 463 | // similar modes. Depending on the order of modes we return to SF, it could |
| 464 | // end up choosing a suboptimal configuration and dropping the preferred |
| 465 | // mode. To workaround this, don't offer interlaced modes to SF if there is |
| 466 | // at least one non-interlaced alternative and only offer a single WxH@R |
| 467 | // mode with at least the prefered mode from in DrmConnector::UpdateModes() |
| 468 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 469 | // TODO(nobody): Remove the following block of code until AOSP handles all |
| 470 | // modes |
Neil Armstrong | b67d049 | 2019-06-20 09:00:21 +0000 | [diff] [blame] | 471 | std::vector<DrmMode> sel_modes; |
| 472 | |
| 473 | // Add the preferred mode first to be sure it's not dropped |
| 474 | auto mode = std::find_if(connector_->modes().begin(), |
| 475 | connector_->modes().end(), [&](DrmMode const &m) { |
| 476 | return m.id() == |
| 477 | connector_->get_preferred_mode_id(); |
| 478 | }); |
| 479 | if (mode != connector_->modes().end()) |
| 480 | sel_modes.push_back(*mode); |
| 481 | |
| 482 | // Add the active mode if different from preferred mode |
| 483 | if (connector_->active_mode().id() != connector_->get_preferred_mode_id()) |
| 484 | sel_modes.push_back(connector_->active_mode()); |
| 485 | |
| 486 | // Cycle over the modes and filter out "similar" modes, keeping only the |
| 487 | // first ones in the order given by DRM (from CEA ids and timings order) |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 488 | for (const DrmMode &mode : connector_->modes()) { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 489 | // TODO(nobody): Remove this when 3D Attributes are in AOSP |
Neil Armstrong | b67d049 | 2019-06-20 09:00:21 +0000 | [diff] [blame] | 490 | if (mode.flags() & DRM_MODE_FLAG_3D_MASK) |
| 491 | continue; |
| 492 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 493 | // TODO(nobody): Remove this when the Interlaced attribute is in AOSP |
Neil Armstrong | 4c027a7 | 2019-06-04 14:48:02 +0000 | [diff] [blame] | 494 | if (mode.flags() & DRM_MODE_FLAG_INTERLACE) { |
| 495 | auto m = std::find_if(connector_->modes().begin(), |
| 496 | connector_->modes().end(), |
| 497 | [&mode](DrmMode const &m) { |
| 498 | return !(m.flags() & DRM_MODE_FLAG_INTERLACE) && |
| 499 | m.h_display() == mode.h_display() && |
| 500 | m.v_display() == mode.v_display(); |
| 501 | }); |
Neil Armstrong | b67d049 | 2019-06-20 09:00:21 +0000 | [diff] [blame] | 502 | if (m == connector_->modes().end()) |
| 503 | sel_modes.push_back(mode); |
| 504 | |
| 505 | continue; |
Neil Armstrong | 4c027a7 | 2019-06-04 14:48:02 +0000 | [diff] [blame] | 506 | } |
Neil Armstrong | b67d049 | 2019-06-20 09:00:21 +0000 | [diff] [blame] | 507 | |
| 508 | // Search for a similar WxH@R mode in the filtered list and drop it if |
| 509 | // another mode with the same WxH@R has already been selected |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 510 | // TODO(nobody): Remove this when AOSP handles duplicates modes |
Neil Armstrong | b67d049 | 2019-06-20 09:00:21 +0000 | [diff] [blame] | 511 | auto m = std::find_if(sel_modes.begin(), sel_modes.end(), |
| 512 | [&mode](DrmMode const &m) { |
| 513 | return m.h_display() == mode.h_display() && |
| 514 | m.v_display() == mode.v_display() && |
| 515 | m.v_refresh() == mode.v_refresh(); |
| 516 | }); |
| 517 | if (m == sel_modes.end()) |
| 518 | sel_modes.push_back(mode); |
| 519 | } |
| 520 | |
| 521 | auto num_modes = static_cast<uint32_t>(sel_modes.size()); |
| 522 | if (!configs) { |
| 523 | *num_configs = num_modes; |
| 524 | return HWC2::Error::None; |
| 525 | } |
| 526 | |
| 527 | uint32_t idx = 0; |
| 528 | for (const DrmMode &mode : sel_modes) { |
| 529 | if (idx >= *num_configs) |
| 530 | break; |
| 531 | configs[idx++] = mode.id(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 532 | } |
| 533 | *num_configs = idx; |
| 534 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayName(uint32_t *size, char *name) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 538 | supported(__func__); |
| 539 | std::ostringstream stream; |
| 540 | stream << "display-" << connector_->id(); |
| 541 | std::string string = stream.str(); |
| 542 | size_t length = string.length(); |
| 543 | if (!name) { |
| 544 | *size = length; |
| 545 | return HWC2::Error::None; |
| 546 | } |
| 547 | |
| 548 | *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size); |
| 549 | strncpy(name, string.c_str(), *size); |
| 550 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 553 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests, |
| 554 | uint32_t *num_elements, |
| 555 | hwc2_layer_t *layers, |
| 556 | int32_t *layer_requests) { |
| 557 | supported(__func__); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 558 | // TODO(nobody): I think virtual display should request |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 559 | // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here |
| 560 | unsupported(__func__, display_requests, num_elements, layers, layer_requests); |
| 561 | *num_elements = 0; |
| 562 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayType(int32_t *type) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 566 | supported(__func__); |
| 567 | *type = static_cast<int32_t>(type_); |
| 568 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDozeSupport(int32_t *support) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 572 | supported(__func__); |
| 573 | *support = 0; |
| 574 | return HWC2::Error::None; |
| 575 | } |
| 576 | |
| 577 | HWC2::Error DrmHwcTwo::HwcDisplay::GetHdrCapabilities( |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 578 | uint32_t *num_types, int32_t * /*types*/, float * /*max_luminance*/, |
| 579 | float * /*max_average_luminance*/, float * /*min_luminance*/) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 580 | supported(__func__); |
| 581 | *num_types = 0; |
| 582 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 586 | hwc2_layer_t *layers, |
| 587 | int32_t *fences) { |
| 588 | supported(__func__); |
| 589 | uint32_t num_layers = 0; |
| 590 | |
| 591 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) { |
| 592 | ++num_layers; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 593 | if (layers == nullptr || fences == nullptr) |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 594 | continue; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 595 | |
| 596 | if (num_layers > *num_elements) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 597 | ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements); |
| 598 | return HWC2::Error::None; |
| 599 | } |
| 600 | |
| 601 | layers[num_layers - 1] = l.first; |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 602 | fences[num_layers - 1] = l.second.release_fence_.Release(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 603 | } |
| 604 | *num_elements = num_layers; |
| 605 | return HWC2::Error::None; |
| 606 | } |
| 607 | |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 608 | void DrmHwcTwo::HwcDisplay::AddFenceToPresentFence(UniqueFd fd) { |
| 609 | if (!fd) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 610 | return; |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 611 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 612 | |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 613 | if (present_fence_) { |
| 614 | present_fence_ = UniqueFd( |
| 615 | sync_merge("dc_present", present_fence_.Get(), fd.Get())); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 616 | } else { |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 617 | present_fence_ = std::move(fd); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 618 | } |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 619 | } |
| 620 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 621 | HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 622 | // order the layers by z-order |
| 623 | bool use_client_layer = false; |
Alexandru Gheorghe | 1542d29 | 2018-06-13 16:46:36 +0100 | [diff] [blame] | 624 | uint32_t client_z_order = UINT32_MAX; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 625 | std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map; |
| 626 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) { |
Roman Stratiienko | f264723 | 2019-11-21 01:58:35 +0200 | [diff] [blame] | 627 | switch (l.second.validated_type()) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 628 | case HWC2::Composition::Device: |
| 629 | z_map.emplace(std::make_pair(l.second.z_order(), &l.second)); |
| 630 | break; |
| 631 | case HWC2::Composition::Client: |
Alexandru Gheorghe | 1542d29 | 2018-06-13 16:46:36 +0100 | [diff] [blame] | 632 | // Place it at the z_order of the lowest client layer |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 633 | use_client_layer = true; |
Alexandru Gheorghe | 1542d29 | 2018-06-13 16:46:36 +0100 | [diff] [blame] | 634 | client_z_order = std::min(client_z_order, l.second.z_order()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 635 | break; |
| 636 | default: |
| 637 | continue; |
| 638 | } |
| 639 | } |
| 640 | if (use_client_layer) |
| 641 | z_map.emplace(std::make_pair(client_z_order, &client_layer_)); |
| 642 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 643 | if (z_map.empty()) |
| 644 | return HWC2::Error::BadLayer; |
| 645 | |
Matvii Zorin | 5368b73 | 2021-01-12 10:53:08 +0200 | [diff] [blame] | 646 | std::vector<DrmHwcLayer> composition_layers; |
| 647 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 648 | // now that they're ordered by z, add them to the composition |
| 649 | for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) { |
| 650 | DrmHwcLayer layer; |
| 651 | l.second->PopulateDrmLayer(&layer); |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 652 | int ret = layer.ImportBuffer(drm_); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 653 | if (ret) { |
| 654 | ALOGE("Failed to import layer, ret=%d", ret); |
| 655 | return HWC2::Error::NoResources; |
| 656 | } |
Matvii Zorin | 5368b73 | 2021-01-12 10:53:08 +0200 | [diff] [blame] | 657 | composition_layers.emplace_back(std::move(layer)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 658 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 659 | |
Matvii Zorin | 704ea0e | 2021-01-08 12:55:45 +0200 | [diff] [blame] | 660 | auto composition = std::make_unique<DrmDisplayComposition>(crtc_, |
| 661 | planner_.get()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 662 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 663 | // TODO(nobody): Don't always assume geometry changed |
Matvii Zorin | 5368b73 | 2021-01-12 10:53:08 +0200 | [diff] [blame] | 664 | int ret = composition->SetLayers(composition_layers.data(), |
| 665 | composition_layers.size(), true); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 666 | if (ret) { |
| 667 | ALOGE("Failed to set layers in the composition ret=%d", ret); |
| 668 | return HWC2::Error::BadLayer; |
| 669 | } |
| 670 | |
| 671 | std::vector<DrmPlane *> primary_planes(primary_planes_); |
| 672 | std::vector<DrmPlane *> overlay_planes(overlay_planes_); |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 673 | ret = composition->Plan(&primary_planes, &overlay_planes); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 674 | if (ret) { |
| 675 | ALOGE("Failed to plan the composition ret=%d", ret); |
| 676 | return HWC2::Error::BadConfig; |
| 677 | } |
| 678 | |
| 679 | // Disable the planes we're not using |
| 680 | for (auto i = primary_planes.begin(); i != primary_planes.end();) { |
| 681 | composition->AddPlaneDisable(*i); |
| 682 | i = primary_planes.erase(i); |
| 683 | } |
| 684 | for (auto i = overlay_planes.begin(); i != overlay_planes.end();) { |
| 685 | composition->AddPlaneDisable(*i); |
| 686 | i = overlay_planes.erase(i); |
| 687 | } |
| 688 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 689 | if (test) { |
| 690 | ret = compositor_.TestComposition(composition.get()); |
| 691 | } else { |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 692 | ret = compositor_.ApplyComposition(std::move(composition)); |
Matteo Franchin | c56eede | 2019-12-03 17:10:38 +0000 | [diff] [blame] | 693 | AddFenceToPresentFence(compositor_.TakeOutFence()); |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 694 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 695 | if (ret) { |
John Stultz | 78c9f6c | 2018-05-24 16:43:35 -0700 | [diff] [blame] | 696 | if (!test) |
| 697 | ALOGE("Failed to apply the frame composition ret=%d", ret); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 698 | return HWC2::Error::BadParameter; |
| 699 | } |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 700 | return HWC2::Error::None; |
| 701 | } |
| 702 | |
Matteo Franchin | c56eede | 2019-12-03 17:10:38 +0000 | [diff] [blame] | 703 | HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *present_fence) { |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 704 | supported(__func__); |
| 705 | HWC2::Error ret; |
| 706 | |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 707 | ++total_stats_.total_frames_; |
| 708 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 709 | ret = CreateComposition(false); |
Roman Stratiienko | 0d1a2cd | 2019-11-28 17:51:16 +0200 | [diff] [blame] | 710 | if (ret != HWC2::Error::None) |
| 711 | ++total_stats_.failed_kms_present_; |
| 712 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 713 | if (ret == HWC2::Error::BadLayer) { |
| 714 | // Can we really have no client or device layers? |
Matteo Franchin | c56eede | 2019-12-03 17:10:38 +0000 | [diff] [blame] | 715 | *present_fence = -1; |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 716 | return HWC2::Error::None; |
| 717 | } |
| 718 | if (ret != HWC2::Error::None) |
| 719 | return ret; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 720 | |
Matteo Franchin | c56eede | 2019-12-03 17:10:38 +0000 | [diff] [blame] | 721 | *present_fence = present_fence_.Release(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 722 | |
| 723 | ++frame_no_; |
| 724 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 728 | supported(__func__); |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 729 | auto mode = std::find_if(connector_->modes().begin(), |
| 730 | connector_->modes().end(), |
| 731 | [config](DrmMode const &m) { |
| 732 | return m.id() == config; |
| 733 | }); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 734 | if (mode == connector_->modes().end()) { |
| 735 | ALOGE("Could not find active mode for %d", config); |
| 736 | return HWC2::Error::BadConfig; |
| 737 | } |
| 738 | |
Matvii Zorin | 704ea0e | 2021-01-08 12:55:45 +0200 | [diff] [blame] | 739 | auto composition = std::make_unique<DrmDisplayComposition>(crtc_, |
| 740 | planner_.get()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 741 | int ret = composition->SetDisplayMode(*mode); |
Roman Stratiienko | 6a10c4c | 2021-02-15 11:25:23 +0200 | [diff] [blame] | 742 | if (ret) { |
| 743 | return HWC2::Error::BadConfig; |
| 744 | } |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 745 | ret = compositor_.ApplyComposition(std::move(composition)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 746 | if (ret) { |
| 747 | ALOGE("Failed to queue dpms composition on %d", ret); |
| 748 | return HWC2::Error::BadConfig; |
| 749 | } |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 750 | |
| 751 | connector_->set_active_mode(*mode); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 752 | |
| 753 | // Setup the client layer's dimensions |
| 754 | hwc_rect_t display_frame = {.left = 0, |
| 755 | .top = 0, |
| 756 | .right = static_cast<int>(mode->h_display()), |
| 757 | .bottom = static_cast<int>(mode->v_display())}; |
| 758 | client_layer_.SetLayerDisplayFrame(display_frame); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 759 | |
| 760 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target, |
| 764 | int32_t acquire_fence, |
| 765 | int32_t dataspace, |
Rob Herring | 1b2685c | 2017-11-29 10:19:57 -0600 | [diff] [blame] | 766 | hwc_region_t /*damage*/) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 767 | supported(__func__); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 768 | |
| 769 | client_layer_.set_buffer(target); |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 770 | client_layer_.acquire_fence_ = UniqueFd( |
| 771 | fcntl(acquire_fence, F_DUPFD_CLOEXEC)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 772 | client_layer_.SetLayerDataspace(dataspace); |
Roman Stratiienko | 33365c2 | 2020-10-10 23:06:36 +0300 | [diff] [blame] | 773 | |
| 774 | /* TODO: Do not update source_crop every call. |
| 775 | * It makes sense to do it once after every hotplug event. */ |
| 776 | hwc_drm_bo bo{}; |
| 777 | BufferInfoGetter::GetInstance()->ConvertBoInfo(target, &bo); |
| 778 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 779 | hwc_frect_t source_crop = {.left = 0.0F, |
| 780 | .top = 0.0F, |
| 781 | .right = bo.width + 0.0F, |
| 782 | .bottom = bo.height + 0.0F}; |
Roman Stratiienko | 33365c2 | 2020-10-10 23:06:36 +0300 | [diff] [blame] | 783 | client_layer_.SetLayerSourceCrop(source_crop); |
| 784 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 785 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 789 | supported(__func__); |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 790 | |
Roman Stratiienko | d146d6d | 2020-10-04 23:56:46 +0300 | [diff] [blame] | 791 | if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_BT2100_HLG) |
| 792 | return HWC2::Error::BadParameter; |
| 793 | |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 794 | if (mode != HAL_COLOR_MODE_NATIVE) |
Roman Stratiienko | 27d2ed6 | 2020-09-26 23:59:19 +0300 | [diff] [blame] | 795 | return HWC2::Error::Unsupported; |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 796 | |
| 797 | color_mode_ = mode; |
| 798 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 802 | int32_t hint) { |
| 803 | supported(__func__); |
Roman Kovalivskyi | 12b91a3 | 2019-12-11 19:09:51 +0200 | [diff] [blame] | 804 | if (hint < HAL_COLOR_TRANSFORM_IDENTITY || |
| 805 | hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA) |
| 806 | return HWC2::Error::BadParameter; |
| 807 | |
| 808 | if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX) |
| 809 | return HWC2::Error::BadParameter; |
| 810 | |
| 811 | color_transform_hint_ = static_cast<android_color_transform_t>(hint); |
| 812 | if (color_transform_hint_ == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX) |
| 813 | std::copy(matrix, matrix + MATRIX_SIZE, color_transform_matrix_.begin()); |
| 814 | |
| 815 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 819 | int32_t release_fence) { |
| 820 | supported(__func__); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 821 | // TODO(nobody): Need virtual display support |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 822 | return unsupported(__func__, buffer, release_fence); |
| 823 | } |
| 824 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 825 | HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) { |
| 826 | supported(__func__); |
| 827 | uint64_t dpms_value = 0; |
| 828 | auto mode = static_cast<HWC2::PowerMode>(mode_in); |
| 829 | switch (mode) { |
| 830 | case HWC2::PowerMode::Off: |
| 831 | dpms_value = DRM_MODE_DPMS_OFF; |
| 832 | break; |
| 833 | case HWC2::PowerMode::On: |
| 834 | dpms_value = DRM_MODE_DPMS_ON; |
| 835 | break; |
Vincent Donnefort | 60ef7eb | 2019-10-09 11:39:28 +0100 | [diff] [blame] | 836 | case HWC2::PowerMode::Doze: |
| 837 | case HWC2::PowerMode::DozeSuspend: |
| 838 | return HWC2::Error::Unsupported; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 839 | default: |
| 840 | ALOGI("Power mode %d is unsupported\n", mode); |
Vincent Donnefort | 60ef7eb | 2019-10-09 11:39:28 +0100 | [diff] [blame] | 841 | return HWC2::Error::BadParameter; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 842 | }; |
| 843 | |
Matvii Zorin | 704ea0e | 2021-01-08 12:55:45 +0200 | [diff] [blame] | 844 | auto composition = std::make_unique<DrmDisplayComposition>(crtc_, |
| 845 | planner_.get()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 846 | composition->SetDpmsMode(dpms_value); |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 847 | int ret = compositor_.ApplyComposition(std::move(composition)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 848 | if (ret) { |
| 849 | ALOGE("Failed to apply the dpms composition ret=%d", ret); |
| 850 | return HWC2::Error::BadParameter; |
| 851 | } |
| 852 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 856 | supported(__func__); |
Andrii Chepurnyi | 4bdd0fe | 2018-07-27 15:14:37 +0300 | [diff] [blame] | 857 | vsync_worker_.VSyncControl(HWC2_VSYNC_ENABLE == enabled); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 858 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 862 | uint32_t *num_requests) { |
| 863 | supported(__func__); |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 864 | |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 865 | return backend_->ValidateDisplay(this, num_types, num_requests); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 866 | } |
| 867 | |
Matvii Zorin | ed90ef9 | 2021-01-29 18:32:06 +0200 | [diff] [blame] | 868 | std::vector<DrmHwcTwo::HwcLayer *> |
| 869 | DrmHwcTwo::HwcDisplay::GetOrderLayersByZPos() { |
| 870 | std::vector<DrmHwcTwo::HwcLayer *> ordered_layers; |
| 871 | ordered_layers.reserve(layers_.size()); |
| 872 | |
| 873 | for (auto &[handle, layer] : layers_) { |
| 874 | ordered_layers.emplace_back(&layer); |
| 875 | } |
| 876 | |
| 877 | std::sort(std::begin(ordered_layers), std::end(ordered_layers), |
| 878 | [](const DrmHwcTwo::HwcLayer *lhs, const DrmHwcTwo::HwcLayer *rhs) { |
| 879 | return lhs->z_order() < rhs->z_order(); |
| 880 | }); |
| 881 | |
| 882 | return ordered_layers; |
| 883 | } |
| 884 | |
Roman Stratiienko | 6f5df17 | 2020-09-27 22:48:08 +0300 | [diff] [blame] | 885 | #if PLATFORM_SDK_VERSION > 29 |
| 886 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConnectionType(uint32_t *outType) { |
| 887 | if (connector_->internal()) |
| 888 | *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal); |
| 889 | else if (connector_->external()) |
| 890 | *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External); |
| 891 | else |
| 892 | return HWC2::Error::BadConfig; |
| 893 | |
| 894 | return HWC2::Error::None; |
| 895 | } |
| 896 | |
| 897 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayVsyncPeriod( |
| 898 | hwc2_vsync_period_t *outVsyncPeriod /* ns */) { |
| 899 | supported(__func__); |
| 900 | DrmMode const &mode = connector_->active_mode(); |
| 901 | if (mode.id() == 0) |
| 902 | return HWC2::Error::BadConfig; |
| 903 | |
| 904 | *outVsyncPeriod = 1E9 / mode.v_refresh(); |
| 905 | return HWC2::Error::None; |
| 906 | } |
| 907 | |
| 908 | HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfigWithConstraints( |
| 909 | hwc2_config_t /*config*/, |
| 910 | hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints, |
| 911 | hwc_vsync_period_change_timeline_t *outTimeline) { |
| 912 | supported(__func__); |
| 913 | |
| 914 | if (vsyncPeriodChangeConstraints == nullptr || outTimeline == nullptr) { |
| 915 | return HWC2::Error::BadParameter; |
| 916 | } |
| 917 | |
| 918 | return HWC2::Error::BadConfig; |
| 919 | } |
| 920 | |
| 921 | HWC2::Error DrmHwcTwo::HwcDisplay::SetAutoLowLatencyMode(bool /*on*/) { |
| 922 | return HWC2::Error::Unsupported; |
| 923 | } |
| 924 | |
| 925 | HWC2::Error DrmHwcTwo::HwcDisplay::GetSupportedContentTypes( |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 926 | uint32_t *outNumSupportedContentTypes, |
| 927 | const uint32_t *outSupportedContentTypes) { |
Roman Stratiienko | 6f5df17 | 2020-09-27 22:48:08 +0300 | [diff] [blame] | 928 | if (outSupportedContentTypes == nullptr) |
| 929 | *outNumSupportedContentTypes = 0; |
| 930 | |
| 931 | return HWC2::Error::None; |
| 932 | } |
| 933 | |
| 934 | HWC2::Error DrmHwcTwo::HwcDisplay::SetContentType(int32_t contentType) { |
| 935 | supported(__func__); |
| 936 | |
| 937 | if (contentType != HWC2_CONTENT_TYPE_NONE) |
| 938 | return HWC2::Error::Unsupported; |
| 939 | |
| 940 | /* TODO: Map to the DRM Connector property: |
| 941 | * https://elixir.bootlin.com/linux/v5.4-rc5/source/drivers/gpu/drm/drm_connector.c#L809 |
| 942 | */ |
| 943 | |
| 944 | return HWC2::Error::None; |
| 945 | } |
| 946 | #endif |
| 947 | |
John Stultz | 8c7229d | 2020-02-07 21:31:08 +0000 | [diff] [blame] | 948 | #if PLATFORM_SDK_VERSION > 28 |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 949 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayIdentificationData( |
| 950 | uint8_t *outPort, uint32_t *outDataSize, uint8_t *outData) { |
| 951 | supported(__func__); |
| 952 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 953 | drmModePropertyBlobPtr blob = nullptr; |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 954 | |
Andrii Chepurnyi | adc5d82 | 2020-07-10 16:07:03 +0300 | [diff] [blame] | 955 | if (connector_->GetEdidBlob(blob)) { |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 956 | ALOGE("Failed to get edid property value."); |
| 957 | return HWC2::Error::Unsupported; |
| 958 | } |
| 959 | |
Andrii Chepurnyi | 8115dbe | 2020-04-14 13:03:57 +0300 | [diff] [blame] | 960 | if (outData) { |
| 961 | *outDataSize = std::min(*outDataSize, blob->length); |
| 962 | memcpy(outData, blob->data, *outDataSize); |
| 963 | } else { |
| 964 | *outDataSize = blob->length; |
| 965 | } |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 966 | *outPort = connector_->id(); |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 967 | |
| 968 | return HWC2::Error::None; |
| 969 | } |
| 970 | |
| 971 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayCapabilities( |
| 972 | uint32_t *outNumCapabilities, uint32_t *outCapabilities) { |
| 973 | unsupported(__func__, outCapabilities); |
| 974 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 975 | if (outNumCapabilities == nullptr) { |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 976 | return HWC2::Error::BadParameter; |
| 977 | } |
| 978 | |
| 979 | *outNumCapabilities = 0; |
| 980 | |
| 981 | return HWC2::Error::None; |
| 982 | } |
Andrii Chepurnyi | 2619aab | 2020-07-03 11:21:33 +0300 | [diff] [blame] | 983 | |
| 984 | HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayBrightnessSupport( |
| 985 | bool *supported) { |
| 986 | *supported = false; |
| 987 | return HWC2::Error::None; |
| 988 | } |
| 989 | |
| 990 | HWC2::Error DrmHwcTwo::HwcDisplay::SetDisplayBrightness( |
| 991 | float /* brightness */) { |
| 992 | return HWC2::Error::Unsupported; |
| 993 | } |
| 994 | |
John Stultz | 8c7229d | 2020-02-07 21:31:08 +0000 | [diff] [blame] | 995 | #endif /* PLATFORM_SDK_VERSION > 28 */ |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 996 | |
Andrii Chepurnyi | 50d3745 | 2020-04-24 14:20:24 +0300 | [diff] [blame] | 997 | #if PLATFORM_SDK_VERSION > 27 |
| 998 | |
| 999 | HWC2::Error DrmHwcTwo::HwcDisplay::GetRenderIntents( |
| 1000 | int32_t mode, uint32_t *outNumIntents, |
| 1001 | int32_t * /*android_render_intent_v1_1_t*/ outIntents) { |
| 1002 | if (mode != HAL_COLOR_MODE_NATIVE) { |
| 1003 | return HWC2::Error::BadParameter; |
| 1004 | } |
| 1005 | |
| 1006 | if (outIntents == nullptr) { |
| 1007 | *outNumIntents = 1; |
| 1008 | return HWC2::Error::None; |
| 1009 | } |
| 1010 | *outNumIntents = 1; |
| 1011 | outIntents[0] = HAL_RENDER_INTENT_COLORIMETRIC; |
| 1012 | return HWC2::Error::None; |
| 1013 | } |
| 1014 | |
Andrii Chepurnyi | 857a53f | 2020-04-29 23:15:28 +0300 | [diff] [blame] | 1015 | HWC2::Error DrmHwcTwo::HwcDisplay::SetColorModeWithIntent(int32_t mode, |
| 1016 | int32_t intent) { |
Roman Stratiienko | 27d2ed6 | 2020-09-26 23:59:19 +0300 | [diff] [blame] | 1017 | if (intent < HAL_RENDER_INTENT_COLORIMETRIC || |
| 1018 | intent > HAL_RENDER_INTENT_TONE_MAP_ENHANCE) |
| 1019 | return HWC2::Error::BadParameter; |
| 1020 | |
| 1021 | if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_BT2100_HLG) |
| 1022 | return HWC2::Error::BadParameter; |
| 1023 | |
Andrii Chepurnyi | 857a53f | 2020-04-29 23:15:28 +0300 | [diff] [blame] | 1024 | if (mode != HAL_COLOR_MODE_NATIVE) |
Roman Stratiienko | 27d2ed6 | 2020-09-26 23:59:19 +0300 | [diff] [blame] | 1025 | return HWC2::Error::Unsupported; |
| 1026 | |
Andrii Chepurnyi | 857a53f | 2020-04-29 23:15:28 +0300 | [diff] [blame] | 1027 | if (intent != HAL_RENDER_INTENT_COLORIMETRIC) |
Roman Stratiienko | 27d2ed6 | 2020-09-26 23:59:19 +0300 | [diff] [blame] | 1028 | return HWC2::Error::Unsupported; |
| 1029 | |
Andrii Chepurnyi | 857a53f | 2020-04-29 23:15:28 +0300 | [diff] [blame] | 1030 | color_mode_ = mode; |
| 1031 | return HWC2::Error::None; |
| 1032 | } |
| 1033 | |
Andrii Chepurnyi | 50d3745 | 2020-04-24 14:20:24 +0300 | [diff] [blame] | 1034 | #endif /* PLATFORM_SDK_VERSION > 27 */ |
| 1035 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1036 | HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t x, int32_t y) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1037 | supported(__func__); |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 1038 | cursor_x_ = x; |
| 1039 | cursor_y_ = y; |
| 1040 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1044 | supported(__func__); |
| 1045 | blending_ = static_cast<HWC2::BlendMode>(mode); |
| 1046 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1050 | int32_t acquire_fence) { |
| 1051 | supported(__func__); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1052 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1053 | set_buffer(buffer); |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 1054 | acquire_fence_ = UniqueFd(fcntl(acquire_fence, F_DUPFD_CLOEXEC)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1055 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1059 | // TODO(nobody): Put to client composition here? |
Roman Kovalivskyi | bb37569 | 2019-12-11 17:48:44 +0200 | [diff] [blame] | 1060 | supported(__func__); |
| 1061 | layer_color_ = color; |
| 1062 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1066 | sf_type_ = static_cast<HWC2::Composition>(type); |
| 1067 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1071 | supported(__func__); |
| 1072 | dataspace_ = static_cast<android_dataspace_t>(dataspace); |
| 1073 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1077 | supported(__func__); |
| 1078 | display_frame_ = frame; |
| 1079 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1083 | supported(__func__); |
| 1084 | alpha_ = alpha; |
| 1085 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream( |
| 1089 | const native_handle_t *stream) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1090 | supported(__func__); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1091 | // TODO(nobody): We don't support sideband |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1092 | return unsupported(__func__, stream); |
| 1093 | } |
| 1094 | |
| 1095 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1096 | supported(__func__); |
| 1097 | source_crop_ = crop; |
| 1098 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1102 | supported(__func__); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1103 | // TODO(nobody): We don't use surface damage, marking as unsupported |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1104 | unsupported(__func__, damage); |
| 1105 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1109 | supported(__func__); |
| 1110 | transform_ = static_cast<HWC2::Transform>(transform); |
| 1111 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1115 | supported(__func__); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1116 | // TODO(nobody): We don't use this information, marking as unsupported |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1117 | unsupported(__func__, visible); |
| 1118 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1119 | } |
| 1120 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1121 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) { |
| 1122 | supported(__func__); |
| 1123 | z_order_ = order; |
| 1124 | return HWC2::Error::None; |
| 1125 | } |
| 1126 | |
| 1127 | void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) { |
| 1128 | supported(__func__); |
| 1129 | switch (blending_) { |
| 1130 | case HWC2::BlendMode::None: |
| 1131 | layer->blending = DrmHwcBlending::kNone; |
| 1132 | break; |
| 1133 | case HWC2::BlendMode::Premultiplied: |
| 1134 | layer->blending = DrmHwcBlending::kPreMult; |
| 1135 | break; |
| 1136 | case HWC2::BlendMode::Coverage: |
| 1137 | layer->blending = DrmHwcBlending::kCoverage; |
| 1138 | break; |
| 1139 | default: |
| 1140 | ALOGE("Unknown blending mode b=%d", blending_); |
| 1141 | layer->blending = DrmHwcBlending::kNone; |
| 1142 | break; |
| 1143 | } |
| 1144 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1145 | layer->sf_handle = buffer_; |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame^] | 1146 | // TODO(rsglobal): Avoid extra fd duplication |
| 1147 | layer->acquire_fence = UniqueFd(fcntl(acquire_fence_.Get(), F_DUPFD_CLOEXEC)); |
Roman Kovalivskyi | b865227 | 2021-01-24 20:32:37 +0200 | [diff] [blame] | 1148 | layer->display_frame = display_frame_; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1149 | layer->alpha = lround(65535.0F * alpha_); |
Roman Kovalivskyi | b865227 | 2021-01-24 20:32:37 +0200 | [diff] [blame] | 1150 | layer->source_crop = source_crop_; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1151 | layer->SetTransform(static_cast<int32_t>(transform_)); |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame] | 1152 | layer->dataspace = dataspace_; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1153 | } |
| 1154 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 1155 | void DrmHwcTwo::HandleDisplayHotplug(hwc2_display_t displayid, int state) { |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 1156 | const std::lock_guard<std::mutex> lock(hotplug_callback_lock); |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 1157 | |
Roman Stratiienko | 2370109 | 2020-09-26 02:08:41 +0300 | [diff] [blame] | 1158 | if (hotplug_callback_hook_ && hotplug_callback_data_) |
| 1159 | hotplug_callback_hook_(hotplug_callback_data_, displayid, |
| 1160 | state == DRM_MODE_CONNECTED |
| 1161 | ? HWC2_CONNECTION_CONNECTED |
| 1162 | : HWC2_CONNECTION_DISCONNECTED); |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | void DrmHwcTwo::HandleInitialHotplugState(DrmDevice *drmDevice) { |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 1166 | for (const auto &conn : drmDevice->connectors()) { |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 1167 | if (conn->state() != DRM_MODE_CONNECTED) |
| 1168 | continue; |
| 1169 | HandleDisplayHotplug(conn->display(), conn->state()); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | void DrmHwcTwo::DrmHotplugHandler::HandleEvent(uint64_t timestamp_us) { |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 1174 | for (const auto &conn : drm_->connectors()) { |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 1175 | drmModeConnection old_state = conn->state(); |
| 1176 | drmModeConnection cur_state = conn->UpdateModes() |
| 1177 | ? DRM_MODE_UNKNOWNCONNECTION |
| 1178 | : conn->state(); |
| 1179 | |
| 1180 | if (cur_state == old_state) |
| 1181 | continue; |
| 1182 | |
| 1183 | ALOGI("%s event @%" PRIu64 " for connector %u on display %d", |
| 1184 | cur_state == DRM_MODE_CONNECTED ? "Plug" : "Unplug", timestamp_us, |
| 1185 | conn->id(), conn->display()); |
| 1186 | |
| 1187 | int display_id = conn->display(); |
| 1188 | if (cur_state == DRM_MODE_CONNECTED) { |
| 1189 | auto &display = hwc2_->displays_.at(display_id); |
| 1190 | display.ChosePreferredConfig(); |
| 1191 | } else { |
| 1192 | auto &display = hwc2_->displays_.at(display_id); |
| 1193 | display.ClearDisplay(); |
| 1194 | } |
| 1195 | |
| 1196 | hwc2_->HandleDisplayHotplug(display_id, cur_state); |
| 1197 | } |
| 1198 | } |
| 1199 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1200 | // static |
| 1201 | int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) { |
| 1202 | unsupported(__func__); |
| 1203 | return 0; |
| 1204 | } |
| 1205 | |
| 1206 | // static |
| 1207 | void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1208 | uint32_t *out_count, |
| 1209 | int32_t * /*out_capabilities*/) { |
| 1210 | supported(__func__); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1211 | *out_count = 0; |
| 1212 | } |
| 1213 | |
| 1214 | // static |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1215 | hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction( |
| 1216 | struct hwc2_device * /*dev*/, int32_t descriptor) { |
| 1217 | supported(__func__); |
| 1218 | auto func = static_cast<HWC2::FunctionDescriptor>(descriptor); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1219 | switch (func) { |
| 1220 | // Device functions |
| 1221 | case HWC2::FunctionDescriptor::CreateVirtualDisplay: |
| 1222 | return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>( |
| 1223 | DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay), |
| 1224 | &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t, |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1225 | int32_t *, hwc2_display_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1226 | case HWC2::FunctionDescriptor::DestroyVirtualDisplay: |
| 1227 | return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>( |
| 1228 | DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay), |
| 1229 | &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>); |
| 1230 | case HWC2::FunctionDescriptor::Dump: |
| 1231 | return ToHook<HWC2_PFN_DUMP>( |
| 1232 | DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump, |
| 1233 | uint32_t *, char *>); |
| 1234 | case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount: |
| 1235 | return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>( |
| 1236 | DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount), |
| 1237 | &DrmHwcTwo::GetMaxVirtualDisplayCount>); |
| 1238 | case HWC2::FunctionDescriptor::RegisterCallback: |
| 1239 | return ToHook<HWC2_PFN_REGISTER_CALLBACK>( |
| 1240 | DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback), |
| 1241 | &DrmHwcTwo::RegisterCallback, int32_t, |
| 1242 | hwc2_callback_data_t, hwc2_function_pointer_t>); |
| 1243 | |
| 1244 | // Display functions |
| 1245 | case HWC2::FunctionDescriptor::AcceptDisplayChanges: |
| 1246 | return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>( |
| 1247 | DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges), |
| 1248 | &HwcDisplay::AcceptDisplayChanges>); |
| 1249 | case HWC2::FunctionDescriptor::CreateLayer: |
| 1250 | return ToHook<HWC2_PFN_CREATE_LAYER>( |
| 1251 | DisplayHook<decltype(&HwcDisplay::CreateLayer), |
| 1252 | &HwcDisplay::CreateLayer, hwc2_layer_t *>); |
| 1253 | case HWC2::FunctionDescriptor::DestroyLayer: |
| 1254 | return ToHook<HWC2_PFN_DESTROY_LAYER>( |
| 1255 | DisplayHook<decltype(&HwcDisplay::DestroyLayer), |
| 1256 | &HwcDisplay::DestroyLayer, hwc2_layer_t>); |
| 1257 | case HWC2::FunctionDescriptor::GetActiveConfig: |
| 1258 | return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>( |
| 1259 | DisplayHook<decltype(&HwcDisplay::GetActiveConfig), |
| 1260 | &HwcDisplay::GetActiveConfig, hwc2_config_t *>); |
| 1261 | case HWC2::FunctionDescriptor::GetChangedCompositionTypes: |
| 1262 | return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>( |
| 1263 | DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes), |
| 1264 | &HwcDisplay::GetChangedCompositionTypes, uint32_t *, |
| 1265 | hwc2_layer_t *, int32_t *>); |
| 1266 | case HWC2::FunctionDescriptor::GetClientTargetSupport: |
| 1267 | return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>( |
| 1268 | DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport), |
| 1269 | &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t, |
| 1270 | int32_t, int32_t>); |
| 1271 | case HWC2::FunctionDescriptor::GetColorModes: |
| 1272 | return ToHook<HWC2_PFN_GET_COLOR_MODES>( |
| 1273 | DisplayHook<decltype(&HwcDisplay::GetColorModes), |
| 1274 | &HwcDisplay::GetColorModes, uint32_t *, int32_t *>); |
| 1275 | case HWC2::FunctionDescriptor::GetDisplayAttribute: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1276 | return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>( |
| 1277 | DisplayHook<decltype(&HwcDisplay::GetDisplayAttribute), |
| 1278 | &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, |
| 1279 | int32_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1280 | case HWC2::FunctionDescriptor::GetDisplayConfigs: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1281 | return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>( |
| 1282 | DisplayHook<decltype(&HwcDisplay::GetDisplayConfigs), |
| 1283 | &HwcDisplay::GetDisplayConfigs, uint32_t *, |
| 1284 | hwc2_config_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1285 | case HWC2::FunctionDescriptor::GetDisplayName: |
| 1286 | return ToHook<HWC2_PFN_GET_DISPLAY_NAME>( |
| 1287 | DisplayHook<decltype(&HwcDisplay::GetDisplayName), |
| 1288 | &HwcDisplay::GetDisplayName, uint32_t *, char *>); |
| 1289 | case HWC2::FunctionDescriptor::GetDisplayRequests: |
| 1290 | return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>( |
| 1291 | DisplayHook<decltype(&HwcDisplay::GetDisplayRequests), |
| 1292 | &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *, |
| 1293 | hwc2_layer_t *, int32_t *>); |
| 1294 | case HWC2::FunctionDescriptor::GetDisplayType: |
| 1295 | return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>( |
| 1296 | DisplayHook<decltype(&HwcDisplay::GetDisplayType), |
| 1297 | &HwcDisplay::GetDisplayType, int32_t *>); |
| 1298 | case HWC2::FunctionDescriptor::GetDozeSupport: |
| 1299 | return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>( |
| 1300 | DisplayHook<decltype(&HwcDisplay::GetDozeSupport), |
| 1301 | &HwcDisplay::GetDozeSupport, int32_t *>); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1302 | case HWC2::FunctionDescriptor::GetHdrCapabilities: |
| 1303 | return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>( |
| 1304 | DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities), |
| 1305 | &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *, |
| 1306 | float *, float *, float *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1307 | case HWC2::FunctionDescriptor::GetReleaseFences: |
| 1308 | return ToHook<HWC2_PFN_GET_RELEASE_FENCES>( |
| 1309 | DisplayHook<decltype(&HwcDisplay::GetReleaseFences), |
| 1310 | &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *, |
| 1311 | int32_t *>); |
| 1312 | case HWC2::FunctionDescriptor::PresentDisplay: |
| 1313 | return ToHook<HWC2_PFN_PRESENT_DISPLAY>( |
| 1314 | DisplayHook<decltype(&HwcDisplay::PresentDisplay), |
| 1315 | &HwcDisplay::PresentDisplay, int32_t *>); |
| 1316 | case HWC2::FunctionDescriptor::SetActiveConfig: |
| 1317 | return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>( |
| 1318 | DisplayHook<decltype(&HwcDisplay::SetActiveConfig), |
| 1319 | &HwcDisplay::SetActiveConfig, hwc2_config_t>); |
| 1320 | case HWC2::FunctionDescriptor::SetClientTarget: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1321 | return ToHook<HWC2_PFN_SET_CLIENT_TARGET>( |
| 1322 | DisplayHook<decltype(&HwcDisplay::SetClientTarget), |
| 1323 | &HwcDisplay::SetClientTarget, buffer_handle_t, int32_t, |
| 1324 | int32_t, hwc_region_t>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1325 | case HWC2::FunctionDescriptor::SetColorMode: |
| 1326 | return ToHook<HWC2_PFN_SET_COLOR_MODE>( |
| 1327 | DisplayHook<decltype(&HwcDisplay::SetColorMode), |
| 1328 | &HwcDisplay::SetColorMode, int32_t>); |
| 1329 | case HWC2::FunctionDescriptor::SetColorTransform: |
| 1330 | return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>( |
| 1331 | DisplayHook<decltype(&HwcDisplay::SetColorTransform), |
| 1332 | &HwcDisplay::SetColorTransform, const float *, int32_t>); |
| 1333 | case HWC2::FunctionDescriptor::SetOutputBuffer: |
| 1334 | return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>( |
| 1335 | DisplayHook<decltype(&HwcDisplay::SetOutputBuffer), |
| 1336 | &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>); |
| 1337 | case HWC2::FunctionDescriptor::SetPowerMode: |
| 1338 | return ToHook<HWC2_PFN_SET_POWER_MODE>( |
| 1339 | DisplayHook<decltype(&HwcDisplay::SetPowerMode), |
| 1340 | &HwcDisplay::SetPowerMode, int32_t>); |
| 1341 | case HWC2::FunctionDescriptor::SetVsyncEnabled: |
| 1342 | return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>( |
| 1343 | DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled), |
| 1344 | &HwcDisplay::SetVsyncEnabled, int32_t>); |
| 1345 | case HWC2::FunctionDescriptor::ValidateDisplay: |
| 1346 | return ToHook<HWC2_PFN_VALIDATE_DISPLAY>( |
| 1347 | DisplayHook<decltype(&HwcDisplay::ValidateDisplay), |
| 1348 | &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>); |
Andrii Chepurnyi | 50d3745 | 2020-04-24 14:20:24 +0300 | [diff] [blame] | 1349 | #if PLATFORM_SDK_VERSION > 27 |
| 1350 | case HWC2::FunctionDescriptor::GetRenderIntents: |
| 1351 | return ToHook<HWC2_PFN_GET_RENDER_INTENTS>( |
| 1352 | DisplayHook<decltype(&HwcDisplay::GetRenderIntents), |
| 1353 | &HwcDisplay::GetRenderIntents, int32_t, uint32_t *, |
| 1354 | int32_t *>); |
Andrii Chepurnyi | 857a53f | 2020-04-29 23:15:28 +0300 | [diff] [blame] | 1355 | case HWC2::FunctionDescriptor::SetColorModeWithRenderIntent: |
| 1356 | return ToHook<HWC2_PFN_SET_COLOR_MODE_WITH_RENDER_INTENT>( |
| 1357 | DisplayHook<decltype(&HwcDisplay::SetColorModeWithIntent), |
| 1358 | &HwcDisplay::SetColorModeWithIntent, int32_t, int32_t>); |
Andrii Chepurnyi | 50d3745 | 2020-04-24 14:20:24 +0300 | [diff] [blame] | 1359 | #endif |
John Stultz | 8c7229d | 2020-02-07 21:31:08 +0000 | [diff] [blame] | 1360 | #if PLATFORM_SDK_VERSION > 28 |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 1361 | case HWC2::FunctionDescriptor::GetDisplayIdentificationData: |
| 1362 | return ToHook<HWC2_PFN_GET_DISPLAY_IDENTIFICATION_DATA>( |
| 1363 | DisplayHook<decltype(&HwcDisplay::GetDisplayIdentificationData), |
| 1364 | &HwcDisplay::GetDisplayIdentificationData, uint8_t *, |
| 1365 | uint32_t *, uint8_t *>); |
| 1366 | case HWC2::FunctionDescriptor::GetDisplayCapabilities: |
| 1367 | return ToHook<HWC2_PFN_GET_DISPLAY_CAPABILITIES>( |
| 1368 | DisplayHook<decltype(&HwcDisplay::GetDisplayCapabilities), |
| 1369 | &HwcDisplay::GetDisplayCapabilities, uint32_t *, |
| 1370 | uint32_t *>); |
Andrii Chepurnyi | 2619aab | 2020-07-03 11:21:33 +0300 | [diff] [blame] | 1371 | case HWC2::FunctionDescriptor::GetDisplayBrightnessSupport: |
| 1372 | return ToHook<HWC2_PFN_GET_DISPLAY_BRIGHTNESS_SUPPORT>( |
| 1373 | DisplayHook<decltype(&HwcDisplay::GetDisplayBrightnessSupport), |
| 1374 | &HwcDisplay::GetDisplayBrightnessSupport, bool *>); |
| 1375 | case HWC2::FunctionDescriptor::SetDisplayBrightness: |
| 1376 | return ToHook<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>( |
| 1377 | DisplayHook<decltype(&HwcDisplay::SetDisplayBrightness), |
| 1378 | &HwcDisplay::SetDisplayBrightness, float>); |
John Stultz | 8c7229d | 2020-02-07 21:31:08 +0000 | [diff] [blame] | 1379 | #endif /* PLATFORM_SDK_VERSION > 28 */ |
Roman Stratiienko | 6f5df17 | 2020-09-27 22:48:08 +0300 | [diff] [blame] | 1380 | #if PLATFORM_SDK_VERSION > 29 |
| 1381 | case HWC2::FunctionDescriptor::GetDisplayConnectionType: |
| 1382 | return ToHook<HWC2_PFN_GET_DISPLAY_CONNECTION_TYPE>( |
| 1383 | DisplayHook<decltype(&HwcDisplay::GetDisplayConnectionType), |
| 1384 | &HwcDisplay::GetDisplayConnectionType, uint32_t *>); |
| 1385 | case HWC2::FunctionDescriptor::GetDisplayVsyncPeriod: |
| 1386 | return ToHook<HWC2_PFN_GET_DISPLAY_VSYNC_PERIOD>( |
| 1387 | DisplayHook<decltype(&HwcDisplay::GetDisplayVsyncPeriod), |
| 1388 | &HwcDisplay::GetDisplayVsyncPeriod, |
| 1389 | hwc2_vsync_period_t *>); |
| 1390 | case HWC2::FunctionDescriptor::SetActiveConfigWithConstraints: |
| 1391 | return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS>( |
| 1392 | DisplayHook<decltype(&HwcDisplay::SetActiveConfigWithConstraints), |
| 1393 | &HwcDisplay::SetActiveConfigWithConstraints, |
| 1394 | hwc2_config_t, hwc_vsync_period_change_constraints_t *, |
| 1395 | hwc_vsync_period_change_timeline_t *>); |
| 1396 | case HWC2::FunctionDescriptor::SetAutoLowLatencyMode: |
| 1397 | return ToHook<HWC2_PFN_SET_AUTO_LOW_LATENCY_MODE>( |
| 1398 | DisplayHook<decltype(&HwcDisplay::SetAutoLowLatencyMode), |
| 1399 | &HwcDisplay::SetAutoLowLatencyMode, bool>); |
| 1400 | case HWC2::FunctionDescriptor::GetSupportedContentTypes: |
| 1401 | return ToHook<HWC2_PFN_GET_SUPPORTED_CONTENT_TYPES>( |
| 1402 | DisplayHook<decltype(&HwcDisplay::GetSupportedContentTypes), |
| 1403 | &HwcDisplay::GetSupportedContentTypes, uint32_t *, |
| 1404 | uint32_t *>); |
| 1405 | case HWC2::FunctionDescriptor::SetContentType: |
| 1406 | return ToHook<HWC2_PFN_SET_CONTENT_TYPE>( |
| 1407 | DisplayHook<decltype(&HwcDisplay::SetContentType), |
| 1408 | &HwcDisplay::SetContentType, int32_t>); |
| 1409 | #endif |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1410 | // Layer functions |
| 1411 | case HWC2::FunctionDescriptor::SetCursorPosition: |
| 1412 | return ToHook<HWC2_PFN_SET_CURSOR_POSITION>( |
| 1413 | LayerHook<decltype(&HwcLayer::SetCursorPosition), |
| 1414 | &HwcLayer::SetCursorPosition, int32_t, int32_t>); |
| 1415 | case HWC2::FunctionDescriptor::SetLayerBlendMode: |
| 1416 | return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>( |
| 1417 | LayerHook<decltype(&HwcLayer::SetLayerBlendMode), |
| 1418 | &HwcLayer::SetLayerBlendMode, int32_t>); |
| 1419 | case HWC2::FunctionDescriptor::SetLayerBuffer: |
| 1420 | return ToHook<HWC2_PFN_SET_LAYER_BUFFER>( |
| 1421 | LayerHook<decltype(&HwcLayer::SetLayerBuffer), |
| 1422 | &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>); |
| 1423 | case HWC2::FunctionDescriptor::SetLayerColor: |
| 1424 | return ToHook<HWC2_PFN_SET_LAYER_COLOR>( |
| 1425 | LayerHook<decltype(&HwcLayer::SetLayerColor), |
| 1426 | &HwcLayer::SetLayerColor, hwc_color_t>); |
| 1427 | case HWC2::FunctionDescriptor::SetLayerCompositionType: |
| 1428 | return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>( |
| 1429 | LayerHook<decltype(&HwcLayer::SetLayerCompositionType), |
| 1430 | &HwcLayer::SetLayerCompositionType, int32_t>); |
| 1431 | case HWC2::FunctionDescriptor::SetLayerDataspace: |
| 1432 | return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>( |
| 1433 | LayerHook<decltype(&HwcLayer::SetLayerDataspace), |
| 1434 | &HwcLayer::SetLayerDataspace, int32_t>); |
| 1435 | case HWC2::FunctionDescriptor::SetLayerDisplayFrame: |
| 1436 | return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>( |
| 1437 | LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame), |
| 1438 | &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>); |
| 1439 | case HWC2::FunctionDescriptor::SetLayerPlaneAlpha: |
| 1440 | return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>( |
| 1441 | LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha), |
| 1442 | &HwcLayer::SetLayerPlaneAlpha, float>); |
| 1443 | case HWC2::FunctionDescriptor::SetLayerSidebandStream: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1444 | return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>( |
| 1445 | LayerHook<decltype(&HwcLayer::SetLayerSidebandStream), |
| 1446 | &HwcLayer::SetLayerSidebandStream, |
| 1447 | const native_handle_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1448 | case HWC2::FunctionDescriptor::SetLayerSourceCrop: |
| 1449 | return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>( |
| 1450 | LayerHook<decltype(&HwcLayer::SetLayerSourceCrop), |
| 1451 | &HwcLayer::SetLayerSourceCrop, hwc_frect_t>); |
| 1452 | case HWC2::FunctionDescriptor::SetLayerSurfaceDamage: |
| 1453 | return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>( |
| 1454 | LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage), |
| 1455 | &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>); |
| 1456 | case HWC2::FunctionDescriptor::SetLayerTransform: |
| 1457 | return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>( |
| 1458 | LayerHook<decltype(&HwcLayer::SetLayerTransform), |
| 1459 | &HwcLayer::SetLayerTransform, int32_t>); |
| 1460 | case HWC2::FunctionDescriptor::SetLayerVisibleRegion: |
| 1461 | return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>( |
| 1462 | LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion), |
| 1463 | &HwcLayer::SetLayerVisibleRegion, hwc_region_t>); |
| 1464 | case HWC2::FunctionDescriptor::SetLayerZOrder: |
| 1465 | return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>( |
| 1466 | LayerHook<decltype(&HwcLayer::SetLayerZOrder), |
| 1467 | &HwcLayer::SetLayerZOrder, uint32_t>); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1468 | case HWC2::FunctionDescriptor::Invalid: |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1469 | default: |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1470 | return nullptr; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1471 | } |
| 1472 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1473 | |
| 1474 | // static |
| 1475 | int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name, |
| 1476 | struct hw_device_t **dev) { |
| 1477 | supported(__func__); |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1478 | if (strcmp(name, HWC_HARDWARE_COMPOSER) != 0) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1479 | ALOGE("Invalid module name- %s", name); |
| 1480 | return -EINVAL; |
| 1481 | } |
| 1482 | |
| 1483 | std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo()); |
| 1484 | if (!ctx) { |
| 1485 | ALOGE("Failed to allocate DrmHwcTwo"); |
| 1486 | return -ENOMEM; |
| 1487 | } |
| 1488 | |
| 1489 | HWC2::Error err = ctx->Init(); |
| 1490 | if (err != HWC2::Error::None) { |
| 1491 | ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err); |
| 1492 | return -EINVAL; |
| 1493 | } |
| 1494 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 1495 | ctx->common.module = (hw_module_t *)module; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1496 | *dev = &ctx->common; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1497 | ctx.release(); // NOLINT(bugprone-unused-return-value) |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1498 | return 0; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1499 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1500 | } // namespace android |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1501 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 1502 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1503 | static struct hw_module_methods_t hwc2_module_methods = { |
| 1504 | .open = android::DrmHwcTwo::HookDevOpen, |
| 1505 | }; |
| 1506 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 1507 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1508 | hw_module_t HAL_MODULE_INFO_SYM = { |
| 1509 | .tag = HARDWARE_MODULE_TAG, |
| 1510 | .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0), |
| 1511 | .id = HWC_HARDWARE_MODULE_ID, |
| 1512 | .name = "DrmHwcTwo module", |
| 1513 | .author = "The Android Open Source Project", |
| 1514 | .methods = &hwc2_module_methods, |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 1515 | .dso = nullptr, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1516 | .reserved = {0}, |
| 1517 | }; |