| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2022 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 |  | 
| Sean Paul | 468a754 | 2024-07-16 19:50:58 +0000 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 19 |  | 
|  | 20 | #include "HwcDisplay.h" | 
|  | 21 |  | 
| Roman Stratiienko | bb594ba | 2022-02-18 16:52:03 +0200 | [diff] [blame] | 22 | #include "backend/Backend.h" | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 23 | #include "backend/BackendManager.h" | 
|  | 24 | #include "bufferinfo/BufferInfoGetter.h" | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 25 | #include "drm/DrmHwc.h" | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 26 | #include "utils/log.h" | 
|  | 27 | #include "utils/properties.h" | 
|  | 28 |  | 
|  | 29 | namespace android { | 
|  | 30 |  | 
|  | 31 | std::string HwcDisplay::DumpDelta(HwcDisplay::Stats delta) { | 
|  | 32 | if (delta.total_pixops_ == 0) | 
|  | 33 | return "No stats yet"; | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 34 | auto ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 35 |  | 
|  | 36 | std::stringstream ss; | 
|  | 37 | ss << " Total frames count: " << delta.total_frames_ << "\n" | 
|  | 38 | << " Failed to test commit frames: " << delta.failed_kms_validate_ << "\n" | 
|  | 39 | << " Failed to commit frames: " << delta.failed_kms_present_ << "\n" | 
|  | 40 | << ((delta.failed_kms_present_ > 0) | 
|  | 41 | ? " !!! Internal failure, FIX it please\n" | 
|  | 42 | : "") | 
|  | 43 | << " Flattened frames: " << delta.frames_flattened_ << "\n" | 
|  | 44 | << " Pixel operations (free units)" | 
|  | 45 | << " : [TOTAL: " << delta.total_pixops_ << " / GPU: " << delta.gpu_pixops_ | 
|  | 46 | << "]\n" | 
|  | 47 | << " Composition efficiency: " << ratio; | 
|  | 48 |  | 
|  | 49 | return ss.str(); | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | std::string HwcDisplay::Dump() { | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 53 | auto connector_name = IsInHeadlessMode() | 
|  | 54 | ? std::string("NULL-DISPLAY") | 
|  | 55 | : GetPipe().connector->Get()->GetName(); | 
| Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 56 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 57 | std::stringstream ss; | 
| Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 58 | ss << "- Display on: " << connector_name << "\n" | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 59 | << "Statistics since system boot:\n" | 
|  | 60 | << DumpDelta(total_stats_) << "\n\n" | 
|  | 61 | << "Statistics since last dumpsys request:\n" | 
|  | 62 | << DumpDelta(total_stats_.minus(prev_stats_)) << "\n\n"; | 
|  | 63 |  | 
|  | 64 | memcpy(&prev_stats_, &total_stats_, sizeof(Stats)); | 
|  | 65 | return ss.str(); | 
|  | 66 | } | 
|  | 67 |  | 
| Roman Stratiienko | bb594ba | 2022-02-18 16:52:03 +0200 | [diff] [blame] | 68 | HwcDisplay::HwcDisplay(hwc2_display_t handle, HWC2::DisplayType type, | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 69 | DrmHwc *hwc) | 
|  | 70 | : hwc_(hwc), handle_(handle), type_(type), client_layer_(this) { | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 71 | if (type_ == HWC2::DisplayType::Virtual) { | 
|  | 72 | writeback_layer_ = std::make_unique<HwcLayer>(this); | 
|  | 73 | } | 
|  | 74 | } | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 75 |  | 
|  | 76 | void HwcDisplay::SetColorMarixToIdentity() { | 
|  | 77 | color_matrix_ = std::make_shared<drm_color_ctm>(); | 
|  | 78 | for (int i = 0; i < kCtmCols; i++) { | 
|  | 79 | for (int j = 0; j < kCtmRows; j++) { | 
| Yongqin Liu | 152bc62 | 2023-01-29 00:48:10 +0800 | [diff] [blame] | 80 | constexpr uint64_t kOne = (1ULL << 32); /* 1.0 in s31.32 format */ | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 81 | color_matrix_->matrix[i * kCtmRows + j] = (i == j) ? kOne : 0; | 
|  | 82 | } | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | color_transform_hint_ = HAL_COLOR_TRANSFORM_IDENTITY; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Normunds Rieksts | 545096d | 2024-03-11 16:37:45 +0000 | [diff] [blame] | 88 | HwcDisplay::~HwcDisplay() { | 
|  | 89 | Deinit(); | 
|  | 90 | }; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 91 |  | 
| Roman Stratiienko | 63762a9 | 2023-09-18 22:33:45 +0300 | [diff] [blame] | 92 | void HwcDisplay::SetPipeline(std::shared_ptr<DrmDisplayPipeline> pipeline) { | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 93 | Deinit(); | 
|  | 94 |  | 
| Roman Stratiienko | 63762a9 | 2023-09-18 22:33:45 +0300 | [diff] [blame] | 95 | pipeline_ = std::move(pipeline); | 
| Roman Stratiienko | bb594ba | 2022-02-18 16:52:03 +0200 | [diff] [blame] | 96 |  | 
| Roman Stratiienko | 63762a9 | 2023-09-18 22:33:45 +0300 | [diff] [blame] | 97 | if (pipeline_ != nullptr || handle_ == kPrimaryDisplay) { | 
| Roman Stratiienko | bb594ba | 2022-02-18 16:52:03 +0200 | [diff] [blame] | 98 | Init(); | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 99 | hwc_->ScheduleHotplugEvent(handle_, /*connected = */ true); | 
| Roman Stratiienko | bb594ba | 2022-02-18 16:52:03 +0200 | [diff] [blame] | 100 | } else { | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 101 | hwc_->ScheduleHotplugEvent(handle_, /*connected = */ false); | 
| Roman Stratiienko | bb594ba | 2022-02-18 16:52:03 +0200 | [diff] [blame] | 102 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 103 | } | 
|  | 104 |  | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 105 | void HwcDisplay::Deinit() { | 
|  | 106 | if (pipeline_ != nullptr) { | 
|  | 107 | AtomicCommitArgs a_args{}; | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 108 | a_args.composition = std::make_shared<DrmKmsPlan>(); | 
|  | 109 | GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args); | 
| John Stultz | 799e8c7 | 2022-06-30 19:49:42 +0000 | [diff] [blame] | 110 | /* | 
|  | 111 | *  TODO: | 
|  | 112 | *  Unfortunately the following causes regressions on db845c | 
|  | 113 | *  with VtsHalGraphicsComposerV2_3TargetTest due to the display | 
|  | 114 | *  never coming back. Patches to avoiding that issue on the | 
|  | 115 | *  the kernel side unfortunately causes further crashes in | 
|  | 116 | *  drm_hwcomposer, because the client detach takes longer then the | 
|  | 117 | *  1 second max VTS expects. So for now as a workaround, lets skip | 
|  | 118 | *  deactivating the display on deinit, which matches previous | 
|  | 119 | *  behavior prior to commit d0494d9b8097 | 
|  | 120 | */ | 
|  | 121 | #if 0 | 
| Roman Stratiienko | af862a5 | 2022-06-22 12:14:22 +0300 | [diff] [blame] | 122 | a_args.composition = {}; | 
|  | 123 | a_args.active = false; | 
|  | 124 | GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args); | 
| John Stultz | 799e8c7 | 2022-06-30 19:49:42 +0000 | [diff] [blame] | 125 | #endif | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 126 |  | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 127 | current_plan_.reset(); | 
|  | 128 | backend_.reset(); | 
| Roman Stratiienko | 22fe961 | 2023-01-17 21:22:29 +0200 | [diff] [blame] | 129 | if (flatcon_) { | 
|  | 130 | flatcon_->StopThread(); | 
|  | 131 | flatcon_.reset(); | 
|  | 132 | } | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 133 | } | 
|  | 134 |  | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 135 | if (vsync_worker_) { | 
| Drew Davenport | 1ac3b62 | 2024-09-05 10:59:16 -0600 | [diff] [blame] | 136 | // TODO: There should be a mechanism to wait for this worker to complete, | 
|  | 137 | // otherwise there is a race condition while destructing the HwcDisplay. | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 138 | vsync_worker_->StopThread(); | 
|  | 139 | vsync_worker_ = {}; | 
|  | 140 | } | 
|  | 141 |  | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 142 | SetClientTarget(nullptr, -1, 0, {}); | 
|  | 143 | } | 
|  | 144 |  | 
| Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 145 | HWC2::Error HwcDisplay::Init() { | 
| Roman Stratiienko | d0494d9 | 2022-03-15 18:02:04 +0200 | [diff] [blame] | 146 | ChosePreferredConfig(); | 
|  | 147 |  | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 148 | auto vsw_callbacks = (VSyncWorkerCallbacks){ | 
|  | 149 | .out_event = | 
|  | 150 | [this](int64_t timestamp) { | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 151 | const std::unique_lock lock(hwc_->GetResMan().GetMainLock()); | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 152 | if (vsync_event_en_) { | 
|  | 153 | uint32_t period_ns{}; | 
|  | 154 | GetDisplayVsyncPeriod(&period_ns); | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 155 | hwc_->SendVsyncEventToClient(handle_, timestamp, period_ns); | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 156 | } | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 157 | if (vsync_tracking_en_) { | 
|  | 158 | last_vsync_ts_ = timestamp; | 
|  | 159 | } | 
| Roman Stratiienko | 22fe961 | 2023-01-17 21:22:29 +0200 | [diff] [blame] | 160 | if (!vsync_event_en_ && !vsync_tracking_en_) { | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 161 | vsync_worker_->VSyncControl(false); | 
|  | 162 | } | 
|  | 163 | }, | 
|  | 164 | .get_vperiod_ns = [this]() -> uint32_t { | 
|  | 165 | uint32_t outVsyncPeriod = 0; | 
|  | 166 | GetDisplayVsyncPeriod(&outVsyncPeriod); | 
|  | 167 | return outVsyncPeriod; | 
|  | 168 | }, | 
|  | 169 | }; | 
|  | 170 |  | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 171 | if (type_ != HWC2::DisplayType::Virtual) { | 
|  | 172 | vsync_worker_ = VSyncWorker::CreateInstance(pipeline_, vsw_callbacks); | 
|  | 173 | if (!vsync_worker_) { | 
|  | 174 | ALOGE("Failed to create event worker for d=%d\n", int(handle_)); | 
|  | 175 | return HWC2::Error::BadDisplay; | 
|  | 176 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 177 | } | 
|  | 178 |  | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 179 | if (!IsInHeadlessMode()) { | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 180 | auto ret = BackendManager::GetInstance().SetBackendForDisplay(this); | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 181 | if (ret) { | 
|  | 182 | ALOGE("Failed to set backend for d=%d %d\n", int(handle_), ret); | 
|  | 183 | return HWC2::Error::BadDisplay; | 
|  | 184 | } | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 185 | auto flatcbk = (struct FlatConCallbacks){ | 
|  | 186 | .trigger = [this]() { hwc_->SendRefreshEventToClient(handle_); }}; | 
| Roman Stratiienko | 22fe961 | 2023-01-17 21:22:29 +0200 | [diff] [blame] | 187 | flatcon_ = FlatteningController::CreateInstance(flatcbk); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
|  | 190 | client_layer_.SetLayerBlendMode(HWC2_BLEND_MODE_PREMULTIPLIED); | 
|  | 191 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 192 | SetColorMarixToIdentity(); | 
|  | 193 |  | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 194 | return HWC2::Error::None; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
|  | 197 | HWC2::Error HwcDisplay::ChosePreferredConfig() { | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 198 | HWC2::Error err{}; | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 199 | if (type_ == HWC2::DisplayType::Virtual) { | 
|  | 200 | configs_.GenFakeMode(virtual_disp_width_, virtual_disp_height_); | 
|  | 201 | } else if (!IsInHeadlessMode()) { | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 202 | err = configs_.Update(*pipeline_->connector->Get()); | 
|  | 203 | } else { | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 204 | configs_.GenFakeMode(0, 0); | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 205 | } | 
|  | 206 | if (!IsInHeadlessMode() && err != HWC2::Error::None) { | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 207 | return HWC2::Error::BadDisplay; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 208 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 209 |  | 
| Roman Stratiienko | 0137f86 | 2022-01-04 18:27:40 +0200 | [diff] [blame] | 210 | return SetActiveConfig(configs_.preferred_config_id); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
|  | 213 | HWC2::Error HwcDisplay::AcceptDisplayChanges() { | 
|  | 214 | for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) | 
|  | 215 | l.second.AcceptTypeChange(); | 
|  | 216 | return HWC2::Error::None; | 
|  | 217 | } | 
|  | 218 |  | 
|  | 219 | HWC2::Error HwcDisplay::CreateLayer(hwc2_layer_t *layer) { | 
| Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 220 | layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer(this)); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 221 | *layer = static_cast<hwc2_layer_t>(layer_idx_); | 
|  | 222 | ++layer_idx_; | 
|  | 223 | return HWC2::Error::None; | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | HWC2::Error HwcDisplay::DestroyLayer(hwc2_layer_t layer) { | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 227 | if (!get_layer(layer)) { | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 228 | return HWC2::Error::BadLayer; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 229 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 230 |  | 
|  | 231 | layers_.erase(layer); | 
|  | 232 | return HWC2::Error::None; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | HWC2::Error HwcDisplay::GetActiveConfig(hwc2_config_t *config) const { | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 236 | if (configs_.hwc_configs.count(staged_mode_config_id_) == 0) | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 237 | return HWC2::Error::BadConfig; | 
|  | 238 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 239 | *config = staged_mode_config_id_; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 240 | return HWC2::Error::None; | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | HWC2::Error HwcDisplay::GetChangedCompositionTypes(uint32_t *num_elements, | 
|  | 244 | hwc2_layer_t *layers, | 
|  | 245 | int32_t *types) { | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 246 | if (IsInHeadlessMode()) { | 
|  | 247 | *num_elements = 0; | 
|  | 248 | return HWC2::Error::None; | 
|  | 249 | } | 
|  | 250 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 251 | uint32_t num_changes = 0; | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 252 | for (auto &l : layers_) { | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 253 | if (l.second.IsTypeChanged()) { | 
|  | 254 | if (layers && num_changes < *num_elements) | 
|  | 255 | layers[num_changes] = l.first; | 
|  | 256 | if (types && num_changes < *num_elements) | 
|  | 257 | types[num_changes] = static_cast<int32_t>(l.second.GetValidatedType()); | 
|  | 258 | ++num_changes; | 
|  | 259 | } | 
|  | 260 | } | 
|  | 261 | if (!layers && !types) | 
|  | 262 | *num_elements = num_changes; | 
|  | 263 | return HWC2::Error::None; | 
|  | 264 | } | 
|  | 265 |  | 
|  | 266 | HWC2::Error HwcDisplay::GetClientTargetSupport(uint32_t width, uint32_t height, | 
|  | 267 | int32_t /*format*/, | 
|  | 268 | int32_t dataspace) { | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 269 | if (IsInHeadlessMode()) { | 
|  | 270 | return HWC2::Error::None; | 
|  | 271 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 272 |  | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 273 | auto min = pipeline_->device->GetMinResolution(); | 
|  | 274 | auto max = pipeline_->device->GetMaxResolution(); | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 275 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 276 | if (width < min.first || height < min.second) | 
|  | 277 | return HWC2::Error::Unsupported; | 
|  | 278 |  | 
|  | 279 | if (width > max.first || height > max.second) | 
|  | 280 | return HWC2::Error::Unsupported; | 
|  | 281 |  | 
|  | 282 | if (dataspace != HAL_DATASPACE_UNKNOWN) | 
|  | 283 | return HWC2::Error::Unsupported; | 
|  | 284 |  | 
|  | 285 | // TODO(nobody): Validate format can be handled by either GL or planes | 
|  | 286 | return HWC2::Error::None; | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | HWC2::Error HwcDisplay::GetColorModes(uint32_t *num_modes, int32_t *modes) { | 
|  | 290 | if (!modes) | 
|  | 291 | *num_modes = 1; | 
|  | 292 |  | 
|  | 293 | if (modes) | 
|  | 294 | *modes = HAL_COLOR_MODE_NATIVE; | 
|  | 295 |  | 
|  | 296 | return HWC2::Error::None; | 
|  | 297 | } | 
|  | 298 |  | 
|  | 299 | HWC2::Error HwcDisplay::GetDisplayAttribute(hwc2_config_t config, | 
|  | 300 | int32_t attribute_in, | 
|  | 301 | int32_t *value) { | 
|  | 302 | int conf = static_cast<int>(config); | 
|  | 303 |  | 
| Roman Stratiienko | 0137f86 | 2022-01-04 18:27:40 +0200 | [diff] [blame] | 304 | if (configs_.hwc_configs.count(conf) == 0) { | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 305 | ALOGE("Could not find mode #%d", conf); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 306 | return HWC2::Error::BadConfig; | 
|  | 307 | } | 
|  | 308 |  | 
| Roman Stratiienko | 0137f86 | 2022-01-04 18:27:40 +0200 | [diff] [blame] | 309 | auto &hwc_config = configs_.hwc_configs[conf]; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 310 |  | 
|  | 311 | static const int32_t kUmPerInch = 25400; | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 312 | auto mm_width = configs_.mm_width; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 313 | auto attribute = static_cast<HWC2::Attribute>(attribute_in); | 
|  | 314 | switch (attribute) { | 
|  | 315 | case HWC2::Attribute::Width: | 
| Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 316 | *value = static_cast<int>(hwc_config.mode.GetRawMode().hdisplay); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 317 | break; | 
|  | 318 | case HWC2::Attribute::Height: | 
| Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 319 | *value = static_cast<int>(hwc_config.mode.GetRawMode().vdisplay); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 320 | break; | 
|  | 321 | case HWC2::Attribute::VsyncPeriod: | 
|  | 322 | // in nanoseconds | 
| Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 323 | *value = static_cast<int>(1E9 / hwc_config.mode.GetVRefresh()); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 324 | break; | 
| Lucas Berthou | df686aa | 2024-08-28 16:15:38 +0000 | [diff] [blame] | 325 | case HWC2::Attribute::DpiY: | 
|  | 326 | // ideally this should be vdisplay/mm_heigth, however mm_height | 
|  | 327 | // comes from edid parsing and is highly unreliable. Viewing the | 
|  | 328 | // rarity of anisotropic displays, falling back to a single value | 
|  | 329 | // for dpi yield more correct output. | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 330 | case HWC2::Attribute::DpiX: | 
|  | 331 | // Dots per 1000 inches | 
| Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 332 | *value = mm_width ? int(hwc_config.mode.GetRawMode().hdisplay * | 
|  | 333 | kUmPerInch / mm_width) | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 334 | : -1; | 
|  | 335 | break; | 
| Roman Stratiienko | 6b40505 | 2022-12-10 19:09:10 +0200 | [diff] [blame] | 336 | #if __ANDROID_API__ > 29 | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 337 | case HWC2::Attribute::ConfigGroup: | 
|  | 338 | /* Dispite ConfigGroup is a part of HWC2.4 API, framework | 
|  | 339 | * able to request it even if service @2.1 is used */ | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 340 | *value = int(hwc_config.group_id); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 341 | break; | 
|  | 342 | #endif | 
|  | 343 | default: | 
|  | 344 | *value = -1; | 
|  | 345 | return HWC2::Error::BadConfig; | 
|  | 346 | } | 
|  | 347 | return HWC2::Error::None; | 
|  | 348 | } | 
|  | 349 |  | 
| Drew Davenport | f7e8833 | 2024-09-06 12:54:38 -0600 | [diff] [blame] | 350 | HWC2::Error HwcDisplay::LegacyGetDisplayConfigs(uint32_t *num_configs, | 
|  | 351 | hwc2_config_t *configs) { | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 352 | uint32_t idx = 0; | 
| Roman Stratiienko | 0137f86 | 2022-01-04 18:27:40 +0200 | [diff] [blame] | 353 | for (auto &hwc_config : configs_.hwc_configs) { | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 354 | if (hwc_config.second.disabled) { | 
|  | 355 | continue; | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | if (configs != nullptr) { | 
|  | 359 | if (idx >= *num_configs) { | 
|  | 360 | break; | 
|  | 361 | } | 
|  | 362 | configs[idx] = hwc_config.second.id; | 
|  | 363 | } | 
|  | 364 |  | 
|  | 365 | idx++; | 
|  | 366 | } | 
|  | 367 | *num_configs = idx; | 
|  | 368 | return HWC2::Error::None; | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | HWC2::Error HwcDisplay::GetDisplayName(uint32_t *size, char *name) { | 
|  | 372 | std::ostringstream stream; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 373 | if (IsInHeadlessMode()) { | 
|  | 374 | stream << "null-display"; | 
|  | 375 | } else { | 
|  | 376 | stream << "display-" << GetPipe().connector->Get()->GetId(); | 
|  | 377 | } | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 378 | auto string = stream.str(); | 
|  | 379 | auto length = string.length(); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 380 | if (!name) { | 
|  | 381 | *size = length; | 
|  | 382 | return HWC2::Error::None; | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size); | 
|  | 386 | strncpy(name, string.c_str(), *size); | 
|  | 387 | return HWC2::Error::None; | 
|  | 388 | } | 
|  | 389 |  | 
|  | 390 | HWC2::Error HwcDisplay::GetDisplayRequests(int32_t * /*display_requests*/, | 
|  | 391 | uint32_t *num_elements, | 
|  | 392 | hwc2_layer_t * /*layers*/, | 
|  | 393 | int32_t * /*layer_requests*/) { | 
|  | 394 | // TODO(nobody): I think virtual display should request | 
|  | 395 | //      HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here | 
|  | 396 | *num_elements = 0; | 
|  | 397 | return HWC2::Error::None; | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | HWC2::Error HwcDisplay::GetDisplayType(int32_t *type) { | 
|  | 401 | *type = static_cast<int32_t>(type_); | 
|  | 402 | return HWC2::Error::None; | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | HWC2::Error HwcDisplay::GetDozeSupport(int32_t *support) { | 
|  | 406 | *support = 0; | 
|  | 407 | return HWC2::Error::None; | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | HWC2::Error HwcDisplay::GetHdrCapabilities(uint32_t *num_types, | 
|  | 411 | int32_t * /*types*/, | 
|  | 412 | float * /*max_luminance*/, | 
|  | 413 | float * /*max_average_luminance*/, | 
|  | 414 | float * /*min_luminance*/) { | 
|  | 415 | *num_types = 0; | 
|  | 416 | return HWC2::Error::None; | 
|  | 417 | } | 
|  | 418 |  | 
|  | 419 | /* Find API details at: | 
|  | 420 | * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1767 | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 421 | * | 
|  | 422 | * Called after PresentDisplay(), CLIENT is expecting release fence for the | 
|  | 423 | * prior buffer (not the one assigned to the layer at the moment). | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 424 | */ | 
|  | 425 | HWC2::Error HwcDisplay::GetReleaseFences(uint32_t *num_elements, | 
|  | 426 | hwc2_layer_t *layers, | 
|  | 427 | int32_t *fences) { | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 428 | if (IsInHeadlessMode()) { | 
|  | 429 | *num_elements = 0; | 
|  | 430 | return HWC2::Error::None; | 
|  | 431 | } | 
|  | 432 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 433 | uint32_t num_layers = 0; | 
|  | 434 |  | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 435 | for (auto &l : layers_) { | 
|  | 436 | if (!l.second.GetPriorBufferScanOutFlag() || !present_fence_) { | 
|  | 437 | continue; | 
|  | 438 | } | 
|  | 439 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 440 | ++num_layers; | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 441 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 442 | if (layers == nullptr || fences == nullptr) | 
|  | 443 | continue; | 
|  | 444 |  | 
|  | 445 | 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; | 
| Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 451 | fences[num_layers - 1] = DupFd(present_fence_); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 452 | } | 
|  | 453 | *num_elements = num_layers; | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 454 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 455 | return HWC2::Error::None; | 
|  | 456 | } | 
|  | 457 |  | 
|  | 458 | HWC2::Error HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) { | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 459 | if (IsInHeadlessMode()) { | 
|  | 460 | ALOGE("%s: Display is in headless mode, should never reach here", __func__); | 
|  | 461 | return HWC2::Error::None; | 
|  | 462 | } | 
|  | 463 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 464 | a_args.color_matrix = color_matrix_; | 
|  | 465 |  | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 466 | uint32_t prev_vperiod_ns = 0; | 
|  | 467 | GetDisplayVsyncPeriod(&prev_vperiod_ns); | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 468 |  | 
|  | 469 | auto mode_update_commited_ = false; | 
|  | 470 | if (staged_mode_ && | 
|  | 471 | staged_mode_change_time_ <= ResourceManager::GetTimeMonotonicNs()) { | 
|  | 472 | client_layer_.SetLayerDisplayFrame( | 
|  | 473 | (hwc_rect_t){.left = 0, | 
|  | 474 | .top = 0, | 
| Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 475 | .right = int(staged_mode_->GetRawMode().hdisplay), | 
|  | 476 | .bottom = int(staged_mode_->GetRawMode().vdisplay)}); | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 477 |  | 
|  | 478 | configs_.active_config_id = staged_mode_config_id_; | 
|  | 479 |  | 
|  | 480 | a_args.display_mode = *staged_mode_; | 
|  | 481 | if (!a_args.test_only) { | 
|  | 482 | mode_update_commited_ = true; | 
|  | 483 | } | 
|  | 484 | } | 
|  | 485 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 486 | // order the layers by z-order | 
|  | 487 | bool use_client_layer = false; | 
|  | 488 | uint32_t client_z_order = UINT32_MAX; | 
|  | 489 | std::map<uint32_t, HwcLayer *> z_map; | 
|  | 490 | for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) { | 
|  | 491 | switch (l.second.GetValidatedType()) { | 
|  | 492 | case HWC2::Composition::Device: | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 493 | z_map.emplace(l.second.GetZOrder(), &l.second); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 494 | break; | 
|  | 495 | case HWC2::Composition::Client: | 
|  | 496 | // Place it at the z_order of the lowest client layer | 
|  | 497 | use_client_layer = true; | 
|  | 498 | client_z_order = std::min(client_z_order, l.second.GetZOrder()); | 
|  | 499 | break; | 
|  | 500 | default: | 
|  | 501 | continue; | 
|  | 502 | } | 
|  | 503 | } | 
|  | 504 | if (use_client_layer) | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 505 | z_map.emplace(client_z_order, &client_layer_); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 506 |  | 
|  | 507 | if (z_map.empty()) | 
|  | 508 | return HWC2::Error::BadLayer; | 
|  | 509 |  | 
| Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 510 | std::vector<LayerData> composition_layers; | 
|  | 511 |  | 
|  | 512 | /* Import & populate */ | 
|  | 513 | for (std::pair<const uint32_t, HwcLayer *> &l : z_map) { | 
| Roman Stratiienko | 359a9d3 | 2023-01-16 17:41:07 +0200 | [diff] [blame] | 514 | l.second->PopulateLayerData(); | 
| Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 515 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 516 |  | 
|  | 517 | // now that they're ordered by z, add them to the composition | 
|  | 518 | for (std::pair<const uint32_t, HwcLayer *> &l : z_map) { | 
| Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 519 | if (!l.second->IsLayerUsableAsDevice()) { | 
|  | 520 | /* This will be normally triggered on validation of the first frame | 
|  | 521 | * containing CLIENT layer. At this moment client buffer is not yet | 
|  | 522 | * provided by the CLIENT. | 
|  | 523 | * This may be triggered once in HwcLayer lifecycle in case FB can't be | 
|  | 524 | * imported. For example when non-contiguous buffer is imported into | 
|  | 525 | * contiguous-only DRM/KMS driver. | 
|  | 526 | */ | 
|  | 527 | return HWC2::Error::BadLayer; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 528 | } | 
| Roman Stratiienko | 359a9d3 | 2023-01-16 17:41:07 +0200 | [diff] [blame] | 529 | composition_layers.emplace_back(l.second->GetLayerData()); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 530 | } | 
|  | 531 |  | 
| Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 532 | /* Store plan to ensure shared planes won't be stolen by other display | 
|  | 533 | * in between of ValidateDisplay() and PresentDisplay() calls | 
|  | 534 | */ | 
|  | 535 | current_plan_ = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(), | 
|  | 536 | std::move(composition_layers)); | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 537 |  | 
|  | 538 | if (type_ == HWC2::DisplayType::Virtual) { | 
|  | 539 | a_args.writeback_fb = writeback_layer_->GetLayerData().fb; | 
|  | 540 | a_args.writeback_release_fence = writeback_layer_->GetLayerData() | 
|  | 541 | .acquire_fence; | 
|  | 542 | } | 
|  | 543 |  | 
| Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 544 | if (!current_plan_) { | 
|  | 545 | if (!a_args.test_only) { | 
|  | 546 | ALOGE("Failed to create DrmKmsPlan"); | 
|  | 547 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 548 | return HWC2::Error::BadConfig; | 
|  | 549 | } | 
|  | 550 |  | 
| Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 551 | a_args.composition = current_plan_; | 
|  | 552 |  | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 553 | auto ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 554 |  | 
|  | 555 | if (ret) { | 
|  | 556 | if (!a_args.test_only) | 
|  | 557 | ALOGE("Failed to apply the frame composition ret=%d", ret); | 
|  | 558 | return HWC2::Error::BadParameter; | 
|  | 559 | } | 
|  | 560 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 561 | if (mode_update_commited_) { | 
|  | 562 | staged_mode_.reset(); | 
|  | 563 | vsync_tracking_en_ = false; | 
|  | 564 | if (last_vsync_ts_ != 0) { | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 565 | hwc_->SendVsyncPeriodTimingChangedEventToClient(handle_, | 
|  | 566 | last_vsync_ts_ + | 
|  | 567 | prev_vperiod_ns); | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 568 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 569 | } | 
|  | 570 |  | 
|  | 571 | return HWC2::Error::None; | 
|  | 572 | } | 
|  | 573 |  | 
|  | 574 | /* Find API details at: | 
|  | 575 | * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1805 | 
|  | 576 | */ | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 577 | HWC2::Error HwcDisplay::PresentDisplay(int32_t *out_present_fence) { | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 578 | if (IsInHeadlessMode()) { | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 579 | *out_present_fence = -1; | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 580 | return HWC2::Error::None; | 
|  | 581 | } | 
| Roman Stratiienko | 780f7da | 2022-01-10 16:04:15 +0200 | [diff] [blame] | 582 | HWC2::Error ret{}; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 583 |  | 
|  | 584 | ++total_stats_.total_frames_; | 
|  | 585 |  | 
|  | 586 | AtomicCommitArgs a_args{}; | 
|  | 587 | ret = CreateComposition(a_args); | 
|  | 588 |  | 
|  | 589 | if (ret != HWC2::Error::None) | 
|  | 590 | ++total_stats_.failed_kms_present_; | 
|  | 591 |  | 
|  | 592 | if (ret == HWC2::Error::BadLayer) { | 
|  | 593 | // Can we really have no client or device layers? | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 594 | *out_present_fence = -1; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 595 | return HWC2::Error::None; | 
|  | 596 | } | 
|  | 597 | if (ret != HWC2::Error::None) | 
|  | 598 | return ret; | 
|  | 599 |  | 
| Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 600 | this->present_fence_ = a_args.out_fence; | 
|  | 601 | *out_present_fence = DupFd(a_args.out_fence); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 602 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 603 | // Reset the color matrix so we don't apply it over and over again. | 
|  | 604 | color_matrix_ = {}; | 
|  | 605 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 606 | ++frame_no_; | 
|  | 607 | return HWC2::Error::None; | 
|  | 608 | } | 
|  | 609 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 610 | HWC2::Error HwcDisplay::SetActiveConfigInternal(uint32_t config, | 
|  | 611 | int64_t change_time) { | 
|  | 612 | if (configs_.hwc_configs.count(config) == 0) { | 
|  | 613 | ALOGE("Could not find active mode for %u", config); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 614 | return HWC2::Error::BadConfig; | 
|  | 615 | } | 
|  | 616 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 617 | staged_mode_ = configs_.hwc_configs[config].mode; | 
|  | 618 | staged_mode_change_time_ = change_time; | 
|  | 619 | staged_mode_config_id_ = config; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 620 |  | 
|  | 621 | return HWC2::Error::None; | 
|  | 622 | } | 
|  | 623 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 624 | HWC2::Error HwcDisplay::SetActiveConfig(hwc2_config_t config) { | 
|  | 625 | return SetActiveConfigInternal(config, ResourceManager::GetTimeMonotonicNs()); | 
|  | 626 | } | 
|  | 627 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 628 | /* Find API details at: | 
|  | 629 | * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1861 | 
|  | 630 | */ | 
|  | 631 | HWC2::Error HwcDisplay::SetClientTarget(buffer_handle_t target, | 
|  | 632 | int32_t acquire_fence, | 
|  | 633 | int32_t dataspace, | 
|  | 634 | hwc_region_t /*damage*/) { | 
|  | 635 | client_layer_.SetLayerBuffer(target, acquire_fence); | 
|  | 636 | client_layer_.SetLayerDataspace(dataspace); | 
|  | 637 |  | 
|  | 638 | /* | 
|  | 639 | * target can be nullptr, this does mean the Composer Service is calling | 
|  | 640 | * cleanDisplayResources() on after receiving HOTPLUG event. See more at: | 
|  | 641 | * https://cs.android.com/android/platform/superproject/+/master:hardware/interfaces/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerClient.h;l=350;drc=944b68180b008456ed2eb4d4d329e33b19bd5166 | 
|  | 642 | */ | 
|  | 643 | if (target == nullptr) { | 
| Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame] | 644 | client_layer_.SwChainClearCache(); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 645 | return HWC2::Error::None; | 
|  | 646 | } | 
|  | 647 |  | 
| Roman Stratiienko | 5070d51 | 2022-05-30 13:41:20 +0300 | [diff] [blame] | 648 | if (IsInHeadlessMode()) { | 
|  | 649 | return HWC2::Error::None; | 
|  | 650 | } | 
|  | 651 |  | 
| Roman Stratiienko | 359a9d3 | 2023-01-16 17:41:07 +0200 | [diff] [blame] | 652 | client_layer_.PopulateLayerData(); | 
| Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 653 | if (!client_layer_.IsLayerUsableAsDevice()) { | 
|  | 654 | ALOGE("Client layer must be always usable by DRM/KMS"); | 
|  | 655 | return HWC2::Error::BadLayer; | 
| Roman Stratiienko | e9fbd8d | 2022-02-21 13:03:29 +0200 | [diff] [blame] | 656 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 657 |  | 
| Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 658 | auto &bi = client_layer_.GetLayerData().bi; | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 659 | if (!bi) { | 
|  | 660 | ALOGE("%s: Invalid state", __func__); | 
|  | 661 | return HWC2::Error::BadLayer; | 
|  | 662 | } | 
|  | 663 |  | 
|  | 664 | auto source_crop = (hwc_frect_t){.left = 0.0F, | 
|  | 665 | .top = 0.0F, | 
|  | 666 | .right = static_cast<float>(bi->width), | 
|  | 667 | .bottom = static_cast<float>(bi->height)}; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 668 | client_layer_.SetLayerSourceCrop(source_crop); | 
|  | 669 |  | 
|  | 670 | return HWC2::Error::None; | 
|  | 671 | } | 
|  | 672 |  | 
|  | 673 | HWC2::Error HwcDisplay::SetColorMode(int32_t mode) { | 
|  | 674 | if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_BT2100_HLG) | 
|  | 675 | return HWC2::Error::BadParameter; | 
|  | 676 |  | 
|  | 677 | if (mode != HAL_COLOR_MODE_NATIVE) | 
|  | 678 | return HWC2::Error::Unsupported; | 
|  | 679 |  | 
|  | 680 | color_mode_ = mode; | 
|  | 681 | return HWC2::Error::None; | 
|  | 682 | } | 
|  | 683 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 684 | #include <xf86drmMode.h> | 
|  | 685 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 686 | HWC2::Error HwcDisplay::SetColorTransform(const float *matrix, int32_t hint) { | 
|  | 687 | if (hint < HAL_COLOR_TRANSFORM_IDENTITY || | 
|  | 688 | hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA) | 
|  | 689 | return HWC2::Error::BadParameter; | 
|  | 690 |  | 
|  | 691 | if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX) | 
|  | 692 | return HWC2::Error::BadParameter; | 
|  | 693 |  | 
|  | 694 | color_transform_hint_ = static_cast<android_color_transform_t>(hint); | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 695 |  | 
| Roman Stratiienko | 5de61b5 | 2023-02-01 16:29:45 +0200 | [diff] [blame] | 696 | if (IsInHeadlessMode()) | 
|  | 697 | return HWC2::Error::None; | 
|  | 698 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 699 | if (!GetPipe().crtc->Get()->GetCtmProperty()) | 
|  | 700 | return HWC2::Error::None; | 
|  | 701 |  | 
|  | 702 | switch (color_transform_hint_) { | 
|  | 703 | case HAL_COLOR_TRANSFORM_IDENTITY: | 
|  | 704 | SetColorMarixToIdentity(); | 
|  | 705 | break; | 
|  | 706 | case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX: | 
|  | 707 | color_matrix_ = std::make_shared<drm_color_ctm>(); | 
|  | 708 | /* DRM expects a 3x3 matrix, but the HAL provides a 4x4 matrix. */ | 
|  | 709 | for (int i = 0; i < kCtmCols; i++) { | 
|  | 710 | for (int j = 0; j < kCtmRows; j++) { | 
|  | 711 | constexpr int kInCtmRows = 4; | 
|  | 712 | /* HAL matrix type is float, but DRM expects a s31.32 fix point */ | 
| Yongqin Liu | 152bc62 | 2023-01-29 00:48:10 +0800 | [diff] [blame] | 713 | auto value = uint64_t(matrix[i * kInCtmRows + j] * float(1ULL << 32)); | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 714 | color_matrix_->matrix[i * kCtmRows + j] = value; | 
|  | 715 | } | 
|  | 716 | } | 
|  | 717 | break; | 
|  | 718 | default: | 
|  | 719 | return HWC2::Error::Unsupported; | 
|  | 720 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 721 |  | 
|  | 722 | return HWC2::Error::None; | 
|  | 723 | } | 
|  | 724 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 725 | bool HwcDisplay::CtmByGpu() { | 
|  | 726 | if (color_transform_hint_ == HAL_COLOR_TRANSFORM_IDENTITY) | 
|  | 727 | return false; | 
|  | 728 |  | 
|  | 729 | if (GetPipe().crtc->Get()->GetCtmProperty()) | 
|  | 730 | return false; | 
|  | 731 |  | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 732 | if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore) | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 733 | return false; | 
|  | 734 |  | 
|  | 735 | return true; | 
|  | 736 | } | 
|  | 737 |  | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 738 | HWC2::Error HwcDisplay::SetOutputBuffer(buffer_handle_t buffer, | 
|  | 739 | int32_t release_fence) { | 
|  | 740 | writeback_layer_->SetLayerBuffer(buffer, release_fence); | 
|  | 741 | writeback_layer_->PopulateLayerData(); | 
|  | 742 | if (!writeback_layer_->IsLayerUsableAsDevice()) { | 
|  | 743 | ALOGE("Output layer must be always usable by DRM/KMS"); | 
|  | 744 | return HWC2::Error::BadLayer; | 
|  | 745 | } | 
|  | 746 | /* TODO: Check if format is supported by writeback connector */ | 
|  | 747 | return HWC2::Error::None; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 748 | } | 
|  | 749 |  | 
|  | 750 | HWC2::Error HwcDisplay::SetPowerMode(int32_t mode_in) { | 
|  | 751 | auto mode = static_cast<HWC2::PowerMode>(mode_in); | 
| Roman Stratiienko | ccaf516 | 2022-04-01 19:26:30 +0300 | [diff] [blame] | 752 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 753 | AtomicCommitArgs a_args{}; | 
|  | 754 |  | 
|  | 755 | switch (mode) { | 
|  | 756 | case HWC2::PowerMode::Off: | 
|  | 757 | a_args.active = false; | 
|  | 758 | break; | 
|  | 759 | case HWC2::PowerMode::On: | 
| Roman Stratiienko | ccaf516 | 2022-04-01 19:26:30 +0300 | [diff] [blame] | 760 | a_args.active = true; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 761 | break; | 
|  | 762 | case HWC2::PowerMode::Doze: | 
|  | 763 | case HWC2::PowerMode::DozeSuspend: | 
|  | 764 | return HWC2::Error::Unsupported; | 
|  | 765 | default: | 
| John Stultz | ffe783c | 2024-02-14 10:51:27 -0800 | [diff] [blame] | 766 | ALOGE("Incorrect power mode value (%d)\n", mode_in); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 767 | return HWC2::Error::BadParameter; | 
| Roman Stratiienko | ccaf516 | 2022-04-01 19:26:30 +0300 | [diff] [blame] | 768 | } | 
|  | 769 |  | 
|  | 770 | if (IsInHeadlessMode()) { | 
|  | 771 | return HWC2::Error::None; | 
|  | 772 | } | 
|  | 773 |  | 
| Jia Ren | 80566fe | 2022-11-17 17:26:00 +0800 | [diff] [blame] | 774 | if (a_args.active && *a_args.active) { | 
| Roman Stratiienko | ccaf516 | 2022-04-01 19:26:30 +0300 | [diff] [blame] | 775 | /* | 
|  | 776 | * Setting the display to active before we have a composition | 
|  | 777 | * can break some drivers, so skip setting a_args.active to | 
|  | 778 | * true, as the next composition frame will implicitly activate | 
|  | 779 | * the display | 
|  | 780 | */ | 
|  | 781 | return GetPipe().atomic_state_manager->ActivateDisplayUsingDPMS() == 0 | 
|  | 782 | ? HWC2::Error::None | 
|  | 783 | : HWC2::Error::BadParameter; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 784 | }; | 
|  | 785 |  | 
| Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 786 | auto err = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 787 | if (err) { | 
|  | 788 | ALOGE("Failed to apply the dpms composition err=%d", err); | 
|  | 789 | return HWC2::Error::BadParameter; | 
|  | 790 | } | 
|  | 791 | return HWC2::Error::None; | 
|  | 792 | } | 
|  | 793 |  | 
|  | 794 | HWC2::Error HwcDisplay::SetVsyncEnabled(int32_t enabled) { | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 795 | if (type_ == HWC2::DisplayType::Virtual) { | 
|  | 796 | return HWC2::Error::None; | 
|  | 797 | } | 
|  | 798 |  | 
| Roman Stratiienko | 099c311 | 2022-01-20 11:50:54 +0200 | [diff] [blame] | 799 | vsync_event_en_ = HWC2_VSYNC_ENABLE == enabled; | 
|  | 800 | if (vsync_event_en_) { | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 801 | vsync_worker_->VSyncControl(true); | 
| Roman Stratiienko | 099c311 | 2022-01-20 11:50:54 +0200 | [diff] [blame] | 802 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 803 | return HWC2::Error::None; | 
|  | 804 | } | 
|  | 805 |  | 
|  | 806 | HWC2::Error HwcDisplay::ValidateDisplay(uint32_t *num_types, | 
|  | 807 | uint32_t *num_requests) { | 
| Roman Stratiienko | f0c507f | 2022-01-17 18:29:24 +0200 | [diff] [blame] | 808 | if (IsInHeadlessMode()) { | 
|  | 809 | *num_types = *num_requests = 0; | 
|  | 810 | return HWC2::Error::None; | 
|  | 811 | } | 
| Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 812 |  | 
|  | 813 | /* In current drm_hwc design in case previous frame layer was not validated as | 
|  | 814 | * a CLIENT, it is used by display controller (Front buffer). We have to store | 
|  | 815 | * this state to provide the CLIENT with the release fences for such buffers. | 
|  | 816 | */ | 
|  | 817 | for (auto &l : layers_) { | 
|  | 818 | l.second.SetPriorBufferScanOutFlag(l.second.GetValidatedType() != | 
|  | 819 | HWC2::Composition::Client); | 
|  | 820 | } | 
|  | 821 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 822 | return backend_->ValidateDisplay(this, num_types, num_requests); | 
|  | 823 | } | 
|  | 824 |  | 
|  | 825 | std::vector<HwcLayer *> HwcDisplay::GetOrderLayersByZPos() { | 
|  | 826 | std::vector<HwcLayer *> ordered_layers; | 
|  | 827 | ordered_layers.reserve(layers_.size()); | 
|  | 828 |  | 
|  | 829 | for (auto &[handle, layer] : layers_) { | 
|  | 830 | ordered_layers.emplace_back(&layer); | 
|  | 831 | } | 
|  | 832 |  | 
|  | 833 | std::sort(std::begin(ordered_layers), std::end(ordered_layers), | 
|  | 834 | [](const HwcLayer *lhs, const HwcLayer *rhs) { | 
|  | 835 | return lhs->GetZOrder() < rhs->GetZOrder(); | 
|  | 836 | }); | 
|  | 837 |  | 
|  | 838 | return ordered_layers; | 
|  | 839 | } | 
|  | 840 |  | 
| Roman Stratiienko | 099c311 | 2022-01-20 11:50:54 +0200 | [diff] [blame] | 841 | HWC2::Error HwcDisplay::GetDisplayVsyncPeriod( | 
|  | 842 | uint32_t *outVsyncPeriod /* ns */) { | 
|  | 843 | return GetDisplayAttribute(configs_.active_config_id, | 
|  | 844 | HWC2_ATTRIBUTE_VSYNC_PERIOD, | 
|  | 845 | (int32_t *)(outVsyncPeriod)); | 
|  | 846 | } | 
|  | 847 |  | 
| Roman Stratiienko | 6b40505 | 2022-12-10 19:09:10 +0200 | [diff] [blame] | 848 | #if __ANDROID_API__ > 29 | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 849 | HWC2::Error HwcDisplay::GetDisplayConnectionType(uint32_t *outType) { | 
| Roman Stratiienko | 456e2d6 | 2022-01-29 01:17:39 +0200 | [diff] [blame] | 850 | if (IsInHeadlessMode()) { | 
|  | 851 | *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal); | 
|  | 852 | return HWC2::Error::None; | 
|  | 853 | } | 
|  | 854 | /* Primary display should be always internal, | 
|  | 855 | * otherwise SF will be unhappy and will crash | 
|  | 856 | */ | 
| Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 857 | if (GetPipe().connector->Get()->IsInternal() || handle_ == kPrimaryDisplay) | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 858 | *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal); | 
| Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 859 | else if (GetPipe().connector->Get()->IsExternal()) | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 860 | *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External); | 
|  | 861 | else | 
|  | 862 | return HWC2::Error::BadConfig; | 
|  | 863 |  | 
|  | 864 | return HWC2::Error::None; | 
|  | 865 | } | 
|  | 866 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 867 | HWC2::Error HwcDisplay::SetActiveConfigWithConstraints( | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 868 | hwc2_config_t config, | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 869 | hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints, | 
|  | 870 | hwc_vsync_period_change_timeline_t *outTimeline) { | 
| Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 871 | if (type_ == HWC2::DisplayType::Virtual) { | 
|  | 872 | return HWC2::Error::None; | 
|  | 873 | } | 
|  | 874 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 875 | if (vsyncPeriodChangeConstraints == nullptr || outTimeline == nullptr) { | 
|  | 876 | return HWC2::Error::BadParameter; | 
|  | 877 | } | 
|  | 878 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 879 | uint32_t current_vsync_period{}; | 
|  | 880 | GetDisplayVsyncPeriod(¤t_vsync_period); | 
|  | 881 |  | 
|  | 882 | if (vsyncPeriodChangeConstraints->seamlessRequired) { | 
|  | 883 | return HWC2::Error::SeamlessNotAllowed; | 
|  | 884 | } | 
|  | 885 |  | 
|  | 886 | outTimeline->refreshTimeNanos = vsyncPeriodChangeConstraints | 
|  | 887 | ->desiredTimeNanos - | 
|  | 888 | current_vsync_period; | 
|  | 889 | auto ret = SetActiveConfigInternal(config, outTimeline->refreshTimeNanos); | 
|  | 890 | if (ret != HWC2::Error::None) { | 
|  | 891 | return ret; | 
|  | 892 | } | 
|  | 893 |  | 
|  | 894 | outTimeline->refreshRequired = true; | 
|  | 895 | outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeConstraints | 
|  | 896 | ->desiredTimeNanos; | 
|  | 897 |  | 
|  | 898 | last_vsync_ts_ = 0; | 
|  | 899 | vsync_tracking_en_ = true; | 
| Roman Stratiienko | d2cc738 | 2022-12-28 18:51:59 +0200 | [diff] [blame] | 900 | vsync_worker_->VSyncControl(true); | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 901 |  | 
|  | 902 | return HWC2::Error::None; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 903 | } | 
|  | 904 |  | 
|  | 905 | HWC2::Error HwcDisplay::SetAutoLowLatencyMode(bool /*on*/) { | 
|  | 906 | return HWC2::Error::Unsupported; | 
|  | 907 | } | 
|  | 908 |  | 
|  | 909 | HWC2::Error HwcDisplay::GetSupportedContentTypes( | 
|  | 910 | uint32_t *outNumSupportedContentTypes, | 
|  | 911 | const uint32_t *outSupportedContentTypes) { | 
|  | 912 | if (outSupportedContentTypes == nullptr) | 
|  | 913 | *outNumSupportedContentTypes = 0; | 
|  | 914 |  | 
|  | 915 | return HWC2::Error::None; | 
|  | 916 | } | 
|  | 917 |  | 
|  | 918 | HWC2::Error HwcDisplay::SetContentType(int32_t contentType) { | 
|  | 919 | if (contentType != HWC2_CONTENT_TYPE_NONE) | 
|  | 920 | return HWC2::Error::Unsupported; | 
|  | 921 |  | 
|  | 922 | /* TODO: Map to the DRM Connector property: | 
|  | 923 | * https://elixir.bootlin.com/linux/v5.4-rc5/source/drivers/gpu/drm/drm_connector.c#L809 | 
|  | 924 | */ | 
|  | 925 |  | 
|  | 926 | return HWC2::Error::None; | 
|  | 927 | } | 
|  | 928 | #endif | 
|  | 929 |  | 
| Roman Stratiienko | 6b40505 | 2022-12-10 19:09:10 +0200 | [diff] [blame] | 930 | #if __ANDROID_API__ > 28 | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 931 | HWC2::Error HwcDisplay::GetDisplayIdentificationData(uint8_t *outPort, | 
|  | 932 | uint32_t *outDataSize, | 
|  | 933 | uint8_t *outData) { | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 934 | if (IsInHeadlessMode()) { | 
| Roman Stratiienko | f87d808 | 2022-05-06 11:33:56 +0300 | [diff] [blame] | 935 | return HWC2::Error::Unsupported; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 936 | } | 
| Roman Stratiienko | f87d808 | 2022-05-06 11:33:56 +0300 | [diff] [blame] | 937 |  | 
| Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 938 | auto blob = GetPipe().connector->Get()->GetEdidBlob(); | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 939 | if (!blob) { | 
| Roman Stratiienko | f87d808 | 2022-05-06 11:33:56 +0300 | [diff] [blame] | 940 | return HWC2::Error::Unsupported; | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 941 | } | 
|  | 942 |  | 
| Roman Stratiienko | f87d808 | 2022-05-06 11:33:56 +0300 | [diff] [blame] | 943 | *outPort = handle_; /* TDOD(nobody): What should be here? */ | 
|  | 944 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 945 | if (outData) { | 
|  | 946 | *outDataSize = std::min(*outDataSize, blob->length); | 
|  | 947 | memcpy(outData, blob->data, *outDataSize); | 
|  | 948 | } else { | 
|  | 949 | *outDataSize = blob->length; | 
|  | 950 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 951 |  | 
|  | 952 | return HWC2::Error::None; | 
|  | 953 | } | 
|  | 954 |  | 
|  | 955 | HWC2::Error HwcDisplay::GetDisplayCapabilities(uint32_t *outNumCapabilities, | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 956 | uint32_t *outCapabilities) { | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 957 | if (outNumCapabilities == nullptr) { | 
|  | 958 | return HWC2::Error::BadParameter; | 
|  | 959 | } | 
|  | 960 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 961 | bool skip_ctm = false; | 
|  | 962 |  | 
|  | 963 | // Skip client CTM if user requested DRM_OR_IGNORE | 
| Drew Davenport | 9344318 | 2023-12-14 09:25:45 +0000 | [diff] [blame] | 964 | if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore) | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 965 | skip_ctm = true; | 
|  | 966 |  | 
|  | 967 | // Skip client CTM if DRM can handle it | 
|  | 968 | if (!skip_ctm && !IsInHeadlessMode() && | 
|  | 969 | GetPipe().crtc->Get()->GetCtmProperty()) | 
|  | 970 | skip_ctm = true; | 
|  | 971 |  | 
|  | 972 | if (!skip_ctm) { | 
|  | 973 | *outNumCapabilities = 0; | 
|  | 974 | return HWC2::Error::None; | 
|  | 975 | } | 
|  | 976 |  | 
|  | 977 | *outNumCapabilities = 1; | 
|  | 978 | if (outCapabilities) { | 
|  | 979 | outCapabilities[0] = HWC2_DISPLAY_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM; | 
|  | 980 | } | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 981 |  | 
|  | 982 | return HWC2::Error::None; | 
|  | 983 | } | 
|  | 984 |  | 
|  | 985 | HWC2::Error HwcDisplay::GetDisplayBrightnessSupport(bool *supported) { | 
|  | 986 | *supported = false; | 
|  | 987 | return HWC2::Error::None; | 
|  | 988 | } | 
|  | 989 |  | 
|  | 990 | HWC2::Error HwcDisplay::SetDisplayBrightness(float /* brightness */) { | 
|  | 991 | return HWC2::Error::Unsupported; | 
|  | 992 | } | 
|  | 993 |  | 
| Roman Stratiienko | 6b40505 | 2022-12-10 19:09:10 +0200 | [diff] [blame] | 994 | #endif /* __ANDROID_API__ > 28 */ | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 995 |  | 
| Roman Stratiienko | 6b40505 | 2022-12-10 19:09:10 +0200 | [diff] [blame] | 996 | #if __ANDROID_API__ > 27 | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 997 |  | 
|  | 998 | HWC2::Error HwcDisplay::GetRenderIntents( | 
|  | 999 | int32_t mode, uint32_t *outNumIntents, | 
|  | 1000 | int32_t * /*android_render_intent_v1_1_t*/ outIntents) { | 
|  | 1001 | if (mode != HAL_COLOR_MODE_NATIVE) { | 
|  | 1002 | return HWC2::Error::BadParameter; | 
|  | 1003 | } | 
|  | 1004 |  | 
|  | 1005 | if (outIntents == nullptr) { | 
|  | 1006 | *outNumIntents = 1; | 
|  | 1007 | return HWC2::Error::None; | 
|  | 1008 | } | 
|  | 1009 | *outNumIntents = 1; | 
|  | 1010 | outIntents[0] = HAL_RENDER_INTENT_COLORIMETRIC; | 
|  | 1011 | return HWC2::Error::None; | 
|  | 1012 | } | 
|  | 1013 |  | 
|  | 1014 | HWC2::Error HwcDisplay::SetColorModeWithIntent(int32_t mode, int32_t intent) { | 
|  | 1015 | if (intent < HAL_RENDER_INTENT_COLORIMETRIC || | 
|  | 1016 | intent > HAL_RENDER_INTENT_TONE_MAP_ENHANCE) | 
|  | 1017 | return HWC2::Error::BadParameter; | 
|  | 1018 |  | 
|  | 1019 | if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_BT2100_HLG) | 
|  | 1020 | return HWC2::Error::BadParameter; | 
|  | 1021 |  | 
|  | 1022 | if (mode != HAL_COLOR_MODE_NATIVE) | 
|  | 1023 | return HWC2::Error::Unsupported; | 
|  | 1024 |  | 
|  | 1025 | if (intent != HAL_RENDER_INTENT_COLORIMETRIC) | 
|  | 1026 | return HWC2::Error::Unsupported; | 
|  | 1027 |  | 
|  | 1028 | color_mode_ = mode; | 
|  | 1029 | return HWC2::Error::None; | 
|  | 1030 | } | 
|  | 1031 |  | 
| Roman Stratiienko | 6b40505 | 2022-12-10 19:09:10 +0200 | [diff] [blame] | 1032 | #endif /* __ANDROID_API__ > 27 */ | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 1033 |  | 
|  | 1034 | const Backend *HwcDisplay::backend() const { | 
|  | 1035 | return backend_.get(); | 
|  | 1036 | } | 
|  | 1037 |  | 
|  | 1038 | void HwcDisplay::set_backend(std::unique_ptr<Backend> backend) { | 
|  | 1039 | backend_ = std::move(backend); | 
|  | 1040 | } | 
|  | 1041 |  | 
| Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 1042 | }  // namespace android |