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