blob: 9db384b2a43edfdd19d31507ea470f148a456190 [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
Drew Davenport97b5abc2024-11-07 10:43:54 -0700190HwcDisplay::ConfigError HwcDisplay::SetConfig(hwc2_config_t config) {
191 const HwcDisplayConfig *new_config = GetConfig(config);
192 if (new_config == nullptr) {
193 ALOGE("Could not find active mode for %u", config);
194 return ConfigError::kBadConfig;
195 }
196
197 const HwcDisplayConfig *current_config = GetCurrentConfig();
198
199 const uint32_t width = new_config->mode.GetRawMode().hdisplay;
Drew Davenport8cfa7ff2024-12-06 13:42:04 -0700200 const uint32_t height = new_config->mode.GetRawMode().vdisplay;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700201
202 std::optional<LayerData> modeset_layer_data;
203 // If a client layer has already been provided, and its size matches the
204 // new config, use it for the modeset.
205 if (client_layer_.IsLayerUsableAsDevice() && current_config &&
206 current_config->mode.GetRawMode().hdisplay == width &&
207 current_config->mode.GetRawMode().vdisplay == height) {
208 ALOGV("Use existing client_layer for blocking config.");
209 modeset_layer_data = client_layer_.GetLayerData();
210 } else {
211 ALOGV("Allocate modeset buffer.");
Roman Stratiienko2290dc62025-02-09 12:53:35 +0200212 auto modeset_buffer = //
213 GetPipe().device->CreateBufferForModeset(width, height);
214 if (modeset_buffer) {
Drew Davenport97b5abc2024-11-07 10:43:54 -0700215 auto modeset_layer = std::make_unique<HwcLayer>(this);
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +0200216 HwcLayer::LayerProperties properties;
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200217 properties.slot_buffer = {
218 .slot_id = 0,
Roman Stratiienko2290dc62025-02-09 12:53:35 +0200219 .bi = modeset_buffer,
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200220 };
221 properties.active_slot = {
222 .slot_id = 0,
223 .fence = {},
224 };
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +0200225 properties.blend_mode = BufferBlendMode::kNone;
226 modeset_layer->SetLayerProperties(properties);
Drew Davenport97b5abc2024-11-07 10:43:54 -0700227 modeset_layer->PopulateLayerData();
228 modeset_layer_data = modeset_layer->GetLayerData();
Drew Davenport97b5abc2024-11-07 10:43:54 -0700229 }
230 }
231
232 ALOGV("Create modeset commit.");
233 // Create atomic commit args for a blocking modeset. There's no need to do a
234 // separate test commit, since the commit does a test anyways.
235 AtomicCommitArgs commit_args = CreateModesetCommit(new_config,
236 modeset_layer_data);
237 commit_args.blocking = true;
238 int ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(commit_args);
239
240 if (ret) {
241 ALOGE("Blocking config failed: %d", ret);
242 return HwcDisplay::ConfigError::kBadConfig;
243 }
244
245 ALOGV("Blocking config succeeded.");
246 configs_.active_config_id = config;
Drew Davenport53da3712024-12-04 13:31:07 -0700247 staged_mode_config_id_.reset();
Drew Davenport59833182024-12-13 10:02:15 -0700248 vsync_worker_->SetVsyncPeriodNs(new_config->mode.GetVSyncPeriodNs());
249 // set new vsync period
Drew Davenport97b5abc2024-11-07 10:43:54 -0700250 return ConfigError::kNone;
251}
252
Drew Davenport8998f8b2024-10-24 10:15:12 -0600253auto HwcDisplay::QueueConfig(hwc2_config_t config, int64_t desired_time,
254 bool seamless, QueuedConfigTiming *out_timing)
255 -> ConfigError {
256 if (configs_.hwc_configs.count(config) == 0) {
257 ALOGE("Could not find active mode for %u", config);
258 return ConfigError::kBadConfig;
259 }
260
261 // TODO: Add support for seamless configuration changes.
262 if (seamless) {
263 return ConfigError::kSeamlessNotAllowed;
264 }
265
266 // Request a refresh from the client one vsync period before the desired
267 // time, or simply at the desired time if there is no active configuration.
268 const HwcDisplayConfig *current_config = GetCurrentConfig();
269 out_timing->refresh_time_ns = desired_time -
270 (current_config
271 ? current_config->mode.GetVSyncPeriodNs()
272 : 0);
273 out_timing->new_vsync_time_ns = desired_time;
274
275 // Queue the config change timing to be consistent with the requested
276 // refresh time.
Drew Davenport8998f8b2024-10-24 10:15:12 -0600277 staged_mode_change_time_ = out_timing->refresh_time_ns;
278 staged_mode_config_id_ = config;
279
280 // Enable vsync events until the mode has been applied.
Drew Davenport33121b72024-12-13 14:59:35 -0700281 vsync_worker_->SetVsyncTimestampTracking(true);
Drew Davenport8998f8b2024-10-24 10:15:12 -0600282
283 return ConfigError::kNone;
284}
285
Drew Davenport7f356c82025-01-17 16:32:06 -0700286auto HwcDisplay::ValidateStagedComposition() -> std::vector<ChangedLayer> {
287 if (IsInHeadlessMode()) {
288 return {};
289 }
290
291 /* In current drm_hwc design in case previous frame layer was not validated as
292 * a CLIENT, it is used by display controller (Front buffer). We have to store
293 * this state to provide the CLIENT with the release fences for such buffers.
294 */
295 for (auto &l : layers_) {
296 l.second.SetPriorBufferScanOutFlag(l.second.GetValidatedType() !=
297 HWC2::Composition::Client);
298 }
299
300 // ValidateDisplay returns the number of layers that may be changed.
301 uint32_t num_types = 0;
302 uint32_t num_requests = 0;
303 backend_->ValidateDisplay(this, &num_types, &num_requests);
304
305 if (num_types == 0) {
306 return {};
307 }
308
309 // Iterate through the layers to find which layers actually changed.
310 std::vector<ChangedLayer> changed_layers;
311 for (auto &l : layers_) {
312 if (l.second.IsTypeChanged()) {
313 changed_layers.emplace_back(l.first, l.second.GetValidatedType());
314 }
315 }
316 return changed_layers;
317}
318
Lucas Berthou30808a22025-02-05 17:52:33 +0000319auto HwcDisplay::GetDisplayBoundsMm() -> std::pair<int32_t, int32_t> {
320
321 const auto bounds = GetEdid()->GetBoundsMm();
322 if (bounds.first > 0 || bounds.second > 0) {
323 return bounds;
324 }
325
326 ALOGE("Failed to get display bounds for d=%d\n", int(handle_));
327 // mm_width and mm_height are unreliable. so only provide mm_width to avoid
328 // wrong dpi computations or other use of the values.
329 return {configs_.mm_width, -1};
330}
331
Drew Davenportb864ccf2025-01-22 14:57:36 -0700332auto HwcDisplay::AcceptValidatedComposition() -> void {
333 for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
334 l.second.AcceptTypeChange();
335 }
336}
337
338auto HwcDisplay::PresentStagedComposition(
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200339 SharedFd &out_present_fence, std::vector<ReleaseFence> &out_release_fences)
340 -> bool {
Roman Stratiienko72ff8c32025-02-09 00:48:44 +0200341 if (IsInHeadlessMode()) {
342 return true;
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200343 }
Roman Stratiienko72ff8c32025-02-09 00:48:44 +0200344 HWC2::Error ret{};
345
346 ++total_stats_.total_frames_;
347
348 AtomicCommitArgs a_args{};
349 ret = CreateComposition(a_args);
350
351 if (ret != HWC2::Error::None)
352 ++total_stats_.failed_kms_present_;
353
354 if (ret == HWC2::Error::BadLayer) {
355 // Can we really have no client or device layers?
356 return true;
357 }
358 if (ret != HWC2::Error::None)
359 return false;
360
361 out_present_fence = a_args.out_fence;
362
363 // Reset the color matrix so we don't apply it over and over again.
364 color_matrix_ = {};
365
366 ++frame_no_;
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200367
368 if (!out_present_fence) {
369 return true;
Drew Davenportb864ccf2025-01-22 14:57:36 -0700370 }
371
372 for (auto &l : layers_) {
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200373 if (l.second.GetPriorBufferScanOutFlag()) {
374 out_release_fences.emplace_back(l.first, out_present_fence);
Drew Davenportb864ccf2025-01-22 14:57:36 -0700375 }
Drew Davenportb864ccf2025-01-22 14:57:36 -0700376 }
Roman Stratiienko16d3a2d2025-01-27 17:09:22 +0200377
378 return true;
Drew Davenportb864ccf2025-01-22 14:57:36 -0700379}
380
Roman Stratiienko63762a92023-09-18 22:33:45 +0300381void HwcDisplay::SetPipeline(std::shared_ptr<DrmDisplayPipeline> pipeline) {
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200382 Deinit();
383
Roman Stratiienko63762a92023-09-18 22:33:45 +0300384 pipeline_ = std::move(pipeline);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200385
Roman Stratiienko63762a92023-09-18 22:33:45 +0300386 if (pipeline_ != nullptr || handle_ == kPrimaryDisplay) {
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200387 Init();
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000388 hwc_->ScheduleHotplugEvent(handle_, DrmHwc::kConnected);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200389 } else {
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000390 hwc_->ScheduleHotplugEvent(handle_, DrmHwc::kDisconnected);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200391 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200392}
393
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200394void HwcDisplay::Deinit() {
395 if (pipeline_ != nullptr) {
396 AtomicCommitArgs a_args{};
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200397 a_args.composition = std::make_shared<DrmKmsPlan>();
398 GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienkoaf862a52022-06-22 12:14:22 +0300399 a_args.composition = {};
400 a_args.active = false;
401 GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200402
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200403 current_plan_.reset();
404 backend_.reset();
Roman Stratiienko22fe9612023-01-17 21:22:29 +0200405 if (flatcon_) {
406 flatcon_->StopThread();
407 flatcon_.reset();
408 }
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200409 }
410
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200411 if (vsync_worker_) {
412 vsync_worker_->StopThread();
413 vsync_worker_ = {};
414 }
415
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200416 client_layer_.ClearSlots();
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200417}
418
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200419HWC2::Error HwcDisplay::Init() {
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200420 ChosePreferredConfig();
421
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300422 if (type_ != HWC2::DisplayType::Virtual) {
Drew Davenport15016c42024-12-13 15:13:28 -0700423 vsync_worker_ = VSyncWorker::CreateInstance(pipeline_);
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300424 if (!vsync_worker_) {
425 ALOGE("Failed to create event worker for d=%d\n", int(handle_));
426 return HWC2::Error::BadDisplay;
427 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200428 }
429
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200430 if (!IsInHeadlessMode()) {
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200431 auto ret = BackendManager::GetInstance().SetBackendForDisplay(this);
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200432 if (ret) {
433 ALOGE("Failed to set backend for d=%d %d\n", int(handle_), ret);
434 return HWC2::Error::BadDisplay;
435 }
Drew Davenport93443182023-12-14 09:25:45 +0000436 auto flatcbk = (struct FlatConCallbacks){
437 .trigger = [this]() { hwc_->SendRefreshEventToClient(handle_); }};
Roman Stratiienko22fe9612023-01-17 21:22:29 +0200438 flatcon_ = FlatteningController::CreateInstance(flatcbk);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200439 }
440
Roman Stratiienko44b95772025-01-22 18:03:36 +0200441 HwcLayer::LayerProperties lp;
442 lp.blend_mode = BufferBlendMode::kPreMult;
443 client_layer_.SetLayerProperties(lp);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200444
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400445 SetColorMatrixToIdentity();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200446
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200447 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200448}
449
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600450std::optional<PanelOrientation> HwcDisplay::getDisplayPhysicalOrientation() {
451 if (IsInHeadlessMode()) {
452 // The pipeline can be nullptr in headless mode, so return the default
453 // "normal" mode.
454 return PanelOrientation::kModePanelOrientationNormal;
455 }
456
457 DrmDisplayPipeline &pipeline = GetPipe();
458 if (pipeline.connector == nullptr || pipeline.connector->Get() == nullptr) {
459 ALOGW(
460 "No display pipeline present to query the panel orientation property.");
461 return {};
462 }
463
464 return pipeline.connector->Get()->GetPanelOrientation();
465}
466
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200467HWC2::Error HwcDisplay::ChosePreferredConfig() {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200468 HWC2::Error err{};
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300469 if (type_ == HWC2::DisplayType::Virtual) {
470 configs_.GenFakeMode(virtual_disp_width_, virtual_disp_height_);
471 } else if (!IsInHeadlessMode()) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200472 err = configs_.Update(*pipeline_->connector->Get());
473 } else {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300474 configs_.GenFakeMode(0, 0);
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200475 }
476 if (!IsInHeadlessMode() && err != HWC2::Error::None) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200477 return HWC2::Error::BadDisplay;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200478 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200479
Roman Stratiienko0137f862022-01-04 18:27:40 +0200480 return SetActiveConfig(configs_.preferred_config_id);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200481}
482
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200483HWC2::Error HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200484 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer(this));
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200485 *layer = static_cast<hwc2_layer_t>(layer_idx_);
486 ++layer_idx_;
487 return HWC2::Error::None;
488}
489
490HWC2::Error HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200491 if (!get_layer(layer)) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200492 return HWC2::Error::BadLayer;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200493 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200494
495 layers_.erase(layer);
496 return HWC2::Error::None;
497}
498
499HWC2::Error HwcDisplay::GetActiveConfig(hwc2_config_t *config) const {
Drew Davenportfe70c802024-11-07 13:02:21 -0700500 // If a config has been queued, it is considered the "active" config.
501 const HwcDisplayConfig *hwc_config = GetLastRequestedConfig();
502 if (hwc_config == nullptr)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200503 return HWC2::Error::BadConfig;
504
Drew Davenportfe70c802024-11-07 13:02:21 -0700505 *config = hwc_config->id;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200506 return HWC2::Error::None;
507}
508
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200509HWC2::Error HwcDisplay::GetColorModes(uint32_t *num_modes, int32_t *modes) {
Roman Stratiienkod7e108e2025-02-11 04:44:00 +0200510 if (IsInHeadlessMode()) {
511 *num_modes = 1;
512 if (modes)
513 modes[0] = HAL_COLOR_MODE_NATIVE;
514 return HWC2::Error::None;
515 }
516
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500517 if (!modes) {
518 std::vector<Colormode> temp_modes;
519 GetEdid()->GetColorModes(temp_modes);
520 *num_modes = temp_modes.size();
521 return HWC2::Error::None;
522 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200523
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500524 std::vector<Colormode> temp_modes;
525 std::vector<int32_t> out_modes(modes, modes + *num_modes);
526 GetEdid()->GetColorModes(temp_modes);
527 if (temp_modes.empty()) {
528 out_modes.emplace_back(HAL_COLOR_MODE_NATIVE);
529 return HWC2::Error::None;
530 }
531
532 for (auto &c : temp_modes)
533 out_modes.emplace_back(static_cast<int32_t>(c));
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200534
535 return HWC2::Error::None;
536}
537
538HWC2::Error HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
539 int32_t attribute_in,
540 int32_t *value) {
541 int conf = static_cast<int>(config);
542
Roman Stratiienko0137f862022-01-04 18:27:40 +0200543 if (configs_.hwc_configs.count(conf) == 0) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200544 ALOGE("Could not find mode #%d", conf);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200545 return HWC2::Error::BadConfig;
546 }
547
Roman Stratiienko0137f862022-01-04 18:27:40 +0200548 auto &hwc_config = configs_.hwc_configs[conf];
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200549
550 static const int32_t kUmPerInch = 25400;
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300551 auto mm_width = configs_.mm_width;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200552 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
553 switch (attribute) {
554 case HWC2::Attribute::Width:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200555 *value = static_cast<int>(hwc_config.mode.GetRawMode().hdisplay);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200556 break;
557 case HWC2::Attribute::Height:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200558 *value = static_cast<int>(hwc_config.mode.GetRawMode().vdisplay);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200559 break;
560 case HWC2::Attribute::VsyncPeriod:
561 // in nanoseconds
Drew Davenport8053f2e2024-10-02 13:44:41 -0600562 *value = hwc_config.mode.GetVSyncPeriodNs();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200563 break;
Lucas Berthoudf686aa2024-08-28 16:15:38 +0000564 case HWC2::Attribute::DpiY:
Lucas Berthou30808a22025-02-05 17:52:33 +0000565 *value = GetEdid()->GetDpiY();
566 if (*value < 0) {
567 // default to raw mode DpiX for both x and y when no good value
568 // can be provided from edid.
569 *value = mm_width ? int(hwc_config.mode.GetRawMode().hdisplay *
570 kUmPerInch / mm_width)
571 : -1;
572 }
573 break;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200574 case HWC2::Attribute::DpiX:
575 // Dots per 1000 inches
Lucas Berthou30808a22025-02-05 17:52:33 +0000576 *value = GetEdid()->GetDpiX();
577 if (*value < 0) {
578 // default to raw mode DpiX for both x and y when no good value
579 // can be provided from edid.
580 *value = mm_width ? int(hwc_config.mode.GetRawMode().hdisplay *
581 kUmPerInch / mm_width)
582 : -1;
583 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200584 break;
Roman Stratiienko6b405052022-12-10 19:09:10 +0200585#if __ANDROID_API__ > 29
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200586 case HWC2::Attribute::ConfigGroup:
587 /* Dispite ConfigGroup is a part of HWC2.4 API, framework
588 * able to request it even if service @2.1 is used */
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200589 *value = int(hwc_config.group_id);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200590 break;
591#endif
592 default:
593 *value = -1;
594 return HWC2::Error::BadConfig;
595 }
596 return HWC2::Error::None;
597}
598
Drew Davenportf7e88332024-09-06 12:54:38 -0600599HWC2::Error HwcDisplay::LegacyGetDisplayConfigs(uint32_t *num_configs,
600 hwc2_config_t *configs) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200601 uint32_t idx = 0;
Roman Stratiienko0137f862022-01-04 18:27:40 +0200602 for (auto &hwc_config : configs_.hwc_configs) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200603 if (hwc_config.second.disabled) {
604 continue;
605 }
606
607 if (configs != nullptr) {
608 if (idx >= *num_configs) {
609 break;
610 }
611 configs[idx] = hwc_config.second.id;
612 }
613
614 idx++;
615 }
616 *num_configs = idx;
617 return HWC2::Error::None;
618}
619
620HWC2::Error HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
621 std::ostringstream stream;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200622 if (IsInHeadlessMode()) {
623 stream << "null-display";
624 } else {
625 stream << "display-" << GetPipe().connector->Get()->GetId();
626 }
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300627 auto string = stream.str();
628 auto length = string.length();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200629 if (!name) {
630 *size = length;
631 return HWC2::Error::None;
632 }
633
634 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
635 strncpy(name, string.c_str(), *size);
636 return HWC2::Error::None;
637}
638
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200639HWC2::Error HwcDisplay::GetDisplayType(int32_t *type) {
640 *type = static_cast<int32_t>(type_);
641 return HWC2::Error::None;
642}
643
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500644HWC2::Error HwcDisplay::GetHdrCapabilities(uint32_t *num_types, int32_t *types,
645 float *max_luminance,
646 float *max_average_luminance,
647 float *min_luminance) {
Roman Stratiienkod7e108e2025-02-11 04:44:00 +0200648 if (IsInHeadlessMode()) {
649 *num_types = 0;
650 return HWC2::Error::None;
651 }
652
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500653 if (!types) {
654 std::vector<ui::Hdr> temp_types;
655 float lums[3] = {0.F};
656 GetEdid()->GetHdrCapabilities(temp_types, &lums[0], &lums[1], &lums[2]);
657 *num_types = temp_types.size();
658 return HWC2::Error::None;
659 }
660
661 std::vector<ui::Hdr> temp_types;
662 std::vector<int32_t> out_types(types, types + *num_types);
663 GetEdid()->GetHdrCapabilities(temp_types, max_luminance,
664 max_average_luminance, min_luminance);
665 for (auto &t : temp_types) {
666 switch (t) {
667 case ui::Hdr::HDR10:
668 out_types.emplace_back(HAL_HDR_HDR10);
669 break;
670 case ui::Hdr::HLG:
671 out_types.emplace_back(HAL_HDR_HLG);
672 break;
673 default:
674 // Ignore any other HDR types
675 break;
676 }
677 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200678 return HWC2::Error::None;
679}
680
Drew Davenport97b5abc2024-11-07 10:43:54 -0700681AtomicCommitArgs HwcDisplay::CreateModesetCommit(
682 const HwcDisplayConfig *config,
683 const std::optional<LayerData> &modeset_layer) {
684 AtomicCommitArgs args{};
685
686 args.color_matrix = color_matrix_;
687 args.content_type = content_type_;
688 args.colorspace = colorspace_;
Sasha McIntoshf9062b62024-11-12 10:55:06 -0500689 args.hdr_metadata = hdr_metadata_;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700690
691 std::vector<LayerData> composition_layers;
692 if (modeset_layer) {
693 composition_layers.emplace_back(modeset_layer.value());
694 }
695
696 if (composition_layers.empty()) {
697 ALOGW("Attempting to create a modeset commit without a layer.");
698 }
699
700 args.display_mode = config->mode;
701 args.active = true;
702 args.composition = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
703 std::move(
704 composition_layers));
705 ALOGW_IF(!args.composition, "No composition for blocking modeset");
706
707 return args;
708}
709
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200710// NOLINTNEXTLINE(readability-function-cognitive-complexity)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200711HWC2::Error HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200712 if (IsInHeadlessMode()) {
713 ALOGE("%s: Display is in headless mode, should never reach here", __func__);
714 return HWC2::Error::None;
715 }
716
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200717 a_args.color_matrix = color_matrix_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400718 a_args.content_type = content_type_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400719 a_args.colorspace = colorspace_;
Sasha McIntoshf9062b62024-11-12 10:55:06 -0500720 a_args.hdr_metadata = hdr_metadata_;
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200721
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200722 uint32_t prev_vperiod_ns = 0;
723 GetDisplayVsyncPeriod(&prev_vperiod_ns);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200724
Drew Davenportd387c842024-12-16 16:57:24 -0700725 std::optional<uint32_t> new_vsync_period_ns;
Drew Davenportfe70c802024-11-07 13:02:21 -0700726 if (staged_mode_config_id_ &&
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200727 staged_mode_change_time_ <= ResourceManager::GetTimeMonotonicNs()) {
Drew Davenportfe70c802024-11-07 13:02:21 -0700728 const HwcDisplayConfig *staged_config = GetConfig(
729 staged_mode_config_id_.value());
730 if (staged_config == nullptr) {
731 return HWC2::Error::BadConfig;
732 }
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200733
Drew Davenportfe70c802024-11-07 13:02:21 -0700734 configs_.active_config_id = staged_mode_config_id_.value();
Drew Davenportfe70c802024-11-07 13:02:21 -0700735 a_args.display_mode = staged_config->mode;
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200736 if (!a_args.test_only) {
Drew Davenportd387c842024-12-16 16:57:24 -0700737 new_vsync_period_ns = staged_config->mode.GetVSyncPeriodNs();
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200738 }
739 }
740
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200741 // order the layers by z-order
742 bool use_client_layer = false;
743 uint32_t client_z_order = UINT32_MAX;
744 std::map<uint32_t, HwcLayer *> z_map;
745 for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
746 switch (l.second.GetValidatedType()) {
747 case HWC2::Composition::Device:
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300748 z_map.emplace(l.second.GetZOrder(), &l.second);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200749 break;
750 case HWC2::Composition::Client:
751 // Place it at the z_order of the lowest client layer
752 use_client_layer = true;
753 client_z_order = std::min(client_z_order, l.second.GetZOrder());
754 break;
755 default:
756 continue;
757 }
758 }
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200759 if (use_client_layer) {
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300760 z_map.emplace(client_z_order, &client_layer_);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200761
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200762 client_layer_.PopulateLayerData();
763 if (!client_layer_.IsLayerUsableAsDevice()) {
764 ALOGE_IF(!a_args.test_only,
765 "Client layer must be always usable by DRM/KMS");
766 /* This may be normally triggered on validation of the first frame
767 * containing CLIENT layer. At this moment client buffer is not yet
768 * provided by the CLIENT.
769 * This may be triggered once in HwcLayer lifecycle in case FB can't be
770 * imported. For example when non-contiguous buffer is imported into
771 * contiguous-only DRM/KMS driver.
772 */
773 return HWC2::Error::BadLayer;
774 }
775 }
776
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200777 if (z_map.empty())
778 return HWC2::Error::BadLayer;
779
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200780 std::vector<LayerData> composition_layers;
781
782 /* Import & populate */
783 for (std::pair<const uint32_t, HwcLayer *> &l : z_map) {
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200784 l.second->PopulateLayerData();
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200785 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200786
787 // now that they're ordered by z, add them to the composition
788 for (std::pair<const uint32_t, HwcLayer *> &l : z_map) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200789 if (!l.second->IsLayerUsableAsDevice()) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200790 return HWC2::Error::BadLayer;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200791 }
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200792 composition_layers.emplace_back(l.second->GetLayerData());
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200793 }
794
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200795 /* Store plan to ensure shared planes won't be stolen by other display
796 * in between of ValidateDisplay() and PresentDisplay() calls
797 */
798 current_plan_ = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
799 std::move(composition_layers));
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300800
801 if (type_ == HWC2::DisplayType::Virtual) {
Roman Stratiienkoe0bbf222025-01-23 02:48:44 +0200802 writeback_layer_->PopulateLayerData();
803 if (!writeback_layer_->IsLayerUsableAsDevice()) {
804 ALOGE("Output layer must be always usable by DRM/KMS");
805 return HWC2::Error::BadLayer;
806 }
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300807 a_args.writeback_fb = writeback_layer_->GetLayerData().fb;
808 a_args.writeback_release_fence = writeback_layer_->GetLayerData()
809 .acquire_fence;
810 }
811
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200812 if (!current_plan_) {
Drew Davenport897a7092024-11-12 12:14:01 -0700813 ALOGE_IF(!a_args.test_only, "Failed to create DrmKmsPlan");
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200814 return HWC2::Error::BadConfig;
815 }
816
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200817 a_args.composition = current_plan_;
818
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300819 auto ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200820
821 if (ret) {
Drew Davenport897a7092024-11-12 12:14:01 -0700822 ALOGE_IF(!a_args.test_only, "Failed to apply the frame composition ret=%d", ret);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200823 return HWC2::Error::BadParameter;
824 }
825
Drew Davenportd387c842024-12-16 16:57:24 -0700826 if (new_vsync_period_ns) {
827 vsync_worker_->SetVsyncPeriodNs(new_vsync_period_ns.value());
Drew Davenportfe70c802024-11-07 13:02:21 -0700828 staged_mode_config_id_.reset();
Drew Davenport33121b72024-12-13 14:59:35 -0700829
830 vsync_worker_->SetVsyncTimestampTracking(false);
831 uint32_t last_vsync_ts = vsync_worker_->GetLastVsyncTimestamp();
832 if (last_vsync_ts != 0) {
Drew Davenport93443182023-12-14 09:25:45 +0000833 hwc_->SendVsyncPeriodTimingChangedEventToClient(handle_,
Drew Davenport33121b72024-12-13 14:59:35 -0700834 last_vsync_ts +
Drew Davenport93443182023-12-14 09:25:45 +0000835 prev_vperiod_ns);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200836 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200837 }
838
839 return HWC2::Error::None;
840}
841
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200842HWC2::Error HwcDisplay::SetActiveConfigInternal(uint32_t config,
843 int64_t change_time) {
844 if (configs_.hwc_configs.count(config) == 0) {
845 ALOGE("Could not find active mode for %u", config);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200846 return HWC2::Error::BadConfig;
847 }
848
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200849 staged_mode_change_time_ = change_time;
850 staged_mode_config_id_ = config;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200851
852 return HWC2::Error::None;
853}
854
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200855HWC2::Error HwcDisplay::SetActiveConfig(hwc2_config_t config) {
856 return SetActiveConfigInternal(config, ResourceManager::GetTimeMonotonicNs());
857}
858
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200859HWC2::Error HwcDisplay::SetColorMode(int32_t mode) {
Sasha McIntosh5294f092024-09-18 18:14:54 -0400860 /* Maps to the Colorspace DRM connector property:
861 * https://elixir.bootlin.com/linux/v6.11/source/include/drm/drm_connector.h#L538
862 */
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500863 if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_DISPLAY_BT2020)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200864 return HWC2::Error::BadParameter;
865
Sasha McIntosh5294f092024-09-18 18:14:54 -0400866 switch (mode) {
867 case HAL_COLOR_MODE_NATIVE:
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500868 hdr_metadata_.reset();
Sasha McIntosh5294f092024-09-18 18:14:54 -0400869 colorspace_ = Colorspace::kDefault;
870 break;
871 case HAL_COLOR_MODE_STANDARD_BT601_625:
872 case HAL_COLOR_MODE_STANDARD_BT601_625_UNADJUSTED:
873 case HAL_COLOR_MODE_STANDARD_BT601_525:
874 case HAL_COLOR_MODE_STANDARD_BT601_525_UNADJUSTED:
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500875 hdr_metadata_.reset();
Sasha McIntosh5294f092024-09-18 18:14:54 -0400876 // The DP spec does not say whether this is the 525 or the 625 line version.
877 colorspace_ = Colorspace::kBt601Ycc;
878 break;
879 case HAL_COLOR_MODE_STANDARD_BT709:
880 case HAL_COLOR_MODE_SRGB:
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500881 hdr_metadata_.reset();
Sasha McIntosh5294f092024-09-18 18:14:54 -0400882 colorspace_ = Colorspace::kBt709Ycc;
883 break;
884 case HAL_COLOR_MODE_DCI_P3:
885 case HAL_COLOR_MODE_DISPLAY_P3:
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500886 hdr_metadata_.reset();
Sasha McIntosh5294f092024-09-18 18:14:54 -0400887 colorspace_ = Colorspace::kDciP3RgbD65;
888 break;
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500889 case HAL_COLOR_MODE_DISPLAY_BT2020: {
890 std::vector<ui::Hdr> hdr_types;
891 GetEdid()->GetSupportedHdrTypes(hdr_types);
892 if (!hdr_types.empty()) {
893 auto ret = SetHdrOutputMetadata(hdr_types.front());
894 if (ret != HWC2::Error::None)
895 return ret;
896 }
897 colorspace_ = Colorspace::kBt2020Rgb;
898 break;
899 }
Sasha McIntosh5294f092024-09-18 18:14:54 -0400900 case HAL_COLOR_MODE_ADOBE_RGB:
Sasha McIntosh851ea4d2024-12-04 17:14:55 -0500901 case HAL_COLOR_MODE_BT2020:
902 case HAL_COLOR_MODE_BT2100_PQ:
903 case HAL_COLOR_MODE_BT2100_HLG:
Sasha McIntosh5294f092024-09-18 18:14:54 -0400904 default:
905 return HWC2::Error::Unsupported;
906 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200907
908 color_mode_ = mode;
909 return HWC2::Error::None;
910}
911
912HWC2::Error HwcDisplay::SetColorTransform(const float *matrix, int32_t hint) {
913 if (hint < HAL_COLOR_TRANSFORM_IDENTITY ||
914 hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA)
915 return HWC2::Error::BadParameter;
916
917 if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX)
918 return HWC2::Error::BadParameter;
919
920 color_transform_hint_ = static_cast<android_color_transform_t>(hint);
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200921
Roman Stratiienko5de61b52023-02-01 16:29:45 +0200922 if (IsInHeadlessMode())
923 return HWC2::Error::None;
924
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200925 if (!GetPipe().crtc->Get()->GetCtmProperty())
926 return HWC2::Error::None;
927
928 switch (color_transform_hint_) {
929 case HAL_COLOR_TRANSFORM_IDENTITY:
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400930 SetColorMatrixToIdentity();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200931 break;
932 case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX:
Sasha McIntosh921c1cd2024-10-09 19:50:52 -0400933 // Without HW support, we cannot correctly process matrices with an offset.
Drew Davenport76c17a82025-01-15 15:02:45 -0700934 {
935 for (int i = 12; i < 14; i++) {
936 if (matrix[i] != 0.F)
937 return HWC2::Error::Unsupported;
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200938 }
Drew Davenport76c17a82025-01-15 15:02:45 -0700939 std::array<float, 16> aidl_matrix = kIdentityMatrix;
940 memcpy(aidl_matrix.data(), matrix, aidl_matrix.size() * sizeof(float));
941 color_matrix_ = ToColorTransform(aidl_matrix);
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200942 }
943 break;
944 default:
945 return HWC2::Error::Unsupported;
946 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200947
948 return HWC2::Error::None;
949}
950
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200951bool HwcDisplay::CtmByGpu() {
952 if (color_transform_hint_ == HAL_COLOR_TRANSFORM_IDENTITY)
953 return false;
954
955 if (GetPipe().crtc->Get()->GetCtmProperty())
956 return false;
957
Drew Davenport93443182023-12-14 09:25:45 +0000958 if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore)
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200959 return false;
960
961 return true;
962}
963
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200964HWC2::Error HwcDisplay::SetPowerMode(int32_t mode_in) {
965 auto mode = static_cast<HWC2::PowerMode>(mode_in);
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300966
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200967 AtomicCommitArgs a_args{};
968
969 switch (mode) {
970 case HWC2::PowerMode::Off:
971 a_args.active = false;
972 break;
973 case HWC2::PowerMode::On:
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300974 a_args.active = true;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200975 break;
976 case HWC2::PowerMode::Doze:
977 case HWC2::PowerMode::DozeSuspend:
978 return HWC2::Error::Unsupported;
979 default:
John Stultzffe783c2024-02-14 10:51:27 -0800980 ALOGE("Incorrect power mode value (%d)\n", mode_in);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200981 return HWC2::Error::BadParameter;
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300982 }
983
984 if (IsInHeadlessMode()) {
985 return HWC2::Error::None;
986 }
987
Jia Ren80566fe2022-11-17 17:26:00 +0800988 if (a_args.active && *a_args.active) {
Roman Stratiienkoccaf5162022-04-01 19:26:30 +0300989 /*
990 * Setting the display to active before we have a composition
991 * can break some drivers, so skip setting a_args.active to
992 * true, as the next composition frame will implicitly activate
993 * the display
994 */
995 return GetPipe().atomic_state_manager->ActivateDisplayUsingDPMS() == 0
996 ? HWC2::Error::None
997 : HWC2::Error::BadParameter;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200998 };
999
Roman Stratiienkoa7913de2022-10-20 13:18:57 +03001000 auto err = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001001 if (err) {
1002 ALOGE("Failed to apply the dpms composition err=%d", err);
1003 return HWC2::Error::BadParameter;
1004 }
1005 return HWC2::Error::None;
1006}
1007
1008HWC2::Error HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001009 if (type_ == HWC2::DisplayType::Virtual) {
1010 return HWC2::Error::None;
1011 }
Lucas Berthoua2928992025-01-07 22:48:28 +00001012 if (!vsync_worker_) {
1013 return HWC2::Error::NoResources;
1014 }
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001015
Roman Stratiienko099c3112022-01-20 11:50:54 +02001016 vsync_event_en_ = HWC2_VSYNC_ENABLE == enabled;
Lucas Berthoua2928992025-01-07 22:48:28 +00001017 std::optional<VSyncWorker::VsyncTimestampCallback> callback = std::nullopt;
Roman Stratiienko099c3112022-01-20 11:50:54 +02001018 if (vsync_event_en_) {
Drew Davenport63a699e2024-12-13 15:00:00 -07001019 DrmHwc *hwc = hwc_;
1020 hwc2_display_t id = handle_;
1021 // Callback will be called from the vsync thread.
Lucas Berthoua2928992025-01-07 22:48:28 +00001022 callback = [hwc, id](int64_t timestamp, uint32_t period_ns) {
Drew Davenport63a699e2024-12-13 15:00:00 -07001023 hwc->SendVsyncEventToClient(id, timestamp, period_ns);
1024 };
Roman Stratiienko099c3112022-01-20 11:50:54 +02001025 }
Lucas Berthoua2928992025-01-07 22:48:28 +00001026 vsync_worker_->SetTimestampCallback(std::move(callback));
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001027 return HWC2::Error::None;
1028}
1029
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001030std::vector<HwcLayer *> HwcDisplay::GetOrderLayersByZPos() {
1031 std::vector<HwcLayer *> ordered_layers;
1032 ordered_layers.reserve(layers_.size());
1033
1034 for (auto &[handle, layer] : layers_) {
1035 ordered_layers.emplace_back(&layer);
1036 }
1037
1038 std::sort(std::begin(ordered_layers), std::end(ordered_layers),
1039 [](const HwcLayer *lhs, const HwcLayer *rhs) {
1040 return lhs->GetZOrder() < rhs->GetZOrder();
1041 });
1042
1043 return ordered_layers;
1044}
1045
Roman Stratiienko099c3112022-01-20 11:50:54 +02001046HWC2::Error HwcDisplay::GetDisplayVsyncPeriod(
1047 uint32_t *outVsyncPeriod /* ns */) {
1048 return GetDisplayAttribute(configs_.active_config_id,
1049 HWC2_ATTRIBUTE_VSYNC_PERIOD,
1050 (int32_t *)(outVsyncPeriod));
1051}
1052
Sasha McIntoshf9062b62024-11-12 10:55:06 -05001053// Display primary values are coded as unsigned 16-bit values in units of
1054// 0.00002, where 0x0000 represents zero and 0xC350 represents 1.0000.
1055static uint64_t ToU16ColorValue(float in) {
1056 constexpr float kPrimariesFixedPoint = 50000.F;
1057 return static_cast<uint64_t>(kPrimariesFixedPoint * in);
1058}
1059
1060HWC2::Error HwcDisplay::SetHdrOutputMetadata(ui::Hdr type) {
1061 hdr_metadata_ = std::make_shared<hdr_output_metadata>();
1062 hdr_metadata_->metadata_type = 0;
1063 auto *m = &hdr_metadata_->hdmi_metadata_type1;
1064 m->metadata_type = 0;
1065
1066 switch (type) {
1067 case ui::Hdr::HDR10:
1068 m->eotf = 2; // PQ
1069 break;
1070 case ui::Hdr::HLG:
1071 m->eotf = 3; // HLG
1072 break;
1073 default:
1074 return HWC2::Error::Unsupported;
1075 }
1076
1077 // Most luminance values are coded as an unsigned 16-bit value in units of 1
1078 // cd/m2, where 0x0001 represents 1 cd/m2 and 0xFFFF represents 65535 cd/m2.
1079 std::vector<ui::Hdr> types;
1080 float hdr_luminance[3]{0.F, 0.F, 0.F};
1081 GetEdid()->GetHdrCapabilities(types, &hdr_luminance[0], &hdr_luminance[1],
1082 &hdr_luminance[2]);
1083 m->max_display_mastering_luminance = m->max_cll = static_cast<uint64_t>(
1084 hdr_luminance[0]);
1085 m->max_fall = static_cast<uint64_t>(hdr_luminance[1]);
1086 // The min luminance value is coded as an unsigned 16-bit value in units of
1087 // 0.0001 cd/m2, where 0x0001 represents 0.0001 cd/m2 and 0xFFFF
1088 // represents 6.5535 cd/m2.
1089 m->min_display_mastering_luminance = static_cast<uint64_t>(hdr_luminance[2] *
1090 10000.F);
1091
1092 auto gamut = ColorGamut::BT2020();
1093 auto primaries = gamut.getPrimaries();
1094 m->display_primaries[0].x = ToU16ColorValue(primaries[0].x);
1095 m->display_primaries[0].y = ToU16ColorValue(primaries[0].y);
1096 m->display_primaries[1].x = ToU16ColorValue(primaries[1].x);
1097 m->display_primaries[1].y = ToU16ColorValue(primaries[1].y);
1098 m->display_primaries[2].x = ToU16ColorValue(primaries[2].x);
1099 m->display_primaries[2].y = ToU16ColorValue(primaries[2].y);
1100
1101 auto whitePoint = gamut.getWhitePoint();
1102 m->white_point.x = ToU16ColorValue(whitePoint.x);
1103 m->white_point.y = ToU16ColorValue(whitePoint.y);
1104
1105 return HWC2::Error::None;
1106}
1107
Roman Stratiienko6b405052022-12-10 19:09:10 +02001108#if __ANDROID_API__ > 29
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001109HWC2::Error HwcDisplay::GetDisplayConnectionType(uint32_t *outType) {
Roman Stratiienko456e2d62022-01-29 01:17:39 +02001110 if (IsInHeadlessMode()) {
1111 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
1112 return HWC2::Error::None;
1113 }
1114 /* Primary display should be always internal,
1115 * otherwise SF will be unhappy and will crash
1116 */
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001117 if (GetPipe().connector->Get()->IsInternal() || handle_ == kPrimaryDisplay)
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001118 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001119 else if (GetPipe().connector->Get()->IsExternal())
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001120 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External);
1121 else
1122 return HWC2::Error::BadConfig;
1123
1124 return HWC2::Error::None;
1125}
1126
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001127HWC2::Error HwcDisplay::SetActiveConfigWithConstraints(
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001128 hwc2_config_t config,
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001129 hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints,
1130 hwc_vsync_period_change_timeline_t *outTimeline) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001131 if (type_ == HWC2::DisplayType::Virtual) {
1132 return HWC2::Error::None;
1133 }
1134
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001135 if (vsyncPeriodChangeConstraints == nullptr || outTimeline == nullptr) {
1136 return HWC2::Error::BadParameter;
1137 }
1138
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001139 uint32_t current_vsync_period{};
1140 GetDisplayVsyncPeriod(&current_vsync_period);
1141
1142 if (vsyncPeriodChangeConstraints->seamlessRequired) {
1143 return HWC2::Error::SeamlessNotAllowed;
1144 }
1145
1146 outTimeline->refreshTimeNanos = vsyncPeriodChangeConstraints
1147 ->desiredTimeNanos -
1148 current_vsync_period;
1149 auto ret = SetActiveConfigInternal(config, outTimeline->refreshTimeNanos);
1150 if (ret != HWC2::Error::None) {
1151 return ret;
1152 }
1153
1154 outTimeline->refreshRequired = true;
1155 outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeConstraints
1156 ->desiredTimeNanos;
1157
Drew Davenport33121b72024-12-13 14:59:35 -07001158 vsync_worker_->SetVsyncTimestampTracking(true);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001159
1160 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001161}
1162
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001163HWC2::Error HwcDisplay::SetContentType(int32_t contentType) {
Sasha McIntosh173247b2024-09-18 18:06:52 -04001164 /* Maps exactly to the content_type DRM connector property:
1165 * https://elixir.bootlin.com/linux/v6.11/source/include/uapi/drm/drm_mode.h#L107
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001166 */
Sasha McIntosh173247b2024-09-18 18:06:52 -04001167 if (contentType < HWC2_CONTENT_TYPE_NONE || contentType > HWC2_CONTENT_TYPE_GAME)
1168 return HWC2::Error::BadParameter;
1169
1170 content_type_ = contentType;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001171
1172 return HWC2::Error::None;
1173}
1174#endif
1175
Roman Stratiienko6b405052022-12-10 19:09:10 +02001176#if __ANDROID_API__ > 28
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001177HWC2::Error HwcDisplay::GetDisplayIdentificationData(uint8_t *outPort,
1178 uint32_t *outDataSize,
1179 uint8_t *outData) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +02001180 if (IsInHeadlessMode()) {
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001181 return HWC2::Error::Unsupported;
Roman Stratiienko3dacd472022-01-11 19:18:34 +02001182 }
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001183
Gil Dekel907a51a2025-02-14 22:44:01 -05001184 auto *connector = GetPipe().connector->Get();
1185 auto blob = connector->GetEdidBlob();
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001186 if (!blob) {
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001187 return HWC2::Error::Unsupported;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001188 }
1189
Gil Dekel907a51a2025-02-14 22:44:01 -05001190 constexpr uint8_t kDrmDeviceBitShift = 5U;
1191 constexpr uint8_t kDrmDeviceBitMask = 0xE0;
1192 constexpr uint8_t kConnectorBitMask = 0x1F;
1193 const auto kDrmIdx = static_cast<uint8_t>(
1194 connector->GetDev().GetIndexInDevArray());
1195 const auto kConnectorIdx = static_cast<uint8_t>(
1196 connector->GetIndexInResArray());
1197 *outPort = (((kDrmIdx << kDrmDeviceBitShift) & kDrmDeviceBitMask) |
1198 (kConnectorIdx & kConnectorBitMask));
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001199
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001200 if (outData) {
1201 *outDataSize = std::min(*outDataSize, blob->length);
1202 memcpy(outData, blob->data, *outDataSize);
1203 } else {
1204 *outDataSize = blob->length;
1205 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001206
1207 return HWC2::Error::None;
1208}
1209
1210HWC2::Error HwcDisplay::GetDisplayCapabilities(uint32_t *outNumCapabilities,
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001211 uint32_t *outCapabilities) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001212 if (outNumCapabilities == nullptr) {
1213 return HWC2::Error::BadParameter;
1214 }
1215
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001216 bool skip_ctm = false;
1217
1218 // Skip client CTM if user requested DRM_OR_IGNORE
Drew Davenport93443182023-12-14 09:25:45 +00001219 if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore)
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001220 skip_ctm = true;
1221
1222 // Skip client CTM if DRM can handle it
1223 if (!skip_ctm && !IsInHeadlessMode() &&
1224 GetPipe().crtc->Get()->GetCtmProperty())
1225 skip_ctm = true;
1226
1227 if (!skip_ctm) {
1228 *outNumCapabilities = 0;
1229 return HWC2::Error::None;
1230 }
1231
1232 *outNumCapabilities = 1;
1233 if (outCapabilities) {
1234 outCapabilities[0] = HWC2_DISPLAY_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM;
1235 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001236
1237 return HWC2::Error::None;
1238}
1239
Roman Stratiienko6b405052022-12-10 19:09:10 +02001240#endif /* __ANDROID_API__ > 28 */
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001241
Roman Stratiienko6b405052022-12-10 19:09:10 +02001242#if __ANDROID_API__ > 27
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001243
1244HWC2::Error HwcDisplay::GetRenderIntents(
1245 int32_t mode, uint32_t *outNumIntents,
1246 int32_t * /*android_render_intent_v1_1_t*/ outIntents) {
1247 if (mode != HAL_COLOR_MODE_NATIVE) {
1248 return HWC2::Error::BadParameter;
1249 }
1250
1251 if (outIntents == nullptr) {
1252 *outNumIntents = 1;
1253 return HWC2::Error::None;
1254 }
1255 *outNumIntents = 1;
1256 outIntents[0] = HAL_RENDER_INTENT_COLORIMETRIC;
1257 return HWC2::Error::None;
1258}
1259
1260HWC2::Error HwcDisplay::SetColorModeWithIntent(int32_t mode, int32_t intent) {
1261 if (intent < HAL_RENDER_INTENT_COLORIMETRIC ||
1262 intent > HAL_RENDER_INTENT_TONE_MAP_ENHANCE)
1263 return HWC2::Error::BadParameter;
1264
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001265 if (intent != HAL_RENDER_INTENT_COLORIMETRIC)
1266 return HWC2::Error::Unsupported;
1267
Sasha McIntosh5294f092024-09-18 18:14:54 -04001268 auto err = SetColorMode(mode);
1269 if (err != HWC2::Error::None) return err;
1270
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001271 return HWC2::Error::None;
1272}
1273
Roman Stratiienko6b405052022-12-10 19:09:10 +02001274#endif /* __ANDROID_API__ > 27 */
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001275
1276const Backend *HwcDisplay::backend() const {
1277 return backend_.get();
1278}
1279
1280void HwcDisplay::set_backend(std::unique_ptr<Backend> backend) {
1281 backend_ = std::move(backend);
1282}
1283
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001284} // namespace android