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