blob: 2df3b4ffea23ed8fc7ddb488660b085d59831e6e [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
Drew Davenport97b5abc2024-11-07 10:43:54 -070024#include <hardware/gralloc.h>
25#include <ui/GraphicBufferAllocator.h>
26#include <ui/GraphicBufferMapper.h>
27#include <ui/PixelFormat.h>
28
Roman Stratiienkobb594ba2022-02-18 16:52:03 +020029#include "backend/Backend.h"
Roman Stratiienko3627beb2022-01-04 16:02:55 +020030#include "backend/BackendManager.h"
31#include "bufferinfo/BufferInfoGetter.h"
Tim Van Pattena2f3efa2024-10-15 17:44:54 -060032#include "compositor/DisplayInfo.h"
33#include "drm/DrmConnector.h"
34#include "drm/DrmDisplayPipeline.h"
Drew Davenport93443182023-12-14 09:25:45 +000035#include "drm/DrmHwc.h"
Roman Stratiienko3627beb2022-01-04 16:02:55 +020036#include "utils/log.h"
37#include "utils/properties.h"
38
Tim Van Pattena2f3efa2024-10-15 17:44:54 -060039using ::android::DrmDisplayPipeline;
40
Roman Stratiienko3627beb2022-01-04 16:02:55 +020041namespace android {
42
Drew Davenport97b5abc2024-11-07 10:43:54 -070043namespace {
44// Allocate a black buffer that can be used for an initial modeset when there.
45// is no appropriate client buffer available to be used.
46// Caller must free the returned buffer with GraphicBufferAllocator::free.
47auto GetModesetBuffer(uint32_t width, uint32_t height) -> buffer_handle_t {
48 constexpr PixelFormat format = PIXEL_FORMAT_RGBA_8888;
49 constexpr uint64_t usage = GRALLOC_USAGE_SW_READ_OFTEN |
50 GRALLOC_USAGE_SW_WRITE_OFTEN |
51 GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
52
53 constexpr uint32_t layer_count = 1;
54 const std::string name = "drm-hwcomposer";
55
56 buffer_handle_t handle = nullptr;
57 uint32_t stride = 0;
58 status_t status = GraphicBufferAllocator::get().allocate(width, height,
59 format, layer_count,
60 usage, &handle,
61 &stride, name);
62 if (status != OK) {
63 ALOGE("Failed to allocate modeset buffer.");
64 return nullptr;
65 }
66
67 void *data = nullptr;
68 Rect bounds = {0, 0, static_cast<int32_t>(width),
69 static_cast<int32_t>(height)};
70 status = GraphicBufferMapper::get().lock(handle, usage, bounds, &data);
71 if (status != OK) {
72 ALOGE("Failed to map modeset buffer.");
73 GraphicBufferAllocator::get().free(handle);
74 return nullptr;
75 }
76
77 // Cast one of the multiplicands to ensure that the multiplication happens
78 // in a wider type (size_t).
79 const size_t buffer_size = static_cast<size_t>(height) * stride *
80 bytesPerPixel(format);
81 memset(data, 0, buffer_size);
82 status = GraphicBufferMapper::get().unlock(handle);
83 ALOGW_IF(status != OK, "Failed to unmap buffer.");
84 return handle;
85}
86
87auto GetModesetLayerProperties(buffer_handle_t buffer, uint32_t width,
88 uint32_t height) -> HwcLayer::LayerProperties {
89 HwcLayer::LayerProperties properties;
90 properties.buffer = {.buffer_handle = buffer, .acquire_fence = {}};
91 properties.display_frame = {
92 .left = 0,
93 .top = 0,
94 .right = int(width),
95 .bottom = int(height),
96 };
97 properties.source_crop = (hwc_frect_t){
98 .left = 0.0F,
99 .top = 0.0F,
100 .right = static_cast<float>(width),
101 .bottom = static_cast<float>(height),
102 };
103 properties.blend_mode = BufferBlendMode::kNone;
104 return properties;
105}
106} // namespace
107
Roman Stratiienko44b95772025-01-22 18:03:36 +0200108static BufferColorSpace Hwc2ToColorSpace(int32_t dataspace) {
109 switch (dataspace & HAL_DATASPACE_STANDARD_MASK) {
110 case HAL_DATASPACE_STANDARD_BT709:
111 return BufferColorSpace::kItuRec709;
112 case HAL_DATASPACE_STANDARD_BT601_625:
113 case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
114 case HAL_DATASPACE_STANDARD_BT601_525:
115 case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
116 return BufferColorSpace::kItuRec601;
117 case HAL_DATASPACE_STANDARD_BT2020:
118 case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
119 return BufferColorSpace::kItuRec2020;
120 default:
121 return BufferColorSpace::kUndefined;
122 }
123}
124
125static BufferSampleRange Hwc2ToSampleRange(int32_t dataspace) {
126 switch (dataspace & HAL_DATASPACE_RANGE_MASK) {
127 case HAL_DATASPACE_RANGE_FULL:
128 return BufferSampleRange::kFullRange;
129 case HAL_DATASPACE_RANGE_LIMITED:
130 return BufferSampleRange::kLimitedRange;
131 default:
132 return BufferSampleRange::kUndefined;
133 }
134}
135
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200136std::string HwcDisplay::DumpDelta(HwcDisplay::Stats delta) {
137 if (delta.total_pixops_ == 0)
138 return "No stats yet";
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300139 auto ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200140
141 std::stringstream ss;
142 ss << " Total frames count: " << delta.total_frames_ << "\n"
143 << " Failed to test commit frames: " << delta.failed_kms_validate_ << "\n"
144 << " Failed to commit frames: " << delta.failed_kms_present_ << "\n"
145 << ((delta.failed_kms_present_ > 0)
146 ? " !!! Internal failure, FIX it please\n"
147 : "")
148 << " Flattened frames: " << delta.frames_flattened_ << "\n"
149 << " Pixel operations (free units)"
150 << " : [TOTAL: " << delta.total_pixops_ << " / GPU: " << delta.gpu_pixops_
151 << "]\n"
152 << " Composition efficiency: " << ratio;
153
154 return ss.str();
155}
156
157std::string HwcDisplay::Dump() {
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300158 auto connector_name = IsInHeadlessMode()
159 ? std::string("NULL-DISPLAY")
160 : GetPipe().connector->Get()->GetName();
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200161
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200162 std::stringstream ss;
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200163 ss << "- Display on: " << connector_name << "\n"
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200164 << "Statistics since system boot:\n"
165 << DumpDelta(total_stats_) << "\n\n"
166 << "Statistics since last dumpsys request:\n"
167 << DumpDelta(total_stats_.minus(prev_stats_)) << "\n\n";
168
169 memcpy(&prev_stats_, &total_stats_, sizeof(Stats));
170 return ss.str();
171}
172
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200173HwcDisplay::HwcDisplay(hwc2_display_t handle, HWC2::DisplayType type,
Drew Davenport93443182023-12-14 09:25:45 +0000174 DrmHwc *hwc)
175 : hwc_(hwc), handle_(handle), type_(type), client_layer_(this) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300176 if (type_ == HWC2::DisplayType::Virtual) {
177 writeback_layer_ = std::make_unique<HwcLayer>(this);
178 }
179}
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200180
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400181void HwcDisplay::SetColorMatrixToIdentity() {
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200182 color_matrix_ = std::make_shared<drm_color_ctm>();
183 for (int i = 0; i < kCtmCols; i++) {
184 for (int j = 0; j < kCtmRows; j++) {
Yongqin Liu152bc622023-01-29 00:48:10 +0800185 constexpr uint64_t kOne = (1ULL << 32); /* 1.0 in s31.32 format */
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200186 color_matrix_->matrix[i * kCtmRows + j] = (i == j) ? kOne : 0;
187 }
188 }
189
190 color_transform_hint_ = HAL_COLOR_TRANSFORM_IDENTITY;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200191}
192
Normunds Rieksts545096d2024-03-11 16:37:45 +0000193HwcDisplay::~HwcDisplay() {
194 Deinit();
195};
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200196
Drew Davenportfe70c802024-11-07 13:02:21 -0700197auto HwcDisplay::GetConfig(hwc2_config_t config_id) const
198 -> const HwcDisplayConfig * {
199 auto config_iter = configs_.hwc_configs.find(config_id);
Drew Davenport9799ab82024-10-23 10:15:45 -0600200 if (config_iter == configs_.hwc_configs.end()) {
201 return nullptr;
202 }
203 return &config_iter->second;
204}
205
Drew Davenportfe70c802024-11-07 13:02:21 -0700206auto HwcDisplay::GetCurrentConfig() const -> const HwcDisplayConfig * {
207 return GetConfig(configs_.active_config_id);
208}
209
Drew Davenport8998f8b2024-10-24 10:15:12 -0600210auto HwcDisplay::GetLastRequestedConfig() const -> const HwcDisplayConfig * {
Drew Davenportfe70c802024-11-07 13:02:21 -0700211 return GetConfig(staged_mode_config_id_.value_or(configs_.active_config_id));
Drew Davenport85be25d2024-10-23 10:26:34 -0600212}
213
Drew Davenport97b5abc2024-11-07 10:43:54 -0700214HwcDisplay::ConfigError HwcDisplay::SetConfig(hwc2_config_t config) {
215 const HwcDisplayConfig *new_config = GetConfig(config);
216 if (new_config == nullptr) {
217 ALOGE("Could not find active mode for %u", config);
218 return ConfigError::kBadConfig;
219 }
220
221 const HwcDisplayConfig *current_config = GetCurrentConfig();
222
223 const uint32_t width = new_config->mode.GetRawMode().hdisplay;
Drew Davenport8cfa7ff2024-12-06 13:42:04 -0700224 const uint32_t height = new_config->mode.GetRawMode().vdisplay;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700225
226 std::optional<LayerData> modeset_layer_data;
227 // If a client layer has already been provided, and its size matches the
228 // new config, use it for the modeset.
229 if (client_layer_.IsLayerUsableAsDevice() && current_config &&
230 current_config->mode.GetRawMode().hdisplay == width &&
231 current_config->mode.GetRawMode().vdisplay == height) {
232 ALOGV("Use existing client_layer for blocking config.");
233 modeset_layer_data = client_layer_.GetLayerData();
234 } else {
235 ALOGV("Allocate modeset buffer.");
236 buffer_handle_t modeset_buffer = GetModesetBuffer(width, height);
237 if (modeset_buffer != nullptr) {
238 auto modeset_layer = std::make_unique<HwcLayer>(this);
239 modeset_layer->SetLayerProperties(
240 GetModesetLayerProperties(modeset_buffer, width, height));
241 modeset_layer->PopulateLayerData();
242 modeset_layer_data = modeset_layer->GetLayerData();
243 GraphicBufferAllocator::get().free(modeset_buffer);
244 }
245 }
246
247 ALOGV("Create modeset commit.");
248 // Create atomic commit args for a blocking modeset. There's no need to do a
249 // separate test commit, since the commit does a test anyways.
250 AtomicCommitArgs commit_args = CreateModesetCommit(new_config,
251 modeset_layer_data);
252 commit_args.blocking = true;
253 int ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(commit_args);
254
255 if (ret) {
256 ALOGE("Blocking config failed: %d", ret);
257 return HwcDisplay::ConfigError::kBadConfig;
258 }
259
260 ALOGV("Blocking config succeeded.");
261 configs_.active_config_id = config;
Drew Davenport53da3712024-12-04 13:31:07 -0700262 staged_mode_config_id_.reset();
Drew Davenport59833182024-12-13 10:02:15 -0700263 vsync_worker_->SetVsyncPeriodNs(new_config->mode.GetVSyncPeriodNs());
264 // set new vsync period
Drew Davenport97b5abc2024-11-07 10:43:54 -0700265 return ConfigError::kNone;
266}
267
Drew Davenport8998f8b2024-10-24 10:15:12 -0600268auto HwcDisplay::QueueConfig(hwc2_config_t config, int64_t desired_time,
269 bool seamless, QueuedConfigTiming *out_timing)
270 -> ConfigError {
271 if (configs_.hwc_configs.count(config) == 0) {
272 ALOGE("Could not find active mode for %u", config);
273 return ConfigError::kBadConfig;
274 }
275
276 // TODO: Add support for seamless configuration changes.
277 if (seamless) {
278 return ConfigError::kSeamlessNotAllowed;
279 }
280
281 // Request a refresh from the client one vsync period before the desired
282 // time, or simply at the desired time if there is no active configuration.
283 const HwcDisplayConfig *current_config = GetCurrentConfig();
284 out_timing->refresh_time_ns = desired_time -
285 (current_config
286 ? current_config->mode.GetVSyncPeriodNs()
287 : 0);
288 out_timing->new_vsync_time_ns = desired_time;
289
290 // Queue the config change timing to be consistent with the requested
291 // refresh time.
Drew Davenport8998f8b2024-10-24 10:15:12 -0600292 staged_mode_change_time_ = out_timing->refresh_time_ns;
293 staged_mode_config_id_ = config;
294
295 // Enable vsync events until the mode has been applied.
Drew Davenport33121b72024-12-13 14:59:35 -0700296 vsync_worker_->SetVsyncTimestampTracking(true);
Drew Davenport8998f8b2024-10-24 10:15:12 -0600297
298 return ConfigError::kNone;
299}
300
Roman Stratiienko63762a92023-09-18 22:33:45 +0300301void HwcDisplay::SetPipeline(std::shared_ptr<DrmDisplayPipeline> pipeline) {
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200302 Deinit();
303
Roman Stratiienko63762a92023-09-18 22:33:45 +0300304 pipeline_ = std::move(pipeline);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200305
Roman Stratiienko63762a92023-09-18 22:33:45 +0300306 if (pipeline_ != nullptr || handle_ == kPrimaryDisplay) {
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200307 Init();
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000308 hwc_->ScheduleHotplugEvent(handle_, DrmHwc::kConnected);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200309 } else {
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000310 hwc_->ScheduleHotplugEvent(handle_, DrmHwc::kDisconnected);
Roman Stratiienkobb594ba2022-02-18 16:52:03 +0200311 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200312}
313
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200314void HwcDisplay::Deinit() {
315 if (pipeline_ != nullptr) {
316 AtomicCommitArgs a_args{};
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200317 a_args.composition = std::make_shared<DrmKmsPlan>();
318 GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienkoaf862a52022-06-22 12:14:22 +0300319 a_args.composition = {};
320 a_args.active = false;
321 GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200322
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200323 current_plan_.reset();
324 backend_.reset();
Roman Stratiienko22fe9612023-01-17 21:22:29 +0200325 if (flatcon_) {
326 flatcon_->StopThread();
327 flatcon_.reset();
328 }
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200329 }
330
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200331 if (vsync_worker_) {
332 vsync_worker_->StopThread();
333 vsync_worker_ = {};
334 }
335
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200336 SetClientTarget(nullptr, -1, 0, {});
337}
338
Roman Stratiienko19c162f2022-02-01 09:35:08 +0200339HWC2::Error HwcDisplay::Init() {
Roman Stratiienkod0494d92022-03-15 18:02:04 +0200340 ChosePreferredConfig();
341
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300342 if (type_ != HWC2::DisplayType::Virtual) {
Drew Davenport15016c42024-12-13 15:13:28 -0700343 vsync_worker_ = VSyncWorker::CreateInstance(pipeline_);
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300344 if (!vsync_worker_) {
345 ALOGE("Failed to create event worker for d=%d\n", int(handle_));
346 return HWC2::Error::BadDisplay;
347 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200348 }
349
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200350 if (!IsInHeadlessMode()) {
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200351 auto ret = BackendManager::GetInstance().SetBackendForDisplay(this);
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200352 if (ret) {
353 ALOGE("Failed to set backend for d=%d %d\n", int(handle_), ret);
354 return HWC2::Error::BadDisplay;
355 }
Drew Davenport93443182023-12-14 09:25:45 +0000356 auto flatcbk = (struct FlatConCallbacks){
357 .trigger = [this]() { hwc_->SendRefreshEventToClient(handle_); }};
Roman Stratiienko22fe9612023-01-17 21:22:29 +0200358 flatcon_ = FlatteningController::CreateInstance(flatcbk);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200359 }
360
Roman Stratiienko44b95772025-01-22 18:03:36 +0200361 HwcLayer::LayerProperties lp;
362 lp.blend_mode = BufferBlendMode::kPreMult;
363 client_layer_.SetLayerProperties(lp);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200364
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400365 SetColorMatrixToIdentity();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200366
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200367 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200368}
369
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600370std::optional<PanelOrientation> HwcDisplay::getDisplayPhysicalOrientation() {
371 if (IsInHeadlessMode()) {
372 // The pipeline can be nullptr in headless mode, so return the default
373 // "normal" mode.
374 return PanelOrientation::kModePanelOrientationNormal;
375 }
376
377 DrmDisplayPipeline &pipeline = GetPipe();
378 if (pipeline.connector == nullptr || pipeline.connector->Get() == nullptr) {
379 ALOGW(
380 "No display pipeline present to query the panel orientation property.");
381 return {};
382 }
383
384 return pipeline.connector->Get()->GetPanelOrientation();
385}
386
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200387HWC2::Error HwcDisplay::ChosePreferredConfig() {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200388 HWC2::Error err{};
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300389 if (type_ == HWC2::DisplayType::Virtual) {
390 configs_.GenFakeMode(virtual_disp_width_, virtual_disp_height_);
391 } else if (!IsInHeadlessMode()) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200392 err = configs_.Update(*pipeline_->connector->Get());
393 } else {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300394 configs_.GenFakeMode(0, 0);
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200395 }
396 if (!IsInHeadlessMode() && err != HWC2::Error::None) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200397 return HWC2::Error::BadDisplay;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200398 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200399
Roman Stratiienko0137f862022-01-04 18:27:40 +0200400 return SetActiveConfig(configs_.preferred_config_id);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200401}
402
403HWC2::Error HwcDisplay::AcceptDisplayChanges() {
404 for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_)
405 l.second.AcceptTypeChange();
406 return HWC2::Error::None;
407}
408
409HWC2::Error HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200410 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer(this));
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200411 *layer = static_cast<hwc2_layer_t>(layer_idx_);
412 ++layer_idx_;
413 return HWC2::Error::None;
414}
415
416HWC2::Error HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200417 if (!get_layer(layer)) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200418 return HWC2::Error::BadLayer;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200419 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200420
421 layers_.erase(layer);
422 return HWC2::Error::None;
423}
424
425HWC2::Error HwcDisplay::GetActiveConfig(hwc2_config_t *config) const {
Drew Davenportfe70c802024-11-07 13:02:21 -0700426 // If a config has been queued, it is considered the "active" config.
427 const HwcDisplayConfig *hwc_config = GetLastRequestedConfig();
428 if (hwc_config == nullptr)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200429 return HWC2::Error::BadConfig;
430
Drew Davenportfe70c802024-11-07 13:02:21 -0700431 *config = hwc_config->id;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200432 return HWC2::Error::None;
433}
434
435HWC2::Error HwcDisplay::GetChangedCompositionTypes(uint32_t *num_elements,
436 hwc2_layer_t *layers,
437 int32_t *types) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200438 if (IsInHeadlessMode()) {
439 *num_elements = 0;
440 return HWC2::Error::None;
441 }
442
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200443 uint32_t num_changes = 0;
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300444 for (auto &l : layers_) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200445 if (l.second.IsTypeChanged()) {
446 if (layers && num_changes < *num_elements)
447 layers[num_changes] = l.first;
448 if (types && num_changes < *num_elements)
449 types[num_changes] = static_cast<int32_t>(l.second.GetValidatedType());
450 ++num_changes;
451 }
452 }
453 if (!layers && !types)
454 *num_elements = num_changes;
455 return HWC2::Error::None;
456}
457
458HWC2::Error HwcDisplay::GetClientTargetSupport(uint32_t width, uint32_t height,
459 int32_t /*format*/,
460 int32_t dataspace) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200461 if (IsInHeadlessMode()) {
462 return HWC2::Error::None;
463 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200464
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300465 auto min = pipeline_->device->GetMinResolution();
466 auto max = pipeline_->device->GetMaxResolution();
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200467
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200468 if (width < min.first || height < min.second)
469 return HWC2::Error::Unsupported;
470
471 if (width > max.first || height > max.second)
472 return HWC2::Error::Unsupported;
473
474 if (dataspace != HAL_DATASPACE_UNKNOWN)
475 return HWC2::Error::Unsupported;
476
477 // TODO(nobody): Validate format can be handled by either GL or planes
478 return HWC2::Error::None;
479}
480
481HWC2::Error HwcDisplay::GetColorModes(uint32_t *num_modes, int32_t *modes) {
482 if (!modes)
483 *num_modes = 1;
484
485 if (modes)
486 *modes = HAL_COLOR_MODE_NATIVE;
487
488 return HWC2::Error::None;
489}
490
491HWC2::Error HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
492 int32_t attribute_in,
493 int32_t *value) {
494 int conf = static_cast<int>(config);
495
Roman Stratiienko0137f862022-01-04 18:27:40 +0200496 if (configs_.hwc_configs.count(conf) == 0) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200497 ALOGE("Could not find mode #%d", conf);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200498 return HWC2::Error::BadConfig;
499 }
500
Roman Stratiienko0137f862022-01-04 18:27:40 +0200501 auto &hwc_config = configs_.hwc_configs[conf];
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200502
503 static const int32_t kUmPerInch = 25400;
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300504 auto mm_width = configs_.mm_width;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200505 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
506 switch (attribute) {
507 case HWC2::Attribute::Width:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200508 *value = static_cast<int>(hwc_config.mode.GetRawMode().hdisplay);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200509 break;
510 case HWC2::Attribute::Height:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200511 *value = static_cast<int>(hwc_config.mode.GetRawMode().vdisplay);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200512 break;
513 case HWC2::Attribute::VsyncPeriod:
514 // in nanoseconds
Drew Davenport8053f2e2024-10-02 13:44:41 -0600515 *value = hwc_config.mode.GetVSyncPeriodNs();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200516 break;
Lucas Berthoudf686aa2024-08-28 16:15:38 +0000517 case HWC2::Attribute::DpiY:
518 // ideally this should be vdisplay/mm_heigth, however mm_height
519 // comes from edid parsing and is highly unreliable. Viewing the
520 // rarity of anisotropic displays, falling back to a single value
521 // for dpi yield more correct output.
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200522 case HWC2::Attribute::DpiX:
523 // Dots per 1000 inches
Roman Stratiienkodf3120f2022-12-07 23:10:55 +0200524 *value = mm_width ? int(hwc_config.mode.GetRawMode().hdisplay *
525 kUmPerInch / mm_width)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200526 : -1;
527 break;
Roman Stratiienko6b405052022-12-10 19:09:10 +0200528#if __ANDROID_API__ > 29
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200529 case HWC2::Attribute::ConfigGroup:
530 /* Dispite ConfigGroup is a part of HWC2.4 API, framework
531 * able to request it even if service @2.1 is used */
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200532 *value = int(hwc_config.group_id);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200533 break;
534#endif
535 default:
536 *value = -1;
537 return HWC2::Error::BadConfig;
538 }
539 return HWC2::Error::None;
540}
541
Drew Davenportf7e88332024-09-06 12:54:38 -0600542HWC2::Error HwcDisplay::LegacyGetDisplayConfigs(uint32_t *num_configs,
543 hwc2_config_t *configs) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200544 uint32_t idx = 0;
Roman Stratiienko0137f862022-01-04 18:27:40 +0200545 for (auto &hwc_config : configs_.hwc_configs) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200546 if (hwc_config.second.disabled) {
547 continue;
548 }
549
550 if (configs != nullptr) {
551 if (idx >= *num_configs) {
552 break;
553 }
554 configs[idx] = hwc_config.second.id;
555 }
556
557 idx++;
558 }
559 *num_configs = idx;
560 return HWC2::Error::None;
561}
562
563HWC2::Error HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
564 std::ostringstream stream;
Roman Stratiienko3dacd472022-01-11 19:18:34 +0200565 if (IsInHeadlessMode()) {
566 stream << "null-display";
567 } else {
568 stream << "display-" << GetPipe().connector->Get()->GetId();
569 }
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300570 auto string = stream.str();
571 auto length = string.length();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200572 if (!name) {
573 *size = length;
574 return HWC2::Error::None;
575 }
576
577 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
578 strncpy(name, string.c_str(), *size);
579 return HWC2::Error::None;
580}
581
582HWC2::Error HwcDisplay::GetDisplayRequests(int32_t * /*display_requests*/,
583 uint32_t *num_elements,
584 hwc2_layer_t * /*layers*/,
585 int32_t * /*layer_requests*/) {
586 // TODO(nobody): I think virtual display should request
587 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
588 *num_elements = 0;
589 return HWC2::Error::None;
590}
591
592HWC2::Error HwcDisplay::GetDisplayType(int32_t *type) {
593 *type = static_cast<int32_t>(type_);
594 return HWC2::Error::None;
595}
596
597HWC2::Error HwcDisplay::GetDozeSupport(int32_t *support) {
598 *support = 0;
599 return HWC2::Error::None;
600}
601
602HWC2::Error HwcDisplay::GetHdrCapabilities(uint32_t *num_types,
603 int32_t * /*types*/,
604 float * /*max_luminance*/,
605 float * /*max_average_luminance*/,
606 float * /*min_luminance*/) {
607 *num_types = 0;
608 return HWC2::Error::None;
609}
610
611/* Find API details at:
612 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1767
Roman Stratiienkodd214942022-05-03 18:24:49 +0300613 *
614 * Called after PresentDisplay(), CLIENT is expecting release fence for the
615 * prior buffer (not the one assigned to the layer at the moment).
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200616 */
617HWC2::Error HwcDisplay::GetReleaseFences(uint32_t *num_elements,
618 hwc2_layer_t *layers,
619 int32_t *fences) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200620 if (IsInHeadlessMode()) {
621 *num_elements = 0;
622 return HWC2::Error::None;
623 }
624
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200625 uint32_t num_layers = 0;
626
Roman Stratiienkodd214942022-05-03 18:24:49 +0300627 for (auto &l : layers_) {
628 if (!l.second.GetPriorBufferScanOutFlag() || !present_fence_) {
629 continue;
630 }
631
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200632 ++num_layers;
Roman Stratiienkodd214942022-05-03 18:24:49 +0300633
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200634 if (layers == nullptr || fences == nullptr)
635 continue;
636
637 if (num_layers > *num_elements) {
638 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
639 return HWC2::Error::None;
640 }
641
642 layers[num_layers - 1] = l.first;
Roman Stratiienko76892782023-01-16 17:15:53 +0200643 fences[num_layers - 1] = DupFd(present_fence_);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200644 }
645 *num_elements = num_layers;
Roman Stratiienkodd214942022-05-03 18:24:49 +0300646
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200647 return HWC2::Error::None;
648}
649
Drew Davenport97b5abc2024-11-07 10:43:54 -0700650AtomicCommitArgs HwcDisplay::CreateModesetCommit(
651 const HwcDisplayConfig *config,
652 const std::optional<LayerData> &modeset_layer) {
653 AtomicCommitArgs args{};
654
655 args.color_matrix = color_matrix_;
656 args.content_type = content_type_;
657 args.colorspace = colorspace_;
658
659 std::vector<LayerData> composition_layers;
660 if (modeset_layer) {
661 composition_layers.emplace_back(modeset_layer.value());
662 }
663
664 if (composition_layers.empty()) {
665 ALOGW("Attempting to create a modeset commit without a layer.");
666 }
667
668 args.display_mode = config->mode;
669 args.active = true;
670 args.composition = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
671 std::move(
672 composition_layers));
673 ALOGW_IF(!args.composition, "No composition for blocking modeset");
674
675 return args;
676}
677
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200678HWC2::Error HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200679 if (IsInHeadlessMode()) {
680 ALOGE("%s: Display is in headless mode, should never reach here", __func__);
681 return HWC2::Error::None;
682 }
683
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200684 a_args.color_matrix = color_matrix_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400685 a_args.content_type = content_type_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400686 a_args.colorspace = colorspace_;
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200687
Roman Stratiienkod2cc7382022-12-28 18:51:59 +0200688 uint32_t prev_vperiod_ns = 0;
689 GetDisplayVsyncPeriod(&prev_vperiod_ns);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200690
Drew Davenportd387c842024-12-16 16:57:24 -0700691 std::optional<uint32_t> new_vsync_period_ns;
Drew Davenportfe70c802024-11-07 13:02:21 -0700692 if (staged_mode_config_id_ &&
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200693 staged_mode_change_time_ <= ResourceManager::GetTimeMonotonicNs()) {
Drew Davenportfe70c802024-11-07 13:02:21 -0700694 const HwcDisplayConfig *staged_config = GetConfig(
695 staged_mode_config_id_.value());
696 if (staged_config == nullptr) {
697 return HWC2::Error::BadConfig;
698 }
Roman Stratiienko44b95772025-01-22 18:03:36 +0200699 HwcLayer::LayerProperties lp;
700 lp.display_frame = {
701 .left = 0,
702 .top = 0,
703 .right = int(staged_config->mode.GetRawMode().hdisplay),
704 .bottom = int(staged_config->mode.GetRawMode().vdisplay),
705 };
706 client_layer_.SetLayerProperties(lp);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200707
Drew Davenportfe70c802024-11-07 13:02:21 -0700708 configs_.active_config_id = staged_mode_config_id_.value();
Drew Davenportfe70c802024-11-07 13:02:21 -0700709 a_args.display_mode = staged_config->mode;
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200710 if (!a_args.test_only) {
Drew Davenportd387c842024-12-16 16:57:24 -0700711 new_vsync_period_ns = staged_config->mode.GetVSyncPeriodNs();
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200712 }
713 }
714
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200715 // order the layers by z-order
716 bool use_client_layer = false;
717 uint32_t client_z_order = UINT32_MAX;
718 std::map<uint32_t, HwcLayer *> z_map;
719 for (std::pair<const hwc2_layer_t, HwcLayer> &l : layers_) {
720 switch (l.second.GetValidatedType()) {
721 case HWC2::Composition::Device:
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300722 z_map.emplace(l.second.GetZOrder(), &l.second);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200723 break;
724 case HWC2::Composition::Client:
725 // Place it at the z_order of the lowest client layer
726 use_client_layer = true;
727 client_z_order = std::min(client_z_order, l.second.GetZOrder());
728 break;
729 default:
730 continue;
731 }
732 }
733 if (use_client_layer)
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300734 z_map.emplace(client_z_order, &client_layer_);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200735
736 if (z_map.empty())
737 return HWC2::Error::BadLayer;
738
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200739 std::vector<LayerData> composition_layers;
740
741 /* Import & populate */
742 for (std::pair<const uint32_t, HwcLayer *> &l : z_map) {
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200743 l.second->PopulateLayerData();
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200744 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200745
746 // now that they're ordered by z, add them to the composition
747 for (std::pair<const uint32_t, HwcLayer *> &l : z_map) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200748 if (!l.second->IsLayerUsableAsDevice()) {
749 /* This will be normally triggered on validation of the first frame
750 * containing CLIENT layer. At this moment client buffer is not yet
751 * provided by the CLIENT.
752 * This may be triggered once in HwcLayer lifecycle in case FB can't be
753 * imported. For example when non-contiguous buffer is imported into
754 * contiguous-only DRM/KMS driver.
755 */
756 return HWC2::Error::BadLayer;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200757 }
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200758 composition_layers.emplace_back(l.second->GetLayerData());
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200759 }
760
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200761 /* Store plan to ensure shared planes won't be stolen by other display
762 * in between of ValidateDisplay() and PresentDisplay() calls
763 */
764 current_plan_ = DrmKmsPlan::CreateDrmKmsPlan(GetPipe(),
765 std::move(composition_layers));
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300766
767 if (type_ == HWC2::DisplayType::Virtual) {
768 a_args.writeback_fb = writeback_layer_->GetLayerData().fb;
769 a_args.writeback_release_fence = writeback_layer_->GetLayerData()
770 .acquire_fence;
771 }
772
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200773 if (!current_plan_) {
Drew Davenport897a7092024-11-12 12:14:01 -0700774 ALOGE_IF(!a_args.test_only, "Failed to create DrmKmsPlan");
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200775 return HWC2::Error::BadConfig;
776 }
777
Roman Stratiienko9362cef2022-02-02 09:53:50 +0200778 a_args.composition = current_plan_;
779
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300780 auto ret = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200781
782 if (ret) {
Drew Davenport897a7092024-11-12 12:14:01 -0700783 ALOGE_IF(!a_args.test_only, "Failed to apply the frame composition ret=%d", ret);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200784 return HWC2::Error::BadParameter;
785 }
786
Drew Davenportd387c842024-12-16 16:57:24 -0700787 if (new_vsync_period_ns) {
788 vsync_worker_->SetVsyncPeriodNs(new_vsync_period_ns.value());
Drew Davenportfe70c802024-11-07 13:02:21 -0700789 staged_mode_config_id_.reset();
Drew Davenport33121b72024-12-13 14:59:35 -0700790
791 vsync_worker_->SetVsyncTimestampTracking(false);
792 uint32_t last_vsync_ts = vsync_worker_->GetLastVsyncTimestamp();
793 if (last_vsync_ts != 0) {
Drew Davenport93443182023-12-14 09:25:45 +0000794 hwc_->SendVsyncPeriodTimingChangedEventToClient(handle_,
Drew Davenport33121b72024-12-13 14:59:35 -0700795 last_vsync_ts +
Drew Davenport93443182023-12-14 09:25:45 +0000796 prev_vperiod_ns);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200797 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200798 }
799
800 return HWC2::Error::None;
801}
802
803/* Find API details at:
804 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1805
805 */
Roman Stratiienkodd214942022-05-03 18:24:49 +0300806HWC2::Error HwcDisplay::PresentDisplay(int32_t *out_present_fence) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200807 if (IsInHeadlessMode()) {
Roman Stratiienkodd214942022-05-03 18:24:49 +0300808 *out_present_fence = -1;
Roman Stratiienkof0c507f2022-01-17 18:29:24 +0200809 return HWC2::Error::None;
810 }
Roman Stratiienko780f7da2022-01-10 16:04:15 +0200811 HWC2::Error ret{};
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200812
813 ++total_stats_.total_frames_;
814
815 AtomicCommitArgs a_args{};
816 ret = CreateComposition(a_args);
817
818 if (ret != HWC2::Error::None)
819 ++total_stats_.failed_kms_present_;
820
821 if (ret == HWC2::Error::BadLayer) {
822 // Can we really have no client or device layers?
Roman Stratiienkodd214942022-05-03 18:24:49 +0300823 *out_present_fence = -1;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200824 return HWC2::Error::None;
825 }
826 if (ret != HWC2::Error::None)
827 return ret;
828
Roman Stratiienko76892782023-01-16 17:15:53 +0200829 this->present_fence_ = a_args.out_fence;
830 *out_present_fence = DupFd(a_args.out_fence);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200831
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200832 // Reset the color matrix so we don't apply it over and over again.
833 color_matrix_ = {};
834
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200835 ++frame_no_;
Drew Davenport97b5abc2024-11-07 10:43:54 -0700836
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200837 return HWC2::Error::None;
838}
839
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200840HWC2::Error HwcDisplay::SetActiveConfigInternal(uint32_t config,
841 int64_t change_time) {
842 if (configs_.hwc_configs.count(config) == 0) {
843 ALOGE("Could not find active mode for %u", config);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200844 return HWC2::Error::BadConfig;
845 }
846
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200847 staged_mode_change_time_ = change_time;
848 staged_mode_config_id_ = config;
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200849
850 return HWC2::Error::None;
851}
852
Roman Stratiienkod0c035b2022-01-21 15:12:56 +0200853HWC2::Error HwcDisplay::SetActiveConfig(hwc2_config_t config) {
854 return SetActiveConfigInternal(config, ResourceManager::GetTimeMonotonicNs());
855}
856
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200857/* Find API details at:
858 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1861
859 */
860HWC2::Error HwcDisplay::SetClientTarget(buffer_handle_t target,
861 int32_t acquire_fence,
862 int32_t dataspace,
863 hwc_region_t /*damage*/) {
Roman Stratiienko44b95772025-01-22 18:03:36 +0200864 HwcLayer::LayerProperties lp;
865 lp.buffer = {.buffer_handle = target,
866 .acquire_fence = MakeSharedFd(acquire_fence)};
867 lp.color_space = Hwc2ToColorSpace(dataspace);
868 lp.sample_range = Hwc2ToSampleRange(dataspace);
869 client_layer_.SetLayerProperties(lp);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200870
871 /*
872 * target can be nullptr, this does mean the Composer Service is calling
873 * cleanDisplayResources() on after receiving HOTPLUG event. See more at:
874 * https://cs.android.com/android/platform/superproject/+/master:hardware/interfaces/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerClient.h;l=350;drc=944b68180b008456ed2eb4d4d329e33b19bd5166
875 */
876 if (target == nullptr) {
Roman Stratiienkoa32f9072022-05-13 12:12:20 +0300877 client_layer_.SwChainClearCache();
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200878 return HWC2::Error::None;
879 }
880
Roman Stratiienko5070d512022-05-30 13:41:20 +0300881 if (IsInHeadlessMode()) {
882 return HWC2::Error::None;
883 }
884
Roman Stratiienko359a9d32023-01-16 17:41:07 +0200885 client_layer_.PopulateLayerData();
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200886 if (!client_layer_.IsLayerUsableAsDevice()) {
887 ALOGE("Client layer must be always usable by DRM/KMS");
888 return HWC2::Error::BadLayer;
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +0200889 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200890
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200891 auto &bi = client_layer_.GetLayerData().bi;
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300892 if (!bi) {
893 ALOGE("%s: Invalid state", __func__);
894 return HWC2::Error::BadLayer;
895 }
896
Roman Stratiienko44b95772025-01-22 18:03:36 +0200897 lp = {};
898 lp.source_crop = {.left = 0.0F,
899 .top = 0.0F,
900 .right = float(bi->width),
901 .bottom = float(bi->height)};
902 client_layer_.SetLayerProperties(lp);
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200903
904 return HWC2::Error::None;
905}
906
907HWC2::Error HwcDisplay::SetColorMode(int32_t mode) {
Sasha McIntosh5294f092024-09-18 18:14:54 -0400908 /* Maps to the Colorspace DRM connector property:
909 * https://elixir.bootlin.com/linux/v6.11/source/include/drm/drm_connector.h#L538
910 */
911 if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_DISPLAY_P3)
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200912 return HWC2::Error::BadParameter;
913
Sasha McIntosh5294f092024-09-18 18:14:54 -0400914 switch (mode) {
915 case HAL_COLOR_MODE_NATIVE:
916 colorspace_ = Colorspace::kDefault;
917 break;
918 case HAL_COLOR_MODE_STANDARD_BT601_625:
919 case HAL_COLOR_MODE_STANDARD_BT601_625_UNADJUSTED:
920 case HAL_COLOR_MODE_STANDARD_BT601_525:
921 case HAL_COLOR_MODE_STANDARD_BT601_525_UNADJUSTED:
922 // The DP spec does not say whether this is the 525 or the 625 line version.
923 colorspace_ = Colorspace::kBt601Ycc;
924 break;
925 case HAL_COLOR_MODE_STANDARD_BT709:
926 case HAL_COLOR_MODE_SRGB:
927 colorspace_ = Colorspace::kBt709Ycc;
928 break;
929 case HAL_COLOR_MODE_DCI_P3:
930 case HAL_COLOR_MODE_DISPLAY_P3:
931 colorspace_ = Colorspace::kDciP3RgbD65;
932 break;
933 case HAL_COLOR_MODE_ADOBE_RGB:
934 default:
935 return HWC2::Error::Unsupported;
936 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200937
938 color_mode_ = mode;
939 return HWC2::Error::None;
940}
941
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200942#include <xf86drmMode.h>
943
Sasha McIntosh921c1cd2024-10-09 19:50:52 -0400944static uint64_t To3132FixPt(float in) {
945 constexpr uint64_t kSignMask = (1ULL << 63);
946 constexpr uint64_t kValueMask = ~(1ULL << 63);
947 constexpr auto kValueScale = static_cast<float>(1ULL << 32);
948 if (in < 0)
949 return (static_cast<uint64_t>(-in * kValueScale) & kValueMask) | kSignMask;
950 return static_cast<uint64_t>(in * kValueScale) & kValueMask;
951}
952
Roman Stratiienko3627beb2022-01-04 16:02:55 +0200953HWC2::Error HwcDisplay::SetColorTransform(const float *matrix, int32_t hint) {
954 if (hint < HAL_COLOR_TRANSFORM_IDENTITY ||
955 hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA)
956 return HWC2::Error::BadParameter;
957
958 if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX)
959 return HWC2::Error::BadParameter;
960
961 color_transform_hint_ = static_cast<android_color_transform_t>(hint);
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200962
Roman Stratiienko5de61b52023-02-01 16:29:45 +0200963 if (IsInHeadlessMode())
964 return HWC2::Error::None;
965
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200966 if (!GetPipe().crtc->Get()->GetCtmProperty())
967 return HWC2::Error::None;
968
969 switch (color_transform_hint_) {
970 case HAL_COLOR_TRANSFORM_IDENTITY:
Sasha McIntosha37df7c2024-09-20 12:31:08 -0400971 SetColorMatrixToIdentity();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +0200972 break;
973 case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX:
Sasha McIntosh921c1cd2024-10-09 19:50:52 -0400974 // Without HW support, we cannot correctly process matrices with an offset.
975 for (int i = 12; i < 14; i++) {
976 if (matrix[i] != 0.F)
977 return HWC2::Error::Unsupported;
978 }
979
980 /* HAL provides a 4x4 float type matrix:
981 * | 0 1 2 3|
982 * | 4 5 6 7|
983 * | 8 9 10 11|
984 * |12 13 14 15|
985 *
986 * R_out = R*0 + G*4 + B*8 + 12
987 * G_out = R*1 + G*5 + B*9 + 13
988 * B_out = R*2 + G*6 + B*10 + 14
989 *
990 * DRM expects a 3x3 s31.32 fixed point matrix:
991 * out matrix in
992 * |R| |0 1 2| |R|
993 * |G| = |3 4 5| x |G|
994 * |B| |6 7 8| |B|
995 *
996 * R_out = R*0 + G*1 + B*2
997 * G_out = R*3 + G*4 + B*5
998 * B_out = R*6 + G*7 + B*8
999 */
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001000 color_matrix_ = std::make_shared<drm_color_ctm>();
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001001 for (int i = 0; i < kCtmCols; i++) {
1002 for (int j = 0; j < kCtmRows; j++) {
1003 constexpr int kInCtmRows = 4;
Sasha McIntosh921c1cd2024-10-09 19:50:52 -04001004 color_matrix_->matrix[i * kCtmRows + j] = To3132FixPt(matrix[j * kInCtmRows + i]);
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001005 }
1006 }
1007 break;
1008 default:
1009 return HWC2::Error::Unsupported;
1010 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001011
1012 return HWC2::Error::None;
1013}
1014
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001015bool HwcDisplay::CtmByGpu() {
1016 if (color_transform_hint_ == HAL_COLOR_TRANSFORM_IDENTITY)
1017 return false;
1018
1019 if (GetPipe().crtc->Get()->GetCtmProperty())
1020 return false;
1021
Drew Davenport93443182023-12-14 09:25:45 +00001022 if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore)
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001023 return false;
1024
1025 return true;
1026}
1027
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001028HWC2::Error HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
1029 int32_t release_fence) {
Roman Stratiienko44b95772025-01-22 18:03:36 +02001030 HwcLayer::LayerProperties lp;
1031 lp.buffer = {.buffer_handle = buffer,
1032 .acquire_fence = MakeSharedFd(release_fence)};
1033 writeback_layer_->SetLayerProperties(lp);
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001034 writeback_layer_->PopulateLayerData();
1035 if (!writeback_layer_->IsLayerUsableAsDevice()) {
1036 ALOGE("Output layer must be always usable by DRM/KMS");
1037 return HWC2::Error::BadLayer;
1038 }
1039 /* TODO: Check if format is supported by writeback connector */
1040 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001041}
1042
1043HWC2::Error HwcDisplay::SetPowerMode(int32_t mode_in) {
1044 auto mode = static_cast<HWC2::PowerMode>(mode_in);
Roman Stratiienkoccaf5162022-04-01 19:26:30 +03001045
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001046 AtomicCommitArgs a_args{};
1047
1048 switch (mode) {
1049 case HWC2::PowerMode::Off:
1050 a_args.active = false;
1051 break;
1052 case HWC2::PowerMode::On:
Roman Stratiienkoccaf5162022-04-01 19:26:30 +03001053 a_args.active = true;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001054 break;
1055 case HWC2::PowerMode::Doze:
1056 case HWC2::PowerMode::DozeSuspend:
1057 return HWC2::Error::Unsupported;
1058 default:
John Stultzffe783c2024-02-14 10:51:27 -08001059 ALOGE("Incorrect power mode value (%d)\n", mode_in);
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001060 return HWC2::Error::BadParameter;
Roman Stratiienkoccaf5162022-04-01 19:26:30 +03001061 }
1062
1063 if (IsInHeadlessMode()) {
1064 return HWC2::Error::None;
1065 }
1066
Jia Ren80566fe2022-11-17 17:26:00 +08001067 if (a_args.active && *a_args.active) {
Roman Stratiienkoccaf5162022-04-01 19:26:30 +03001068 /*
1069 * Setting the display to active before we have a composition
1070 * can break some drivers, so skip setting a_args.active to
1071 * true, as the next composition frame will implicitly activate
1072 * the display
1073 */
1074 return GetPipe().atomic_state_manager->ActivateDisplayUsingDPMS() == 0
1075 ? HWC2::Error::None
1076 : HWC2::Error::BadParameter;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001077 };
1078
Roman Stratiienkoa7913de2022-10-20 13:18:57 +03001079 auto err = GetPipe().atomic_state_manager->ExecuteAtomicCommit(a_args);
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001080 if (err) {
1081 ALOGE("Failed to apply the dpms composition err=%d", err);
1082 return HWC2::Error::BadParameter;
1083 }
1084 return HWC2::Error::None;
1085}
1086
1087HWC2::Error HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001088 if (type_ == HWC2::DisplayType::Virtual) {
1089 return HWC2::Error::None;
1090 }
Lucas Berthoua2928992025-01-07 22:48:28 +00001091 if (!vsync_worker_) {
1092 return HWC2::Error::NoResources;
1093 }
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001094
Roman Stratiienko099c3112022-01-20 11:50:54 +02001095 vsync_event_en_ = HWC2_VSYNC_ENABLE == enabled;
Lucas Berthoua2928992025-01-07 22:48:28 +00001096 std::optional<VSyncWorker::VsyncTimestampCallback> callback = std::nullopt;
Roman Stratiienko099c3112022-01-20 11:50:54 +02001097 if (vsync_event_en_) {
Drew Davenport63a699e2024-12-13 15:00:00 -07001098 DrmHwc *hwc = hwc_;
1099 hwc2_display_t id = handle_;
1100 // Callback will be called from the vsync thread.
Lucas Berthoua2928992025-01-07 22:48:28 +00001101 callback = [hwc, id](int64_t timestamp, uint32_t period_ns) {
Drew Davenport63a699e2024-12-13 15:00:00 -07001102 hwc->SendVsyncEventToClient(id, timestamp, period_ns);
1103 };
Roman Stratiienko099c3112022-01-20 11:50:54 +02001104 }
Lucas Berthoua2928992025-01-07 22:48:28 +00001105 vsync_worker_->SetTimestampCallback(std::move(callback));
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001106 return HWC2::Error::None;
1107}
1108
1109HWC2::Error HwcDisplay::ValidateDisplay(uint32_t *num_types,
1110 uint32_t *num_requests) {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +02001111 if (IsInHeadlessMode()) {
1112 *num_types = *num_requests = 0;
1113 return HWC2::Error::None;
1114 }
Roman Stratiienkodd214942022-05-03 18:24:49 +03001115
1116 /* In current drm_hwc design in case previous frame layer was not validated as
1117 * a CLIENT, it is used by display controller (Front buffer). We have to store
1118 * this state to provide the CLIENT with the release fences for such buffers.
1119 */
1120 for (auto &l : layers_) {
1121 l.second.SetPriorBufferScanOutFlag(l.second.GetValidatedType() !=
1122 HWC2::Composition::Client);
1123 }
1124
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001125 return backend_->ValidateDisplay(this, num_types, num_requests);
1126}
1127
1128std::vector<HwcLayer *> HwcDisplay::GetOrderLayersByZPos() {
1129 std::vector<HwcLayer *> ordered_layers;
1130 ordered_layers.reserve(layers_.size());
1131
1132 for (auto &[handle, layer] : layers_) {
1133 ordered_layers.emplace_back(&layer);
1134 }
1135
1136 std::sort(std::begin(ordered_layers), std::end(ordered_layers),
1137 [](const HwcLayer *lhs, const HwcLayer *rhs) {
1138 return lhs->GetZOrder() < rhs->GetZOrder();
1139 });
1140
1141 return ordered_layers;
1142}
1143
Roman Stratiienko099c3112022-01-20 11:50:54 +02001144HWC2::Error HwcDisplay::GetDisplayVsyncPeriod(
1145 uint32_t *outVsyncPeriod /* ns */) {
1146 return GetDisplayAttribute(configs_.active_config_id,
1147 HWC2_ATTRIBUTE_VSYNC_PERIOD,
1148 (int32_t *)(outVsyncPeriod));
1149}
1150
Roman Stratiienko6b405052022-12-10 19:09:10 +02001151#if __ANDROID_API__ > 29
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001152HWC2::Error HwcDisplay::GetDisplayConnectionType(uint32_t *outType) {
Roman Stratiienko456e2d62022-01-29 01:17:39 +02001153 if (IsInHeadlessMode()) {
1154 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
1155 return HWC2::Error::None;
1156 }
1157 /* Primary display should be always internal,
1158 * otherwise SF will be unhappy and will crash
1159 */
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001160 if (GetPipe().connector->Get()->IsInternal() || handle_ == kPrimaryDisplay)
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001161 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001162 else if (GetPipe().connector->Get()->IsExternal())
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001163 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External);
1164 else
1165 return HWC2::Error::BadConfig;
1166
1167 return HWC2::Error::None;
1168}
1169
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001170HWC2::Error HwcDisplay::SetActiveConfigWithConstraints(
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001171 hwc2_config_t config,
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001172 hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints,
1173 hwc_vsync_period_change_timeline_t *outTimeline) {
Roman Stratiienkof2c060f2023-09-18 22:46:08 +03001174 if (type_ == HWC2::DisplayType::Virtual) {
1175 return HWC2::Error::None;
1176 }
1177
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001178 if (vsyncPeriodChangeConstraints == nullptr || outTimeline == nullptr) {
1179 return HWC2::Error::BadParameter;
1180 }
1181
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001182 uint32_t current_vsync_period{};
1183 GetDisplayVsyncPeriod(&current_vsync_period);
1184
1185 if (vsyncPeriodChangeConstraints->seamlessRequired) {
1186 return HWC2::Error::SeamlessNotAllowed;
1187 }
1188
1189 outTimeline->refreshTimeNanos = vsyncPeriodChangeConstraints
1190 ->desiredTimeNanos -
1191 current_vsync_period;
1192 auto ret = SetActiveConfigInternal(config, outTimeline->refreshTimeNanos);
1193 if (ret != HWC2::Error::None) {
1194 return ret;
1195 }
1196
1197 outTimeline->refreshRequired = true;
1198 outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeConstraints
1199 ->desiredTimeNanos;
1200
Drew Davenport33121b72024-12-13 14:59:35 -07001201 vsync_worker_->SetVsyncTimestampTracking(true);
Roman Stratiienkod0c035b2022-01-21 15:12:56 +02001202
1203 return HWC2::Error::None;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001204}
1205
1206HWC2::Error HwcDisplay::SetAutoLowLatencyMode(bool /*on*/) {
1207 return HWC2::Error::Unsupported;
1208}
1209
1210HWC2::Error HwcDisplay::GetSupportedContentTypes(
1211 uint32_t *outNumSupportedContentTypes,
1212 const uint32_t *outSupportedContentTypes) {
1213 if (outSupportedContentTypes == nullptr)
1214 *outNumSupportedContentTypes = 0;
1215
1216 return HWC2::Error::None;
1217}
1218
1219HWC2::Error HwcDisplay::SetContentType(int32_t contentType) {
Sasha McIntosh173247b2024-09-18 18:06:52 -04001220 /* Maps exactly to the content_type DRM connector property:
1221 * https://elixir.bootlin.com/linux/v6.11/source/include/uapi/drm/drm_mode.h#L107
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001222 */
Sasha McIntosh173247b2024-09-18 18:06:52 -04001223 if (contentType < HWC2_CONTENT_TYPE_NONE || contentType > HWC2_CONTENT_TYPE_GAME)
1224 return HWC2::Error::BadParameter;
1225
1226 content_type_ = contentType;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001227
1228 return HWC2::Error::None;
1229}
1230#endif
1231
Roman Stratiienko6b405052022-12-10 19:09:10 +02001232#if __ANDROID_API__ > 28
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001233HWC2::Error HwcDisplay::GetDisplayIdentificationData(uint8_t *outPort,
1234 uint32_t *outDataSize,
1235 uint8_t *outData) {
Roman Stratiienko3dacd472022-01-11 19:18:34 +02001236 if (IsInHeadlessMode()) {
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001237 return HWC2::Error::Unsupported;
Roman Stratiienko3dacd472022-01-11 19:18:34 +02001238 }
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001239
Roman Stratiienko19c162f2022-02-01 09:35:08 +02001240 auto blob = GetPipe().connector->Get()->GetEdidBlob();
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001241 if (!blob) {
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001242 return HWC2::Error::Unsupported;
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001243 }
1244
Roman Stratiienkof87d8082022-05-06 11:33:56 +03001245 *outPort = handle_; /* TDOD(nobody): What should be here? */
1246
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001247 if (outData) {
1248 *outDataSize = std::min(*outDataSize, blob->length);
1249 memcpy(outData, blob->data, *outDataSize);
1250 } else {
1251 *outDataSize = blob->length;
1252 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001253
1254 return HWC2::Error::None;
1255}
1256
1257HWC2::Error HwcDisplay::GetDisplayCapabilities(uint32_t *outNumCapabilities,
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001258 uint32_t *outCapabilities) {
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001259 if (outNumCapabilities == nullptr) {
1260 return HWC2::Error::BadParameter;
1261 }
1262
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001263 bool skip_ctm = false;
1264
1265 // Skip client CTM if user requested DRM_OR_IGNORE
Drew Davenport93443182023-12-14 09:25:45 +00001266 if (GetHwc()->GetResMan().GetCtmHandling() == CtmHandling::kDrmOrIgnore)
Roman Stratiienko0da91bf2023-01-17 18:06:04 +02001267 skip_ctm = true;
1268
1269 // Skip client CTM if DRM can handle it
1270 if (!skip_ctm && !IsInHeadlessMode() &&
1271 GetPipe().crtc->Get()->GetCtmProperty())
1272 skip_ctm = true;
1273
1274 if (!skip_ctm) {
1275 *outNumCapabilities = 0;
1276 return HWC2::Error::None;
1277 }
1278
1279 *outNumCapabilities = 1;
1280 if (outCapabilities) {
1281 outCapabilities[0] = HWC2_DISPLAY_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM;
1282 }
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001283
1284 return HWC2::Error::None;
1285}
1286
1287HWC2::Error HwcDisplay::GetDisplayBrightnessSupport(bool *supported) {
1288 *supported = false;
1289 return HWC2::Error::None;
1290}
1291
1292HWC2::Error HwcDisplay::SetDisplayBrightness(float /* brightness */) {
1293 return HWC2::Error::Unsupported;
1294}
1295
Roman Stratiienko6b405052022-12-10 19:09:10 +02001296#endif /* __ANDROID_API__ > 28 */
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001297
Roman Stratiienko6b405052022-12-10 19:09:10 +02001298#if __ANDROID_API__ > 27
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001299
1300HWC2::Error HwcDisplay::GetRenderIntents(
1301 int32_t mode, uint32_t *outNumIntents,
1302 int32_t * /*android_render_intent_v1_1_t*/ outIntents) {
1303 if (mode != HAL_COLOR_MODE_NATIVE) {
1304 return HWC2::Error::BadParameter;
1305 }
1306
1307 if (outIntents == nullptr) {
1308 *outNumIntents = 1;
1309 return HWC2::Error::None;
1310 }
1311 *outNumIntents = 1;
1312 outIntents[0] = HAL_RENDER_INTENT_COLORIMETRIC;
1313 return HWC2::Error::None;
1314}
1315
1316HWC2::Error HwcDisplay::SetColorModeWithIntent(int32_t mode, int32_t intent) {
1317 if (intent < HAL_RENDER_INTENT_COLORIMETRIC ||
1318 intent > HAL_RENDER_INTENT_TONE_MAP_ENHANCE)
1319 return HWC2::Error::BadParameter;
1320
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001321 if (intent != HAL_RENDER_INTENT_COLORIMETRIC)
1322 return HWC2::Error::Unsupported;
1323
Sasha McIntosh5294f092024-09-18 18:14:54 -04001324 auto err = SetColorMode(mode);
1325 if (err != HWC2::Error::None) return err;
1326
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001327 return HWC2::Error::None;
1328}
1329
Roman Stratiienko6b405052022-12-10 19:09:10 +02001330#endif /* __ANDROID_API__ > 27 */
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001331
1332const Backend *HwcDisplay::backend() const {
1333 return backend_.get();
1334}
1335
1336void HwcDisplay::set_backend(std::unique_ptr<Backend> backend) {
1337 backend_ = std::move(backend);
1338}
1339
Roman Stratiienko3627beb2022-01-04 16:02:55 +02001340} // namespace android