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