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