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