blob: 13287ef1230b148bf777d66549162dfe96d87598 [file] [log] [blame]
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001/*
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 Paul468a7542024-07-16 19:50:58 +000017#define LOG_TAG "drmhwc"
Roman Stratiienko3627beb2022-01-04 16:02:55 +020018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
19
20#include "HwcDisplay.h"
21
Manasi Navare3f0c01a2024-10-04 18:01:55 +000022#include <cinttypes>
23
Sasha McIntoshf9062b62024-11-12 10:55:06 -050024#include <ui/ColorSpace.h>
Drew Davenport97b5abc2024-11-07 10:43:54 -070025
Roman Stratiienkobb594ba2022-02-18 16:52:03 +020026#include "backend/Backend.h"
Roman Stratiienko3627beb2022-01-04 16:02:55 +020027#include "backend/BackendManager.h"
28#include "bufferinfo/BufferInfoGetter.h"
Tim Van Pattena2f3efa2024-10-15 17:44:54 -060029#include "compositor/DisplayInfo.h"
30#include "drm/DrmConnector.h"
31#include "drm/DrmDisplayPipeline.h"
Drew Davenport93443182023-12-14 09:25:45 +000032#include "drm/DrmHwc.h"
Roman Stratiienko3627beb2022-01-04 16:02:55 +020033#include "utils/log.h"
34#include "utils/properties.h"
35
Tim Van Pattena2f3efa2024-10-15 17:44:54 -060036using ::android::DrmDisplayPipeline;
Sasha McIntoshf9062b62024-11-12 10:55:06 -050037using ColorGamut = ::android::ColorSpace;
Tim Van Pattena2f3efa2024-10-15 17:44:54 -060038
Roman Stratiienko3627beb2022-01-04 16:02:55 +020039namespace android {
40
Drew Davenport97b5abc2024-11-07 10:43:54 -070041namespace {
Drew Davenport76c17a82025-01-15 15:02:45 -070042
43constexpr int kCtmRows = 3;
44constexpr int kCtmCols = 3;
45
46constexpr std::array<float, 16> kIdentityMatrix = {
47 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F,
48 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F,
49};
50
51uint64_t To3132FixPt(float in) {
52 constexpr uint64_t kSignMask = (1ULL << 63);
53 constexpr uint64_t kValueMask = ~(1ULL << 63);
54 constexpr auto kValueScale = static_cast<float>(1ULL << 32);
55 if (in < 0)
56 return (static_cast<uint64_t>(-in * kValueScale) & kValueMask) | kSignMask;
57 return static_cast<uint64_t>(in * kValueScale) & kValueMask;
58}
59
60auto ToColorTransform(const std::array<float, 16> &color_transform_matrix) {
61 /* HAL provides a 4x4 float type matrix:
62 * | 0 1 2 3|
63 * | 4 5 6 7|
64 * | 8 9 10 11|
65 * |12 13 14 15|
66 *
67 * R_out = R*0 + G*4 + B*8 + 12
68 * G_out = R*1 + G*5 + B*9 + 13
69 * B_out = R*2 + G*6 + B*10 + 14
70 *
71 * DRM expects a 3x3 s31.32 fixed point matrix:
72 * out matrix in
73 * |R| |0 1 2| |R|
74 * |G| = |3 4 5| x |G|
75 * |B| |6 7 8| |B|
76 *
77 * R_out = R*0 + G*1 + B*2
78 * G_out = R*3 + G*4 + B*5
79 * B_out = R*6 + G*7 + B*8
80 */
81 auto color_matrix = std::make_shared<drm_color_ctm>();
82 for (int i = 0; i < kCtmCols; i++) {
83 for (int j = 0; j < kCtmRows; j++) {
84 constexpr int kInCtmRows = 4;
Roman Stratiienko88bd6a22025-01-24 23:55:44 +020085 color_matrix->matrix[(i * kCtmRows) + j] = To3132FixPt(
86 color_transform_matrix[(j * kInCtmRows) + i]);
Drew Davenport76c17a82025-01-15 15:02:45 -070087 }
88 }
89 return color_matrix;
90}
91
Drew Davenport97b5abc2024-11-07 10:43:54 -070092} // namespace
93
Roman Stratiienko3627beb2022-01-04 16:02:55 +020094std::string HwcDisplay::DumpDelta(HwcDisplay::Stats delta) {
95 if (delta.total_pixops_ == 0)
96 return "No stats yet";
Roman Stratiienko88bd6a22025-01-24 23:55:44 +020097 auto ratio = 1.0 - (double(delta.gpu_pixops_) / double(delta.total_pixops_));
Roman Stratiienko3627beb2022-01-04 16:02:55 +020098
99 std::stringstream ss;
100 ss << " Total frames count: " << delta.total_frames_ << "\n"
101 << " Failed to test commit frames: " << delta.failed_kms_validate_ << "\n"
102 << " Failed to commit frames: " << delta.failed_kms_present_ << "\n"
103 << ((delta.failed_kms_present_ > 0)
104 ? " !!! Internal failure, FIX it please\n"
105 : "")
106 << " Flattened frames: " << delta.frames_flattened_ << "\n"
107 << " Pixel operations (free units)"
108 << " : [TOTAL: " << delta.total_pixops_ << " / GPU: " << delta.gpu_pixops_
109 << "]\n"
110 << " Composition efficiency: " << ratio;
111
112 return ss.str();
113}
114
115std::string HwcDisplay::Dump() {
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300116 auto connector_name = IsInHeadlessMode()
117 ? std::string("NULL-DISPLAY")
118 : GetPipe().connector->Get()->GetName();
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200119
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200120 std::stringstream ss;
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200121 ss << "- Display on: " << connector_name << "\n"
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200122 << "Statistics since system boot:\n"
123 << DumpDelta(total_stats_) << "\n\n"
124 << "Statistics since last dumpsys request:\n"
125 << DumpDelta(total_stats_.minus(prev_stats_)) << "\n\n";
126
127 memcpy(&prev_stats_, &total_stats_, sizeof(Stats));
128 return ss.str();
129}
130
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200131HwcDisplay::HwcDisplay(hwc2_display_t handle, HWC2::DisplayType type,
Drew Davenport93443182023-12-14 09:25:45 +0000132 DrmHwc *hwc)
133 : hwc_(hwc), handle_(handle), type_(type), client_layer_(this) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300134 if (type_ == HWC2::DisplayType::Virtual) {
135 writeback_layer_ = std::make_unique<HwcLayer>(this);
136 }
137}
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200138
Drew Davenport76c17a82025-01-15 15:02:45 -0700139void HwcDisplay::SetColorTransformMatrix(
140 const std::array<float, 16> &color_transform_matrix) {
141 auto almost_equal = [](auto a, auto b) {
142 const float epsilon = 0.001F;
143 return std::abs(a - b) < epsilon;
144 };
145 const bool is_identity = std::equal(color_transform_matrix.begin(),
146 color_transform_matrix.end(),
147 kIdentityMatrix.begin(), almost_equal);
148 color_transform_hint_ = is_identity ? HAL_COLOR_TRANSFORM_IDENTITY
149 : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
150 if (color_transform_hint_ == is_identity) {
151 SetColorMatrixToIdentity();
152 } else {
153 color_matrix_ = ToColorTransform(color_transform_matrix);
154 }
155}
156
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400157void HwcDisplay::SetColorMatrixToIdentity() {
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200158 color_matrix_ = std::make_shared<drm_color_ctm>();
159 for (int i = 0; i < kCtmCols; i++) {
160 for (int j = 0; j < kCtmRows; j++) {
Yongqin Liu152bc622023-01-29 00:48:10 +0800161 constexpr uint64_t kOne = (1ULL << 32); /* 1.0 in s31.32 format */
Roman Stratiienko88bd6a22025-01-24 23:55:44 +0200162 color_matrix_->matrix[(i * kCtmRows) + j] = (i == j) ? kOne : 0;
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200163 }
164 }
165
166 color_transform_hint_ = HAL_COLOR_TRANSFORM_IDENTITY;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200167}
168
Normunds Rieksts545096d2024-03-11 16:37:45 +0000169HwcDisplay::~HwcDisplay() {
170 Deinit();
171};
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200172
Drew Davenportfe70c802024-11-07 13:02:21 -0700173auto HwcDisplay::GetConfig(hwc2_config_t config_id) const
174 -> const HwcDisplayConfig * {
175 auto config_iter = configs_.hwc_configs.find(config_id);
Drew Davenport9799ab82024-10-23 10:15:45 -0600176 if (config_iter == configs_.hwc_configs.end()) {
177 return nullptr;
178 }
179 return &config_iter->second;
180}
181
Drew Davenportfe70c802024-11-07 13:02:21 -0700182auto HwcDisplay::GetCurrentConfig() const -> const HwcDisplayConfig * {
183 return GetConfig(configs_.active_config_id);
184}
185
Drew Davenport8998f8b2024-10-24 10:15:12 -0600186auto HwcDisplay::GetLastRequestedConfig() const -> const HwcDisplayConfig * {
Drew Davenportfe70c802024-11-07 13:02:21 -0700187 return GetConfig(staged_mode_config_id_.value_or(configs_.active_config_id));
Drew Davenport85be25d2024-10-23 10:26:34 -0600188}
189
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500190HWC2::Error HwcDisplay::SetOutputType(uint32_t hdr_output_type) {
191 switch (hdr_output_type) {
192 case 3: { // HDR10
193 auto ret = SetHdrOutputMetadata(ui::Hdr::HDR10);
194 if (ret != HWC2::Error::None)
195 return ret;
196 min_bpc_ = 8;
197 colorspace_ = Colorspace::kBt2020Rgb;
198 break;
199 }
200 case 1: { // SYSTEM
201 std::vector<ui::Hdr> hdr_types;
202 GetEdid()->GetSupportedHdrTypes(hdr_types);
203 if (!hdr_types.empty()) {
204 auto ret = SetHdrOutputMetadata(hdr_types.front());
205 if (ret != HWC2::Error::None)
206 return ret;
207 min_bpc_ = 8;
208 colorspace_ = Colorspace::kBt2020Rgb;
209 break;
210 } else {
211 [[fallthrough]];
212 }
213 }
214 case 0: // INVALID
215 [[fallthrough]];
216 case 2: // SDR
217 [[fallthrough]];
218 default:
219 hdr_metadata_.reset();
220 min_bpc_ = 6;
221 colorspace_ = Colorspace::kDefault;
222 }
223
224 return HWC2::Error::None;
225}
226
Drew Davenport97b5abc2024-11-07 10:43:54 -0700227HwcDisplay::ConfigError HwcDisplay::SetConfig(hwc2_config_t config) {
228 const HwcDisplayConfig *new_config = GetConfig(config);
229 if (new_config == nullptr) {
230 ALOGE("Could not find active mode for %u", config);
231 return ConfigError::kBadConfig;
232 }
233
234 const HwcDisplayConfig *current_config = GetCurrentConfig();
235
236 const uint32_t width = new_config->mode.GetRawMode().hdisplay;
Drew Davenport8cfa7ff2024-12-06 13:42:04 -0700237 const uint32_t height = new_config->mode.GetRawMode().vdisplay;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700238
239 std::optional<LayerData> modeset_layer_data;
240 // If a client layer has already been provided, and its size matches the
241 // new config, use it for the modeset.
242 if (client_layer_.IsLayerUsableAsDevice() && current_config &&
243 current_config->mode.GetRawMode().hdisplay == width &&
244 current_config->mode.GetRawMode().vdisplay == height) {
245 ALOGV("Use existing client_layer for blocking config.");
246 modeset_layer_data = client_layer_.GetLayerData();
247 } else {
248 ALOGV("Allocate modeset buffer.");
Roman Stratiienko2290dc62025-02-09 12:53:35 +0200249 auto modeset_buffer = //
250 GetPipe().device->CreateBufferForModeset(width, height);
251 if (modeset_buffer) {
Drew Davenport97b5abc2024-11-07 10:43:54 -0700252 auto modeset_layer = std::make_unique<HwcLayer>(this);
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +0200253 HwcLayer::LayerProperties properties;
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200254 properties.slot_buffer = {
255 .slot_id = 0,
Roman Stratiienko2290dc62025-02-09 12:53:35 +0200256 .bi = modeset_buffer,
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200257 };
258 properties.active_slot = {
259 .slot_id = 0,
260 .fence = {},
261 };
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +0200262 properties.blend_mode = BufferBlendMode::kNone;
263 modeset_layer->SetLayerProperties(properties);
Drew Davenport97b5abc2024-11-07 10:43:54 -0700264 modeset_layer->PopulateLayerData();
265 modeset_layer_data = modeset_layer->GetLayerData();
Drew Davenport97b5abc2024-11-07 10:43:54 -0700266 }
267 }
268
269 ALOGV("Create modeset commit.");
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500270 SetOutputType(new_config->output_type);
271
Drew Davenport97b5abc2024-11-07 10:43:54 -0700272 // Create atomic commit args for a blocking modeset. There's no need to do a
273 // separate test commit, since the commit does a test anyways.
274 AtomicCommitArgs commit_args = CreateModesetCommit(new_config,
275 modeset_layer_data);
276 commit_args.blocking = true;
277 int ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(commit_args);
278
279 if (ret) {
280 ALOGE("Blocking config failed: %d", ret);
Manasi Navare23bcfb72025-01-29 22:57:19 +0000281 return HwcDisplay::ConfigError::kConfigFailed;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700282 }
283
284 ALOGV("Blocking config succeeded.");
285 configs_.active_config_id = config;
Drew Davenport53da3712024-12-04 13:31:07 -0700286 staged_mode_config_id_.reset();
Drew Davenport59833182024-12-13 10:02:15 -0700287 vsync_worker_->SetVsyncPeriodNs(new_config->mode.GetVSyncPeriodNs());
288 // set new vsync period
Drew Davenport97b5abc2024-11-07 10:43:54 -0700289 return ConfigError::kNone;
290}
291
Drew Davenport8998f8b2024-10-24 10:15:12 -0600292auto HwcDisplay::QueueConfig(hwc2_config_t config, int64_t desired_time,
293 bool seamless, QueuedConfigTiming *out_timing)
294 -> ConfigError {
295 if (configs_.hwc_configs.count(config) == 0) {
296 ALOGE("Could not find active mode for %u", config);
297 return ConfigError::kBadConfig;
298 }
299
300 // TODO: Add support for seamless configuration changes.
301 if (seamless) {
302 return ConfigError::kSeamlessNotAllowed;
303 }
304
305 // Request a refresh from the client one vsync period before the desired
306 // time, or simply at the desired time if there is no active configuration.
307 const HwcDisplayConfig *current_config = GetCurrentConfig();
308 out_timing->refresh_time_ns = desired_time -
309 (current_config
310 ? current_config->mode.GetVSyncPeriodNs()
311 : 0);
312 out_timing->new_vsync_time_ns = desired_time;
313
314 // Queue the config change timing to be consistent with the requested
315 // refresh time.
Drew Davenport8998f8b2024-10-24 10:15:12 -0600316 staged_mode_change_time_ = out_timing->refresh_time_ns;
317 staged_mode_config_id_ = config;
318
319 // Enable vsync events until the mode has been applied.
Drew Davenport33121b72024-12-13 14:59:35 -0700320 vsync_worker_->SetVsyncTimestampTracking(true);
Drew Davenport8998f8b2024-10-24 10:15:12 -0600321
322 return ConfigError::kNone;
323}
324
Drew Davenport7f356c82025-01-17 16:32:06 -0700325auto HwcDisplay::ValidateStagedComposition() -> std::vector<ChangedLayer> {
326 if (IsInHeadlessMode()) {
327 return {};
328 }
329
330 /* In current drm_hwc design in case previous frame layer was not validated as
331 * a CLIENT, it is used by display controller (Front buffer). We have to store
332 * this state to provide the CLIENT with the release fences for such buffers.
333 */
334 for (auto &l : layers_) {
335 l.second.SetPriorBufferScanOutFlag(l.second.GetValidatedType() !=
336 HWC2::Composition::Client);
337 }
338
339 // ValidateDisplay returns the number of layers that may be changed.
340 uint32_t num_types = 0;
341 uint32_t num_requests = 0;
342 backend_->ValidateDisplay(this, &num_types, &num_requests);
343
344 if (num_types == 0) {
345 return {};
346 }
347
348 // Iterate through the layers to find which layers actually changed.
349 std::vector<ChangedLayer> changed_layers;
350 for (auto &l : layers_) {
351 if (l.second.IsTypeChanged()) {
352 changed_layers.emplace_back(l.first, l.second.GetValidatedType());
353 }
354 }
355 return changed_layers;
356}
357
Drew Davenportb864ccf2025-01-22 14:57:36 -0700358auto HwcDisplay::AcceptValidatedComposition() -> void {
359 for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
360 l.second.AcceptTypeChange();
361 }
362}
363
364auto HwcDisplay::PresentStagedComposition(
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200365 SharedFd &out_present_fence, std::vector<ReleaseFence> &out_release_fences)
366 -> bool {
Roman Stratiienko72ff8c32025-02-09 00:48:44 +0200367 if (IsInHeadlessMode()) {
368 return true;
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200369 }
Roman Stratiienko72ff8c32025-02-09 00:48:44 +0200370 HWC2::Error ret{};
371
372 ++total_stats_.total_frames_;
373
374 AtomicCommitArgs a_args{};
375 ret = CreateComposition(a_args);
376
377 if (ret != HWC2::Error::None)
378 ++total_stats_.failed_kms_present_;
379
380 if (ret == HWC2::Error::BadLayer) {
381 // Can we really have no client or device layers?
382 return true;
383 }
384 if (ret != HWC2::Error::None)
385 return false;
386
387 out_present_fence = a_args.out_fence;
388
389 // Reset the color matrix so we don't apply it over and over again.
390 color_matrix_ = {};
391
392 ++frame_no_;
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200393
394 if (!out_present_fence) {
395 return true;
Drew Davenportb864ccf2025-01-22 14:57:36 -0700396 }
397
398 for (auto &l : layers_) {
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200399 if (l.second.GetPriorBufferScanOutFlag()) {
400 out_release_fences.emplace_back(l.first, out_present_fence);
Drew Davenportb864ccf2025-01-22 14:57:36 -0700401 }
Drew Davenportb864ccf2025-01-22 14:57:36 -0700402 }
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200403
404 return true;
Drew Davenportb864ccf2025-01-22 14:57:36 -0700405}
406
Roman Stratiienko63762a92023-09-18 22:33:45 +0300407void HwcDisplay::SetPipeline(std::shared_ptr<DrmDisplayPipeline> pipeline) {
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200408 Deinit();
409
Roman Stratiienko63762a92023-09-18 22:33:45 +0300410 pipeline_ = std::move(pipeline);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200411
Roman Stratiienko63762a92023-09-18 22:33:45 +0300412 if (pipeline_ != nullptr || handle_ == kPrimaryDisplay) {
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200413 Init();
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000414 hwc_->ScheduleHotplugEvent(handle_, DrmHwc::kConnected);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200415 } else {
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000416 hwc_->ScheduleHotplugEvent(handle_, DrmHwc::kDisconnected);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200417 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200418}
419
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200420void HwcDisplay::Deinit() {
421 if (pipeline_ != nullptr) {
422 AtomicCommitArgs a_args{};
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200423 a_args.composition = std::make_shared<DrmKmsPlan>();
424 GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienkoaf862a52022-06-22 12:14:22 +0300425 a_args.composition = {};
426 a_args.active = false;
427 GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200428
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200429 current_plan_.reset();
430 backend_.reset();
Roman Stratiienko22fe9612023-01-17 21:22:29 +0200431 if (flatcon_) {
432 flatcon_->StopThread();
433 flatcon_.reset();
434 }
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200435 }
436
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200437 if (vsync_worker_) {
438 vsync_worker_->StopThread();
439 vsync_worker_ = {};
440 }
441
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200442 client_layer_.ClearSlots();
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200443}
444
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200445HWC2::Error HwcDisplay::Init() {
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200446 ChosePreferredConfig();
447
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300448 if (type_ != HWC2::DisplayType::Virtual) {
Drew Davenport15016c42024-12-13 15:13:28 -0700449 vsync_worker_ = VSyncWorker::CreateInstance(pipeline_);
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300450 if (!vsync_worker_) {
451 ALOGE("Failed to create event worker for d=%d\n", int(handle_));
452 return HWC2::Error::BadDisplay;
453 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200454 }
455
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200456 if (!IsInHeadlessMode()) {
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200457 auto ret = BackendManager::GetInstance().SetBackendForDisplay(this);
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200458 if (ret) {
459 ALOGE("Failed to set backend for d=%d %d\n", int(handle_), ret);
460 return HWC2::Error::BadDisplay;
461 }
Drew Davenport93443182023-12-14 09:25:45 +0000462 auto flatcbk = (struct FlatConCallbacks){
463 .trigger = [this]() { hwc_->SendRefreshEventToClient(handle_); }};
Roman Stratiienko22fe9612023-01-17 21:22:29 +0200464 flatcon_ = FlatteningController::CreateInstance(flatcbk);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200465 }
466
Roman Stratiienko44b95772025-01-22 18:03:36 +0200467 HwcLayer::LayerProperties lp;
468 lp.blend_mode = BufferBlendMode::kPreMult;
469 client_layer_.SetLayerProperties(lp);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200470
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400471 SetColorMatrixToIdentity();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200472
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200473 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200474}
475
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600476std::optional<PanelOrientation> HwcDisplay::getDisplayPhysicalOrientation() {
477 if (IsInHeadlessMode()) {
478 // The pipeline can be nullptr in headless mode, so return the default
479 // "normal" mode.
480 return PanelOrientation::kModePanelOrientationNormal;
481 }
482
483 DrmDisplayPipeline &pipeline = GetPipe();
484 if (pipeline.connector == nullptr || pipeline.connector->Get() == nullptr) {
485 ALOGW(
486 "No display pipeline present to query the panel orientation property.");
487 return {};
488 }
489
490 return pipeline.connector->Get()->GetPanelOrientation();
491}
492
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200493HWC2::Error HwcDisplay::ChosePreferredConfig() {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200494 HWC2::Error err{};
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300495 if (type_ == HWC2::DisplayType::Virtual) {
496 configs_.GenFakeMode(virtual_disp_width_, virtual_disp_height_);
497 } else if (!IsInHeadlessMode()) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200498 err = configs_.Update(*pipeline_->connector->Get());
499 } else {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300500 configs_.GenFakeMode(0, 0);
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200501 }
502 if (!IsInHeadlessMode() && err != HWC2::Error::None) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200503 return HWC2::Error::BadDisplay;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200504 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200505
Roman Stratiienko0137f862022-01-04 18:27:40 +0200506 return SetActiveConfig(configs_.preferred_config_id);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200507}
508
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200509HWC2::Error HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200510 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer(this));
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200511 *layer = static_cast<hwc2_layer_t>(layer_idx_);
512 ++layer_idx_;
513 return HWC2::Error::None;
514}
515
516HWC2::Error HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200517 if (!get_layer(layer)) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200518 return HWC2::Error::BadLayer;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200519 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200520
521 layers_.erase(layer);
522 return HWC2::Error::None;
523}
524
525HWC2::Error HwcDisplay::GetActiveConfig(hwc2_config_t *config) const {
Drew Davenportfe70c802024-11-07 13:02:21 -0700526 // If a config has been queued, it is considered the "active" config.
527 const HwcDisplayConfig *hwc_config = GetLastRequestedConfig();
528 if (hwc_config == nullptr)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200529 return HWC2::Error::BadConfig;
530
Drew Davenportfe70c802024-11-07 13:02:21 -0700531 *config = hwc_config->id;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200532 return HWC2::Error::None;
533}
534
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200535HWC2::Error HwcDisplay::GetColorModes(uint32_t *num_modes, int32_t *modes) {
Roman Stratiienkod7e108e2025-02-11 04:44:00 +0200536 if (IsInHeadlessMode()) {
537 *num_modes = 1;
538 if (modes)
539 modes[0] = HAL_COLOR_MODE_NATIVE;
540 return HWC2::Error::None;
541 }
542
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500543 if (!modes) {
544 std::vector<Colormode> temp_modes;
545 GetEdid()->GetColorModes(temp_modes);
546 *num_modes = temp_modes.size();
547 return HWC2::Error::None;
548 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200549
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500550 std::vector<Colormode> temp_modes;
551 std::vector<int32_t> out_modes(modes, modes + *num_modes);
552 GetEdid()->GetColorModes(temp_modes);
553 if (temp_modes.empty()) {
554 out_modes.emplace_back(HAL_COLOR_MODE_NATIVE);
555 return HWC2::Error::None;
556 }
557
558 for (auto &c : temp_modes)
559 out_modes.emplace_back(static_cast<int32_t>(c));
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200560
561 return HWC2::Error::None;
562}
563
564HWC2::Error HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
565 int32_t attribute_in,
566 int32_t *value) {
567 int conf = static_cast<int>(config);
568
Roman Stratiienko0137f862022-01-04 18:27:40 +0200569 if (configs_.hwc_configs.count(conf) == 0) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200570 ALOGE("Could not find mode #%d", conf);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200571 return HWC2::Error::BadConfig;
572 }
573
Roman Stratiienko0137f862022-01-04 18:27:40 +0200574 auto &hwc_config = configs_.hwc_configs[conf];
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200575
576 static const int32_t kUmPerInch = 25400;
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300577 auto mm_width = configs_.mm_width;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200578 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
579 switch (attribute) {
580 case HWC2::Attribute::Width:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200581 *value = static_cast<int>(hwc_config.mode.GetRawMode().hdisplay);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200582 break;
583 case HWC2::Attribute::Height:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200584 *value = static_cast<int>(hwc_config.mode.GetRawMode().vdisplay);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200585 break;
586 case HWC2::Attribute::VsyncPeriod:
587 // in nanoseconds
Drew Davenport8053f2e2024-10-02 13:44:41 -0600588 *value = hwc_config.mode.GetVSyncPeriodNs();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200589 break;
Lucas Berthoudf686aa2024-08-28 16:15:38 +0000590 case HWC2::Attribute::DpiY:
591 // ideally this should be vdisplay/mm_heigth, however mm_height
592 // comes from edid parsing and is highly unreliable. Viewing the
593 // rarity of anisotropic displays, falling back to a single value
594 // for dpi yield more correct output.
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200595 case HWC2::Attribute::DpiX:
596 // Dots per 1000 inches
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200597 *value = mm_width ? int(hwc_config.mode.GetRawMode().hdisplay *
598 kUmPerInch / mm_width)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200599 : -1;
600 break;
Roman Stratiienko6b405052022-12-10 19:09:10 +0200601#if __ANDROID_API__ > 29
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200602 case HWC2::Attribute::ConfigGroup:
603 /* Dispite ConfigGroup is a part of HWC2.4 API, framework
604 * able to request it even if service @2.1 is used */
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200605 *value = int(hwc_config.group_id);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200606 break;
607#endif
608 default:
609 *value = -1;
610 return HWC2::Error::BadConfig;
611 }
612 return HWC2::Error::None;
613}
614
Drew Davenportf7e88332024-09-06 12:54:38 -0600615HWC2::Error HwcDisplay::LegacyGetDisplayConfigs(uint32_t *num_configs,
616 hwc2_config_t *configs) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200617 uint32_t idx = 0;
Roman Stratiienko0137f862022-01-04 18:27:40 +0200618 for (auto &hwc_config : configs_.hwc_configs) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200619 if (hwc_config.second.disabled) {
620 continue;
621 }
622
623 if (configs != nullptr) {
624 if (idx >= *num_configs) {
625 break;
626 }
627 configs[idx] = hwc_config.second.id;
628 }
629
630 idx++;
631 }
632 *num_configs = idx;
633 return HWC2::Error::None;
634}
635
636HWC2::Error HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
637 std::ostringstream stream;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200638 if (IsInHeadlessMode()) {
639 stream << "null-display";
640 } else {
641 stream << "display-" << GetPipe().connector->Get()->GetId();
642 }
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300643 auto string = stream.str();
644 auto length = string.length();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200645 if (!name) {
646 *size = length;
647 return HWC2::Error::None;
648 }
649
650 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
651 strncpy(name, string.c_str(), *size);
652 return HWC2::Error::None;
653}
654
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200655HWC2::Error HwcDisplay::GetDisplayType(int32_t *type) {
656 *type = static_cast<int32_t>(type_);
657 return HWC2::Error::None;
658}
659
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500660HWC2::Error HwcDisplay::GetHdrCapabilities(uint32_t *num_types, int32_t *types,
661 float *max_luminance,
662 float *max_average_luminance,
663 float *min_luminance) {
Roman Stratiienkod7e108e2025-02-11 04:44:00 +0200664 if (IsInHeadlessMode()) {
665 *num_types = 0;
666 return HWC2::Error::None;
667 }
668
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500669 if (!types) {
670 std::vector<ui::Hdr> temp_types;
671 float lums[3] = {0.F};
672 GetEdid()->GetHdrCapabilities(temp_types, &lums[0], &lums[1], &lums[2]);
673 *num_types = temp_types.size();
674 return HWC2::Error::None;
675 }
676
677 std::vector<ui::Hdr> temp_types;
678 std::vector<int32_t> out_types(types, types + *num_types);
679 GetEdid()->GetHdrCapabilities(temp_types, max_luminance,
680 max_average_luminance, min_luminance);
681 for (auto &t : temp_types) {
682 switch (t) {
683 case ui::Hdr::HDR10:
684 out_types.emplace_back(HAL_HDR_HDR10);
685 break;
686 case ui::Hdr::HLG:
687 out_types.emplace_back(HAL_HDR_HLG);
688 break;
689 default:
690 // Ignore any other HDR types
691 break;
692 }
693 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200694 return HWC2::Error::None;
695}
696
Drew Davenport97b5abc2024-11-07 10:43:54 -0700697AtomicCommitArgs HwcDisplay::CreateModesetCommit(
698 const HwcDisplayConfig *config,
699 const std::optional<LayerData> &modeset_layer) {
700 AtomicCommitArgs args{};
701
702 args.color_matrix = color_matrix_;
703 args.content_type = content_type_;
704 args.colorspace = colorspace_;
Sasha McIntoshf9062b62024-11-12 10:55:06 -0500705 args.hdr_metadata = hdr_metadata_;
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500706 args.min_bpc = min_bpc_;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700707
708 std::vector<LayerData> composition_layers;
709 if (modeset_layer) {
710 composition_layers.emplace_back(modeset_layer.value());
711 }
712
713 if (composition_layers.empty()) {
714 ALOGW("Attempting to create a modeset commit without a layer.");
715 }
716
717 args.display_mode = config->mode;
718 args.active = true;
719 args.composition = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
720 std::move(
721 composition_layers));
722 ALOGW_IF(!args.composition, "No composition for blocking modeset");
723
724 return args;
725}
726
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200727// NOLINTNEXTLINE(readability-function-cognitive-complexity)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200728HWC2::Error HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200729 if (IsInHeadlessMode()) {
730 ALOGE("%s: Display is in headless mode, should never reach here", __func__);
731 return HWC2::Error::None;
732 }
733
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200734 a_args.color_matrix = color_matrix_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400735 a_args.content_type = content_type_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400736 a_args.colorspace = colorspace_;
Sasha McIntoshf9062b62024-11-12 10:55:06 -0500737 a_args.hdr_metadata = hdr_metadata_;
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500738 a_args.min_bpc = min_bpc_;
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200739
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200740 uint32_t prev_vperiod_ns = 0;
741 GetDisplayVsyncPeriod(&prev_vperiod_ns);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200742
Drew Davenportd387c842024-12-16 16:57:24 -0700743 std::optional<uint32_t> new_vsync_period_ns;
Drew Davenportfe70c802024-11-07 13:02:21 -0700744 if (staged_mode_config_id_ &&
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200745 staged_mode_change_time_ <= ResourceManager::GetTimeMonotonicNs()) {
Drew Davenportfe70c802024-11-07 13:02:21 -0700746 const HwcDisplayConfig *staged_config = GetConfig(
747 staged_mode_config_id_.value());
748 if (staged_config == nullptr) {
749 return HWC2::Error::BadConfig;
750 }
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200751
Drew Davenportfe70c802024-11-07 13:02:21 -0700752 configs_.active_config_id = staged_mode_config_id_.value();
Drew Davenportfe70c802024-11-07 13:02:21 -0700753 a_args.display_mode = staged_config->mode;
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200754 if (!a_args.test_only) {
Drew Davenportd387c842024-12-16 16:57:24 -0700755 new_vsync_period_ns = staged_config->mode.GetVSyncPeriodNs();
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200756 }
757 }
758
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200759 // order the layers by z-order
760 bool use_client_layer = false;
761 uint32_t client_z_order = UINT32_MAX;
762 std::map<uint32_t, HwcLayer *> z_map;
763 for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
764 switch (l.second.GetValidatedType()) {
765 case HWC2::Composition::Device:
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300766 z_map.emplace(l.second.GetZOrder(), &l.second);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200767 break;
768 case HWC2::Composition::Client:
769 // Place it at the z_order of the lowest client layer
770 use_client_layer = true;
771 client_z_order = std::min(client_z_order, l.second.GetZOrder());
772 break;
773 default:
774 continue;
775 }
776 }
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200777 if (use_client_layer) {
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300778 z_map.emplace(client_z_order, &client_layer_);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200779
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200780 client_layer_.PopulateLayerData();
781 if (!client_layer_.IsLayerUsableAsDevice()) {
782 ALOGE_IF(!a_args.test_only,
783 "Client layer must be always usable by DRM/KMS");
784 /* This may be normally triggered on validation of the first frame
785 * containing CLIENT layer. At this moment client buffer is not yet
786 * provided by the CLIENT.
787 * This may be triggered once in HwcLayer lifecycle in case FB can't be
788 * imported. For example when non-contiguous buffer is imported into
789 * contiguous-only DRM/KMS driver.
790 */
791 return HWC2::Error::BadLayer;
792 }
793 }
794
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200795 if (z_map.empty())
796 return HWC2::Error::BadLayer;
797
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200798 std::vector<LayerData> composition_layers;
799
800 /* Import & populate */
801 for (std::pair<const uint32_t, HwcLayer *> &l : z_map) {
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200802 l.second->PopulateLayerData();
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200803 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200804
805 // now that they're ordered by z, add them to the composition
806 for (std::pair<const uint32_t, HwcLayer *> &l : z_map) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200807 if (!l.second->IsLayerUsableAsDevice()) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200808 return HWC2::Error::BadLayer;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200809 }
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200810 composition_layers.emplace_back(l.second->GetLayerData());
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200811 }
812
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200813 /* Store plan to ensure shared planes won't be stolen by other display
814 * in between of ValidateDisplay() and PresentDisplay() calls
815 */
816 current_plan_ = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
817 std::move(composition_layers));
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300818
819 if (type_ == HWC2::DisplayType::Virtual) {
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200820 writeback_layer_->PopulateLayerData();
821 if (!writeback_layer_->IsLayerUsableAsDevice()) {
822 ALOGE("Output layer must be always usable by DRM/KMS");
823 return HWC2::Error::BadLayer;
824 }
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300825 a_args.writeback_fb = writeback_layer_->GetLayerData().fb;
826 a_args.writeback_release_fence = writeback_layer_->GetLayerData()
827 .acquire_fence;
828 }
829
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200830 if (!current_plan_) {
Drew Davenport897a7092024-11-12 12:14:01 -0700831 ALOGE_IF(!a_args.test_only, "Failed to create DrmKmsPlan");
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200832 return HWC2::Error::BadConfig;
833 }
834
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200835 a_args.composition = current_plan_;
836
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300837 auto ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200838
839 if (ret) {
Drew Davenport897a7092024-11-12 12:14:01 -0700840 ALOGE_IF(!a_args.test_only, "Failed to apply the frame composition ret=%d", ret);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200841 return HWC2::Error::BadParameter;
842 }
843
Drew Davenportd387c842024-12-16 16:57:24 -0700844 if (new_vsync_period_ns) {
845 vsync_worker_->SetVsyncPeriodNs(new_vsync_period_ns.value());
Drew Davenportfe70c802024-11-07 13:02:21 -0700846 staged_mode_config_id_.reset();
Drew Davenport33121b72024-12-13 14:59:35 -0700847
848 vsync_worker_->SetVsyncTimestampTracking(false);
849 uint32_t last_vsync_ts = vsync_worker_->GetLastVsyncTimestamp();
850 if (last_vsync_ts != 0) {
Drew Davenport93443182023-12-14 09:25:45 +0000851 hwc_->SendVsyncPeriodTimingChangedEventToClient(handle_,
Drew Davenport33121b72024-12-13 14:59:35 -0700852 last_vsync_ts +
Drew Davenport93443182023-12-14 09:25:45 +0000853 prev_vperiod_ns);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200854 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200855 }
856
857 return HWC2::Error::None;
858}
859
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200860HWC2::Error HwcDisplay::SetActiveConfigInternal(uint32_t config,
861 int64_t change_time) {
862 if (configs_.hwc_configs.count(config) == 0) {
863 ALOGE("Could not find active mode for %u", config);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200864 return HWC2::Error::BadConfig;
865 }
866
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200867 staged_mode_change_time_ = change_time;
868 staged_mode_config_id_ = config;
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500869 if (const HwcDisplayConfig *new_config = GetConfig(config))
870 SetOutputType(new_config->output_type);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200871
872 return HWC2::Error::None;
873}
874
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200875HWC2::Error HwcDisplay::SetActiveConfig(hwc2_config_t config) {
876 return SetActiveConfigInternal(config, ResourceManager::GetTimeMonotonicNs());
877}
878
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200879HWC2::Error HwcDisplay::SetColorMode(int32_t mode) {
Sasha McIntosh5294f092024-09-18 18:14:54 -0400880 /* Maps to the Colorspace DRM connector property:
881 * https://elixir.bootlin.com/linux/v6.11/source/include/drm/drm_connector.h#L538
882 */
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500883 if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_DISPLAY_BT2020)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200884 return HWC2::Error::BadParameter;
885
Sasha McIntosh5294f092024-09-18 18:14:54 -0400886 switch (mode) {
887 case HAL_COLOR_MODE_NATIVE:
888 colorspace_ = Colorspace::kDefault;
889 break;
890 case HAL_COLOR_MODE_STANDARD_BT601_625:
891 case HAL_COLOR_MODE_STANDARD_BT601_625_UNADJUSTED:
892 case HAL_COLOR_MODE_STANDARD_BT601_525:
893 case HAL_COLOR_MODE_STANDARD_BT601_525_UNADJUSTED:
894 // The DP spec does not say whether this is the 525 or the 625 line version.
895 colorspace_ = Colorspace::kBt601Ycc;
896 break;
897 case HAL_COLOR_MODE_STANDARD_BT709:
898 case HAL_COLOR_MODE_SRGB:
899 colorspace_ = Colorspace::kBt709Ycc;
900 break;
901 case HAL_COLOR_MODE_DCI_P3:
902 case HAL_COLOR_MODE_DISPLAY_P3:
903 colorspace_ = Colorspace::kDciP3RgbD65;
904 break;
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500905 case HAL_COLOR_MODE_DISPLAY_BT2020:
Sasha McIntosh5294f092024-09-18 18:14:54 -0400906 case HAL_COLOR_MODE_ADOBE_RGB:
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500907 case HAL_COLOR_MODE_BT2020:
908 case HAL_COLOR_MODE_BT2100_PQ:
909 case HAL_COLOR_MODE_BT2100_HLG:
Sasha McIntosh5294f092024-09-18 18:14:54 -0400910 default:
911 return HWC2::Error::Unsupported;
912 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200913
914 color_mode_ = mode;
915 return HWC2::Error::None;
916}
917
918HWC2::Error HwcDisplay::SetColorTransform(const float *matrix, int32_t hint) {
919 if (hint < HAL_COLOR_TRANSFORM_IDENTITY ||
920 hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA)
921 return HWC2::Error::BadParameter;
922
923 if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX)
924 return HWC2::Error::BadParameter;
925
926 color_transform_hint_ = static_cast<android_color_transform_t>(hint);
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200927
Roman Stratiienko5de61b52023-02-01 16:29:45 +0200928 if (IsInHeadlessMode())
929 return HWC2::Error::None;
930
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200931 if (!GetPipe().crtc->Get()->GetCtmProperty())
932 return HWC2::Error::None;
933
934 switch (color_transform_hint_) {
935 case HAL_COLOR_TRANSFORM_IDENTITY:
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400936 SetColorMatrixToIdentity();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200937 break;
938 case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX:
Sasha McIntosh921c1cd2024-10-09 19:50:52 -0400939 // Without HW support, we cannot correctly process matrices with an offset.
Drew Davenport76c17a82025-01-15 15:02:45 -0700940 {
941 for (int i = 12; i < 14; i++) {
942 if (matrix[i] != 0.F)
943 return HWC2::Error::Unsupported;
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200944 }
Drew Davenport76c17a82025-01-15 15:02:45 -0700945 std::array<float, 16> aidl_matrix = kIdentityMatrix;
946 memcpy(aidl_matrix.data(), matrix, aidl_matrix.size() * sizeof(float));
947 color_matrix_ = ToColorTransform(aidl_matrix);
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200948 }
949 break;
950 default:
951 return HWC2::Error::Unsupported;
952 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200953
954 return HWC2::Error::None;
955}
956
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200957bool HwcDisplay::CtmByGpu() {
958 if (color_transform_hint_ == HAL_COLOR_TRANSFORM_IDENTITY)
959 return false;
960
961 if (GetPipe().crtc->Get()->GetCtmProperty())
962 return false;
963
Drew Davenport93443182023-12-14 09:25:45 +0000964 if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore)
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200965 return false;
966
967 return true;
968}
969
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200970HWC2::Error HwcDisplay::SetPowerMode(int32_t mode_in) {
971 auto mode = static_cast<HWC2::PowerMode>(mode_in);
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300972
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200973 AtomicCommitArgs a_args{};
974
975 switch (mode) {
976 case HWC2::PowerMode::Off:
977 a_args.active = false;
978 break;
979 case HWC2::PowerMode::On:
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300980 a_args.active = true;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200981 break;
982 case HWC2::PowerMode::Doze:
983 case HWC2::PowerMode::DozeSuspend:
984 return HWC2::Error::Unsupported;
985 default:
John Stultzffe783c2024-02-14 10:51:27 -0800986 ALOGE("Incorrect power mode value (%d)\n", mode_in);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200987 return HWC2::Error::BadParameter;
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300988 }
989
990 if (IsInHeadlessMode()) {
991 return HWC2::Error::None;
992 }
993
Jia Ren80566fe2022-11-17 17:26:00 +0800994 if (a_args.active && *a_args.active) {
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300995 /*
996 * Setting the display to active before we have a composition
997 * can break some drivers, so skip setting a_args.active to
998 * true, as the next composition frame will implicitly activate
999 * the display
1000 */
1001 return GetPipe().atomic_state_manager->ActivateDisplayUsingDPMS() == 0
1002 ? HWC2::Error::None
1003 : HWC2::Error::BadParameter;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001004 };
1005
Roman Stratiienkoa7913de2022-10-20 13:18:57 +03001006 auto err = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001007 if (err) {
1008 ALOGE("Failed to apply the dpms composition err=%d", err);
1009 return HWC2::Error::BadParameter;
1010 }
1011 return HWC2::Error::None;
1012}
1013
1014HWC2::Error HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001015 if (type_ == HWC2::DisplayType::Virtual) {
1016 return HWC2::Error::None;
1017 }
Lucas Berthoua2928992025-01-07 22:48:28 +00001018 if (!vsync_worker_) {
1019 return HWC2::Error::NoResources;
1020 }
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001021
Roman Stratiienko099c3112022-01-20 11:50:54 +02001022 vsync_event_en_ = HWC2_VSYNC_ENABLE == enabled;
Lucas Berthoua2928992025-01-07 22:48:28 +00001023 std::optional<VSyncWorker::VsyncTimestampCallback> callback = std::nullopt;
Roman Stratiienko099c3112022-01-20 11:50:54 +02001024 if (vsync_event_en_) {
Drew Davenport63a699e2024-12-13 15:00:00 -07001025 DrmHwc *hwc = hwc_;
1026 hwc2_display_t id = handle_;
1027 // Callback will be called from the vsync thread.
Lucas Berthoua2928992025-01-07 22:48:28 +00001028 callback = [hwc, id](int64_t timestamp, uint32_t period_ns) {
Drew Davenport63a699e2024-12-13 15:00:00 -07001029 hwc->SendVsyncEventToClient(id, timestamp, period_ns);
1030 };
Roman Stratiienko099c3112022-01-20 11:50:54 +02001031 }
Lucas Berthoua2928992025-01-07 22:48:28 +00001032 vsync_worker_->SetTimestampCallback(std::move(callback));
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001033 return HWC2::Error::None;
1034}
1035
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001036std::vector<HwcLayer *> HwcDisplay::GetOrderLayersByZPos() {
1037 std::vector<HwcLayer *> ordered_layers;
1038 ordered_layers.reserve(layers_.size());
1039
1040 for (auto &[handle, layer] : layers_) {
1041 ordered_layers.emplace_back(&layer);
1042 }
1043
1044 std::sort(std::begin(ordered_layers), std::end(ordered_layers),
1045 [](const HwcLayer *lhs, const HwcLayer *rhs) {
1046 return lhs->GetZOrder() < rhs->GetZOrder();
1047 });
1048
1049 return ordered_layers;
1050}
1051
Roman Stratiienko099c3112022-01-20 11:50:54 +02001052HWC2::Error HwcDisplay::GetDisplayVsyncPeriod(
1053 uint32_t *outVsyncPeriod /* ns */) {
1054 return GetDisplayAttribute(configs_.active_config_id,
1055 HWC2_ATTRIBUTE_VSYNC_PERIOD,
1056 (int32_t *)(outVsyncPeriod));
1057}
1058
Sasha McIntoshf9062b62024-11-12 10:55:06 -05001059// Display primary values are coded as unsigned 16-bit values in units of
1060// 0.00002, where 0x0000 represents zero and 0xC350 represents 1.0000.
1061static uint64_t ToU16ColorValue(float in) {
1062 constexpr float kPrimariesFixedPoint = 50000.F;
1063 return static_cast<uint64_t>(kPrimariesFixedPoint * in);
1064}
1065
1066HWC2::Error HwcDisplay::SetHdrOutputMetadata(ui::Hdr type) {
1067 hdr_metadata_ = std::make_shared<hdr_output_metadata>();
1068 hdr_metadata_->metadata_type = 0;
1069 auto *m = &hdr_metadata_->hdmi_metadata_type1;
1070 m->metadata_type = 0;
1071
1072 switch (type) {
1073 case ui::Hdr::HDR10:
1074 m->eotf = 2; // PQ
1075 break;
1076 case ui::Hdr::HLG:
1077 m->eotf = 3; // HLG
1078 break;
1079 default:
1080 return HWC2::Error::Unsupported;
1081 }
1082
1083 // Most luminance values are coded as an unsigned 16-bit value in units of 1
1084 // cd/m2, where 0x0001 represents 1 cd/m2 and 0xFFFF represents 65535 cd/m2.
1085 std::vector<ui::Hdr> types;
1086 float hdr_luminance[3]{0.F, 0.F, 0.F};
1087 GetEdid()->GetHdrCapabilities(types, &hdr_luminance[0], &hdr_luminance[1],
1088 &hdr_luminance[2]);
1089 m->max_display_mastering_luminance = m->max_cll = static_cast<uint64_t>(
1090 hdr_luminance[0]);
1091 m->max_fall = static_cast<uint64_t>(hdr_luminance[1]);
1092 // The min luminance value is coded as an unsigned 16-bit value in units of
1093 // 0.0001 cd/m2, where 0x0001 represents 0.0001 cd/m2 and 0xFFFF
1094 // represents 6.5535 cd/m2.
1095 m->min_display_mastering_luminance = static_cast<uint64_t>(hdr_luminance[2] *
1096 10000.F);
1097
1098 auto gamut = ColorGamut::BT2020();
1099 auto primaries = gamut.getPrimaries();
1100 m->display_primaries[0].x = ToU16ColorValue(primaries[0].x);
1101 m->display_primaries[0].y = ToU16ColorValue(primaries[0].y);
1102 m->display_primaries[1].x = ToU16ColorValue(primaries[1].x);
1103 m->display_primaries[1].y = ToU16ColorValue(primaries[1].y);
1104 m->display_primaries[2].x = ToU16ColorValue(primaries[2].x);
1105 m->display_primaries[2].y = ToU16ColorValue(primaries[2].y);
1106
1107 auto whitePoint = gamut.getWhitePoint();
1108 m->white_point.x = ToU16ColorValue(whitePoint.x);
1109 m->white_point.y = ToU16ColorValue(whitePoint.y);
1110
1111 return HWC2::Error::None;
1112}
1113
Roman Stratiienko6b405052022-12-10 19:09:10 +02001114#if __ANDROID_API__ > 29
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001115HWC2::Error HwcDisplay::GetDisplayConnectionType(uint32_t *outType) {
Roman Stratiienko456e2d62022-01-29 01:17:39 +02001116 if (IsInHeadlessMode()) {
1117 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
1118 return HWC2::Error::None;
1119 }
1120 /* Primary display should be always internal,
1121 * otherwise SF will be unhappy and will crash
1122 */
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001123 if (GetPipe().connector->Get()->IsInternal() || handle_ == kPrimaryDisplay)
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001124 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001125 else if (GetPipe().connector->Get()->IsExternal())
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001126 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External);
1127 else
1128 return HWC2::Error::BadConfig;
1129
1130 return HWC2::Error::None;
1131}
1132
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001133HWC2::Error HwcDisplay::SetActiveConfigWithConstraints(
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001134 hwc2_config_t config,
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001135 hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints,
1136 hwc_vsync_period_change_timeline_t *outTimeline) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001137 if (type_ == HWC2::DisplayType::Virtual) {
1138 return HWC2::Error::None;
1139 }
1140
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001141 if (vsyncPeriodChangeConstraints == nullptr || outTimeline == nullptr) {
1142 return HWC2::Error::BadParameter;
1143 }
1144
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001145 uint32_t current_vsync_period{};
1146 GetDisplayVsyncPeriod(&current_vsync_period);
1147
1148 if (vsyncPeriodChangeConstraints->seamlessRequired) {
1149 return HWC2::Error::SeamlessNotAllowed;
1150 }
1151
1152 outTimeline->refreshTimeNanos = vsyncPeriodChangeConstraints
1153 ->desiredTimeNanos -
1154 current_vsync_period;
1155 auto ret = SetActiveConfigInternal(config, outTimeline->refreshTimeNanos);
1156 if (ret != HWC2::Error::None) {
1157 return ret;
1158 }
1159
1160 outTimeline->refreshRequired = true;
1161 outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeConstraints
1162 ->desiredTimeNanos;
1163
Drew Davenport33121b72024-12-13 14:59:35 -07001164 vsync_worker_->SetVsyncTimestampTracking(true);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001165
1166 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001167}
1168
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001169HWC2::Error HwcDisplay::SetContentType(int32_t contentType) {
Sasha McIntosh173247b2024-09-18 18:06:52 -04001170 /* Maps exactly to the content_type DRM connector property:
1171 * https://elixir.bootlin.com/linux/v6.11/source/include/uapi/drm/drm_mode.h#L107
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001172 */
Sasha McIntosh173247b2024-09-18 18:06:52 -04001173 if (contentType < HWC2_CONTENT_TYPE_NONE || contentType > HWC2_CONTENT_TYPE_GAME)
1174 return HWC2::Error::BadParameter;
1175
1176 content_type_ = contentType;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001177
1178 return HWC2::Error::None;
1179}
1180#endif
1181
Roman Stratiienko6b405052022-12-10 19:09:10 +02001182#if __ANDROID_API__ > 28
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001183HWC2::Error HwcDisplay::GetDisplayIdentificationData(uint8_t *outPort,
1184 uint32_t *outDataSize,
1185 uint8_t *outData) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +02001186 if (IsInHeadlessMode()) {
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001187 return HWC2::Error::Unsupported;
Roman Stratiienko3dacd472022-01-11 19:18:34 +02001188 }
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001189
Gil Dekel907a51a2025-02-14 22:44:01 -05001190 auto *connector = GetPipe().connector->Get();
1191 auto blob = connector->GetEdidBlob();
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001192 if (!blob) {
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001193 return HWC2::Error::Unsupported;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001194 }
1195
Gil Dekel907a51a2025-02-14 22:44:01 -05001196 constexpr uint8_t kDrmDeviceBitShift = 5U;
1197 constexpr uint8_t kDrmDeviceBitMask = 0xE0;
1198 constexpr uint8_t kConnectorBitMask = 0x1F;
1199 const auto kDrmIdx = static_cast<uint8_t>(
1200 connector->GetDev().GetIndexInDevArray());
1201 const auto kConnectorIdx = static_cast<uint8_t>(
1202 connector->GetIndexInResArray());
1203 *outPort = (((kDrmIdx << kDrmDeviceBitShift) & kDrmDeviceBitMask) |
1204 (kConnectorIdx & kConnectorBitMask));
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001205
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001206 if (outData) {
1207 *outDataSize = std::min(*outDataSize, blob->length);
1208 memcpy(outData, blob->data, *outDataSize);
1209 } else {
1210 *outDataSize = blob->length;
1211 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001212
1213 return HWC2::Error::None;
1214}
1215
1216HWC2::Error HwcDisplay::GetDisplayCapabilities(uint32_t *outNumCapabilities,
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001217 uint32_t *outCapabilities) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001218 if (outNumCapabilities == nullptr) {
1219 return HWC2::Error::BadParameter;
1220 }
1221
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001222 bool skip_ctm = false;
1223
1224 // Skip client CTM if user requested DRM_OR_IGNORE
Drew Davenport93443182023-12-14 09:25:45 +00001225 if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore)
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001226 skip_ctm = true;
1227
1228 // Skip client CTM if DRM can handle it
1229 if (!skip_ctm && !IsInHeadlessMode() &&
1230 GetPipe().crtc->Get()->GetCtmProperty())
1231 skip_ctm = true;
1232
1233 if (!skip_ctm) {
1234 *outNumCapabilities = 0;
1235 return HWC2::Error::None;
1236 }
1237
1238 *outNumCapabilities = 1;
1239 if (outCapabilities) {
1240 outCapabilities[0] = HWC2_DISPLAY_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM;
1241 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001242
1243 return HWC2::Error::None;
1244}
1245
Roman Stratiienko6b405052022-12-10 19:09:10 +02001246#endif /* __ANDROID_API__ > 28 */
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001247
Roman Stratiienko6b405052022-12-10 19:09:10 +02001248#if __ANDROID_API__ > 27
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001249
1250HWC2::Error HwcDisplay::GetRenderIntents(
1251 int32_t mode, uint32_t *outNumIntents,
1252 int32_t * /*android_render_intent_v1_1_t*/ outIntents) {
1253 if (mode != HAL_COLOR_MODE_NATIVE) {
1254 return HWC2::Error::BadParameter;
1255 }
1256
1257 if (outIntents == nullptr) {
1258 *outNumIntents = 1;
1259 return HWC2::Error::None;
1260 }
1261 *outNumIntents = 1;
1262 outIntents[0] = HAL_RENDER_INTENT_COLORIMETRIC;
1263 return HWC2::Error::None;
1264}
1265
1266HWC2::Error HwcDisplay::SetColorModeWithIntent(int32_t mode, int32_t intent) {
1267 if (intent < HAL_RENDER_INTENT_COLORIMETRIC ||
1268 intent > HAL_RENDER_INTENT_TONE_MAP_ENHANCE)
1269 return HWC2::Error::BadParameter;
1270
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001271 if (intent != HAL_RENDER_INTENT_COLORIMETRIC)
1272 return HWC2::Error::Unsupported;
1273
Sasha McIntosh5294f092024-09-18 18:14:54 -04001274 auto err = SetColorMode(mode);
1275 if (err != HWC2::Error::None) return err;
1276
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001277 return HWC2::Error::None;
1278}
1279
Roman Stratiienko6b405052022-12-10 19:09:10 +02001280#endif /* __ANDROID_API__ > 27 */
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001281
1282const Backend *HwcDisplay::backend() const {
1283 return backend_.get();
1284}
1285
1286void HwcDisplay::set_backend(std::unique_ptr<Backend> backend) {
1287 backend_ = std::move(backend);
1288}
1289
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001290} // namespace android