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