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