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