blob: b7e20f0e3d3f345928694a0c338caca1fd357946 [file] [log] [blame]
Sean Pauled2ec4b2016-03-10 15:35:40 -05001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18#define LOG_TAG "hwc-drm-two"
19
Roman Stratiienko13cc3662020-08-29 21:35:39 +030020#include "DrmHwcTwo.h"
Sean Pauled2ec4b2016-03-10 15:35:40 -050021
Roman Stratiienko0fade372021-02-20 13:59:55 +020022#include <fcntl.h>
Sean Paulac874152016-03-10 16:00:26 -050023#include <hardware/hardware.h>
Sean Pauled2ec4b2016-03-10 15:35:40 -050024#include <hardware/hwcomposer2.h>
Roman Stratiienko74774712021-02-05 16:32:47 +020025#include <sync/sync.h>
Roman Stratiienko0fade372021-02-20 13:59:55 +020026#include <unistd.h>
Sean Pauled2ec4b2016-03-10 15:35:40 -050027
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020028#include <cinttypes>
Roman Stratiienkod21071f2021-03-09 21:56:50 +020029#include <iostream>
30#include <sstream>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030031#include <string>
32
Roman Stratiienko13cc3662020-08-29 21:35:39 +030033#include "backend/BackendManager.h"
Roman Stratiienko33365c22020-10-10 23:06:36 +030034#include "bufferinfo/BufferInfoGetter.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030035#include "compositor/DrmDisplayComposition.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020036#include "utils/log.h"
37#include "utils/properties.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030038
Sean Pauled2ec4b2016-03-10 15:35:40 -050039namespace android {
40
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020041DrmHwcTwo::DrmHwcTwo() : hwc2_device() {
Sean Paulac874152016-03-10 16:00:26 -050042 common.tag = HARDWARE_DEVICE_TAG;
43 common.version = HWC_DEVICE_API_VERSION_2_0;
Sean Pauled2ec4b2016-03-10 15:35:40 -050044 common.close = HookDevClose;
45 getCapabilities = HookDevGetCapabilities;
46 getFunction = HookDevGetFunction;
47}
48
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030049HWC2::Error DrmHwcTwo::CreateDisplay(hwc2_display_t displ,
50 HWC2::DisplayType type) {
Roman Stratiienkod26619b2021-08-04 19:55:37 +030051 DrmDevice *drm = resource_manager_.GetDrmDevice(static_cast<int>(displ));
Roman Stratiienko8666dc92021-02-09 17:49:55 +020052 if (!drm) {
53 ALOGE("Failed to get a valid drmresource");
Sean Paulac874152016-03-10 16:00:26 -050054 return HWC2::Error::NoResources;
55 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030056 displays_.emplace(std::piecewise_construct, std::forward_as_tuple(displ),
Roman Stratiienko863a3c22021-09-29 13:00:29 +030057 std::forward_as_tuple(&resource_manager_, drm, displ, type,
58 this));
Sean Paulac874152016-03-10 16:00:26 -050059
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030060 DrmCrtc *crtc = drm->GetCrtcForDisplay(static_cast<int>(displ));
Sean Paulac874152016-03-10 16:00:26 -050061 if (!crtc) {
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030062 ALOGE("Failed to get crtc for display %d", static_cast<int>(displ));
Sean Paulac874152016-03-10 16:00:26 -050063 return HWC2::Error::BadDisplay;
64 }
Roman Stratiienkod21071f2021-03-09 21:56:50 +020065 auto display_planes = std::vector<DrmPlane *>();
66 for (const auto &plane : drm->planes()) {
Sean Paulac874152016-03-10 16:00:26 -050067 if (plane->GetCrtcSupported(*crtc))
68 display_planes.push_back(plane.get());
69 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030070 displays_.at(displ).Init(&display_planes);
Sean Paulac874152016-03-10 16:00:26 -050071 return HWC2::Error::None;
72}
73
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030074HWC2::Error DrmHwcTwo::Init() {
75 int rv = resource_manager_.Init();
76 if (rv) {
77 ALOGE("Can't initialize the resource manager %d", rv);
78 return HWC2::Error::NoResources;
79 }
80
81 HWC2::Error ret = HWC2::Error::None;
82 for (int i = 0; i < resource_manager_.getDisplayCount(); i++) {
83 ret = CreateDisplay(i, HWC2::DisplayType::Physical);
84 if (ret != HWC2::Error::None) {
85 ALOGE("Failed to create display %d with error %d", i, ret);
86 return ret;
87 }
88 }
89
Roman Stratiienkod21071f2021-03-09 21:56:50 +020090 const auto &drm_devices = resource_manager_.getDrmDevices();
91 for (const auto &device : drm_devices) {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020092 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030093 device->RegisterHotplugHandler(new DrmHotplugHandler(this, device.get()));
94 }
95 return ret;
96}
97
Sean Pauled2ec4b2016-03-10 15:35:40 -050098template <typename... Args>
99static inline HWC2::Error unsupported(char const *func, Args... /*args*/) {
100 ALOGV("Unsupported function: %s", func);
101 return HWC2::Error::Unsupported;
102}
103
Sean Paulac874152016-03-10 16:00:26 -0500104static inline void supported(char const *func) {
105 ALOGV("Supported function: %s", func);
106}
107
Sean Pauled2ec4b2016-03-10 15:35:40 -0500108HWC2::Error DrmHwcTwo::CreateVirtualDisplay(uint32_t width, uint32_t height,
109 int32_t *format,
110 hwc2_display_t *display) {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200111 // TODO(nobody): Implement virtual display
Sean Paulac874152016-03-10 16:00:26 -0500112 return unsupported(__func__, width, height, format, display);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500113}
114
115HWC2::Error DrmHwcTwo::DestroyVirtualDisplay(hwc2_display_t display) {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200116 // TODO(nobody): Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500117 return unsupported(__func__, display);
118}
119
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200120std::string DrmHwcTwo::HwcDisplay::DumpDelta(
121 DrmHwcTwo::HwcDisplay::Stats delta) {
122 if (delta.total_pixops_ == 0)
123 return "No stats yet";
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200124 double ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200125
Roman Stratiienkod21071f2021-03-09 21:56:50 +0200126 std::stringstream ss;
127 ss << " Total frames count: " << delta.total_frames_ << "\n"
128 << " Failed to test commit frames: " << delta.failed_kms_validate_ << "\n"
129 << " Failed to commit frames: " << delta.failed_kms_present_ << "\n"
130 << ((delta.failed_kms_present_ > 0)
131 ? " !!! Internal failure, FIX it please\n"
132 : "")
133 << " Flattened frames: " << delta.frames_flattened_ << "\n"
134 << " Pixel operations (free units)"
135 << " : [TOTAL: " << delta.total_pixops_ << " / GPU: " << delta.gpu_pixops_
136 << "]\n"
137 << " Composition efficiency: " << ratio;
138
139 return ss.str();
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200140}
141
142std::string DrmHwcTwo::HwcDisplay::Dump() {
Roman Stratiienkod21071f2021-03-09 21:56:50 +0200143 std::stringstream ss;
144 ss << "- Display on: " << connector_->name() << "\n"
145 << " Flattening state: " << compositor_.GetFlatteningState() << "\n"
146 << "Statistics since system boot:\n"
147 << DumpDelta(total_stats_) << "\n\n"
148 << "Statistics since last dumpsys request:\n"
149 << DumpDelta(total_stats_.minus(prev_stats_)) << "\n\n";
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200150
151 memcpy(&prev_stats_, &total_stats_, sizeof(Stats));
Roman Stratiienkod21071f2021-03-09 21:56:50 +0200152 return ss.str();
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200153}
154
155void DrmHwcTwo::Dump(uint32_t *outSize, char *outBuffer) {
156 supported(__func__);
157
158 if (outBuffer != nullptr) {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200159 auto copied_bytes = mDumpString.copy(outBuffer, *outSize);
160 *outSize = static_cast<uint32_t>(copied_bytes);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200161 return;
162 }
163
164 std::stringstream output;
165
166 output << "-- drm_hwcomposer --\n\n";
167
168 for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &dp : displays_)
169 output << dp.second.Dump();
170
171 mDumpString = output.str();
172 *outSize = static_cast<uint32_t>(mDumpString.size());
Sean Pauled2ec4b2016-03-10 15:35:40 -0500173}
174
175uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200176 // TODO(nobody): Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500177 unsupported(__func__);
178 return 0;
179}
180
181HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor,
Sean Paulac874152016-03-10 16:00:26 -0500182 hwc2_callback_data_t data,
183 hwc2_function_pointer_t function) {
184 supported(__func__);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300185
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300186 std::unique_lock<std::mutex> lock(callback_lock_);
187
Roman Stratiienko23701092020-09-26 02:08:41 +0300188 switch (static_cast<HWC2::Callback>(descriptor)) {
Sean Paulac874152016-03-10 16:00:26 -0500189 case HWC2::Callback::Hotplug: {
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300190 hotplug_callback_ = std::make_pair(HWC2_PFN_HOTPLUG(function), data);
191 lock.unlock();
Roman Stratiienkod21071f2021-03-09 21:56:50 +0200192 const auto &drm_devices = resource_manager_.getDrmDevices();
193 for (const auto &device : drm_devices)
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300194 HandleInitialHotplugState(device.get());
Sean Paulac874152016-03-10 16:00:26 -0500195 break;
196 }
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +0200197 case HWC2::Callback::Refresh: {
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300198 refresh_callback_ = std::make_pair(HWC2_PFN_REFRESH(function), data);
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +0200199 break;
200 }
Sean Paulac874152016-03-10 16:00:26 -0500201 case HWC2::Callback::Vsync: {
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300202 vsync_callback_ = std::make_pair(HWC2_PFN_VSYNC(function), data);
Sean Paulac874152016-03-10 16:00:26 -0500203 break;
204 }
205 default:
206 break;
207 }
208 return HWC2::Error::None;
209}
210
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100211DrmHwcTwo::HwcDisplay::HwcDisplay(ResourceManager *resource_manager,
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200212 DrmDevice *drm, hwc2_display_t handle,
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300213 HWC2::DisplayType type, DrmHwcTwo *hwc2)
214 : hwc2_(hwc2),
215 resource_manager_(resource_manager),
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100216 drm_(drm),
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100217 handle_(handle),
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200218 type_(type),
219 color_transform_hint_(HAL_COLOR_TRANSFORM_IDENTITY) {
Sean Paulac874152016-03-10 16:00:26 -0500220 supported(__func__);
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200221
222 // clang-format off
223 color_transform_matrix_ = {1.0, 0.0, 0.0, 0.0,
224 0.0, 1.0, 0.0, 0.0,
225 0.0, 0.0, 1.0, 0.0,
226 0.0, 0.0, 0.0, 1.0};
227 // clang-format on
Sean Paulac874152016-03-10 16:00:26 -0500228}
229
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300230void DrmHwcTwo::HwcDisplay::ClearDisplay() {
231 compositor_.ClearDisplay();
232}
233
Sean Paulac874152016-03-10 16:00:26 -0500234HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) {
235 supported(__func__);
236 planner_ = Planner::CreateInstance(drm_);
237 if (!planner_) {
238 ALOGE("Failed to create planner instance for composition");
239 return HWC2::Error::NoResources;
240 }
241
242 int display = static_cast<int>(handle_);
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300243 int ret = compositor_.Init(resource_manager_, display, [this] {
244 /* refresh callback */
245 const std::lock_guard<std::mutex> lock(hwc2_->callback_lock_);
246 if (hwc2_->refresh_callback_.first != nullptr &&
247 hwc2_->refresh_callback_.second != nullptr) {
248 hwc2_->refresh_callback_.first(hwc2_->refresh_callback_.second, handle_);
249 }
250 });
Sean Paulac874152016-03-10 16:00:26 -0500251 if (ret) {
252 ALOGE("Failed display compositor init for display %d (%d)", display, ret);
253 return HWC2::Error::NoResources;
254 }
255
256 // Split up the given display planes into primary and overlay to properly
257 // interface with the composition
258 char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
Jason Macnakf1af9572020-08-20 11:49:51 -0700259 property_get("vendor.hwc.drm.use_overlay_planes", use_overlay_planes_prop,
260 "1");
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200261 bool use_overlay_planes = strtol(use_overlay_planes_prop, nullptr, 10);
Sean Paulac874152016-03-10 16:00:26 -0500262 for (auto &plane : *planes) {
263 if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
264 primary_planes_.push_back(plane);
265 else if (use_overlay_planes && (plane)->type() == DRM_PLANE_TYPE_OVERLAY)
266 overlay_planes_.push_back(plane);
267 }
268
269 crtc_ = drm_->GetCrtcForDisplay(display);
270 if (!crtc_) {
271 ALOGE("Failed to get crtc for display %d", display);
272 return HWC2::Error::BadDisplay;
273 }
274
275 connector_ = drm_->GetConnectorForDisplay(display);
276 if (!connector_) {
277 ALOGE("Failed to get connector for display %d", display);
278 return HWC2::Error::BadDisplay;
279 }
280
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300281 ret = vsync_worker_.Init(drm_, display, [this](int64_t timestamp) {
282 /* vsync callback */
283 const std::lock_guard<std::mutex> lock(hwc2_->callback_lock_);
284 if (hwc2_->vsync_callback_.first != nullptr &&
285 hwc2_->vsync_callback_.second != nullptr) {
286 hwc2_->vsync_callback_.first(hwc2_->vsync_callback_.second, handle_,
287 timestamp);
288 }
289 });
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300290 if (ret) {
291 ALOGE("Failed to create event worker for d=%d %d\n", display, ret);
292 return HWC2::Error::BadDisplay;
293 }
294
Matvii Zorinef3c7972020-08-11 15:15:44 +0300295 ret = BackendManager::GetInstance().SetBackendForDisplay(this);
296 if (ret) {
297 ALOGE("Failed to set backend for d=%d %d\n", display, ret);
298 return HWC2::Error::BadDisplay;
299 }
300
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300301 return ChosePreferredConfig();
302}
303
304HWC2::Error DrmHwcTwo::HwcDisplay::ChosePreferredConfig() {
Sean Paulac874152016-03-10 16:00:26 -0500305 // Fetch the number of modes from the display
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200306 uint32_t num_configs = 0;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200307 HWC2::Error err = GetDisplayConfigs(&num_configs, nullptr);
Sean Paulac874152016-03-10 16:00:26 -0500308 if (err != HWC2::Error::None || !num_configs)
309 return err;
310
Andrii Chepurnyi1b1e35e2019-02-19 21:38:13 +0200311 return SetActiveConfig(connector_->get_preferred_mode_id());
Sean Paulac874152016-03-10 16:00:26 -0500312}
313
Sean Pauled2ec4b2016-03-10 15:35:40 -0500314HWC2::Error DrmHwcTwo::HwcDisplay::AcceptDisplayChanges() {
Sean Paulac874152016-03-10 16:00:26 -0500315 supported(__func__);
Sean Paulac874152016-03-10 16:00:26 -0500316 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_)
317 l.second.accept_type_change();
318 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500319}
320
321HWC2::Error DrmHwcTwo::HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Sean Paulac874152016-03-10 16:00:26 -0500322 supported(__func__);
323 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer());
324 *layer = static_cast<hwc2_layer_t>(layer_idx_);
325 ++layer_idx_;
326 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500327}
328
329HWC2::Error DrmHwcTwo::HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Sean Paulac874152016-03-10 16:00:26 -0500330 supported(__func__);
Vincent Donnefort9abec032019-10-09 15:43:43 +0100331 if (!get_layer(layer))
332 return HWC2::Error::BadLayer;
333
Sean Paulac874152016-03-10 16:00:26 -0500334 layers_.erase(layer);
335 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500336}
337
338HWC2::Error DrmHwcTwo::HwcDisplay::GetActiveConfig(hwc2_config_t *config) {
Sean Paulac874152016-03-10 16:00:26 -0500339 supported(__func__);
340 DrmMode const &mode = connector_->active_mode();
341 if (mode.id() == 0)
342 return HWC2::Error::BadConfig;
343
344 *config = mode.id();
345 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500346}
347
348HWC2::Error DrmHwcTwo::HwcDisplay::GetChangedCompositionTypes(
349 uint32_t *num_elements, hwc2_layer_t *layers, int32_t *types) {
Sean Paulac874152016-03-10 16:00:26 -0500350 supported(__func__);
351 uint32_t num_changes = 0;
352 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
353 if (l.second.type_changed()) {
354 if (layers && num_changes < *num_elements)
355 layers[num_changes] = l.first;
356 if (types && num_changes < *num_elements)
357 types[num_changes] = static_cast<int32_t>(l.second.validated_type());
358 ++num_changes;
359 }
360 }
361 if (!layers && !types)
362 *num_elements = num_changes;
363 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500364}
365
366HWC2::Error DrmHwcTwo::HwcDisplay::GetClientTargetSupport(uint32_t width,
Sean Paulac874152016-03-10 16:00:26 -0500367 uint32_t height,
368 int32_t /*format*/,
369 int32_t dataspace) {
370 supported(__func__);
371 std::pair<uint32_t, uint32_t> min = drm_->min_resolution();
372 std::pair<uint32_t, uint32_t> max = drm_->max_resolution();
373
374 if (width < min.first || height < min.second)
375 return HWC2::Error::Unsupported;
376
377 if (width > max.first || height > max.second)
378 return HWC2::Error::Unsupported;
379
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200380 if (dataspace != HAL_DATASPACE_UNKNOWN)
Sean Paulac874152016-03-10 16:00:26 -0500381 return HWC2::Error::Unsupported;
382
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200383 // TODO(nobody): Validate format can be handled by either GL or planes
Sean Paulac874152016-03-10 16:00:26 -0500384 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500385}
386
387HWC2::Error DrmHwcTwo::HwcDisplay::GetColorModes(uint32_t *num_modes,
Sean Paulac874152016-03-10 16:00:26 -0500388 int32_t *modes) {
389 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800390 if (!modes)
391 *num_modes = 1;
392
393 if (modes)
394 *modes = HAL_COLOR_MODE_NATIVE;
395
396 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500397}
398
399HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
Sean Paulac874152016-03-10 16:00:26 -0500400 int32_t attribute_in,
401 int32_t *value) {
402 supported(__func__);
Sean Paulf72cccd2018-08-27 13:59:08 -0400403 auto mode = std::find_if(connector_->modes().begin(),
404 connector_->modes().end(),
405 [config](DrmMode const &m) {
406 return m.id() == config;
407 });
Sean Paulac874152016-03-10 16:00:26 -0500408 if (mode == connector_->modes().end()) {
409 ALOGE("Could not find active mode for %d", config);
410 return HWC2::Error::BadConfig;
411 }
412
413 static const int32_t kUmPerInch = 25400;
414 uint32_t mm_width = connector_->mm_width();
415 uint32_t mm_height = connector_->mm_height();
416 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
417 switch (attribute) {
418 case HWC2::Attribute::Width:
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300419 *value = static_cast<int>(mode->h_display());
Sean Paulac874152016-03-10 16:00:26 -0500420 break;
421 case HWC2::Attribute::Height:
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300422 *value = static_cast<int>(mode->v_display());
Sean Paulac874152016-03-10 16:00:26 -0500423 break;
424 case HWC2::Attribute::VsyncPeriod:
425 // in nanoseconds
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300426 *value = static_cast<int>(1E9 / mode->v_refresh());
Sean Paulac874152016-03-10 16:00:26 -0500427 break;
428 case HWC2::Attribute::DpiX:
429 // Dots per 1000 inches
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300430 *value = mm_width
431 ? static_cast<int>(mode->h_display() * kUmPerInch / mm_width)
432 : -1;
Sean Paulac874152016-03-10 16:00:26 -0500433 break;
434 case HWC2::Attribute::DpiY:
435 // Dots per 1000 inches
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300436 *value = mm_height ? static_cast<int>(mode->v_display() * kUmPerInch /
437 mm_height)
438 : -1;
Sean Paulac874152016-03-10 16:00:26 -0500439 break;
Roman Stratiienko6f5df172020-09-27 22:48:08 +0300440#if PLATFORM_SDK_VERSION > 29
441 case HWC2::Attribute::ConfigGroup:
442 *value = 0; /* TODO: Add support for config groups */
443 break;
444#endif
Sean Paulac874152016-03-10 16:00:26 -0500445 default:
446 *value = -1;
447 return HWC2::Error::BadConfig;
448 }
449 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500450}
451
452HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
453 hwc2_config_t *configs) {
Sean Paulac874152016-03-10 16:00:26 -0500454 supported(__func__);
455 // Since this callback is normally invoked twice (once to get the count, and
456 // once to populate configs), we don't really want to read the edid
457 // redundantly. Instead, only update the modes on the first invocation. While
458 // it's possible this will result in stale modes, it'll all come out in the
459 // wash when we try to set the active config later.
460 if (!configs) {
461 int ret = connector_->UpdateModes();
462 if (ret) {
463 ALOGE("Failed to update display modes %d", ret);
464 return HWC2::Error::BadDisplay;
465 }
466 }
467
Neil Armstrongb67d0492019-06-20 09:00:21 +0000468 // Since the upper layers only look at vactive/hactive/refresh, height and
469 // width, it doesn't differentiate interlaced from progressive and other
470 // similar modes. Depending on the order of modes we return to SF, it could
471 // end up choosing a suboptimal configuration and dropping the preferred
472 // mode. To workaround this, don't offer interlaced modes to SF if there is
473 // at least one non-interlaced alternative and only offer a single WxH@R
474 // mode with at least the prefered mode from in DrmConnector::UpdateModes()
475
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200476 // TODO(nobody): Remove the following block of code until AOSP handles all
477 // modes
Neil Armstrongb67d0492019-06-20 09:00:21 +0000478 std::vector<DrmMode> sel_modes;
479
480 // Add the preferred mode first to be sure it's not dropped
481 auto mode = std::find_if(connector_->modes().begin(),
482 connector_->modes().end(), [&](DrmMode const &m) {
483 return m.id() ==
484 connector_->get_preferred_mode_id();
485 });
486 if (mode != connector_->modes().end())
487 sel_modes.push_back(*mode);
488
489 // Add the active mode if different from preferred mode
490 if (connector_->active_mode().id() != connector_->get_preferred_mode_id())
491 sel_modes.push_back(connector_->active_mode());
492
493 // Cycle over the modes and filter out "similar" modes, keeping only the
494 // first ones in the order given by DRM (from CEA ids and timings order)
Sean Paulac874152016-03-10 16:00:26 -0500495 for (const DrmMode &mode : connector_->modes()) {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200496 // TODO(nobody): Remove this when 3D Attributes are in AOSP
Neil Armstrongb67d0492019-06-20 09:00:21 +0000497 if (mode.flags() & DRM_MODE_FLAG_3D_MASK)
498 continue;
499
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200500 // TODO(nobody): Remove this when the Interlaced attribute is in AOSP
Neil Armstrong4c027a72019-06-04 14:48:02 +0000501 if (mode.flags() & DRM_MODE_FLAG_INTERLACE) {
502 auto m = std::find_if(connector_->modes().begin(),
503 connector_->modes().end(),
504 [&mode](DrmMode const &m) {
505 return !(m.flags() & DRM_MODE_FLAG_INTERLACE) &&
506 m.h_display() == mode.h_display() &&
507 m.v_display() == mode.v_display();
508 });
Neil Armstrongb67d0492019-06-20 09:00:21 +0000509 if (m == connector_->modes().end())
510 sel_modes.push_back(mode);
511
512 continue;
Neil Armstrong4c027a72019-06-04 14:48:02 +0000513 }
Neil Armstrongb67d0492019-06-20 09:00:21 +0000514
515 // Search for a similar WxH@R mode in the filtered list and drop it if
516 // another mode with the same WxH@R has already been selected
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200517 // TODO(nobody): Remove this when AOSP handles duplicates modes
Neil Armstrongb67d0492019-06-20 09:00:21 +0000518 auto m = std::find_if(sel_modes.begin(), sel_modes.end(),
519 [&mode](DrmMode const &m) {
520 return m.h_display() == mode.h_display() &&
521 m.v_display() == mode.v_display() &&
522 m.v_refresh() == mode.v_refresh();
523 });
524 if (m == sel_modes.end())
525 sel_modes.push_back(mode);
526 }
527
528 auto num_modes = static_cast<uint32_t>(sel_modes.size());
529 if (!configs) {
530 *num_configs = num_modes;
531 return HWC2::Error::None;
532 }
533
534 uint32_t idx = 0;
535 for (const DrmMode &mode : sel_modes) {
536 if (idx >= *num_configs)
537 break;
538 configs[idx++] = mode.id();
Sean Paulac874152016-03-10 16:00:26 -0500539 }
540 *num_configs = idx;
541 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500542}
543
544HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
Sean Paulac874152016-03-10 16:00:26 -0500545 supported(__func__);
546 std::ostringstream stream;
547 stream << "display-" << connector_->id();
548 std::string string = stream.str();
549 size_t length = string.length();
550 if (!name) {
551 *size = length;
552 return HWC2::Error::None;
553 }
554
555 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
556 strncpy(name, string.c_str(), *size);
557 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500558}
559
Sean Paulac874152016-03-10 16:00:26 -0500560HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
561 uint32_t *num_elements,
562 hwc2_layer_t *layers,
563 int32_t *layer_requests) {
564 supported(__func__);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200565 // TODO(nobody): I think virtual display should request
Sean Paulac874152016-03-10 16:00:26 -0500566 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
567 unsupported(__func__, display_requests, num_elements, layers, layer_requests);
568 *num_elements = 0;
569 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500570}
571
572HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayType(int32_t *type) {
Sean Paulac874152016-03-10 16:00:26 -0500573 supported(__func__);
574 *type = static_cast<int32_t>(type_);
575 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500576}
577
578HWC2::Error DrmHwcTwo::HwcDisplay::GetDozeSupport(int32_t *support) {
Sean Paulac874152016-03-10 16:00:26 -0500579 supported(__func__);
580 *support = 0;
581 return HWC2::Error::None;
582}
583
584HWC2::Error DrmHwcTwo::HwcDisplay::GetHdrCapabilities(
Sean Paulf72cccd2018-08-27 13:59:08 -0400585 uint32_t *num_types, int32_t * /*types*/, float * /*max_luminance*/,
586 float * /*max_average_luminance*/, float * /*min_luminance*/) {
Sean Paulac874152016-03-10 16:00:26 -0500587 supported(__func__);
588 *num_types = 0;
589 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500590}
591
Roman Stratiienko3e2f9e72021-05-21 14:33:28 +0300592/* Find API details at:
593 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1767
594 */
Sean Pauled2ec4b2016-03-10 15:35:40 -0500595HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
Sean Paulac874152016-03-10 16:00:26 -0500596 hwc2_layer_t *layers,
597 int32_t *fences) {
598 supported(__func__);
599 uint32_t num_layers = 0;
600
601 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
602 ++num_layers;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200603 if (layers == nullptr || fences == nullptr)
Sean Paulac874152016-03-10 16:00:26 -0500604 continue;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200605
606 if (num_layers > *num_elements) {
Sean Paulac874152016-03-10 16:00:26 -0500607 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
608 return HWC2::Error::None;
609 }
610
611 layers[num_layers - 1] = l.first;
Roman Stratiienko0fade372021-02-20 13:59:55 +0200612 fences[num_layers - 1] = l.second.release_fence_.Release();
Sean Paulac874152016-03-10 16:00:26 -0500613 }
614 *num_elements = num_layers;
615 return HWC2::Error::None;
616}
617
Roman Stratiienko0fade372021-02-20 13:59:55 +0200618void DrmHwcTwo::HwcDisplay::AddFenceToPresentFence(UniqueFd fd) {
619 if (!fd) {
Sean Paulac874152016-03-10 16:00:26 -0500620 return;
Roman Stratiienko0fade372021-02-20 13:59:55 +0200621 }
Sean Paulac874152016-03-10 16:00:26 -0500622
Roman Stratiienko0fade372021-02-20 13:59:55 +0200623 if (present_fence_) {
624 present_fence_ = UniqueFd(
625 sync_merge("dc_present", present_fence_.Get(), fd.Get()));
Sean Paulac874152016-03-10 16:00:26 -0500626 } else {
Roman Stratiienko0fade372021-02-20 13:59:55 +0200627 present_fence_ = std::move(fd);
Sean Paulac874152016-03-10 16:00:26 -0500628 }
Sean Pauled2ec4b2016-03-10 15:35:40 -0500629}
630
Rob Herring4f6c62e2018-05-17 14:33:02 -0500631HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) {
Sean Paulac874152016-03-10 16:00:26 -0500632 // order the layers by z-order
633 bool use_client_layer = false;
Alexandru Gheorghe1542d292018-06-13 16:46:36 +0100634 uint32_t client_z_order = UINT32_MAX;
Sean Paulac874152016-03-10 16:00:26 -0500635 std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
636 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
Roman Stratiienkof2647232019-11-21 01:58:35 +0200637 switch (l.second.validated_type()) {
Sean Paulac874152016-03-10 16:00:26 -0500638 case HWC2::Composition::Device:
639 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
640 break;
641 case HWC2::Composition::Client:
Alexandru Gheorghe1542d292018-06-13 16:46:36 +0100642 // Place it at the z_order of the lowest client layer
Sean Paulac874152016-03-10 16:00:26 -0500643 use_client_layer = true;
Alexandru Gheorghe1542d292018-06-13 16:46:36 +0100644 client_z_order = std::min(client_z_order, l.second.z_order());
Sean Paulac874152016-03-10 16:00:26 -0500645 break;
646 default:
647 continue;
648 }
649 }
650 if (use_client_layer)
651 z_map.emplace(std::make_pair(client_z_order, &client_layer_));
652
Rob Herring4f6c62e2018-05-17 14:33:02 -0500653 if (z_map.empty())
654 return HWC2::Error::BadLayer;
655
Matvii Zorin5368b732021-01-12 10:53:08 +0200656 std::vector<DrmHwcLayer> composition_layers;
657
Sean Paulac874152016-03-10 16:00:26 -0500658 // now that they're ordered by z, add them to the composition
659 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
660 DrmHwcLayer layer;
661 l.second->PopulateDrmLayer(&layer);
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200662 int ret = layer.ImportBuffer(drm_);
Sean Paulac874152016-03-10 16:00:26 -0500663 if (ret) {
664 ALOGE("Failed to import layer, ret=%d", ret);
665 return HWC2::Error::NoResources;
666 }
Matvii Zorin5368b732021-01-12 10:53:08 +0200667 composition_layers.emplace_back(std::move(layer));
Sean Paulac874152016-03-10 16:00:26 -0500668 }
Sean Paulac874152016-03-10 16:00:26 -0500669
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200670 auto composition = std::make_unique<DrmDisplayComposition>(crtc_,
671 planner_.get());
Sean Paulac874152016-03-10 16:00:26 -0500672
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200673 // TODO(nobody): Don't always assume geometry changed
Matvii Zorin5368b732021-01-12 10:53:08 +0200674 int ret = composition->SetLayers(composition_layers.data(),
675 composition_layers.size(), true);
Sean Paulac874152016-03-10 16:00:26 -0500676 if (ret) {
677 ALOGE("Failed to set layers in the composition ret=%d", ret);
678 return HWC2::Error::BadLayer;
679 }
680
681 std::vector<DrmPlane *> primary_planes(primary_planes_);
682 std::vector<DrmPlane *> overlay_planes(overlay_planes_);
Rob Herringaf0d9752018-05-04 16:34:19 -0500683 ret = composition->Plan(&primary_planes, &overlay_planes);
Sean Paulac874152016-03-10 16:00:26 -0500684 if (ret) {
John Stultz66763d52021-08-24 04:59:25 +0000685 ALOGV("Failed to plan the composition ret=%d", ret);
Sean Paulac874152016-03-10 16:00:26 -0500686 return HWC2::Error::BadConfig;
687 }
688
689 // Disable the planes we're not using
690 for (auto i = primary_planes.begin(); i != primary_planes.end();) {
691 composition->AddPlaneDisable(*i);
692 i = primary_planes.erase(i);
693 }
694 for (auto i = overlay_planes.begin(); i != overlay_planes.end();) {
695 composition->AddPlaneDisable(*i);
696 i = overlay_planes.erase(i);
697 }
698
Rob Herring4f6c62e2018-05-17 14:33:02 -0500699 if (test) {
700 ret = compositor_.TestComposition(composition.get());
701 } else {
Rob Herring4f6c62e2018-05-17 14:33:02 -0500702 ret = compositor_.ApplyComposition(std::move(composition));
Matteo Franchinc56eede2019-12-03 17:10:38 +0000703 AddFenceToPresentFence(compositor_.TakeOutFence());
Rob Herring4f6c62e2018-05-17 14:33:02 -0500704 }
Sean Paulac874152016-03-10 16:00:26 -0500705 if (ret) {
John Stultz78c9f6c2018-05-24 16:43:35 -0700706 if (!test)
707 ALOGE("Failed to apply the frame composition ret=%d", ret);
Sean Paulac874152016-03-10 16:00:26 -0500708 return HWC2::Error::BadParameter;
709 }
Rob Herring4f6c62e2018-05-17 14:33:02 -0500710 return HWC2::Error::None;
711}
712
Roman Stratiienko3e2f9e72021-05-21 14:33:28 +0300713/* Find API details at:
714 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1805
715 */
Matteo Franchinc56eede2019-12-03 17:10:38 +0000716HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *present_fence) {
Rob Herring4f6c62e2018-05-17 14:33:02 -0500717 supported(__func__);
718 HWC2::Error ret;
719
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200720 ++total_stats_.total_frames_;
721
Rob Herring4f6c62e2018-05-17 14:33:02 -0500722 ret = CreateComposition(false);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200723 if (ret != HWC2::Error::None)
724 ++total_stats_.failed_kms_present_;
725
Rob Herring4f6c62e2018-05-17 14:33:02 -0500726 if (ret == HWC2::Error::BadLayer) {
727 // Can we really have no client or device layers?
Matteo Franchinc56eede2019-12-03 17:10:38 +0000728 *present_fence = -1;
Rob Herring4f6c62e2018-05-17 14:33:02 -0500729 return HWC2::Error::None;
730 }
731 if (ret != HWC2::Error::None)
732 return ret;
Sean Paulac874152016-03-10 16:00:26 -0500733
Matteo Franchinc56eede2019-12-03 17:10:38 +0000734 *present_fence = present_fence_.Release();
Sean Paulac874152016-03-10 16:00:26 -0500735
736 ++frame_no_;
737 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500738}
739
740HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
Sean Paulac874152016-03-10 16:00:26 -0500741 supported(__func__);
Sean Paulf72cccd2018-08-27 13:59:08 -0400742 auto mode = std::find_if(connector_->modes().begin(),
743 connector_->modes().end(),
744 [config](DrmMode const &m) {
745 return m.id() == config;
746 });
Sean Paulac874152016-03-10 16:00:26 -0500747 if (mode == connector_->modes().end()) {
748 ALOGE("Could not find active mode for %d", config);
749 return HWC2::Error::BadConfig;
750 }
751
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200752 auto composition = std::make_unique<DrmDisplayComposition>(crtc_,
753 planner_.get());
Sean Paulac874152016-03-10 16:00:26 -0500754 int ret = composition->SetDisplayMode(*mode);
Roman Stratiienko6a10c4c2021-02-15 11:25:23 +0200755 if (ret) {
756 return HWC2::Error::BadConfig;
757 }
Sean Pauled45a8e2017-02-28 13:17:34 -0500758 ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500759 if (ret) {
760 ALOGE("Failed to queue dpms composition on %d", ret);
761 return HWC2::Error::BadConfig;
762 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300763
764 connector_->set_active_mode(*mode);
Sean Paulac874152016-03-10 16:00:26 -0500765
766 // Setup the client layer's dimensions
767 hwc_rect_t display_frame = {.left = 0,
768 .top = 0,
769 .right = static_cast<int>(mode->h_display()),
770 .bottom = static_cast<int>(mode->v_display())};
771 client_layer_.SetLayerDisplayFrame(display_frame);
Sean Paulac874152016-03-10 16:00:26 -0500772
773 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500774}
775
Roman Stratiienko3e2f9e72021-05-21 14:33:28 +0300776/* Find API details at:
777 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=1861
778 */
Sean Pauled2ec4b2016-03-10 15:35:40 -0500779HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target,
780 int32_t acquire_fence,
781 int32_t dataspace,
Rob Herring1b2685c2017-11-29 10:19:57 -0600782 hwc_region_t /*damage*/) {
Sean Paulac874152016-03-10 16:00:26 -0500783 supported(__func__);
Sean Paulac874152016-03-10 16:00:26 -0500784
785 client_layer_.set_buffer(target);
John Stultz8adf5442021-07-31 00:19:50 +0000786 client_layer_.acquire_fence_ = UniqueFd(acquire_fence);
Sean Paulac874152016-03-10 16:00:26 -0500787 client_layer_.SetLayerDataspace(dataspace);
Roman Stratiienko33365c22020-10-10 23:06:36 +0300788
789 /* TODO: Do not update source_crop every call.
790 * It makes sense to do it once after every hotplug event. */
791 hwc_drm_bo bo{};
792 BufferInfoGetter::GetInstance()->ConvertBoInfo(target, &bo);
793
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200794 hwc_frect_t source_crop = {.left = 0.0F,
795 .top = 0.0F,
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300796 .right = static_cast<float>(bo.width),
797 .bottom = static_cast<float>(bo.height)};
Roman Stratiienko33365c22020-10-10 23:06:36 +0300798 client_layer_.SetLayerSourceCrop(source_crop);
799
Sean Paulac874152016-03-10 16:00:26 -0500800 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500801}
802
803HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500804 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800805
Roman Stratiienkod146d6d2020-10-04 23:56:46 +0300806 if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_BT2100_HLG)
807 return HWC2::Error::BadParameter;
808
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800809 if (mode != HAL_COLOR_MODE_NATIVE)
Roman Stratiienko27d2ed62020-09-26 23:59:19 +0300810 return HWC2::Error::Unsupported;
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800811
812 color_mode_ = mode;
813 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500814}
815
816HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix,
Sean Paulac874152016-03-10 16:00:26 -0500817 int32_t hint) {
818 supported(__func__);
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200819 if (hint < HAL_COLOR_TRANSFORM_IDENTITY ||
820 hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA)
821 return HWC2::Error::BadParameter;
822
823 if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX)
824 return HWC2::Error::BadParameter;
825
826 color_transform_hint_ = static_cast<android_color_transform_t>(hint);
827 if (color_transform_hint_ == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX)
828 std::copy(matrix, matrix + MATRIX_SIZE, color_transform_matrix_.begin());
829
830 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500831}
832
833HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500834 int32_t release_fence) {
835 supported(__func__);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200836 // TODO(nobody): Need virtual display support
Sean Pauled2ec4b2016-03-10 15:35:40 -0500837 return unsupported(__func__, buffer, release_fence);
838}
839
Sean Paulac874152016-03-10 16:00:26 -0500840HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) {
841 supported(__func__);
842 uint64_t dpms_value = 0;
843 auto mode = static_cast<HWC2::PowerMode>(mode_in);
844 switch (mode) {
845 case HWC2::PowerMode::Off:
846 dpms_value = DRM_MODE_DPMS_OFF;
847 break;
848 case HWC2::PowerMode::On:
849 dpms_value = DRM_MODE_DPMS_ON;
850 break;
Vincent Donnefort60ef7eb2019-10-09 11:39:28 +0100851 case HWC2::PowerMode::Doze:
852 case HWC2::PowerMode::DozeSuspend:
853 return HWC2::Error::Unsupported;
Sean Paulac874152016-03-10 16:00:26 -0500854 default:
855 ALOGI("Power mode %d is unsupported\n", mode);
Vincent Donnefort60ef7eb2019-10-09 11:39:28 +0100856 return HWC2::Error::BadParameter;
Sean Paulac874152016-03-10 16:00:26 -0500857 };
858
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200859 auto composition = std::make_unique<DrmDisplayComposition>(crtc_,
860 planner_.get());
Sean Paulac874152016-03-10 16:00:26 -0500861 composition->SetDpmsMode(dpms_value);
Sean Pauled45a8e2017-02-28 13:17:34 -0500862 int ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500863 if (ret) {
864 ALOGE("Failed to apply the dpms composition ret=%d", ret);
865 return HWC2::Error::BadParameter;
866 }
867 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500868}
869
870HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Sean Paulac874152016-03-10 16:00:26 -0500871 supported(__func__);
Andrii Chepurnyi4bdd0fe2018-07-27 15:14:37 +0300872 vsync_worker_.VSyncControl(HWC2_VSYNC_ENABLE == enabled);
Sean Paulac874152016-03-10 16:00:26 -0500873 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500874}
875
876HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types,
Sean Paulac874152016-03-10 16:00:26 -0500877 uint32_t *num_requests) {
878 supported(__func__);
Rob Herring4f6c62e2018-05-17 14:33:02 -0500879
Matvii Zorinef3c7972020-08-11 15:15:44 +0300880 return backend_->ValidateDisplay(this, num_types, num_requests);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500881}
882
Matvii Zorined90ef92021-01-29 18:32:06 +0200883std::vector<DrmHwcTwo::HwcLayer *>
884DrmHwcTwo::HwcDisplay::GetOrderLayersByZPos() {
885 std::vector<DrmHwcTwo::HwcLayer *> ordered_layers;
886 ordered_layers.reserve(layers_.size());
887
888 for (auto &[handle, layer] : layers_) {
889 ordered_layers.emplace_back(&layer);
890 }
891
892 std::sort(std::begin(ordered_layers), std::end(ordered_layers),
893 [](const DrmHwcTwo::HwcLayer *lhs, const DrmHwcTwo::HwcLayer *rhs) {
894 return lhs->z_order() < rhs->z_order();
895 });
896
897 return ordered_layers;
898}
899
Roman Stratiienko6f5df172020-09-27 22:48:08 +0300900#if PLATFORM_SDK_VERSION > 29
901HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConnectionType(uint32_t *outType) {
902 if (connector_->internal())
903 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::Internal);
904 else if (connector_->external())
905 *outType = static_cast<uint32_t>(HWC2::DisplayConnectionType::External);
906 else
907 return HWC2::Error::BadConfig;
908
909 return HWC2::Error::None;
910}
911
912HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayVsyncPeriod(
913 hwc2_vsync_period_t *outVsyncPeriod /* ns */) {
914 supported(__func__);
915 DrmMode const &mode = connector_->active_mode();
916 if (mode.id() == 0)
917 return HWC2::Error::BadConfig;
918
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300919 *outVsyncPeriod = static_cast<hwc2_vsync_period_t>(1E9 / mode.v_refresh());
Roman Stratiienko6f5df172020-09-27 22:48:08 +0300920 return HWC2::Error::None;
921}
922
923HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfigWithConstraints(
924 hwc2_config_t /*config*/,
925 hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints,
926 hwc_vsync_period_change_timeline_t *outTimeline) {
927 supported(__func__);
928
929 if (vsyncPeriodChangeConstraints == nullptr || outTimeline == nullptr) {
930 return HWC2::Error::BadParameter;
931 }
932
933 return HWC2::Error::BadConfig;
934}
935
936HWC2::Error DrmHwcTwo::HwcDisplay::SetAutoLowLatencyMode(bool /*on*/) {
937 return HWC2::Error::Unsupported;
938}
939
940HWC2::Error DrmHwcTwo::HwcDisplay::GetSupportedContentTypes(
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200941 uint32_t *outNumSupportedContentTypes,
942 const uint32_t *outSupportedContentTypes) {
Roman Stratiienko6f5df172020-09-27 22:48:08 +0300943 if (outSupportedContentTypes == nullptr)
944 *outNumSupportedContentTypes = 0;
945
946 return HWC2::Error::None;
947}
948
949HWC2::Error DrmHwcTwo::HwcDisplay::SetContentType(int32_t contentType) {
950 supported(__func__);
951
952 if (contentType != HWC2_CONTENT_TYPE_NONE)
953 return HWC2::Error::Unsupported;
954
955 /* TODO: Map to the DRM Connector property:
956 * https://elixir.bootlin.com/linux/v5.4-rc5/source/drivers/gpu/drm/drm_connector.c#L809
957 */
958
959 return HWC2::Error::None;
960}
961#endif
962
John Stultz8c7229d2020-02-07 21:31:08 +0000963#if PLATFORM_SDK_VERSION > 28
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800964HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayIdentificationData(
965 uint8_t *outPort, uint32_t *outDataSize, uint8_t *outData) {
966 supported(__func__);
967
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300968 auto blob = connector_->GetEdidBlob();
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800969
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300970 if (!blob) {
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800971 ALOGE("Failed to get edid property value.");
972 return HWC2::Error::Unsupported;
973 }
974
Andrii Chepurnyi8115dbe2020-04-14 13:03:57 +0300975 if (outData) {
976 *outDataSize = std::min(*outDataSize, blob->length);
977 memcpy(outData, blob->data, *outDataSize);
978 } else {
979 *outDataSize = blob->length;
980 }
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800981 *outPort = connector_->id();
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800982
983 return HWC2::Error::None;
984}
985
986HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayCapabilities(
987 uint32_t *outNumCapabilities, uint32_t *outCapabilities) {
988 unsupported(__func__, outCapabilities);
989
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200990 if (outNumCapabilities == nullptr) {
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800991 return HWC2::Error::BadParameter;
992 }
993
994 *outNumCapabilities = 0;
995
996 return HWC2::Error::None;
997}
Andrii Chepurnyi2619aab2020-07-03 11:21:33 +0300998
999HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayBrightnessSupport(
1000 bool *supported) {
1001 *supported = false;
1002 return HWC2::Error::None;
1003}
1004
1005HWC2::Error DrmHwcTwo::HwcDisplay::SetDisplayBrightness(
1006 float /* brightness */) {
1007 return HWC2::Error::Unsupported;
1008}
1009
John Stultz8c7229d2020-02-07 21:31:08 +00001010#endif /* PLATFORM_SDK_VERSION > 28 */
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +08001011
Andrii Chepurnyi50d37452020-04-24 14:20:24 +03001012#if PLATFORM_SDK_VERSION > 27
1013
1014HWC2::Error DrmHwcTwo::HwcDisplay::GetRenderIntents(
1015 int32_t mode, uint32_t *outNumIntents,
1016 int32_t * /*android_render_intent_v1_1_t*/ outIntents) {
1017 if (mode != HAL_COLOR_MODE_NATIVE) {
1018 return HWC2::Error::BadParameter;
1019 }
1020
1021 if (outIntents == nullptr) {
1022 *outNumIntents = 1;
1023 return HWC2::Error::None;
1024 }
1025 *outNumIntents = 1;
1026 outIntents[0] = HAL_RENDER_INTENT_COLORIMETRIC;
1027 return HWC2::Error::None;
1028}
1029
Andrii Chepurnyi857a53f2020-04-29 23:15:28 +03001030HWC2::Error DrmHwcTwo::HwcDisplay::SetColorModeWithIntent(int32_t mode,
1031 int32_t intent) {
Roman Stratiienko27d2ed62020-09-26 23:59:19 +03001032 if (intent < HAL_RENDER_INTENT_COLORIMETRIC ||
1033 intent > HAL_RENDER_INTENT_TONE_MAP_ENHANCE)
1034 return HWC2::Error::BadParameter;
1035
1036 if (mode < HAL_COLOR_MODE_NATIVE || mode > HAL_COLOR_MODE_BT2100_HLG)
1037 return HWC2::Error::BadParameter;
1038
Andrii Chepurnyi857a53f2020-04-29 23:15:28 +03001039 if (mode != HAL_COLOR_MODE_NATIVE)
Roman Stratiienko27d2ed62020-09-26 23:59:19 +03001040 return HWC2::Error::Unsupported;
1041
Andrii Chepurnyi857a53f2020-04-29 23:15:28 +03001042 if (intent != HAL_RENDER_INTENT_COLORIMETRIC)
Roman Stratiienko27d2ed62020-09-26 23:59:19 +03001043 return HWC2::Error::Unsupported;
1044
Andrii Chepurnyi857a53f2020-04-29 23:15:28 +03001045 color_mode_ = mode;
1046 return HWC2::Error::None;
1047}
1048
Andrii Chepurnyi50d37452020-04-24 14:20:24 +03001049#endif /* PLATFORM_SDK_VERSION > 27 */
1050
Roman Stratiienkoaaaa4692021-09-29 12:50:10 +03001051HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t /*x*/,
1052 int32_t /*y*/) {
Sean Paulac874152016-03-10 16:00:26 -05001053 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -08001054 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001055}
1056
1057HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -05001058 supported(__func__);
Roman Stratiienko5063d532021-09-29 12:47:31 +03001059 switch (static_cast<HWC2::BlendMode>(mode)) {
1060 case HWC2::BlendMode::None:
1061 blending_ = DrmHwcBlending::kNone;
1062 break;
1063 case HWC2::BlendMode::Premultiplied:
1064 blending_ = DrmHwcBlending::kPreMult;
1065 break;
1066 case HWC2::BlendMode::Coverage:
1067 blending_ = DrmHwcBlending::kCoverage;
1068 break;
1069 default:
1070 ALOGE("Unknown blending mode b=%d", blending_);
1071 blending_ = DrmHwcBlending::kNone;
1072 break;
1073 }
Sean Paulac874152016-03-10 16:00:26 -05001074 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001075}
1076
Roman Stratiienko3e2f9e72021-05-21 14:33:28 +03001077/* Find API details at:
1078 * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=2314
1079 */
Sean Pauled2ec4b2016-03-10 15:35:40 -05001080HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -05001081 int32_t acquire_fence) {
1082 supported(__func__);
Sean Paulac874152016-03-10 16:00:26 -05001083
Sean Paulac874152016-03-10 16:00:26 -05001084 set_buffer(buffer);
John Stultz8adf5442021-07-31 00:19:50 +00001085 acquire_fence_ = UniqueFd(acquire_fence);
Sean Paulac874152016-03-10 16:00:26 -05001086 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001087}
1088
Roman Stratiienkoaaaa4692021-09-29 12:50:10 +03001089HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t /*color*/) {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001090 // TODO(nobody): Put to client composition here?
Roman Kovalivskyibb375692019-12-11 17:48:44 +02001091 supported(__func__);
Roman Kovalivskyibb375692019-12-11 17:48:44 +02001092 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001093}
1094
1095HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) {
Sean Paulac874152016-03-10 16:00:26 -05001096 sf_type_ = static_cast<HWC2::Composition>(type);
1097 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001098}
1099
1100HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) {
Sean Paulac874152016-03-10 16:00:26 -05001101 supported(__func__);
Roman Stratiienko515da8f2021-09-29 12:47:21 +03001102 switch (dataspace & HAL_DATASPACE_STANDARD_MASK) {
1103 case HAL_DATASPACE_STANDARD_BT709:
1104 color_space_ = DrmHwcColorSpace::kItuRec709;
1105 break;
1106 case HAL_DATASPACE_STANDARD_BT601_625:
1107 case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
1108 case HAL_DATASPACE_STANDARD_BT601_525:
1109 case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
1110 color_space_ = DrmHwcColorSpace::kItuRec601;
1111 break;
1112 case HAL_DATASPACE_STANDARD_BT2020:
1113 case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
1114 color_space_ = DrmHwcColorSpace::kItuRec2020;
1115 break;
1116 default:
1117 color_space_ = DrmHwcColorSpace::kUndefined;
1118 }
1119
1120 switch (dataspace & HAL_DATASPACE_RANGE_MASK) {
1121 case HAL_DATASPACE_RANGE_FULL:
1122 sample_range_ = DrmHwcSampleRange::kFullRange;
1123 break;
1124 case HAL_DATASPACE_RANGE_LIMITED:
1125 sample_range_ = DrmHwcSampleRange::kLimitedRange;
1126 break;
1127 default:
1128 sample_range_ = DrmHwcSampleRange::kUndefined;
1129 }
Sean Paulac874152016-03-10 16:00:26 -05001130 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001131}
1132
1133HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
Sean Paulac874152016-03-10 16:00:26 -05001134 supported(__func__);
1135 display_frame_ = frame;
1136 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001137}
1138
1139HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) {
Sean Paulac874152016-03-10 16:00:26 -05001140 supported(__func__);
1141 alpha_ = alpha;
1142 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001143}
1144
1145HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream(
1146 const native_handle_t *stream) {
Sean Paulac874152016-03-10 16:00:26 -05001147 supported(__func__);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001148 // TODO(nobody): We don't support sideband
Sean Pauled2ec4b2016-03-10 15:35:40 -05001149 return unsupported(__func__, stream);
1150}
1151
1152HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
Sean Paulac874152016-03-10 16:00:26 -05001153 supported(__func__);
1154 source_crop_ = crop;
1155 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001156}
1157
1158HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -05001159 supported(__func__);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001160 // TODO(nobody): We don't use surface damage, marking as unsupported
Sean Paulac874152016-03-10 16:00:26 -05001161 unsupported(__func__, damage);
1162 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001163}
1164
1165HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) {
Sean Paulac874152016-03-10 16:00:26 -05001166 supported(__func__);
Roman Stratiienko2ed4cbe2021-09-29 12:47:35 +03001167
1168 uint32_t l_transform = 0;
1169
1170 // 270* and 180* cannot be combined with flips. More specifically, they
1171 // already contain both horizontal and vertical flips, so those fields are
1172 // redundant in this case. 90* rotation can be combined with either horizontal
1173 // flip or vertical flip, so treat it differently
1174 if (transform == HWC_TRANSFORM_ROT_270) {
1175 l_transform = DrmHwcTransform::kRotate270;
1176 } else if (transform == HWC_TRANSFORM_ROT_180) {
1177 l_transform = DrmHwcTransform::kRotate180;
1178 } else {
1179 if (transform & HWC_TRANSFORM_FLIP_H)
1180 l_transform |= DrmHwcTransform::kFlipH;
1181 if (transform & HWC_TRANSFORM_FLIP_V)
1182 l_transform |= DrmHwcTransform::kFlipV;
1183 if (transform & HWC_TRANSFORM_ROT_90)
1184 l_transform |= DrmHwcTransform::kRotate90;
1185 }
1186
1187 transform_ = static_cast<DrmHwcTransform>(l_transform);
Sean Paulac874152016-03-10 16:00:26 -05001188 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001189}
1190
1191HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) {
Sean Paulac874152016-03-10 16:00:26 -05001192 supported(__func__);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001193 // TODO(nobody): We don't use this information, marking as unsupported
Sean Paulac874152016-03-10 16:00:26 -05001194 unsupported(__func__, visible);
1195 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001196}
1197
Sean Paulac874152016-03-10 16:00:26 -05001198HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) {
1199 supported(__func__);
1200 z_order_ = order;
1201 return HWC2::Error::None;
1202}
1203
1204void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) {
1205 supported(__func__);
Sean Paulac874152016-03-10 16:00:26 -05001206 layer->sf_handle = buffer_;
Roman Stratiienko0fade372021-02-20 13:59:55 +02001207 // TODO(rsglobal): Avoid extra fd duplication
1208 layer->acquire_fence = UniqueFd(fcntl(acquire_fence_.Get(), F_DUPFD_CLOEXEC));
Roman Kovalivskyib8652272021-01-24 20:32:37 +02001209 layer->display_frame = display_frame_;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001210 layer->alpha = lround(65535.0F * alpha_);
Roman Stratiienko5063d532021-09-29 12:47:31 +03001211 layer->blending = blending_;
Roman Kovalivskyib8652272021-01-24 20:32:37 +02001212 layer->source_crop = source_crop_;
Roman Stratiienko2ed4cbe2021-09-29 12:47:35 +03001213 layer->transform = transform_;
Roman Stratiienko515da8f2021-09-29 12:47:21 +03001214 layer->color_space = color_space_;
1215 layer->sample_range = sample_range_;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001216}
1217
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +03001218void DrmHwcTwo::HandleDisplayHotplug(hwc2_display_t displayid, int state) {
Roman Stratiienko863a3c22021-09-29 13:00:29 +03001219 const std::lock_guard<std::mutex> lock(callback_lock_);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +03001220
Roman Stratiienko863a3c22021-09-29 13:00:29 +03001221 if (hotplug_callback_.first != nullptr &&
1222 hotplug_callback_.second != nullptr) {
1223 hotplug_callback_.first(hotplug_callback_.second, displayid,
1224 state == DRM_MODE_CONNECTED
1225 ? HWC2_CONNECTION_CONNECTED
1226 : HWC2_CONNECTION_DISCONNECTED);
1227 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +03001228}
1229
1230void DrmHwcTwo::HandleInitialHotplugState(DrmDevice *drmDevice) {
Roman Stratiienkod21071f2021-03-09 21:56:50 +02001231 for (const auto &conn : drmDevice->connectors()) {
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +03001232 if (conn->state() != DRM_MODE_CONNECTED)
1233 continue;
1234 HandleDisplayHotplug(conn->display(), conn->state());
1235 }
1236}
1237
1238void DrmHwcTwo::DrmHotplugHandler::HandleEvent(uint64_t timestamp_us) {
Roman Stratiienkod21071f2021-03-09 21:56:50 +02001239 for (const auto &conn : drm_->connectors()) {
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +03001240 drmModeConnection old_state = conn->state();
1241 drmModeConnection cur_state = conn->UpdateModes()
1242 ? DRM_MODE_UNKNOWNCONNECTION
1243 : conn->state();
1244
1245 if (cur_state == old_state)
1246 continue;
1247
1248 ALOGI("%s event @%" PRIu64 " for connector %u on display %d",
1249 cur_state == DRM_MODE_CONNECTED ? "Plug" : "Unplug", timestamp_us,
1250 conn->id(), conn->display());
1251
1252 int display_id = conn->display();
1253 if (cur_state == DRM_MODE_CONNECTED) {
1254 auto &display = hwc2_->displays_.at(display_id);
1255 display.ChosePreferredConfig();
1256 } else {
1257 auto &display = hwc2_->displays_.at(display_id);
1258 display.ClearDisplay();
1259 }
1260
1261 hwc2_->HandleDisplayHotplug(display_id, cur_state);
1262 }
1263}
1264
Sean Pauled2ec4b2016-03-10 15:35:40 -05001265// static
1266int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) {
1267 unsupported(__func__);
1268 return 0;
1269}
1270
1271// static
1272void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/,
Sean Paulac874152016-03-10 16:00:26 -05001273 uint32_t *out_count,
1274 int32_t * /*out_capabilities*/) {
1275 supported(__func__);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001276 *out_count = 0;
1277}
1278
1279// static
Sean Paulac874152016-03-10 16:00:26 -05001280hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
1281 struct hwc2_device * /*dev*/, int32_t descriptor) {
1282 supported(__func__);
1283 auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001284 switch (func) {
1285 // Device functions
1286 case HWC2::FunctionDescriptor::CreateVirtualDisplay:
1287 return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
1288 DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
1289 &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
Sean Paulf72cccd2018-08-27 13:59:08 -04001290 int32_t *, hwc2_display_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001291 case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
1292 return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
1293 DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
1294 &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
1295 case HWC2::FunctionDescriptor::Dump:
1296 return ToHook<HWC2_PFN_DUMP>(
1297 DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump,
1298 uint32_t *, char *>);
1299 case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
1300 return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
1301 DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
1302 &DrmHwcTwo::GetMaxVirtualDisplayCount>);
1303 case HWC2::FunctionDescriptor::RegisterCallback:
1304 return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
1305 DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
1306 &DrmHwcTwo::RegisterCallback, int32_t,
1307 hwc2_callback_data_t, hwc2_function_pointer_t>);
1308
1309 // Display functions
1310 case HWC2::FunctionDescriptor::AcceptDisplayChanges:
1311 return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
1312 DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
1313 &HwcDisplay::AcceptDisplayChanges>);
1314 case HWC2::FunctionDescriptor::CreateLayer:
1315 return ToHook<HWC2_PFN_CREATE_LAYER>(
1316 DisplayHook<decltype(&HwcDisplay::CreateLayer),
1317 &HwcDisplay::CreateLayer, hwc2_layer_t *>);
1318 case HWC2::FunctionDescriptor::DestroyLayer:
1319 return ToHook<HWC2_PFN_DESTROY_LAYER>(
1320 DisplayHook<decltype(&HwcDisplay::DestroyLayer),
1321 &HwcDisplay::DestroyLayer, hwc2_layer_t>);
1322 case HWC2::FunctionDescriptor::GetActiveConfig:
1323 return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
1324 DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
1325 &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
1326 case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
1327 return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
1328 DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
1329 &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
1330 hwc2_layer_t *, int32_t *>);
1331 case HWC2::FunctionDescriptor::GetClientTargetSupport:
1332 return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
1333 DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
1334 &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
1335 int32_t, int32_t>);
1336 case HWC2::FunctionDescriptor::GetColorModes:
1337 return ToHook<HWC2_PFN_GET_COLOR_MODES>(
1338 DisplayHook<decltype(&HwcDisplay::GetColorModes),
1339 &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
1340 case HWC2::FunctionDescriptor::GetDisplayAttribute:
Sean Paulf72cccd2018-08-27 13:59:08 -04001341 return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(
1342 DisplayHook<decltype(&HwcDisplay::GetDisplayAttribute),
1343 &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t,
1344 int32_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001345 case HWC2::FunctionDescriptor::GetDisplayConfigs:
Sean Paulf72cccd2018-08-27 13:59:08 -04001346 return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(
1347 DisplayHook<decltype(&HwcDisplay::GetDisplayConfigs),
1348 &HwcDisplay::GetDisplayConfigs, uint32_t *,
1349 hwc2_config_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001350 case HWC2::FunctionDescriptor::GetDisplayName:
1351 return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
1352 DisplayHook<decltype(&HwcDisplay::GetDisplayName),
1353 &HwcDisplay::GetDisplayName, uint32_t *, char *>);
1354 case HWC2::FunctionDescriptor::GetDisplayRequests:
1355 return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
1356 DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
1357 &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
1358 hwc2_layer_t *, int32_t *>);
1359 case HWC2::FunctionDescriptor::GetDisplayType:
1360 return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
1361 DisplayHook<decltype(&HwcDisplay::GetDisplayType),
1362 &HwcDisplay::GetDisplayType, int32_t *>);
1363 case HWC2::FunctionDescriptor::GetDozeSupport:
1364 return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
1365 DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
1366 &HwcDisplay::GetDozeSupport, int32_t *>);
Sean Paulac874152016-03-10 16:00:26 -05001367 case HWC2::FunctionDescriptor::GetHdrCapabilities:
1368 return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
1369 DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
1370 &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
1371 float *, float *, float *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001372 case HWC2::FunctionDescriptor::GetReleaseFences:
1373 return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
1374 DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
1375 &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
1376 int32_t *>);
1377 case HWC2::FunctionDescriptor::PresentDisplay:
1378 return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
1379 DisplayHook<decltype(&HwcDisplay::PresentDisplay),
1380 &HwcDisplay::PresentDisplay, int32_t *>);
1381 case HWC2::FunctionDescriptor::SetActiveConfig:
1382 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
1383 DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
1384 &HwcDisplay::SetActiveConfig, hwc2_config_t>);
1385 case HWC2::FunctionDescriptor::SetClientTarget:
Sean Paulf72cccd2018-08-27 13:59:08 -04001386 return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(
1387 DisplayHook<decltype(&HwcDisplay::SetClientTarget),
1388 &HwcDisplay::SetClientTarget, buffer_handle_t, int32_t,
1389 int32_t, hwc_region_t>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001390 case HWC2::FunctionDescriptor::SetColorMode:
1391 return ToHook<HWC2_PFN_SET_COLOR_MODE>(
1392 DisplayHook<decltype(&HwcDisplay::SetColorMode),
1393 &HwcDisplay::SetColorMode, int32_t>);
1394 case HWC2::FunctionDescriptor::SetColorTransform:
1395 return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
1396 DisplayHook<decltype(&HwcDisplay::SetColorTransform),
1397 &HwcDisplay::SetColorTransform, const float *, int32_t>);
1398 case HWC2::FunctionDescriptor::SetOutputBuffer:
1399 return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
1400 DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
1401 &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
1402 case HWC2::FunctionDescriptor::SetPowerMode:
1403 return ToHook<HWC2_PFN_SET_POWER_MODE>(
1404 DisplayHook<decltype(&HwcDisplay::SetPowerMode),
1405 &HwcDisplay::SetPowerMode, int32_t>);
1406 case HWC2::FunctionDescriptor::SetVsyncEnabled:
1407 return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
1408 DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
1409 &HwcDisplay::SetVsyncEnabled, int32_t>);
1410 case HWC2::FunctionDescriptor::ValidateDisplay:
1411 return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
1412 DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
1413 &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
Andrii Chepurnyi50d37452020-04-24 14:20:24 +03001414#if PLATFORM_SDK_VERSION > 27
1415 case HWC2::FunctionDescriptor::GetRenderIntents:
1416 return ToHook<HWC2_PFN_GET_RENDER_INTENTS>(
1417 DisplayHook<decltype(&HwcDisplay::GetRenderIntents),
1418 &HwcDisplay::GetRenderIntents, int32_t, uint32_t *,
1419 int32_t *>);
Andrii Chepurnyi857a53f2020-04-29 23:15:28 +03001420 case HWC2::FunctionDescriptor::SetColorModeWithRenderIntent:
1421 return ToHook<HWC2_PFN_SET_COLOR_MODE_WITH_RENDER_INTENT>(
1422 DisplayHook<decltype(&HwcDisplay::SetColorModeWithIntent),
1423 &HwcDisplay::SetColorModeWithIntent, int32_t, int32_t>);
Andrii Chepurnyi50d37452020-04-24 14:20:24 +03001424#endif
John Stultz8c7229d2020-02-07 21:31:08 +00001425#if PLATFORM_SDK_VERSION > 28
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +08001426 case HWC2::FunctionDescriptor::GetDisplayIdentificationData:
1427 return ToHook<HWC2_PFN_GET_DISPLAY_IDENTIFICATION_DATA>(
1428 DisplayHook<decltype(&HwcDisplay::GetDisplayIdentificationData),
1429 &HwcDisplay::GetDisplayIdentificationData, uint8_t *,
1430 uint32_t *, uint8_t *>);
1431 case HWC2::FunctionDescriptor::GetDisplayCapabilities:
1432 return ToHook<HWC2_PFN_GET_DISPLAY_CAPABILITIES>(
1433 DisplayHook<decltype(&HwcDisplay::GetDisplayCapabilities),
1434 &HwcDisplay::GetDisplayCapabilities, uint32_t *,
1435 uint32_t *>);
Andrii Chepurnyi2619aab2020-07-03 11:21:33 +03001436 case HWC2::FunctionDescriptor::GetDisplayBrightnessSupport:
1437 return ToHook<HWC2_PFN_GET_DISPLAY_BRIGHTNESS_SUPPORT>(
1438 DisplayHook<decltype(&HwcDisplay::GetDisplayBrightnessSupport),
1439 &HwcDisplay::GetDisplayBrightnessSupport, bool *>);
1440 case HWC2::FunctionDescriptor::SetDisplayBrightness:
1441 return ToHook<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>(
1442 DisplayHook<decltype(&HwcDisplay::SetDisplayBrightness),
1443 &HwcDisplay::SetDisplayBrightness, float>);
John Stultz8c7229d2020-02-07 21:31:08 +00001444#endif /* PLATFORM_SDK_VERSION > 28 */
Roman Stratiienko6f5df172020-09-27 22:48:08 +03001445#if PLATFORM_SDK_VERSION > 29
1446 case HWC2::FunctionDescriptor::GetDisplayConnectionType:
1447 return ToHook<HWC2_PFN_GET_DISPLAY_CONNECTION_TYPE>(
1448 DisplayHook<decltype(&HwcDisplay::GetDisplayConnectionType),
1449 &HwcDisplay::GetDisplayConnectionType, uint32_t *>);
1450 case HWC2::FunctionDescriptor::GetDisplayVsyncPeriod:
1451 return ToHook<HWC2_PFN_GET_DISPLAY_VSYNC_PERIOD>(
1452 DisplayHook<decltype(&HwcDisplay::GetDisplayVsyncPeriod),
1453 &HwcDisplay::GetDisplayVsyncPeriod,
1454 hwc2_vsync_period_t *>);
1455 case HWC2::FunctionDescriptor::SetActiveConfigWithConstraints:
1456 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS>(
1457 DisplayHook<decltype(&HwcDisplay::SetActiveConfigWithConstraints),
1458 &HwcDisplay::SetActiveConfigWithConstraints,
1459 hwc2_config_t, hwc_vsync_period_change_constraints_t *,
1460 hwc_vsync_period_change_timeline_t *>);
1461 case HWC2::FunctionDescriptor::SetAutoLowLatencyMode:
1462 return ToHook<HWC2_PFN_SET_AUTO_LOW_LATENCY_MODE>(
1463 DisplayHook<decltype(&HwcDisplay::SetAutoLowLatencyMode),
1464 &HwcDisplay::SetAutoLowLatencyMode, bool>);
1465 case HWC2::FunctionDescriptor::GetSupportedContentTypes:
1466 return ToHook<HWC2_PFN_GET_SUPPORTED_CONTENT_TYPES>(
1467 DisplayHook<decltype(&HwcDisplay::GetSupportedContentTypes),
1468 &HwcDisplay::GetSupportedContentTypes, uint32_t *,
1469 uint32_t *>);
1470 case HWC2::FunctionDescriptor::SetContentType:
1471 return ToHook<HWC2_PFN_SET_CONTENT_TYPE>(
1472 DisplayHook<decltype(&HwcDisplay::SetContentType),
1473 &HwcDisplay::SetContentType, int32_t>);
1474#endif
Sean Pauled2ec4b2016-03-10 15:35:40 -05001475 // Layer functions
1476 case HWC2::FunctionDescriptor::SetCursorPosition:
1477 return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
1478 LayerHook<decltype(&HwcLayer::SetCursorPosition),
1479 &HwcLayer::SetCursorPosition, int32_t, int32_t>);
1480 case HWC2::FunctionDescriptor::SetLayerBlendMode:
1481 return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
1482 LayerHook<decltype(&HwcLayer::SetLayerBlendMode),
1483 &HwcLayer::SetLayerBlendMode, int32_t>);
1484 case HWC2::FunctionDescriptor::SetLayerBuffer:
1485 return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
1486 LayerHook<decltype(&HwcLayer::SetLayerBuffer),
1487 &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>);
1488 case HWC2::FunctionDescriptor::SetLayerColor:
1489 return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
1490 LayerHook<decltype(&HwcLayer::SetLayerColor),
1491 &HwcLayer::SetLayerColor, hwc_color_t>);
1492 case HWC2::FunctionDescriptor::SetLayerCompositionType:
1493 return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
1494 LayerHook<decltype(&HwcLayer::SetLayerCompositionType),
1495 &HwcLayer::SetLayerCompositionType, int32_t>);
1496 case HWC2::FunctionDescriptor::SetLayerDataspace:
1497 return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
1498 LayerHook<decltype(&HwcLayer::SetLayerDataspace),
1499 &HwcLayer::SetLayerDataspace, int32_t>);
1500 case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
1501 return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
1502 LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame),
1503 &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>);
1504 case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
1505 return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
1506 LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha),
1507 &HwcLayer::SetLayerPlaneAlpha, float>);
1508 case HWC2::FunctionDescriptor::SetLayerSidebandStream:
Sean Paulf72cccd2018-08-27 13:59:08 -04001509 return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(
1510 LayerHook<decltype(&HwcLayer::SetLayerSidebandStream),
1511 &HwcLayer::SetLayerSidebandStream,
1512 const native_handle_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001513 case HWC2::FunctionDescriptor::SetLayerSourceCrop:
1514 return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
1515 LayerHook<decltype(&HwcLayer::SetLayerSourceCrop),
1516 &HwcLayer::SetLayerSourceCrop, hwc_frect_t>);
1517 case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
1518 return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
1519 LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage),
1520 &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>);
1521 case HWC2::FunctionDescriptor::SetLayerTransform:
1522 return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
1523 LayerHook<decltype(&HwcLayer::SetLayerTransform),
1524 &HwcLayer::SetLayerTransform, int32_t>);
1525 case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
1526 return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
1527 LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion),
1528 &HwcLayer::SetLayerVisibleRegion, hwc_region_t>);
1529 case HWC2::FunctionDescriptor::SetLayerZOrder:
1530 return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
1531 LayerHook<decltype(&HwcLayer::SetLayerZOrder),
1532 &HwcLayer::SetLayerZOrder, uint32_t>);
Sean Paulac874152016-03-10 16:00:26 -05001533 case HWC2::FunctionDescriptor::Invalid:
Sean Pauled2ec4b2016-03-10 15:35:40 -05001534 default:
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001535 return nullptr;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001536 }
1537}
Sean Paulac874152016-03-10 16:00:26 -05001538
1539// static
1540int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
1541 struct hw_device_t **dev) {
1542 supported(__func__);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001543 if (strcmp(name, HWC_HARDWARE_COMPOSER) != 0) {
Sean Paulac874152016-03-10 16:00:26 -05001544 ALOGE("Invalid module name- %s", name);
1545 return -EINVAL;
1546 }
1547
1548 std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo());
1549 if (!ctx) {
1550 ALOGE("Failed to allocate DrmHwcTwo");
1551 return -ENOMEM;
1552 }
1553
1554 HWC2::Error err = ctx->Init();
1555 if (err != HWC2::Error::None) {
1556 ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err);
1557 return -EINVAL;
1558 }
1559
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +02001560 ctx->common.module = (hw_module_t *)module;
Sean Paulac874152016-03-10 16:00:26 -05001561 *dev = &ctx->common;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001562 ctx.release(); // NOLINT(bugprone-unused-return-value)
Sean Paulac874152016-03-10 16:00:26 -05001563 return 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001564}
Sean Paulf72cccd2018-08-27 13:59:08 -04001565} // namespace android
Sean Paulac874152016-03-10 16:00:26 -05001566
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +02001567// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
Sean Paulac874152016-03-10 16:00:26 -05001568static struct hw_module_methods_t hwc2_module_methods = {
1569 .open = android::DrmHwcTwo::HookDevOpen,
1570};
1571
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +02001572// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
Sean Paulac874152016-03-10 16:00:26 -05001573hw_module_t HAL_MODULE_INFO_SYM = {
1574 .tag = HARDWARE_MODULE_TAG,
1575 .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
1576 .id = HWC_HARDWARE_MODULE_ID,
1577 .name = "DrmHwcTwo module",
1578 .author = "The Android Open Source Project",
1579 .methods = &hwc2_module_methods,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +02001580 .dso = nullptr,
Sean Paulac874152016-03-10 16:00:26 -05001581 .reserved = {0},
1582};