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 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 563 | HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 564 | std::vector<DrmCompositionDisplayLayersMap> layers_map; |
| 565 | layers_map.emplace_back(); |
| 566 | DrmCompositionDisplayLayersMap &map = layers_map.back(); |
| 567 | |
| 568 | map.display = static_cast<int>(handle_); |
| 569 | map.geometry_changed = true; // TODO: Fix this |
| 570 | |
| 571 | // order the layers by z-order |
| 572 | bool use_client_layer = false; |
Alexandru Gheorghe | 1542d29 | 2018-06-13 16:46:36 +0100 | [diff] [blame] | 573 | uint32_t client_z_order = UINT32_MAX; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 574 | std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map; |
| 575 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) { |
Roman Stratiienko | f264723 | 2019-11-21 01:58:35 +0200 | [diff] [blame^] | 576 | switch (l.second.validated_type()) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 577 | case HWC2::Composition::Device: |
| 578 | z_map.emplace(std::make_pair(l.second.z_order(), &l.second)); |
| 579 | break; |
| 580 | case HWC2::Composition::Client: |
Alexandru Gheorghe | 1542d29 | 2018-06-13 16:46:36 +0100 | [diff] [blame] | 581 | // Place it at the z_order of the lowest client layer |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 582 | use_client_layer = true; |
Alexandru Gheorghe | 1542d29 | 2018-06-13 16:46:36 +0100 | [diff] [blame] | 583 | client_z_order = std::min(client_z_order, l.second.z_order()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 584 | break; |
| 585 | default: |
| 586 | continue; |
| 587 | } |
| 588 | } |
| 589 | if (use_client_layer) |
| 590 | z_map.emplace(std::make_pair(client_z_order, &client_layer_)); |
| 591 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 592 | if (z_map.empty()) |
| 593 | return HWC2::Error::BadLayer; |
| 594 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 595 | // now that they're ordered by z, add them to the composition |
| 596 | for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) { |
| 597 | DrmHwcLayer layer; |
| 598 | l.second->PopulateDrmLayer(&layer); |
Andrii Chepurnyi | dc1278c | 2018-03-20 19:41:18 +0200 | [diff] [blame] | 599 | int ret = layer.ImportBuffer(importer_.get()); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 600 | if (ret) { |
| 601 | ALOGE("Failed to import layer, ret=%d", ret); |
| 602 | return HWC2::Error::NoResources; |
| 603 | } |
| 604 | map.layers.emplace_back(std::move(layer)); |
| 605 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 606 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 607 | std::unique_ptr<DrmDisplayComposition> composition = compositor_ |
| 608 | .CreateComposition(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 609 | composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_); |
| 610 | |
| 611 | // TODO: Don't always assume geometry changed |
| 612 | int ret = composition->SetLayers(map.layers.data(), map.layers.size(), true); |
| 613 | if (ret) { |
| 614 | ALOGE("Failed to set layers in the composition ret=%d", ret); |
| 615 | return HWC2::Error::BadLayer; |
| 616 | } |
| 617 | |
| 618 | std::vector<DrmPlane *> primary_planes(primary_planes_); |
| 619 | std::vector<DrmPlane *> overlay_planes(overlay_planes_); |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 620 | ret = composition->Plan(&primary_planes, &overlay_planes); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 621 | if (ret) { |
| 622 | ALOGE("Failed to plan the composition ret=%d", ret); |
| 623 | return HWC2::Error::BadConfig; |
| 624 | } |
| 625 | |
| 626 | // Disable the planes we're not using |
| 627 | for (auto i = primary_planes.begin(); i != primary_planes.end();) { |
| 628 | composition->AddPlaneDisable(*i); |
| 629 | i = primary_planes.erase(i); |
| 630 | } |
| 631 | for (auto i = overlay_planes.begin(); i != overlay_planes.end();) { |
| 632 | composition->AddPlaneDisable(*i); |
| 633 | i = overlay_planes.erase(i); |
| 634 | } |
| 635 | |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 636 | if (test) { |
| 637 | ret = compositor_.TestComposition(composition.get()); |
| 638 | } else { |
| 639 | AddFenceToRetireFence(composition->take_out_fence()); |
| 640 | ret = compositor_.ApplyComposition(std::move(composition)); |
| 641 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 642 | if (ret) { |
John Stultz | 78c9f6c | 2018-05-24 16:43:35 -0700 | [diff] [blame] | 643 | if (!test) |
| 644 | ALOGE("Failed to apply the frame composition ret=%d", ret); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 645 | return HWC2::Error::BadParameter; |
| 646 | } |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 647 | return HWC2::Error::None; |
| 648 | } |
| 649 | |
| 650 | HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { |
| 651 | supported(__func__); |
| 652 | HWC2::Error ret; |
| 653 | |
| 654 | ret = CreateComposition(false); |
| 655 | if (ret == HWC2::Error::BadLayer) { |
| 656 | // Can we really have no client or device layers? |
| 657 | *retire_fence = -1; |
| 658 | return HWC2::Error::None; |
| 659 | } |
| 660 | if (ret != HWC2::Error::None) |
| 661 | return ret; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 662 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 663 | // The retire fence returned here is for the last frame, so return it and |
| 664 | // promote the next retire fence |
| 665 | *retire_fence = retire_fence_.Release(); |
| 666 | retire_fence_ = std::move(next_retire_fence_); |
| 667 | |
| 668 | ++frame_no_; |
| 669 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 673 | supported(__func__); |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 674 | auto mode = std::find_if(connector_->modes().begin(), |
| 675 | connector_->modes().end(), |
| 676 | [config](DrmMode const &m) { |
| 677 | return m.id() == config; |
| 678 | }); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 679 | if (mode == connector_->modes().end()) { |
| 680 | ALOGE("Could not find active mode for %d", config); |
| 681 | return HWC2::Error::BadConfig; |
| 682 | } |
| 683 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 684 | std::unique_ptr<DrmDisplayComposition> composition = compositor_ |
| 685 | .CreateComposition(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 686 | composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_); |
| 687 | int ret = composition->SetDisplayMode(*mode); |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 688 | ret = compositor_.ApplyComposition(std::move(composition)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 689 | if (ret) { |
| 690 | ALOGE("Failed to queue dpms composition on %d", ret); |
| 691 | return HWC2::Error::BadConfig; |
| 692 | } |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 693 | |
| 694 | connector_->set_active_mode(*mode); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 695 | |
| 696 | // Setup the client layer's dimensions |
| 697 | hwc_rect_t display_frame = {.left = 0, |
| 698 | .top = 0, |
| 699 | .right = static_cast<int>(mode->h_display()), |
| 700 | .bottom = static_cast<int>(mode->v_display())}; |
| 701 | client_layer_.SetLayerDisplayFrame(display_frame); |
| 702 | hwc_frect_t source_crop = {.left = 0.0f, |
| 703 | .top = 0.0f, |
| 704 | .right = mode->h_display() + 0.0f, |
| 705 | .bottom = mode->v_display() + 0.0f}; |
| 706 | client_layer_.SetLayerSourceCrop(source_crop); |
| 707 | |
| 708 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target, |
| 712 | int32_t acquire_fence, |
| 713 | int32_t dataspace, |
Rob Herring | 1b2685c | 2017-11-29 10:19:57 -0600 | [diff] [blame] | 714 | hwc_region_t /*damage*/) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 715 | supported(__func__); |
| 716 | UniqueFd uf(acquire_fence); |
| 717 | |
| 718 | client_layer_.set_buffer(target); |
| 719 | client_layer_.set_acquire_fence(uf.get()); |
| 720 | client_layer_.SetLayerDataspace(dataspace); |
| 721 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 725 | supported(__func__); |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 726 | |
| 727 | if (mode != HAL_COLOR_MODE_NATIVE) |
Vincent Donnefort | 7834a89 | 2019-10-09 15:53:56 +0100 | [diff] [blame] | 728 | return HWC2::Error::BadParameter; |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 729 | |
| 730 | color_mode_ = mode; |
| 731 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 735 | int32_t hint) { |
| 736 | supported(__func__); |
| 737 | // TODO: Force client composition if we get this |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 738 | return unsupported(__func__, matrix, hint); |
| 739 | } |
| 740 | |
| 741 | HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 742 | int32_t release_fence) { |
| 743 | supported(__func__); |
| 744 | // TODO: Need virtual display support |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 745 | return unsupported(__func__, buffer, release_fence); |
| 746 | } |
| 747 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 748 | HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) { |
| 749 | supported(__func__); |
| 750 | uint64_t dpms_value = 0; |
| 751 | auto mode = static_cast<HWC2::PowerMode>(mode_in); |
| 752 | switch (mode) { |
| 753 | case HWC2::PowerMode::Off: |
| 754 | dpms_value = DRM_MODE_DPMS_OFF; |
| 755 | break; |
| 756 | case HWC2::PowerMode::On: |
| 757 | dpms_value = DRM_MODE_DPMS_ON; |
| 758 | break; |
Vincent Donnefort | 60ef7eb | 2019-10-09 11:39:28 +0100 | [diff] [blame] | 759 | case HWC2::PowerMode::Doze: |
| 760 | case HWC2::PowerMode::DozeSuspend: |
| 761 | return HWC2::Error::Unsupported; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 762 | default: |
| 763 | ALOGI("Power mode %d is unsupported\n", mode); |
Vincent Donnefort | 60ef7eb | 2019-10-09 11:39:28 +0100 | [diff] [blame] | 764 | return HWC2::Error::BadParameter; |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 765 | }; |
| 766 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 767 | std::unique_ptr<DrmDisplayComposition> composition = compositor_ |
| 768 | .CreateComposition(); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 769 | composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_); |
| 770 | composition->SetDpmsMode(dpms_value); |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 771 | int ret = compositor_.ApplyComposition(std::move(composition)); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 772 | if (ret) { |
| 773 | ALOGE("Failed to apply the dpms composition ret=%d", ret); |
| 774 | return HWC2::Error::BadParameter; |
| 775 | } |
| 776 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 780 | supported(__func__); |
Andrii Chepurnyi | 4bdd0fe | 2018-07-27 15:14:37 +0300 | [diff] [blame] | 781 | vsync_worker_.VSyncControl(HWC2_VSYNC_ENABLE == enabled); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 782 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 786 | uint32_t *num_requests) { |
| 787 | supported(__func__); |
| 788 | *num_types = 0; |
| 789 | *num_requests = 0; |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 790 | size_t avail_planes = primary_planes_.size() + overlay_planes_.size(); |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 791 | |
| 792 | /* |
| 793 | * If more layers then planes, save one plane |
| 794 | * for client composited layers |
| 795 | */ |
| 796 | if (avail_planes < layers_.size()) |
| 797 | avail_planes--; |
| 798 | |
Roman Stratiienko | f264723 | 2019-11-21 01:58:35 +0200 | [diff] [blame^] | 799 | std::map<uint32_t, DrmHwcTwo::HwcLayer *, std::greater<int>> z_map; |
| 800 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) |
| 801 | z_map.emplace(std::make_pair(l.second.z_order(), &l.second)); |
| 802 | |
| 803 | bool gpu_block = false; |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 804 | for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) { |
Roman Stratiienko | f264723 | 2019-11-21 01:58:35 +0200 | [diff] [blame^] | 805 | if (gpu_block || avail_planes == 0 || |
| 806 | l.second->sf_type() != HWC2::Composition::Device || |
| 807 | !importer_->CanImportBuffer(l.second->buffer())) { |
| 808 | gpu_block = true; |
| 809 | ++*num_types; |
| 810 | } else { |
| 811 | avail_planes--; |
| 812 | } |
| 813 | |
| 814 | l.second->set_validated_type(gpu_block ? HWC2::Composition::Client |
| 815 | : HWC2::Composition::Device); |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 816 | } |
| 817 | |
Roman Stratiienko | f264723 | 2019-11-21 01:58:35 +0200 | [diff] [blame^] | 818 | if (CreateComposition(true) != HWC2::Error::None) |
| 819 | for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) |
| 820 | l.second.set_validated_type(HWC2::Composition::Client); |
| 821 | |
Rob Herring | ee8f45b | 2017-06-09 15:15:55 -0500 | [diff] [blame] | 822 | return *num_types ? HWC2::Error::HasChanges : HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t x, int32_t y) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 826 | supported(__func__); |
Kalyan Kondapally | da5839c | 2016-11-10 10:59:50 -0800 | [diff] [blame] | 827 | cursor_x_ = x; |
| 828 | cursor_y_ = y; |
| 829 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 833 | supported(__func__); |
| 834 | blending_ = static_cast<HWC2::BlendMode>(mode); |
| 835 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 839 | int32_t acquire_fence) { |
| 840 | supported(__func__); |
| 841 | UniqueFd uf(acquire_fence); |
| 842 | |
| 843 | // The buffer and acquire_fence are handled elsewhere |
| 844 | if (sf_type_ == HWC2::Composition::Client || |
| 845 | sf_type_ == HWC2::Composition::Sideband || |
| 846 | sf_type_ == HWC2::Composition::SolidColor) |
| 847 | return HWC2::Error::None; |
| 848 | |
| 849 | set_buffer(buffer); |
| 850 | set_acquire_fence(uf.get()); |
| 851 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 855 | // TODO: Punt to client composition here? |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 856 | return unsupported(__func__, color); |
| 857 | } |
| 858 | |
| 859 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 860 | sf_type_ = static_cast<HWC2::Composition>(type); |
| 861 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 865 | supported(__func__); |
| 866 | dataspace_ = static_cast<android_dataspace_t>(dataspace); |
| 867 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 871 | supported(__func__); |
| 872 | display_frame_ = frame; |
| 873 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 877 | supported(__func__); |
| 878 | alpha_ = alpha; |
| 879 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream( |
| 883 | const native_handle_t *stream) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 884 | supported(__func__); |
| 885 | // TODO: We don't support sideband |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 886 | return unsupported(__func__, stream); |
| 887 | } |
| 888 | |
| 889 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 890 | supported(__func__); |
| 891 | source_crop_ = crop; |
| 892 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 896 | supported(__func__); |
| 897 | // TODO: We don't use surface damage, marking as unsupported |
| 898 | unsupported(__func__, damage); |
| 899 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 903 | supported(__func__); |
| 904 | transform_ = static_cast<HWC2::Transform>(transform); |
| 905 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) { |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 909 | supported(__func__); |
| 910 | // TODO: We don't use this information, marking as unsupported |
| 911 | unsupported(__func__, visible); |
| 912 | return HWC2::Error::None; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 913 | } |
| 914 | |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 915 | HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) { |
| 916 | supported(__func__); |
| 917 | z_order_ = order; |
| 918 | return HWC2::Error::None; |
| 919 | } |
| 920 | |
| 921 | void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) { |
| 922 | supported(__func__); |
| 923 | switch (blending_) { |
| 924 | case HWC2::BlendMode::None: |
| 925 | layer->blending = DrmHwcBlending::kNone; |
| 926 | break; |
| 927 | case HWC2::BlendMode::Premultiplied: |
| 928 | layer->blending = DrmHwcBlending::kPreMult; |
| 929 | break; |
| 930 | case HWC2::BlendMode::Coverage: |
| 931 | layer->blending = DrmHwcBlending::kCoverage; |
| 932 | break; |
| 933 | default: |
| 934 | ALOGE("Unknown blending mode b=%d", blending_); |
| 935 | layer->blending = DrmHwcBlending::kNone; |
| 936 | break; |
| 937 | } |
| 938 | |
| 939 | OutputFd release_fence = release_fence_output(); |
| 940 | |
| 941 | layer->sf_handle = buffer_; |
| 942 | layer->acquire_fence = acquire_fence_.Release(); |
| 943 | layer->release_fence = std::move(release_fence); |
| 944 | layer->SetDisplayFrame(display_frame_); |
Stefan Schake | 025d0a6 | 2018-05-04 18:03:00 +0200 | [diff] [blame] | 945 | layer->alpha = static_cast<uint16_t>(65535.0f * alpha_ + 0.5f); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 946 | layer->SetSourceCrop(source_crop_); |
| 947 | layer->SetTransform(static_cast<int32_t>(transform_)); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 948 | } |
| 949 | |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 950 | void DrmHwcTwo::HandleDisplayHotplug(hwc2_display_t displayid, int state) { |
| 951 | auto cb = callbacks_.find(HWC2::Callback::Hotplug); |
| 952 | if (cb == callbacks_.end()) |
| 953 | return; |
| 954 | |
| 955 | auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(cb->second.func); |
| 956 | hotplug(cb->second.data, displayid, |
| 957 | (state == DRM_MODE_CONNECTED ? HWC2_CONNECTION_CONNECTED |
| 958 | : HWC2_CONNECTION_DISCONNECTED)); |
| 959 | } |
| 960 | |
| 961 | void DrmHwcTwo::HandleInitialHotplugState(DrmDevice *drmDevice) { |
| 962 | for (auto &conn : drmDevice->connectors()) { |
| 963 | if (conn->state() != DRM_MODE_CONNECTED) |
| 964 | continue; |
| 965 | HandleDisplayHotplug(conn->display(), conn->state()); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | void DrmHwcTwo::DrmHotplugHandler::HandleEvent(uint64_t timestamp_us) { |
| 970 | for (auto &conn : drm_->connectors()) { |
| 971 | drmModeConnection old_state = conn->state(); |
| 972 | drmModeConnection cur_state = conn->UpdateModes() |
| 973 | ? DRM_MODE_UNKNOWNCONNECTION |
| 974 | : conn->state(); |
| 975 | |
| 976 | if (cur_state == old_state) |
| 977 | continue; |
| 978 | |
| 979 | ALOGI("%s event @%" PRIu64 " for connector %u on display %d", |
| 980 | cur_state == DRM_MODE_CONNECTED ? "Plug" : "Unplug", timestamp_us, |
| 981 | conn->id(), conn->display()); |
| 982 | |
| 983 | int display_id = conn->display(); |
| 984 | if (cur_state == DRM_MODE_CONNECTED) { |
| 985 | auto &display = hwc2_->displays_.at(display_id); |
| 986 | display.ChosePreferredConfig(); |
| 987 | } else { |
| 988 | auto &display = hwc2_->displays_.at(display_id); |
| 989 | display.ClearDisplay(); |
| 990 | } |
| 991 | |
| 992 | hwc2_->HandleDisplayHotplug(display_id, cur_state); |
| 993 | } |
| 994 | } |
| 995 | |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 996 | // static |
| 997 | int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) { |
| 998 | unsupported(__func__); |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | // static |
| 1003 | void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/, |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1004 | uint32_t *out_count, |
| 1005 | int32_t * /*out_capabilities*/) { |
| 1006 | supported(__func__); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1007 | *out_count = 0; |
| 1008 | } |
| 1009 | |
| 1010 | // static |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1011 | hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction( |
| 1012 | struct hwc2_device * /*dev*/, int32_t descriptor) { |
| 1013 | supported(__func__); |
| 1014 | auto func = static_cast<HWC2::FunctionDescriptor>(descriptor); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1015 | switch (func) { |
| 1016 | // Device functions |
| 1017 | case HWC2::FunctionDescriptor::CreateVirtualDisplay: |
| 1018 | return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>( |
| 1019 | DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay), |
| 1020 | &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t, |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1021 | int32_t *, hwc2_display_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1022 | case HWC2::FunctionDescriptor::DestroyVirtualDisplay: |
| 1023 | return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>( |
| 1024 | DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay), |
| 1025 | &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>); |
| 1026 | case HWC2::FunctionDescriptor::Dump: |
| 1027 | return ToHook<HWC2_PFN_DUMP>( |
| 1028 | DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump, |
| 1029 | uint32_t *, char *>); |
| 1030 | case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount: |
| 1031 | return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>( |
| 1032 | DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount), |
| 1033 | &DrmHwcTwo::GetMaxVirtualDisplayCount>); |
| 1034 | case HWC2::FunctionDescriptor::RegisterCallback: |
| 1035 | return ToHook<HWC2_PFN_REGISTER_CALLBACK>( |
| 1036 | DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback), |
| 1037 | &DrmHwcTwo::RegisterCallback, int32_t, |
| 1038 | hwc2_callback_data_t, hwc2_function_pointer_t>); |
| 1039 | |
| 1040 | // Display functions |
| 1041 | case HWC2::FunctionDescriptor::AcceptDisplayChanges: |
| 1042 | return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>( |
| 1043 | DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges), |
| 1044 | &HwcDisplay::AcceptDisplayChanges>); |
| 1045 | case HWC2::FunctionDescriptor::CreateLayer: |
| 1046 | return ToHook<HWC2_PFN_CREATE_LAYER>( |
| 1047 | DisplayHook<decltype(&HwcDisplay::CreateLayer), |
| 1048 | &HwcDisplay::CreateLayer, hwc2_layer_t *>); |
| 1049 | case HWC2::FunctionDescriptor::DestroyLayer: |
| 1050 | return ToHook<HWC2_PFN_DESTROY_LAYER>( |
| 1051 | DisplayHook<decltype(&HwcDisplay::DestroyLayer), |
| 1052 | &HwcDisplay::DestroyLayer, hwc2_layer_t>); |
| 1053 | case HWC2::FunctionDescriptor::GetActiveConfig: |
| 1054 | return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>( |
| 1055 | DisplayHook<decltype(&HwcDisplay::GetActiveConfig), |
| 1056 | &HwcDisplay::GetActiveConfig, hwc2_config_t *>); |
| 1057 | case HWC2::FunctionDescriptor::GetChangedCompositionTypes: |
| 1058 | return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>( |
| 1059 | DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes), |
| 1060 | &HwcDisplay::GetChangedCompositionTypes, uint32_t *, |
| 1061 | hwc2_layer_t *, int32_t *>); |
| 1062 | case HWC2::FunctionDescriptor::GetClientTargetSupport: |
| 1063 | return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>( |
| 1064 | DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport), |
| 1065 | &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t, |
| 1066 | int32_t, int32_t>); |
| 1067 | case HWC2::FunctionDescriptor::GetColorModes: |
| 1068 | return ToHook<HWC2_PFN_GET_COLOR_MODES>( |
| 1069 | DisplayHook<decltype(&HwcDisplay::GetColorModes), |
| 1070 | &HwcDisplay::GetColorModes, uint32_t *, int32_t *>); |
| 1071 | case HWC2::FunctionDescriptor::GetDisplayAttribute: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1072 | return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>( |
| 1073 | DisplayHook<decltype(&HwcDisplay::GetDisplayAttribute), |
| 1074 | &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, |
| 1075 | int32_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1076 | case HWC2::FunctionDescriptor::GetDisplayConfigs: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1077 | return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>( |
| 1078 | DisplayHook<decltype(&HwcDisplay::GetDisplayConfigs), |
| 1079 | &HwcDisplay::GetDisplayConfigs, uint32_t *, |
| 1080 | hwc2_config_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1081 | case HWC2::FunctionDescriptor::GetDisplayName: |
| 1082 | return ToHook<HWC2_PFN_GET_DISPLAY_NAME>( |
| 1083 | DisplayHook<decltype(&HwcDisplay::GetDisplayName), |
| 1084 | &HwcDisplay::GetDisplayName, uint32_t *, char *>); |
| 1085 | case HWC2::FunctionDescriptor::GetDisplayRequests: |
| 1086 | return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>( |
| 1087 | DisplayHook<decltype(&HwcDisplay::GetDisplayRequests), |
| 1088 | &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *, |
| 1089 | hwc2_layer_t *, int32_t *>); |
| 1090 | case HWC2::FunctionDescriptor::GetDisplayType: |
| 1091 | return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>( |
| 1092 | DisplayHook<decltype(&HwcDisplay::GetDisplayType), |
| 1093 | &HwcDisplay::GetDisplayType, int32_t *>); |
| 1094 | case HWC2::FunctionDescriptor::GetDozeSupport: |
| 1095 | return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>( |
| 1096 | DisplayHook<decltype(&HwcDisplay::GetDozeSupport), |
| 1097 | &HwcDisplay::GetDozeSupport, int32_t *>); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1098 | case HWC2::FunctionDescriptor::GetHdrCapabilities: |
| 1099 | return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>( |
| 1100 | DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities), |
| 1101 | &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *, |
| 1102 | float *, float *, float *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1103 | case HWC2::FunctionDescriptor::GetReleaseFences: |
| 1104 | return ToHook<HWC2_PFN_GET_RELEASE_FENCES>( |
| 1105 | DisplayHook<decltype(&HwcDisplay::GetReleaseFences), |
| 1106 | &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *, |
| 1107 | int32_t *>); |
| 1108 | case HWC2::FunctionDescriptor::PresentDisplay: |
| 1109 | return ToHook<HWC2_PFN_PRESENT_DISPLAY>( |
| 1110 | DisplayHook<decltype(&HwcDisplay::PresentDisplay), |
| 1111 | &HwcDisplay::PresentDisplay, int32_t *>); |
| 1112 | case HWC2::FunctionDescriptor::SetActiveConfig: |
| 1113 | return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>( |
| 1114 | DisplayHook<decltype(&HwcDisplay::SetActiveConfig), |
| 1115 | &HwcDisplay::SetActiveConfig, hwc2_config_t>); |
| 1116 | case HWC2::FunctionDescriptor::SetClientTarget: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1117 | return ToHook<HWC2_PFN_SET_CLIENT_TARGET>( |
| 1118 | DisplayHook<decltype(&HwcDisplay::SetClientTarget), |
| 1119 | &HwcDisplay::SetClientTarget, buffer_handle_t, int32_t, |
| 1120 | int32_t, hwc_region_t>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1121 | case HWC2::FunctionDescriptor::SetColorMode: |
| 1122 | return ToHook<HWC2_PFN_SET_COLOR_MODE>( |
| 1123 | DisplayHook<decltype(&HwcDisplay::SetColorMode), |
| 1124 | &HwcDisplay::SetColorMode, int32_t>); |
| 1125 | case HWC2::FunctionDescriptor::SetColorTransform: |
| 1126 | return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>( |
| 1127 | DisplayHook<decltype(&HwcDisplay::SetColorTransform), |
| 1128 | &HwcDisplay::SetColorTransform, const float *, int32_t>); |
| 1129 | case HWC2::FunctionDescriptor::SetOutputBuffer: |
| 1130 | return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>( |
| 1131 | DisplayHook<decltype(&HwcDisplay::SetOutputBuffer), |
| 1132 | &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>); |
| 1133 | case HWC2::FunctionDescriptor::SetPowerMode: |
| 1134 | return ToHook<HWC2_PFN_SET_POWER_MODE>( |
| 1135 | DisplayHook<decltype(&HwcDisplay::SetPowerMode), |
| 1136 | &HwcDisplay::SetPowerMode, int32_t>); |
| 1137 | case HWC2::FunctionDescriptor::SetVsyncEnabled: |
| 1138 | return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>( |
| 1139 | DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled), |
| 1140 | &HwcDisplay::SetVsyncEnabled, int32_t>); |
| 1141 | case HWC2::FunctionDescriptor::ValidateDisplay: |
| 1142 | return ToHook<HWC2_PFN_VALIDATE_DISPLAY>( |
| 1143 | DisplayHook<decltype(&HwcDisplay::ValidateDisplay), |
| 1144 | &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>); |
| 1145 | |
| 1146 | // Layer functions |
| 1147 | case HWC2::FunctionDescriptor::SetCursorPosition: |
| 1148 | return ToHook<HWC2_PFN_SET_CURSOR_POSITION>( |
| 1149 | LayerHook<decltype(&HwcLayer::SetCursorPosition), |
| 1150 | &HwcLayer::SetCursorPosition, int32_t, int32_t>); |
| 1151 | case HWC2::FunctionDescriptor::SetLayerBlendMode: |
| 1152 | return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>( |
| 1153 | LayerHook<decltype(&HwcLayer::SetLayerBlendMode), |
| 1154 | &HwcLayer::SetLayerBlendMode, int32_t>); |
| 1155 | case HWC2::FunctionDescriptor::SetLayerBuffer: |
| 1156 | return ToHook<HWC2_PFN_SET_LAYER_BUFFER>( |
| 1157 | LayerHook<decltype(&HwcLayer::SetLayerBuffer), |
| 1158 | &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>); |
| 1159 | case HWC2::FunctionDescriptor::SetLayerColor: |
| 1160 | return ToHook<HWC2_PFN_SET_LAYER_COLOR>( |
| 1161 | LayerHook<decltype(&HwcLayer::SetLayerColor), |
| 1162 | &HwcLayer::SetLayerColor, hwc_color_t>); |
| 1163 | case HWC2::FunctionDescriptor::SetLayerCompositionType: |
| 1164 | return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>( |
| 1165 | LayerHook<decltype(&HwcLayer::SetLayerCompositionType), |
| 1166 | &HwcLayer::SetLayerCompositionType, int32_t>); |
| 1167 | case HWC2::FunctionDescriptor::SetLayerDataspace: |
| 1168 | return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>( |
| 1169 | LayerHook<decltype(&HwcLayer::SetLayerDataspace), |
| 1170 | &HwcLayer::SetLayerDataspace, int32_t>); |
| 1171 | case HWC2::FunctionDescriptor::SetLayerDisplayFrame: |
| 1172 | return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>( |
| 1173 | LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame), |
| 1174 | &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>); |
| 1175 | case HWC2::FunctionDescriptor::SetLayerPlaneAlpha: |
| 1176 | return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>( |
| 1177 | LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha), |
| 1178 | &HwcLayer::SetLayerPlaneAlpha, float>); |
| 1179 | case HWC2::FunctionDescriptor::SetLayerSidebandStream: |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1180 | return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>( |
| 1181 | LayerHook<decltype(&HwcLayer::SetLayerSidebandStream), |
| 1182 | &HwcLayer::SetLayerSidebandStream, |
| 1183 | const native_handle_t *>); |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1184 | case HWC2::FunctionDescriptor::SetLayerSourceCrop: |
| 1185 | return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>( |
| 1186 | LayerHook<decltype(&HwcLayer::SetLayerSourceCrop), |
| 1187 | &HwcLayer::SetLayerSourceCrop, hwc_frect_t>); |
| 1188 | case HWC2::FunctionDescriptor::SetLayerSurfaceDamage: |
| 1189 | return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>( |
| 1190 | LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage), |
| 1191 | &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>); |
| 1192 | case HWC2::FunctionDescriptor::SetLayerTransform: |
| 1193 | return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>( |
| 1194 | LayerHook<decltype(&HwcLayer::SetLayerTransform), |
| 1195 | &HwcLayer::SetLayerTransform, int32_t>); |
| 1196 | case HWC2::FunctionDescriptor::SetLayerVisibleRegion: |
| 1197 | return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>( |
| 1198 | LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion), |
| 1199 | &HwcLayer::SetLayerVisibleRegion, hwc_region_t>); |
| 1200 | case HWC2::FunctionDescriptor::SetLayerZOrder: |
| 1201 | return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>( |
| 1202 | LayerHook<decltype(&HwcLayer::SetLayerZOrder), |
| 1203 | &HwcLayer::SetLayerZOrder, uint32_t>); |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1204 | case HWC2::FunctionDescriptor::Invalid: |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1205 | default: |
| 1206 | return NULL; |
| 1207 | } |
| 1208 | } |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1209 | |
| 1210 | // static |
| 1211 | int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name, |
| 1212 | struct hw_device_t **dev) { |
| 1213 | supported(__func__); |
| 1214 | if (strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 1215 | ALOGE("Invalid module name- %s", name); |
| 1216 | return -EINVAL; |
| 1217 | } |
| 1218 | |
| 1219 | std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo()); |
| 1220 | if (!ctx) { |
| 1221 | ALOGE("Failed to allocate DrmHwcTwo"); |
| 1222 | return -ENOMEM; |
| 1223 | } |
| 1224 | |
| 1225 | HWC2::Error err = ctx->Init(); |
| 1226 | if (err != HWC2::Error::None) { |
| 1227 | ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err); |
| 1228 | return -EINVAL; |
| 1229 | } |
| 1230 | |
| 1231 | ctx->common.module = const_cast<hw_module_t *>(module); |
| 1232 | *dev = &ctx->common; |
| 1233 | ctx.release(); |
| 1234 | return 0; |
Sean Paul | ed2ec4b | 2016-03-10 15:35:40 -0500 | [diff] [blame] | 1235 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 1236 | } // namespace android |
Sean Paul | ac87415 | 2016-03-10 16:00:26 -0500 | [diff] [blame] | 1237 | |
| 1238 | static struct hw_module_methods_t hwc2_module_methods = { |
| 1239 | .open = android::DrmHwcTwo::HookDevOpen, |
| 1240 | }; |
| 1241 | |
| 1242 | hw_module_t HAL_MODULE_INFO_SYM = { |
| 1243 | .tag = HARDWARE_MODULE_TAG, |
| 1244 | .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0), |
| 1245 | .id = HWC_HARDWARE_MODULE_ID, |
| 1246 | .name = "DrmHwcTwo module", |
| 1247 | .author = "The Android Open Source Project", |
| 1248 | .methods = &hwc2_module_methods, |
| 1249 | .dso = NULL, |
| 1250 | .reserved = {0}, |
| 1251 | }; |