blob: c34c0b7405ec66a336cbc4d6258f9ed58931dc22 [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
Sean Paulf72cccd2018-08-27 13:59:08 -040020#include "drmhwctwo.h"
Sean Paulac874152016-03-10 16:00:26 -050021#include "drmdisplaycomposition.h"
22#include "drmhwcomposer.h"
Sean Paulac874152016-03-10 16:00:26 -050023#include "platform.h"
24#include "vsyncworker.h"
25
26#include <inttypes.h>
27#include <string>
Sean Pauled2ec4b2016-03-10 15:35:40 -050028
Sean Paulac874152016-03-10 16:00:26 -050029#include <cutils/properties.h>
30#include <hardware/hardware.h>
Sean Pauled2ec4b2016-03-10 15:35:40 -050031#include <hardware/hwcomposer2.h>
Sean Paulf72cccd2018-08-27 13:59:08 -040032#include <log/log.h>
Sean Pauled2ec4b2016-03-10 15:35:40 -050033
34namespace android {
35
Sean Paulac874152016-03-10 16:00:26 -050036class DrmVsyncCallback : public VsyncCallback {
37 public:
38 DrmVsyncCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
39 : data_(data), hook_(hook) {
40 }
41
42 void Callback(int display, int64_t timestamp) {
43 auto hook = reinterpret_cast<HWC2_PFN_VSYNC>(hook_);
44 hook(data_, display, timestamp);
45 }
46
47 private:
48 hwc2_callback_data_t data_;
49 hwc2_function_pointer_t hook_;
50};
51
Sean Pauled2ec4b2016-03-10 15:35:40 -050052DrmHwcTwo::DrmHwcTwo() {
Sean Paulac874152016-03-10 16:00:26 -050053 common.tag = HARDWARE_DEVICE_TAG;
54 common.version = HWC_DEVICE_API_VERSION_2_0;
Sean Pauled2ec4b2016-03-10 15:35:40 -050055 common.close = HookDevClose;
56 getCapabilities = HookDevGetCapabilities;
57 getFunction = HookDevGetFunction;
58}
59
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030060HWC2::Error DrmHwcTwo::CreateDisplay(hwc2_display_t displ,
61 HWC2::DisplayType type) {
62 DrmDevice *drm = resource_manager_.GetDrmDevice(displ);
63 std::shared_ptr<Importer> importer = resource_manager_.GetImporter(displ);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010064 if (!drm || !importer) {
65 ALOGE("Failed to get a valid drmresource and importer");
Sean Paulac874152016-03-10 16:00:26 -050066 return HWC2::Error::NoResources;
67 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030068 displays_.emplace(std::piecewise_construct, std::forward_as_tuple(displ),
Sean Paulf72cccd2018-08-27 13:59:08 -040069 std::forward_as_tuple(&resource_manager_, drm, importer,
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030070 displ, type));
Sean Paulac874152016-03-10 16:00:26 -050071
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030072 DrmCrtc *crtc = drm->GetCrtcForDisplay(static_cast<int>(displ));
Sean Paulac874152016-03-10 16:00:26 -050073 if (!crtc) {
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030074 ALOGE("Failed to get crtc for display %d", static_cast<int>(displ));
Sean Paulac874152016-03-10 16:00:26 -050075 return HWC2::Error::BadDisplay;
76 }
Sean Paulac874152016-03-10 16:00:26 -050077 std::vector<DrmPlane *> display_planes;
Alexandru Gheorghec5463582018-03-27 15:52:02 +010078 for (auto &plane : drm->planes()) {
Sean Paulac874152016-03-10 16:00:26 -050079 if (plane->GetCrtcSupported(*crtc))
80 display_planes.push_back(plane.get());
81 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030082 displays_.at(displ).Init(&display_planes);
Sean Paulac874152016-03-10 16:00:26 -050083 return HWC2::Error::None;
84}
85
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030086HWC2::Error DrmHwcTwo::Init() {
87 int rv = resource_manager_.Init();
88 if (rv) {
89 ALOGE("Can't initialize the resource manager %d", rv);
90 return HWC2::Error::NoResources;
91 }
92
93 HWC2::Error ret = HWC2::Error::None;
94 for (int i = 0; i < resource_manager_.getDisplayCount(); i++) {
95 ret = CreateDisplay(i, HWC2::DisplayType::Physical);
96 if (ret != HWC2::Error::None) {
97 ALOGE("Failed to create display %d with error %d", i, ret);
98 return ret;
99 }
100 }
101
102 auto &drmDevices = resource_manager_.getDrmDevices();
103 for (auto &device : drmDevices) {
104 device->RegisterHotplugHandler(new DrmHotplugHandler(this, device.get()));
105 }
106 return ret;
107}
108
Sean Pauled2ec4b2016-03-10 15:35:40 -0500109template <typename... Args>
110static inline HWC2::Error unsupported(char const *func, Args... /*args*/) {
111 ALOGV("Unsupported function: %s", func);
112 return HWC2::Error::Unsupported;
113}
114
Sean Paulac874152016-03-10 16:00:26 -0500115static inline void supported(char const *func) {
116 ALOGV("Supported function: %s", func);
117}
118
Sean Pauled2ec4b2016-03-10 15:35:40 -0500119HWC2::Error DrmHwcTwo::CreateVirtualDisplay(uint32_t width, uint32_t height,
120 int32_t *format,
121 hwc2_display_t *display) {
122 // TODO: Implement virtual display
Sean Paulac874152016-03-10 16:00:26 -0500123 return unsupported(__func__, width, height, format, display);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500124}
125
126HWC2::Error DrmHwcTwo::DestroyVirtualDisplay(hwc2_display_t display) {
Sean Paulac874152016-03-10 16:00:26 -0500127 // TODO: Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500128 return unsupported(__func__, display);
129}
130
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200131std::string DrmHwcTwo::HwcDisplay::DumpDelta(
132 DrmHwcTwo::HwcDisplay::Stats delta) {
133 if (delta.total_pixops_ == 0)
134 return "No stats yet";
135 double Ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
136
137 return (std::stringstream()
138 << " Total frames count: " << delta.total_frames_ << "\n"
139 << " Failed to test commit frames: " << delta.failed_kms_validate_
140 << "\n"
141 << " Failed to commit frames: " << delta.failed_kms_present_ << "\n"
142 << ((delta.failed_kms_present_ > 0)
143 ? " !!! Internal failure, FIX it please\n"
144 : "")
145 << " Pixel operations (free units)"
146 << " : [TOTAL: " << delta.total_pixops_
147 << " / GPU: " << delta.gpu_pixops_ << "]\n"
148 << " Composition efficiency: " << Ratio)
149 .str();
150}
151
152std::string DrmHwcTwo::HwcDisplay::Dump() {
153 auto out = (std::stringstream()
154 << "- Display on: " << connector_->name() << "\n"
155 << "Statistics since system boot:\n"
156 << DumpDelta(total_stats_) << "\n\n"
157 << "Statistics since last dumpsys request:\n"
158 << DumpDelta(total_stats_.minus(prev_stats_)) << "\n\n")
159 .str();
160
161 memcpy(&prev_stats_, &total_stats_, sizeof(Stats));
162 return out;
163}
164
165void DrmHwcTwo::Dump(uint32_t *outSize, char *outBuffer) {
166 supported(__func__);
167
168 if (outBuffer != nullptr) {
169 auto copiedBytes = mDumpString.copy(outBuffer, *outSize);
170 *outSize = static_cast<uint32_t>(copiedBytes);
171 return;
172 }
173
174 std::stringstream output;
175
176 output << "-- drm_hwcomposer --\n\n";
177
178 for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &dp : displays_)
179 output << dp.second.Dump();
180
181 mDumpString = output.str();
182 *outSize = static_cast<uint32_t>(mDumpString.size());
Sean Pauled2ec4b2016-03-10 15:35:40 -0500183}
184
185uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() {
Sean Paulac874152016-03-10 16:00:26 -0500186 // TODO: Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500187 unsupported(__func__);
188 return 0;
189}
190
191HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor,
Sean Paulac874152016-03-10 16:00:26 -0500192 hwc2_callback_data_t data,
193 hwc2_function_pointer_t function) {
194 supported(__func__);
195 auto callback = static_cast<HWC2::Callback>(descriptor);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300196
197 if (!function) {
198 callbacks_.erase(callback);
199 return HWC2::Error::None;
200 }
201
Sean Paulac874152016-03-10 16:00:26 -0500202 callbacks_.emplace(callback, HwcCallback(data, function));
203
204 switch (callback) {
205 case HWC2::Callback::Hotplug: {
206 auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(function);
207 hotplug(data, HWC_DISPLAY_PRIMARY,
208 static_cast<int32_t>(HWC2::Connection::Connected));
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300209 auto &drmDevices = resource_manager_.getDrmDevices();
210 for (auto &device : drmDevices)
211 HandleInitialHotplugState(device.get());
Sean Paulac874152016-03-10 16:00:26 -0500212 break;
213 }
214 case HWC2::Callback::Vsync: {
215 for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &d :
216 displays_)
217 d.second.RegisterVsyncCallback(data, function);
218 break;
219 }
220 default:
221 break;
222 }
223 return HWC2::Error::None;
224}
225
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100226DrmHwcTwo::HwcDisplay::HwcDisplay(ResourceManager *resource_manager,
227 DrmDevice *drm,
Sean Paulac874152016-03-10 16:00:26 -0500228 std::shared_ptr<Importer> importer,
Sean Paulac874152016-03-10 16:00:26 -0500229 hwc2_display_t handle, HWC2::DisplayType type)
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100230 : resource_manager_(resource_manager),
231 drm_(drm),
232 importer_(importer),
233 handle_(handle),
234 type_(type) {
Sean Paulac874152016-03-10 16:00:26 -0500235 supported(__func__);
236}
237
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300238void DrmHwcTwo::HwcDisplay::ClearDisplay() {
239 compositor_.ClearDisplay();
240}
241
Sean Paulac874152016-03-10 16:00:26 -0500242HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) {
243 supported(__func__);
244 planner_ = Planner::CreateInstance(drm_);
245 if (!planner_) {
246 ALOGE("Failed to create planner instance for composition");
247 return HWC2::Error::NoResources;
248 }
249
250 int display = static_cast<int>(handle_);
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100251 int ret = compositor_.Init(resource_manager_, display);
Sean Paulac874152016-03-10 16:00:26 -0500252 if (ret) {
253 ALOGE("Failed display compositor init for display %d (%d)", display, ret);
254 return HWC2::Error::NoResources;
255 }
256
257 // Split up the given display planes into primary and overlay to properly
258 // interface with the composition
259 char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
260 property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
261 bool use_overlay_planes = atoi(use_overlay_planes_prop);
262 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
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300281 ret = vsync_worker_.Init(drm_, display);
282 if (ret) {
283 ALOGE("Failed to create event worker for d=%d %d\n", display, ret);
284 return HWC2::Error::BadDisplay;
285 }
286
287 return ChosePreferredConfig();
288}
289
290HWC2::Error DrmHwcTwo::HwcDisplay::ChosePreferredConfig() {
Sean Paulac874152016-03-10 16:00:26 -0500291 // Fetch the number of modes from the display
292 uint32_t num_configs;
293 HWC2::Error err = GetDisplayConfigs(&num_configs, NULL);
294 if (err != HWC2::Error::None || !num_configs)
295 return err;
296
Andrii Chepurnyi1b1e35e2019-02-19 21:38:13 +0200297 return SetActiveConfig(connector_->get_preferred_mode_id());
Sean Paulac874152016-03-10 16:00:26 -0500298}
299
300HWC2::Error DrmHwcTwo::HwcDisplay::RegisterVsyncCallback(
301 hwc2_callback_data_t data, hwc2_function_pointer_t func) {
302 supported(__func__);
303 auto callback = std::make_shared<DrmVsyncCallback>(data, func);
Adrian Salidofa37f672017-02-16 10:29:46 -0800304 vsync_worker_.RegisterCallback(std::move(callback));
Sean Paulac874152016-03-10 16:00:26 -0500305 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500306}
307
308HWC2::Error DrmHwcTwo::HwcDisplay::AcceptDisplayChanges() {
Sean Paulac874152016-03-10 16:00:26 -0500309 supported(__func__);
Sean Paulac874152016-03-10 16:00:26 -0500310 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_)
311 l.second.accept_type_change();
312 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500313}
314
315HWC2::Error DrmHwcTwo::HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Sean Paulac874152016-03-10 16:00:26 -0500316 supported(__func__);
317 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer());
318 *layer = static_cast<hwc2_layer_t>(layer_idx_);
319 ++layer_idx_;
320 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500321}
322
323HWC2::Error DrmHwcTwo::HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Sean Paulac874152016-03-10 16:00:26 -0500324 supported(__func__);
Vincent Donnefort9abec032019-10-09 15:43:43 +0100325 if (!get_layer(layer))
326 return HWC2::Error::BadLayer;
327
Sean Paulac874152016-03-10 16:00:26 -0500328 layers_.erase(layer);
329 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500330}
331
332HWC2::Error DrmHwcTwo::HwcDisplay::GetActiveConfig(hwc2_config_t *config) {
Sean Paulac874152016-03-10 16:00:26 -0500333 supported(__func__);
334 DrmMode const &mode = connector_->active_mode();
335 if (mode.id() == 0)
336 return HWC2::Error::BadConfig;
337
338 *config = mode.id();
339 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500340}
341
342HWC2::Error DrmHwcTwo::HwcDisplay::GetChangedCompositionTypes(
343 uint32_t *num_elements, hwc2_layer_t *layers, int32_t *types) {
Sean Paulac874152016-03-10 16:00:26 -0500344 supported(__func__);
345 uint32_t num_changes = 0;
346 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
347 if (l.second.type_changed()) {
348 if (layers && num_changes < *num_elements)
349 layers[num_changes] = l.first;
350 if (types && num_changes < *num_elements)
351 types[num_changes] = static_cast<int32_t>(l.second.validated_type());
352 ++num_changes;
353 }
354 }
355 if (!layers && !types)
356 *num_elements = num_changes;
357 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500358}
359
360HWC2::Error DrmHwcTwo::HwcDisplay::GetClientTargetSupport(uint32_t width,
Sean Paulac874152016-03-10 16:00:26 -0500361 uint32_t height,
362 int32_t /*format*/,
363 int32_t dataspace) {
364 supported(__func__);
365 std::pair<uint32_t, uint32_t> min = drm_->min_resolution();
366 std::pair<uint32_t, uint32_t> max = drm_->max_resolution();
367
368 if (width < min.first || height < min.second)
369 return HWC2::Error::Unsupported;
370
371 if (width > max.first || height > max.second)
372 return HWC2::Error::Unsupported;
373
374 if (dataspace != HAL_DATASPACE_UNKNOWN &&
375 dataspace != HAL_DATASPACE_STANDARD_UNSPECIFIED)
376 return HWC2::Error::Unsupported;
377
378 // TODO: Validate format can be handled by either GL or planes
379 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500380}
381
382HWC2::Error DrmHwcTwo::HwcDisplay::GetColorModes(uint32_t *num_modes,
Sean Paulac874152016-03-10 16:00:26 -0500383 int32_t *modes) {
384 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800385 if (!modes)
386 *num_modes = 1;
387
388 if (modes)
389 *modes = HAL_COLOR_MODE_NATIVE;
390
391 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500392}
393
394HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
Sean Paulac874152016-03-10 16:00:26 -0500395 int32_t attribute_in,
396 int32_t *value) {
397 supported(__func__);
Sean Paulf72cccd2018-08-27 13:59:08 -0400398 auto mode = std::find_if(connector_->modes().begin(),
399 connector_->modes().end(),
400 [config](DrmMode const &m) {
401 return m.id() == config;
402 });
Sean Paulac874152016-03-10 16:00:26 -0500403 if (mode == connector_->modes().end()) {
404 ALOGE("Could not find active mode for %d", config);
405 return HWC2::Error::BadConfig;
406 }
407
408 static const int32_t kUmPerInch = 25400;
409 uint32_t mm_width = connector_->mm_width();
410 uint32_t mm_height = connector_->mm_height();
411 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
412 switch (attribute) {
413 case HWC2::Attribute::Width:
414 *value = mode->h_display();
415 break;
416 case HWC2::Attribute::Height:
417 *value = mode->v_display();
418 break;
419 case HWC2::Attribute::VsyncPeriod:
420 // in nanoseconds
421 *value = 1000 * 1000 * 1000 / mode->v_refresh();
422 break;
423 case HWC2::Attribute::DpiX:
424 // Dots per 1000 inches
425 *value = mm_width ? (mode->h_display() * kUmPerInch) / mm_width : -1;
426 break;
427 case HWC2::Attribute::DpiY:
428 // Dots per 1000 inches
429 *value = mm_height ? (mode->v_display() * kUmPerInch) / mm_height : -1;
430 break;
431 default:
432 *value = -1;
433 return HWC2::Error::BadConfig;
434 }
435 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500436}
437
438HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
439 hwc2_config_t *configs) {
Sean Paulac874152016-03-10 16:00:26 -0500440 supported(__func__);
441 // Since this callback is normally invoked twice (once to get the count, and
442 // once to populate configs), we don't really want to read the edid
443 // redundantly. Instead, only update the modes on the first invocation. While
444 // it's possible this will result in stale modes, it'll all come out in the
445 // wash when we try to set the active config later.
446 if (!configs) {
447 int ret = connector_->UpdateModes();
448 if (ret) {
449 ALOGE("Failed to update display modes %d", ret);
450 return HWC2::Error::BadDisplay;
451 }
452 }
453
Neil Armstrongb67d0492019-06-20 09:00:21 +0000454 // Since the upper layers only look at vactive/hactive/refresh, height and
455 // width, it doesn't differentiate interlaced from progressive and other
456 // similar modes. Depending on the order of modes we return to SF, it could
457 // end up choosing a suboptimal configuration and dropping the preferred
458 // mode. To workaround this, don't offer interlaced modes to SF if there is
459 // at least one non-interlaced alternative and only offer a single WxH@R
460 // mode with at least the prefered mode from in DrmConnector::UpdateModes()
461
462 // TODO: Remove the following block of code until AOSP handles all modes
463 std::vector<DrmMode> sel_modes;
464
465 // Add the preferred mode first to be sure it's not dropped
466 auto mode = std::find_if(connector_->modes().begin(),
467 connector_->modes().end(), [&](DrmMode const &m) {
468 return m.id() ==
469 connector_->get_preferred_mode_id();
470 });
471 if (mode != connector_->modes().end())
472 sel_modes.push_back(*mode);
473
474 // Add the active mode if different from preferred mode
475 if (connector_->active_mode().id() != connector_->get_preferred_mode_id())
476 sel_modes.push_back(connector_->active_mode());
477
478 // Cycle over the modes and filter out "similar" modes, keeping only the
479 // first ones in the order given by DRM (from CEA ids and timings order)
Sean Paulac874152016-03-10 16:00:26 -0500480 for (const DrmMode &mode : connector_->modes()) {
Neil Armstrongb67d0492019-06-20 09:00:21 +0000481 // TODO: Remove this when 3D Attributes are in AOSP
482 if (mode.flags() & DRM_MODE_FLAG_3D_MASK)
483 continue;
484
Neil Armstrong4c027a72019-06-04 14:48:02 +0000485 // TODO: Remove this when the Interlaced attribute is in AOSP
486 if (mode.flags() & DRM_MODE_FLAG_INTERLACE) {
487 auto m = std::find_if(connector_->modes().begin(),
488 connector_->modes().end(),
489 [&mode](DrmMode const &m) {
490 return !(m.flags() & DRM_MODE_FLAG_INTERLACE) &&
491 m.h_display() == mode.h_display() &&
492 m.v_display() == mode.v_display();
493 });
Neil Armstrongb67d0492019-06-20 09:00:21 +0000494 if (m == connector_->modes().end())
495 sel_modes.push_back(mode);
496
497 continue;
Neil Armstrong4c027a72019-06-04 14:48:02 +0000498 }
Neil Armstrongb67d0492019-06-20 09:00:21 +0000499
500 // Search for a similar WxH@R mode in the filtered list and drop it if
501 // another mode with the same WxH@R has already been selected
502 // TODO: Remove this when AOSP handles duplicates modes
503 auto m = std::find_if(sel_modes.begin(), sel_modes.end(),
504 [&mode](DrmMode const &m) {
505 return m.h_display() == mode.h_display() &&
506 m.v_display() == mode.v_display() &&
507 m.v_refresh() == mode.v_refresh();
508 });
509 if (m == sel_modes.end())
510 sel_modes.push_back(mode);
511 }
512
513 auto num_modes = static_cast<uint32_t>(sel_modes.size());
514 if (!configs) {
515 *num_configs = num_modes;
516 return HWC2::Error::None;
517 }
518
519 uint32_t idx = 0;
520 for (const DrmMode &mode : sel_modes) {
521 if (idx >= *num_configs)
522 break;
523 configs[idx++] = mode.id();
Sean Paulac874152016-03-10 16:00:26 -0500524 }
525 *num_configs = idx;
526 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500527}
528
529HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
Sean Paulac874152016-03-10 16:00:26 -0500530 supported(__func__);
531 std::ostringstream stream;
532 stream << "display-" << connector_->id();
533 std::string string = stream.str();
534 size_t length = string.length();
535 if (!name) {
536 *size = length;
537 return HWC2::Error::None;
538 }
539
540 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
541 strncpy(name, string.c_str(), *size);
542 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500543}
544
Sean Paulac874152016-03-10 16:00:26 -0500545HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
546 uint32_t *num_elements,
547 hwc2_layer_t *layers,
548 int32_t *layer_requests) {
549 supported(__func__);
550 // TODO: I think virtual display should request
551 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
552 unsupported(__func__, display_requests, num_elements, layers, layer_requests);
553 *num_elements = 0;
554 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500555}
556
557HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayType(int32_t *type) {
Sean Paulac874152016-03-10 16:00:26 -0500558 supported(__func__);
559 *type = static_cast<int32_t>(type_);
560 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500561}
562
563HWC2::Error DrmHwcTwo::HwcDisplay::GetDozeSupport(int32_t *support) {
Sean Paulac874152016-03-10 16:00:26 -0500564 supported(__func__);
565 *support = 0;
566 return HWC2::Error::None;
567}
568
569HWC2::Error DrmHwcTwo::HwcDisplay::GetHdrCapabilities(
Sean Paulf72cccd2018-08-27 13:59:08 -0400570 uint32_t *num_types, int32_t * /*types*/, float * /*max_luminance*/,
571 float * /*max_average_luminance*/, float * /*min_luminance*/) {
Sean Paulac874152016-03-10 16:00:26 -0500572 supported(__func__);
573 *num_types = 0;
574 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500575}
576
577HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
Sean Paulac874152016-03-10 16:00:26 -0500578 hwc2_layer_t *layers,
579 int32_t *fences) {
580 supported(__func__);
581 uint32_t num_layers = 0;
582
583 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
584 ++num_layers;
585 if (layers == NULL || fences == NULL) {
586 continue;
587 } else if (num_layers > *num_elements) {
588 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
589 return HWC2::Error::None;
590 }
591
592 layers[num_layers - 1] = l.first;
593 fences[num_layers - 1] = l.second.take_release_fence();
594 }
595 *num_elements = num_layers;
596 return HWC2::Error::None;
597}
598
Matteo Franchinc56eede2019-12-03 17:10:38 +0000599void DrmHwcTwo::HwcDisplay::AddFenceToPresentFence(int fd) {
Sean Paulac874152016-03-10 16:00:26 -0500600 if (fd < 0)
601 return;
602
Matteo Franchinc56eede2019-12-03 17:10:38 +0000603 if (present_fence_.get() >= 0) {
604 int old_fence = present_fence_.get();
605 present_fence_.Set(sync_merge("dc_present", old_fence, fd));
606 close(fd);
Sean Paulac874152016-03-10 16:00:26 -0500607 } else {
Matteo Franchinc56eede2019-12-03 17:10:38 +0000608 present_fence_.Set(fd);
Sean Paulac874152016-03-10 16:00:26 -0500609 }
Sean Pauled2ec4b2016-03-10 15:35:40 -0500610}
611
Roman Stratiienkoafb36892019-11-08 17:16:11 +0200612bool DrmHwcTwo::HwcDisplay::HardwareSupportsLayerType(
613 HWC2::Composition comp_type) {
614 return comp_type == HWC2::Composition::Device ||
615 comp_type == HWC2::Composition::Cursor;
616}
617
Rob Herring4f6c62e2018-05-17 14:33:02 -0500618HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) {
Sean Paulac874152016-03-10 16:00:26 -0500619 std::vector<DrmCompositionDisplayLayersMap> layers_map;
620 layers_map.emplace_back();
621 DrmCompositionDisplayLayersMap &map = layers_map.back();
622
623 map.display = static_cast<int>(handle_);
624 map.geometry_changed = true; // TODO: Fix this
625
626 // order the layers by z-order
627 bool use_client_layer = false;
Alexandru Gheorghe1542d292018-06-13 16:46:36 +0100628 uint32_t client_z_order = UINT32_MAX;
Sean Paulac874152016-03-10 16:00:26 -0500629 std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
630 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
Roman Stratiienkof2647232019-11-21 01:58:35 +0200631 switch (l.second.validated_type()) {
Sean Paulac874152016-03-10 16:00:26 -0500632 case HWC2::Composition::Device:
633 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
634 break;
635 case HWC2::Composition::Client:
Alexandru Gheorghe1542d292018-06-13 16:46:36 +0100636 // Place it at the z_order of the lowest client layer
Sean Paulac874152016-03-10 16:00:26 -0500637 use_client_layer = true;
Alexandru Gheorghe1542d292018-06-13 16:46:36 +0100638 client_z_order = std::min(client_z_order, l.second.z_order());
Sean Paulac874152016-03-10 16:00:26 -0500639 break;
640 default:
641 continue;
642 }
643 }
644 if (use_client_layer)
645 z_map.emplace(std::make_pair(client_z_order, &client_layer_));
646
Rob Herring4f6c62e2018-05-17 14:33:02 -0500647 if (z_map.empty())
648 return HWC2::Error::BadLayer;
649
Sean Paulac874152016-03-10 16:00:26 -0500650 // now that they're ordered by z, add them to the composition
651 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
652 DrmHwcLayer layer;
653 l.second->PopulateDrmLayer(&layer);
Andrii Chepurnyidc1278c2018-03-20 19:41:18 +0200654 int ret = layer.ImportBuffer(importer_.get());
Sean Paulac874152016-03-10 16:00:26 -0500655 if (ret) {
656 ALOGE("Failed to import layer, ret=%d", ret);
657 return HWC2::Error::NoResources;
658 }
659 map.layers.emplace_back(std::move(layer));
660 }
Sean Paulac874152016-03-10 16:00:26 -0500661
Sean Paulf72cccd2018-08-27 13:59:08 -0400662 std::unique_ptr<DrmDisplayComposition> composition = compositor_
663 .CreateComposition();
Sean Paulac874152016-03-10 16:00:26 -0500664 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
665
666 // TODO: Don't always assume geometry changed
667 int ret = composition->SetLayers(map.layers.data(), map.layers.size(), true);
668 if (ret) {
669 ALOGE("Failed to set layers in the composition ret=%d", ret);
670 return HWC2::Error::BadLayer;
671 }
672
673 std::vector<DrmPlane *> primary_planes(primary_planes_);
674 std::vector<DrmPlane *> overlay_planes(overlay_planes_);
Rob Herringaf0d9752018-05-04 16:34:19 -0500675 ret = composition->Plan(&primary_planes, &overlay_planes);
Sean Paulac874152016-03-10 16:00:26 -0500676 if (ret) {
677 ALOGE("Failed to plan the composition ret=%d", ret);
678 return HWC2::Error::BadConfig;
679 }
680
681 // Disable the planes we're not using
682 for (auto i = primary_planes.begin(); i != primary_planes.end();) {
683 composition->AddPlaneDisable(*i);
684 i = primary_planes.erase(i);
685 }
686 for (auto i = overlay_planes.begin(); i != overlay_planes.end();) {
687 composition->AddPlaneDisable(*i);
688 i = overlay_planes.erase(i);
689 }
690
Rob Herring4f6c62e2018-05-17 14:33:02 -0500691 if (test) {
692 ret = compositor_.TestComposition(composition.get());
693 } else {
Rob Herring4f6c62e2018-05-17 14:33:02 -0500694 ret = compositor_.ApplyComposition(std::move(composition));
Matteo Franchinc56eede2019-12-03 17:10:38 +0000695 AddFenceToPresentFence(compositor_.TakeOutFence());
Rob Herring4f6c62e2018-05-17 14:33:02 -0500696 }
Sean Paulac874152016-03-10 16:00:26 -0500697 if (ret) {
John Stultz78c9f6c2018-05-24 16:43:35 -0700698 if (!test)
699 ALOGE("Failed to apply the frame composition ret=%d", ret);
Sean Paulac874152016-03-10 16:00:26 -0500700 return HWC2::Error::BadParameter;
701 }
Rob Herring4f6c62e2018-05-17 14:33:02 -0500702 return HWC2::Error::None;
703}
704
Matteo Franchinc56eede2019-12-03 17:10:38 +0000705HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *present_fence) {
Rob Herring4f6c62e2018-05-17 14:33:02 -0500706 supported(__func__);
707 HWC2::Error ret;
708
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200709 ++total_stats_.total_frames_;
710
Rob Herring4f6c62e2018-05-17 14:33:02 -0500711 ret = CreateComposition(false);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200712 if (ret != HWC2::Error::None)
713 ++total_stats_.failed_kms_present_;
714
Rob Herring4f6c62e2018-05-17 14:33:02 -0500715 if (ret == HWC2::Error::BadLayer) {
716 // Can we really have no client or device layers?
Matteo Franchinc56eede2019-12-03 17:10:38 +0000717 *present_fence = -1;
Rob Herring4f6c62e2018-05-17 14:33:02 -0500718 return HWC2::Error::None;
719 }
720 if (ret != HWC2::Error::None)
721 return ret;
Sean Paulac874152016-03-10 16:00:26 -0500722
Matteo Franchinc56eede2019-12-03 17:10:38 +0000723 *present_fence = present_fence_.Release();
Sean Paulac874152016-03-10 16:00:26 -0500724
725 ++frame_no_;
726 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500727}
728
729HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
Sean Paulac874152016-03-10 16:00:26 -0500730 supported(__func__);
Sean Paulf72cccd2018-08-27 13:59:08 -0400731 auto mode = std::find_if(connector_->modes().begin(),
732 connector_->modes().end(),
733 [config](DrmMode const &m) {
734 return m.id() == config;
735 });
Sean Paulac874152016-03-10 16:00:26 -0500736 if (mode == connector_->modes().end()) {
737 ALOGE("Could not find active mode for %d", config);
738 return HWC2::Error::BadConfig;
739 }
740
Sean Paulf72cccd2018-08-27 13:59:08 -0400741 std::unique_ptr<DrmDisplayComposition> composition = compositor_
742 .CreateComposition();
Sean Paulac874152016-03-10 16:00:26 -0500743 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
744 int ret = composition->SetDisplayMode(*mode);
Sean Pauled45a8e2017-02-28 13:17:34 -0500745 ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500746 if (ret) {
747 ALOGE("Failed to queue dpms composition on %d", ret);
748 return HWC2::Error::BadConfig;
749 }
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300750
751 connector_->set_active_mode(*mode);
Sean Paulac874152016-03-10 16:00:26 -0500752
753 // Setup the client layer's dimensions
754 hwc_rect_t display_frame = {.left = 0,
755 .top = 0,
756 .right = static_cast<int>(mode->h_display()),
757 .bottom = static_cast<int>(mode->v_display())};
758 client_layer_.SetLayerDisplayFrame(display_frame);
759 hwc_frect_t source_crop = {.left = 0.0f,
760 .top = 0.0f,
761 .right = mode->h_display() + 0.0f,
762 .bottom = mode->v_display() + 0.0f};
763 client_layer_.SetLayerSourceCrop(source_crop);
764
765 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500766}
767
768HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target,
769 int32_t acquire_fence,
770 int32_t dataspace,
Rob Herring1b2685c2017-11-29 10:19:57 -0600771 hwc_region_t /*damage*/) {
Sean Paulac874152016-03-10 16:00:26 -0500772 supported(__func__);
773 UniqueFd uf(acquire_fence);
774
775 client_layer_.set_buffer(target);
776 client_layer_.set_acquire_fence(uf.get());
777 client_layer_.SetLayerDataspace(dataspace);
778 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500779}
780
781HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500782 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800783
784 if (mode != HAL_COLOR_MODE_NATIVE)
Vincent Donnefort7834a892019-10-09 15:53:56 +0100785 return HWC2::Error::BadParameter;
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800786
787 color_mode_ = mode;
788 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500789}
790
791HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix,
Sean Paulac874152016-03-10 16:00:26 -0500792 int32_t hint) {
793 supported(__func__);
794 // TODO: Force client composition if we get this
Sean Pauled2ec4b2016-03-10 15:35:40 -0500795 return unsupported(__func__, matrix, hint);
796}
797
798HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500799 int32_t release_fence) {
800 supported(__func__);
801 // TODO: Need virtual display support
Sean Pauled2ec4b2016-03-10 15:35:40 -0500802 return unsupported(__func__, buffer, release_fence);
803}
804
Sean Paulac874152016-03-10 16:00:26 -0500805HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) {
806 supported(__func__);
807 uint64_t dpms_value = 0;
808 auto mode = static_cast<HWC2::PowerMode>(mode_in);
809 switch (mode) {
810 case HWC2::PowerMode::Off:
811 dpms_value = DRM_MODE_DPMS_OFF;
812 break;
813 case HWC2::PowerMode::On:
814 dpms_value = DRM_MODE_DPMS_ON;
815 break;
Vincent Donnefort60ef7eb2019-10-09 11:39:28 +0100816 case HWC2::PowerMode::Doze:
817 case HWC2::PowerMode::DozeSuspend:
818 return HWC2::Error::Unsupported;
Sean Paulac874152016-03-10 16:00:26 -0500819 default:
820 ALOGI("Power mode %d is unsupported\n", mode);
Vincent Donnefort60ef7eb2019-10-09 11:39:28 +0100821 return HWC2::Error::BadParameter;
Sean Paulac874152016-03-10 16:00:26 -0500822 };
823
Sean Paulf72cccd2018-08-27 13:59:08 -0400824 std::unique_ptr<DrmDisplayComposition> composition = compositor_
825 .CreateComposition();
Sean Paulac874152016-03-10 16:00:26 -0500826 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
827 composition->SetDpmsMode(dpms_value);
Sean Pauled45a8e2017-02-28 13:17:34 -0500828 int ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500829 if (ret) {
830 ALOGE("Failed to apply the dpms composition ret=%d", ret);
831 return HWC2::Error::BadParameter;
832 }
833 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500834}
835
836HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Sean Paulac874152016-03-10 16:00:26 -0500837 supported(__func__);
Andrii Chepurnyi4bdd0fe2018-07-27 15:14:37 +0300838 vsync_worker_.VSyncControl(HWC2_VSYNC_ENABLE == enabled);
Sean Paulac874152016-03-10 16:00:26 -0500839 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500840}
841
842HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types,
Sean Paulac874152016-03-10 16:00:26 -0500843 uint32_t *num_requests) {
844 supported(__func__);
845 *num_types = 0;
846 *num_requests = 0;
Rob Herring4f6c62e2018-05-17 14:33:02 -0500847 size_t avail_planes = primary_planes_.size() + overlay_planes_.size();
Rob Herring4f6c62e2018-05-17 14:33:02 -0500848
849 /*
850 * If more layers then planes, save one plane
851 * for client composited layers
852 */
853 if (avail_planes < layers_.size())
854 avail_planes--;
855
Roman Stratiienkof2647232019-11-21 01:58:35 +0200856 std::map<uint32_t, DrmHwcTwo::HwcLayer *, std::greater<int>> z_map;
857 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_)
858 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
859
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200860 uint32_t total_pixops = 0, gpu_pixops = 0;
861
Roman Stratiienkof2647232019-11-21 01:58:35 +0200862 bool gpu_block = false;
Rob Herring4f6c62e2018-05-17 14:33:02 -0500863 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200864 hwc_rect_t df = l.second->display_frame();
865 uint32_t pixops = (df.right - df.left) * (df.bottom - df.top);
Roman Stratiienkof2647232019-11-21 01:58:35 +0200866 if (gpu_block || avail_planes == 0 ||
Roman Stratiienkoafb36892019-11-08 17:16:11 +0200867 !HardwareSupportsLayerType(l.second->sf_type()) ||
Roman Stratiienkof2647232019-11-21 01:58:35 +0200868 !importer_->CanImportBuffer(l.second->buffer())) {
869 gpu_block = true;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200870 gpu_pixops += pixops;
Roman Stratiienkof2647232019-11-21 01:58:35 +0200871 ++*num_types;
872 } else {
873 avail_planes--;
874 }
875
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200876 total_pixops += pixops;
Roman Stratiienkof2647232019-11-21 01:58:35 +0200877 l.second->set_validated_type(gpu_block ? HWC2::Composition::Client
878 : HWC2::Composition::Device);
Rob Herring4f6c62e2018-05-17 14:33:02 -0500879 }
880
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200881 if (CreateComposition(true) != HWC2::Error::None) {
882 ++total_stats_.failed_kms_validate_;
883 gpu_pixops = total_pixops;
Roman Stratiienkof2647232019-11-21 01:58:35 +0200884 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_)
885 l.second.set_validated_type(HWC2::Composition::Client);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200886 }
887
888 total_stats_.gpu_pixops_ += gpu_pixops;
889 total_stats_.total_pixops_ += total_pixops;
Roman Stratiienkof2647232019-11-21 01:58:35 +0200890
Rob Herringee8f45b2017-06-09 15:15:55 -0500891 return *num_types ? HWC2::Error::HasChanges : HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500892}
893
894HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t x, int32_t y) {
Sean Paulac874152016-03-10 16:00:26 -0500895 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800896 cursor_x_ = x;
897 cursor_y_ = y;
898 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500899}
900
901HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500902 supported(__func__);
903 blending_ = static_cast<HWC2::BlendMode>(mode);
904 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500905}
906
907HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500908 int32_t acquire_fence) {
909 supported(__func__);
910 UniqueFd uf(acquire_fence);
911
912 // The buffer and acquire_fence are handled elsewhere
913 if (sf_type_ == HWC2::Composition::Client ||
914 sf_type_ == HWC2::Composition::Sideband ||
915 sf_type_ == HWC2::Composition::SolidColor)
916 return HWC2::Error::None;
917
918 set_buffer(buffer);
919 set_acquire_fence(uf.get());
920 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500921}
922
923HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) {
Sean Paulac874152016-03-10 16:00:26 -0500924 // TODO: Punt to client composition here?
Sean Pauled2ec4b2016-03-10 15:35:40 -0500925 return unsupported(__func__, color);
926}
927
928HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) {
Sean Paulac874152016-03-10 16:00:26 -0500929 sf_type_ = static_cast<HWC2::Composition>(type);
930 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500931}
932
933HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) {
Sean Paulac874152016-03-10 16:00:26 -0500934 supported(__func__);
935 dataspace_ = static_cast<android_dataspace_t>(dataspace);
936 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500937}
938
939HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
Sean Paulac874152016-03-10 16:00:26 -0500940 supported(__func__);
941 display_frame_ = frame;
942 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500943}
944
945HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) {
Sean Paulac874152016-03-10 16:00:26 -0500946 supported(__func__);
947 alpha_ = alpha;
948 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500949}
950
951HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream(
952 const native_handle_t *stream) {
Sean Paulac874152016-03-10 16:00:26 -0500953 supported(__func__);
954 // TODO: We don't support sideband
Sean Pauled2ec4b2016-03-10 15:35:40 -0500955 return unsupported(__func__, stream);
956}
957
958HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
Sean Paulac874152016-03-10 16:00:26 -0500959 supported(__func__);
960 source_crop_ = crop;
961 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500962}
963
964HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -0500965 supported(__func__);
966 // TODO: We don't use surface damage, marking as unsupported
967 unsupported(__func__, damage);
968 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500969}
970
971HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) {
Sean Paulac874152016-03-10 16:00:26 -0500972 supported(__func__);
973 transform_ = static_cast<HWC2::Transform>(transform);
974 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500975}
976
977HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) {
Sean Paulac874152016-03-10 16:00:26 -0500978 supported(__func__);
979 // TODO: We don't use this information, marking as unsupported
980 unsupported(__func__, visible);
981 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500982}
983
Sean Paulac874152016-03-10 16:00:26 -0500984HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) {
985 supported(__func__);
986 z_order_ = order;
987 return HWC2::Error::None;
988}
989
990void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) {
991 supported(__func__);
992 switch (blending_) {
993 case HWC2::BlendMode::None:
994 layer->blending = DrmHwcBlending::kNone;
995 break;
996 case HWC2::BlendMode::Premultiplied:
997 layer->blending = DrmHwcBlending::kPreMult;
998 break;
999 case HWC2::BlendMode::Coverage:
1000 layer->blending = DrmHwcBlending::kCoverage;
1001 break;
1002 default:
1003 ALOGE("Unknown blending mode b=%d", blending_);
1004 layer->blending = DrmHwcBlending::kNone;
1005 break;
1006 }
1007
1008 OutputFd release_fence = release_fence_output();
1009
1010 layer->sf_handle = buffer_;
1011 layer->acquire_fence = acquire_fence_.Release();
1012 layer->release_fence = std::move(release_fence);
1013 layer->SetDisplayFrame(display_frame_);
Stefan Schake025d0a62018-05-04 18:03:00 +02001014 layer->alpha = static_cast<uint16_t>(65535.0f * alpha_ + 0.5f);
Sean Paulac874152016-03-10 16:00:26 -05001015 layer->SetSourceCrop(source_crop_);
1016 layer->SetTransform(static_cast<int32_t>(transform_));
Sean Pauled2ec4b2016-03-10 15:35:40 -05001017}
1018
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +03001019void DrmHwcTwo::HandleDisplayHotplug(hwc2_display_t displayid, int state) {
1020 auto cb = callbacks_.find(HWC2::Callback::Hotplug);
1021 if (cb == callbacks_.end())
1022 return;
1023
1024 auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(cb->second.func);
1025 hotplug(cb->second.data, displayid,
1026 (state == DRM_MODE_CONNECTED ? HWC2_CONNECTION_CONNECTED
1027 : HWC2_CONNECTION_DISCONNECTED));
1028}
1029
1030void DrmHwcTwo::HandleInitialHotplugState(DrmDevice *drmDevice) {
1031 for (auto &conn : drmDevice->connectors()) {
1032 if (conn->state() != DRM_MODE_CONNECTED)
1033 continue;
1034 HandleDisplayHotplug(conn->display(), conn->state());
1035 }
1036}
1037
1038void DrmHwcTwo::DrmHotplugHandler::HandleEvent(uint64_t timestamp_us) {
1039 for (auto &conn : drm_->connectors()) {
1040 drmModeConnection old_state = conn->state();
1041 drmModeConnection cur_state = conn->UpdateModes()
1042 ? DRM_MODE_UNKNOWNCONNECTION
1043 : conn->state();
1044
1045 if (cur_state == old_state)
1046 continue;
1047
1048 ALOGI("%s event @%" PRIu64 " for connector %u on display %d",
1049 cur_state == DRM_MODE_CONNECTED ? "Plug" : "Unplug", timestamp_us,
1050 conn->id(), conn->display());
1051
1052 int display_id = conn->display();
1053 if (cur_state == DRM_MODE_CONNECTED) {
1054 auto &display = hwc2_->displays_.at(display_id);
1055 display.ChosePreferredConfig();
1056 } else {
1057 auto &display = hwc2_->displays_.at(display_id);
1058 display.ClearDisplay();
1059 }
1060
1061 hwc2_->HandleDisplayHotplug(display_id, cur_state);
1062 }
1063}
1064
Sean Pauled2ec4b2016-03-10 15:35:40 -05001065// static
1066int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) {
1067 unsupported(__func__);
1068 return 0;
1069}
1070
1071// static
1072void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/,
Sean Paulac874152016-03-10 16:00:26 -05001073 uint32_t *out_count,
1074 int32_t * /*out_capabilities*/) {
1075 supported(__func__);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001076 *out_count = 0;
1077}
1078
1079// static
Sean Paulac874152016-03-10 16:00:26 -05001080hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
1081 struct hwc2_device * /*dev*/, int32_t descriptor) {
1082 supported(__func__);
1083 auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001084 switch (func) {
1085 // Device functions
1086 case HWC2::FunctionDescriptor::CreateVirtualDisplay:
1087 return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
1088 DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
1089 &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
Sean Paulf72cccd2018-08-27 13:59:08 -04001090 int32_t *, hwc2_display_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001091 case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
1092 return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
1093 DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
1094 &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
1095 case HWC2::FunctionDescriptor::Dump:
1096 return ToHook<HWC2_PFN_DUMP>(
1097 DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump,
1098 uint32_t *, char *>);
1099 case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
1100 return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
1101 DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
1102 &DrmHwcTwo::GetMaxVirtualDisplayCount>);
1103 case HWC2::FunctionDescriptor::RegisterCallback:
1104 return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
1105 DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
1106 &DrmHwcTwo::RegisterCallback, int32_t,
1107 hwc2_callback_data_t, hwc2_function_pointer_t>);
1108
1109 // Display functions
1110 case HWC2::FunctionDescriptor::AcceptDisplayChanges:
1111 return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
1112 DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
1113 &HwcDisplay::AcceptDisplayChanges>);
1114 case HWC2::FunctionDescriptor::CreateLayer:
1115 return ToHook<HWC2_PFN_CREATE_LAYER>(
1116 DisplayHook<decltype(&HwcDisplay::CreateLayer),
1117 &HwcDisplay::CreateLayer, hwc2_layer_t *>);
1118 case HWC2::FunctionDescriptor::DestroyLayer:
1119 return ToHook<HWC2_PFN_DESTROY_LAYER>(
1120 DisplayHook<decltype(&HwcDisplay::DestroyLayer),
1121 &HwcDisplay::DestroyLayer, hwc2_layer_t>);
1122 case HWC2::FunctionDescriptor::GetActiveConfig:
1123 return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
1124 DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
1125 &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
1126 case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
1127 return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
1128 DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
1129 &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
1130 hwc2_layer_t *, int32_t *>);
1131 case HWC2::FunctionDescriptor::GetClientTargetSupport:
1132 return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
1133 DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
1134 &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
1135 int32_t, int32_t>);
1136 case HWC2::FunctionDescriptor::GetColorModes:
1137 return ToHook<HWC2_PFN_GET_COLOR_MODES>(
1138 DisplayHook<decltype(&HwcDisplay::GetColorModes),
1139 &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
1140 case HWC2::FunctionDescriptor::GetDisplayAttribute:
Sean Paulf72cccd2018-08-27 13:59:08 -04001141 return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(
1142 DisplayHook<decltype(&HwcDisplay::GetDisplayAttribute),
1143 &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t,
1144 int32_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001145 case HWC2::FunctionDescriptor::GetDisplayConfigs:
Sean Paulf72cccd2018-08-27 13:59:08 -04001146 return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(
1147 DisplayHook<decltype(&HwcDisplay::GetDisplayConfigs),
1148 &HwcDisplay::GetDisplayConfigs, uint32_t *,
1149 hwc2_config_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001150 case HWC2::FunctionDescriptor::GetDisplayName:
1151 return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
1152 DisplayHook<decltype(&HwcDisplay::GetDisplayName),
1153 &HwcDisplay::GetDisplayName, uint32_t *, char *>);
1154 case HWC2::FunctionDescriptor::GetDisplayRequests:
1155 return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
1156 DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
1157 &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
1158 hwc2_layer_t *, int32_t *>);
1159 case HWC2::FunctionDescriptor::GetDisplayType:
1160 return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
1161 DisplayHook<decltype(&HwcDisplay::GetDisplayType),
1162 &HwcDisplay::GetDisplayType, int32_t *>);
1163 case HWC2::FunctionDescriptor::GetDozeSupport:
1164 return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
1165 DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
1166 &HwcDisplay::GetDozeSupport, int32_t *>);
Sean Paulac874152016-03-10 16:00:26 -05001167 case HWC2::FunctionDescriptor::GetHdrCapabilities:
1168 return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
1169 DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
1170 &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
1171 float *, float *, float *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001172 case HWC2::FunctionDescriptor::GetReleaseFences:
1173 return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
1174 DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
1175 &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
1176 int32_t *>);
1177 case HWC2::FunctionDescriptor::PresentDisplay:
1178 return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
1179 DisplayHook<decltype(&HwcDisplay::PresentDisplay),
1180 &HwcDisplay::PresentDisplay, int32_t *>);
1181 case HWC2::FunctionDescriptor::SetActiveConfig:
1182 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
1183 DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
1184 &HwcDisplay::SetActiveConfig, hwc2_config_t>);
1185 case HWC2::FunctionDescriptor::SetClientTarget:
Sean Paulf72cccd2018-08-27 13:59:08 -04001186 return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(
1187 DisplayHook<decltype(&HwcDisplay::SetClientTarget),
1188 &HwcDisplay::SetClientTarget, buffer_handle_t, int32_t,
1189 int32_t, hwc_region_t>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001190 case HWC2::FunctionDescriptor::SetColorMode:
1191 return ToHook<HWC2_PFN_SET_COLOR_MODE>(
1192 DisplayHook<decltype(&HwcDisplay::SetColorMode),
1193 &HwcDisplay::SetColorMode, int32_t>);
1194 case HWC2::FunctionDescriptor::SetColorTransform:
1195 return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
1196 DisplayHook<decltype(&HwcDisplay::SetColorTransform),
1197 &HwcDisplay::SetColorTransform, const float *, int32_t>);
1198 case HWC2::FunctionDescriptor::SetOutputBuffer:
1199 return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
1200 DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
1201 &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
1202 case HWC2::FunctionDescriptor::SetPowerMode:
1203 return ToHook<HWC2_PFN_SET_POWER_MODE>(
1204 DisplayHook<decltype(&HwcDisplay::SetPowerMode),
1205 &HwcDisplay::SetPowerMode, int32_t>);
1206 case HWC2::FunctionDescriptor::SetVsyncEnabled:
1207 return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
1208 DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
1209 &HwcDisplay::SetVsyncEnabled, int32_t>);
1210 case HWC2::FunctionDescriptor::ValidateDisplay:
1211 return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
1212 DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
1213 &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
1214
1215 // Layer functions
1216 case HWC2::FunctionDescriptor::SetCursorPosition:
1217 return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
1218 LayerHook<decltype(&HwcLayer::SetCursorPosition),
1219 &HwcLayer::SetCursorPosition, int32_t, int32_t>);
1220 case HWC2::FunctionDescriptor::SetLayerBlendMode:
1221 return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
1222 LayerHook<decltype(&HwcLayer::SetLayerBlendMode),
1223 &HwcLayer::SetLayerBlendMode, int32_t>);
1224 case HWC2::FunctionDescriptor::SetLayerBuffer:
1225 return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
1226 LayerHook<decltype(&HwcLayer::SetLayerBuffer),
1227 &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>);
1228 case HWC2::FunctionDescriptor::SetLayerColor:
1229 return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
1230 LayerHook<decltype(&HwcLayer::SetLayerColor),
1231 &HwcLayer::SetLayerColor, hwc_color_t>);
1232 case HWC2::FunctionDescriptor::SetLayerCompositionType:
1233 return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
1234 LayerHook<decltype(&HwcLayer::SetLayerCompositionType),
1235 &HwcLayer::SetLayerCompositionType, int32_t>);
1236 case HWC2::FunctionDescriptor::SetLayerDataspace:
1237 return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
1238 LayerHook<decltype(&HwcLayer::SetLayerDataspace),
1239 &HwcLayer::SetLayerDataspace, int32_t>);
1240 case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
1241 return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
1242 LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame),
1243 &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>);
1244 case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
1245 return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
1246 LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha),
1247 &HwcLayer::SetLayerPlaneAlpha, float>);
1248 case HWC2::FunctionDescriptor::SetLayerSidebandStream:
Sean Paulf72cccd2018-08-27 13:59:08 -04001249 return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(
1250 LayerHook<decltype(&HwcLayer::SetLayerSidebandStream),
1251 &HwcLayer::SetLayerSidebandStream,
1252 const native_handle_t *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -05001253 case HWC2::FunctionDescriptor::SetLayerSourceCrop:
1254 return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
1255 LayerHook<decltype(&HwcLayer::SetLayerSourceCrop),
1256 &HwcLayer::SetLayerSourceCrop, hwc_frect_t>);
1257 case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
1258 return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
1259 LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage),
1260 &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>);
1261 case HWC2::FunctionDescriptor::SetLayerTransform:
1262 return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
1263 LayerHook<decltype(&HwcLayer::SetLayerTransform),
1264 &HwcLayer::SetLayerTransform, int32_t>);
1265 case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
1266 return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
1267 LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion),
1268 &HwcLayer::SetLayerVisibleRegion, hwc_region_t>);
1269 case HWC2::FunctionDescriptor::SetLayerZOrder:
1270 return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
1271 LayerHook<decltype(&HwcLayer::SetLayerZOrder),
1272 &HwcLayer::SetLayerZOrder, uint32_t>);
Sean Paulac874152016-03-10 16:00:26 -05001273 case HWC2::FunctionDescriptor::Invalid:
Sean Pauled2ec4b2016-03-10 15:35:40 -05001274 default:
1275 return NULL;
1276 }
1277}
Sean Paulac874152016-03-10 16:00:26 -05001278
1279// static
1280int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
1281 struct hw_device_t **dev) {
1282 supported(__func__);
1283 if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
1284 ALOGE("Invalid module name- %s", name);
1285 return -EINVAL;
1286 }
1287
1288 std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo());
1289 if (!ctx) {
1290 ALOGE("Failed to allocate DrmHwcTwo");
1291 return -ENOMEM;
1292 }
1293
1294 HWC2::Error err = ctx->Init();
1295 if (err != HWC2::Error::None) {
1296 ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err);
1297 return -EINVAL;
1298 }
1299
1300 ctx->common.module = const_cast<hw_module_t *>(module);
1301 *dev = &ctx->common;
1302 ctx.release();
1303 return 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001304}
Sean Paulf72cccd2018-08-27 13:59:08 -04001305} // namespace android
Sean Paulac874152016-03-10 16:00:26 -05001306
1307static struct hw_module_methods_t hwc2_module_methods = {
1308 .open = android::DrmHwcTwo::HookDevOpen,
1309};
1310
1311hw_module_t HAL_MODULE_INFO_SYM = {
1312 .tag = HARDWARE_MODULE_TAG,
1313 .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
1314 .id = HWC_HARDWARE_MODULE_ID,
1315 .name = "DrmHwcTwo module",
1316 .author = "The Android Open Source Project",
1317 .methods = &hwc2_module_methods,
1318 .dso = NULL,
1319 .reserved = {0},
1320};