blob: 617467a561955f1cf7d7c132267f71a523d63840 [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 Paulac874152016-03-10 16:00:26 -050020#include "drmdisplaycomposition.h"
21#include "drmhwcomposer.h"
Sean Pauled2ec4b2016-03-10 15:35:40 -050022#include "drmhwctwo.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
John Stultz9057a6f2018-04-26 12:05:55 -070029#include <log/log.h>
Sean Paulac874152016-03-10 16:00:26 -050030#include <cutils/properties.h>
31#include <hardware/hardware.h>
Sean Pauled2ec4b2016-03-10 15:35:40 -050032#include <hardware/hwcomposer2.h>
33
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
Sean Paulac874152016-03-10 16:00:26 -050060HWC2::Error DrmHwcTwo::Init() {
61 int ret = drm_.Init();
62 if (ret) {
63 ALOGE("Can't initialize drm object %d", ret);
64 return HWC2::Error::NoResources;
65 }
66
67 importer_.reset(Importer::CreateInstance(&drm_));
68 if (!importer_) {
69 ALOGE("Failed to create importer instance");
70 return HWC2::Error::NoResources;
71 }
72
Sean Paulac874152016-03-10 16:00:26 -050073 displays_.emplace(std::piecewise_construct,
74 std::forward_as_tuple(HWC_DISPLAY_PRIMARY),
Andrii Chepurnyi1d224e82018-05-17 18:34:01 +030075 std::forward_as_tuple(&drm_, importer_, HWC_DISPLAY_PRIMARY,
Sean Paulac874152016-03-10 16:00:26 -050076 HWC2::DisplayType::Physical));
77
78 DrmCrtc *crtc = drm_.GetCrtcForDisplay(static_cast<int>(HWC_DISPLAY_PRIMARY));
79 if (!crtc) {
80 ALOGE("Failed to get crtc for display %d",
81 static_cast<int>(HWC_DISPLAY_PRIMARY));
82 return HWC2::Error::BadDisplay;
83 }
84
85 std::vector<DrmPlane *> display_planes;
86 for (auto &plane : drm_.planes()) {
87 if (plane->GetCrtcSupported(*crtc))
88 display_planes.push_back(plane.get());
89 }
90 displays_.at(HWC_DISPLAY_PRIMARY).Init(&display_planes);
91 return HWC2::Error::None;
92}
93
Sean Pauled2ec4b2016-03-10 15:35:40 -050094template <typename... Args>
95static inline HWC2::Error unsupported(char const *func, Args... /*args*/) {
96 ALOGV("Unsupported function: %s", func);
97 return HWC2::Error::Unsupported;
98}
99
Sean Paulac874152016-03-10 16:00:26 -0500100static inline void supported(char const *func) {
101 ALOGV("Supported function: %s", func);
102}
103
Sean Pauled2ec4b2016-03-10 15:35:40 -0500104HWC2::Error DrmHwcTwo::CreateVirtualDisplay(uint32_t width, uint32_t height,
105 int32_t *format,
106 hwc2_display_t *display) {
107 // TODO: Implement virtual display
Sean Paulac874152016-03-10 16:00:26 -0500108 return unsupported(__func__, width, height, format, display);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500109}
110
111HWC2::Error DrmHwcTwo::DestroyVirtualDisplay(hwc2_display_t display) {
Sean Paulac874152016-03-10 16:00:26 -0500112 // TODO: Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500113 return unsupported(__func__, display);
114}
115
116void DrmHwcTwo::Dump(uint32_t *size, char *buffer) {
Sean Paulac874152016-03-10 16:00:26 -0500117 // TODO: Implement dump
Sean Pauled2ec4b2016-03-10 15:35:40 -0500118 unsupported(__func__, size, buffer);
119}
120
121uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() {
Sean Paulac874152016-03-10 16:00:26 -0500122 // TODO: Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500123 unsupported(__func__);
124 return 0;
125}
126
127HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor,
Sean Paulac874152016-03-10 16:00:26 -0500128 hwc2_callback_data_t data,
129 hwc2_function_pointer_t function) {
130 supported(__func__);
131 auto callback = static_cast<HWC2::Callback>(descriptor);
132 callbacks_.emplace(callback, HwcCallback(data, function));
133
134 switch (callback) {
135 case HWC2::Callback::Hotplug: {
136 auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(function);
137 hotplug(data, HWC_DISPLAY_PRIMARY,
138 static_cast<int32_t>(HWC2::Connection::Connected));
139 break;
140 }
141 case HWC2::Callback::Vsync: {
142 for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &d :
143 displays_)
144 d.second.RegisterVsyncCallback(data, function);
145 break;
146 }
147 default:
148 break;
149 }
150 return HWC2::Error::None;
151}
152
153DrmHwcTwo::HwcDisplay::HwcDisplay(DrmResources *drm,
154 std::shared_ptr<Importer> importer,
Sean Paulac874152016-03-10 16:00:26 -0500155 hwc2_display_t handle, HWC2::DisplayType type)
Andrii Chepurnyi1d224e82018-05-17 18:34:01 +0300156 : drm_(drm), importer_(importer), handle_(handle), type_(type) {
Sean Paulac874152016-03-10 16:00:26 -0500157 supported(__func__);
158}
159
160HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) {
161 supported(__func__);
162 planner_ = Planner::CreateInstance(drm_);
163 if (!planner_) {
164 ALOGE("Failed to create planner instance for composition");
165 return HWC2::Error::NoResources;
166 }
167
168 int display = static_cast<int>(handle_);
169 int ret = compositor_.Init(drm_, display);
170 if (ret) {
171 ALOGE("Failed display compositor init for display %d (%d)", display, ret);
172 return HWC2::Error::NoResources;
173 }
174
175 // Split up the given display planes into primary and overlay to properly
176 // interface with the composition
177 char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
178 property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
179 bool use_overlay_planes = atoi(use_overlay_planes_prop);
180 for (auto &plane : *planes) {
181 if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
182 primary_planes_.push_back(plane);
183 else if (use_overlay_planes && (plane)->type() == DRM_PLANE_TYPE_OVERLAY)
184 overlay_planes_.push_back(plane);
185 }
186
187 crtc_ = drm_->GetCrtcForDisplay(display);
188 if (!crtc_) {
189 ALOGE("Failed to get crtc for display %d", display);
190 return HWC2::Error::BadDisplay;
191 }
192
193 connector_ = drm_->GetConnectorForDisplay(display);
194 if (!connector_) {
195 ALOGE("Failed to get connector for display %d", display);
196 return HWC2::Error::BadDisplay;
197 }
198
199 // Fetch the number of modes from the display
200 uint32_t num_configs;
201 HWC2::Error err = GetDisplayConfigs(&num_configs, NULL);
202 if (err != HWC2::Error::None || !num_configs)
203 return err;
204
205 // Grab the first mode, we'll choose this as the active mode
206 // TODO: Should choose the preferred mode here
207 hwc2_config_t default_config;
208 num_configs = 1;
209 err = GetDisplayConfigs(&num_configs, &default_config);
210 if (err != HWC2::Error::None)
211 return err;
212
213 ret = vsync_worker_.Init(drm_, display);
214 if (ret) {
215 ALOGE("Failed to create event worker for d=%d %d\n", display, ret);
216 return HWC2::Error::BadDisplay;
217 }
218
219 return SetActiveConfig(default_config);
220}
221
222HWC2::Error DrmHwcTwo::HwcDisplay::RegisterVsyncCallback(
223 hwc2_callback_data_t data, hwc2_function_pointer_t func) {
224 supported(__func__);
225 auto callback = std::make_shared<DrmVsyncCallback>(data, func);
Adrian Salidofa37f672017-02-16 10:29:46 -0800226 vsync_worker_.RegisterCallback(std::move(callback));
Sean Paulac874152016-03-10 16:00:26 -0500227 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500228}
229
230HWC2::Error DrmHwcTwo::HwcDisplay::AcceptDisplayChanges() {
Sean Paulac874152016-03-10 16:00:26 -0500231 supported(__func__);
Sean Paulac874152016-03-10 16:00:26 -0500232 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_)
233 l.second.accept_type_change();
234 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500235}
236
237HWC2::Error DrmHwcTwo::HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Sean Paulac874152016-03-10 16:00:26 -0500238 supported(__func__);
239 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer());
240 *layer = static_cast<hwc2_layer_t>(layer_idx_);
241 ++layer_idx_;
242 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500243}
244
245HWC2::Error DrmHwcTwo::HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Sean Paulac874152016-03-10 16:00:26 -0500246 supported(__func__);
247 layers_.erase(layer);
248 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500249}
250
251HWC2::Error DrmHwcTwo::HwcDisplay::GetActiveConfig(hwc2_config_t *config) {
Sean Paulac874152016-03-10 16:00:26 -0500252 supported(__func__);
253 DrmMode const &mode = connector_->active_mode();
254 if (mode.id() == 0)
255 return HWC2::Error::BadConfig;
256
257 *config = mode.id();
258 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500259}
260
261HWC2::Error DrmHwcTwo::HwcDisplay::GetChangedCompositionTypes(
262 uint32_t *num_elements, hwc2_layer_t *layers, int32_t *types) {
Sean Paulac874152016-03-10 16:00:26 -0500263 supported(__func__);
264 uint32_t num_changes = 0;
265 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
266 if (l.second.type_changed()) {
267 if (layers && num_changes < *num_elements)
268 layers[num_changes] = l.first;
269 if (types && num_changes < *num_elements)
270 types[num_changes] = static_cast<int32_t>(l.second.validated_type());
271 ++num_changes;
272 }
273 }
274 if (!layers && !types)
275 *num_elements = num_changes;
276 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500277}
278
279HWC2::Error DrmHwcTwo::HwcDisplay::GetClientTargetSupport(uint32_t width,
Sean Paulac874152016-03-10 16:00:26 -0500280 uint32_t height,
281 int32_t /*format*/,
282 int32_t dataspace) {
283 supported(__func__);
284 std::pair<uint32_t, uint32_t> min = drm_->min_resolution();
285 std::pair<uint32_t, uint32_t> max = drm_->max_resolution();
286
287 if (width < min.first || height < min.second)
288 return HWC2::Error::Unsupported;
289
290 if (width > max.first || height > max.second)
291 return HWC2::Error::Unsupported;
292
293 if (dataspace != HAL_DATASPACE_UNKNOWN &&
294 dataspace != HAL_DATASPACE_STANDARD_UNSPECIFIED)
295 return HWC2::Error::Unsupported;
296
297 // TODO: Validate format can be handled by either GL or planes
298 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500299}
300
301HWC2::Error DrmHwcTwo::HwcDisplay::GetColorModes(uint32_t *num_modes,
Sean Paulac874152016-03-10 16:00:26 -0500302 int32_t *modes) {
303 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800304 if (!modes)
305 *num_modes = 1;
306
307 if (modes)
308 *modes = HAL_COLOR_MODE_NATIVE;
309
310 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500311}
312
313HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
Sean Paulac874152016-03-10 16:00:26 -0500314 int32_t attribute_in,
315 int32_t *value) {
316 supported(__func__);
317 auto mode =
318 std::find_if(connector_->modes().begin(), connector_->modes().end(),
319 [config](DrmMode const &m) { return m.id() == config; });
320 if (mode == connector_->modes().end()) {
321 ALOGE("Could not find active mode for %d", config);
322 return HWC2::Error::BadConfig;
323 }
324
325 static const int32_t kUmPerInch = 25400;
326 uint32_t mm_width = connector_->mm_width();
327 uint32_t mm_height = connector_->mm_height();
328 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
329 switch (attribute) {
330 case HWC2::Attribute::Width:
331 *value = mode->h_display();
332 break;
333 case HWC2::Attribute::Height:
334 *value = mode->v_display();
335 break;
336 case HWC2::Attribute::VsyncPeriod:
337 // in nanoseconds
338 *value = 1000 * 1000 * 1000 / mode->v_refresh();
339 break;
340 case HWC2::Attribute::DpiX:
341 // Dots per 1000 inches
342 *value = mm_width ? (mode->h_display() * kUmPerInch) / mm_width : -1;
343 break;
344 case HWC2::Attribute::DpiY:
345 // Dots per 1000 inches
346 *value = mm_height ? (mode->v_display() * kUmPerInch) / mm_height : -1;
347 break;
348 default:
349 *value = -1;
350 return HWC2::Error::BadConfig;
351 }
352 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500353}
354
355HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
356 hwc2_config_t *configs) {
Sean Paulac874152016-03-10 16:00:26 -0500357 supported(__func__);
358 // Since this callback is normally invoked twice (once to get the count, and
359 // once to populate configs), we don't really want to read the edid
360 // redundantly. Instead, only update the modes on the first invocation. While
361 // it's possible this will result in stale modes, it'll all come out in the
362 // wash when we try to set the active config later.
363 if (!configs) {
364 int ret = connector_->UpdateModes();
365 if (ret) {
366 ALOGE("Failed to update display modes %d", ret);
367 return HWC2::Error::BadDisplay;
368 }
369 }
370
371 auto num_modes = static_cast<uint32_t>(connector_->modes().size());
372 if (!configs) {
373 *num_configs = num_modes;
374 return HWC2::Error::None;
375 }
376
377 uint32_t idx = 0;
378 for (const DrmMode &mode : connector_->modes()) {
379 if (idx >= *num_configs)
380 break;
381 configs[idx++] = mode.id();
382 }
383 *num_configs = idx;
384 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500385}
386
387HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
Sean Paulac874152016-03-10 16:00:26 -0500388 supported(__func__);
389 std::ostringstream stream;
390 stream << "display-" << connector_->id();
391 std::string string = stream.str();
392 size_t length = string.length();
393 if (!name) {
394 *size = length;
395 return HWC2::Error::None;
396 }
397
398 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
399 strncpy(name, string.c_str(), *size);
400 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500401}
402
Sean Paulac874152016-03-10 16:00:26 -0500403HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
404 uint32_t *num_elements,
405 hwc2_layer_t *layers,
406 int32_t *layer_requests) {
407 supported(__func__);
408 // TODO: I think virtual display should request
409 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
410 unsupported(__func__, display_requests, num_elements, layers, layer_requests);
411 *num_elements = 0;
412 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500413}
414
415HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayType(int32_t *type) {
Sean Paulac874152016-03-10 16:00:26 -0500416 supported(__func__);
417 *type = static_cast<int32_t>(type_);
418 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500419}
420
421HWC2::Error DrmHwcTwo::HwcDisplay::GetDozeSupport(int32_t *support) {
Sean Paulac874152016-03-10 16:00:26 -0500422 supported(__func__);
423 *support = 0;
424 return HWC2::Error::None;
425}
426
427HWC2::Error DrmHwcTwo::HwcDisplay::GetHdrCapabilities(
428 uint32_t *num_types, int32_t */*types*/, float */*max_luminance*/,
429 float */*max_average_luminance*/, float */*min_luminance*/) {
430 supported(__func__);
431 *num_types = 0;
432 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500433}
434
435HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
Sean Paulac874152016-03-10 16:00:26 -0500436 hwc2_layer_t *layers,
437 int32_t *fences) {
438 supported(__func__);
439 uint32_t num_layers = 0;
440
441 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
442 ++num_layers;
443 if (layers == NULL || fences == NULL) {
444 continue;
445 } else if (num_layers > *num_elements) {
446 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
447 return HWC2::Error::None;
448 }
449
450 layers[num_layers - 1] = l.first;
451 fences[num_layers - 1] = l.second.take_release_fence();
452 }
453 *num_elements = num_layers;
454 return HWC2::Error::None;
455}
456
457void DrmHwcTwo::HwcDisplay::AddFenceToRetireFence(int fd) {
458 supported(__func__);
459 if (fd < 0)
460 return;
461
462 if (next_retire_fence_.get() >= 0) {
463 int old_fence = next_retire_fence_.get();
464 next_retire_fence_.Set(sync_merge("dc_retire", old_fence, fd));
465 } else {
466 next_retire_fence_.Set(dup(fd));
467 }
Sean Pauled2ec4b2016-03-10 15:35:40 -0500468}
469
470HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) {
Sean Paulac874152016-03-10 16:00:26 -0500471 supported(__func__);
472 std::vector<DrmCompositionDisplayLayersMap> layers_map;
473 layers_map.emplace_back();
474 DrmCompositionDisplayLayersMap &map = layers_map.back();
475
476 map.display = static_cast<int>(handle_);
477 map.geometry_changed = true; // TODO: Fix this
478
479 // order the layers by z-order
480 bool use_client_layer = false;
481 uint32_t client_z_order = 0;
482 std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
483 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
484 switch (l.second.validated_type()) {
485 case HWC2::Composition::Device:
486 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
487 break;
488 case HWC2::Composition::Client:
489 // Place it at the z_order of the highest client layer
490 use_client_layer = true;
491 client_z_order = std::max(client_z_order, l.second.z_order());
492 break;
493 default:
494 continue;
495 }
496 }
497 if (use_client_layer)
498 z_map.emplace(std::make_pair(client_z_order, &client_layer_));
499
500 // now that they're ordered by z, add them to the composition
501 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
502 DrmHwcLayer layer;
503 l.second->PopulateDrmLayer(&layer);
Andrii Chepurnyidc1278c2018-03-20 19:41:18 +0200504 int ret = layer.ImportBuffer(importer_.get());
Sean Paulac874152016-03-10 16:00:26 -0500505 if (ret) {
506 ALOGE("Failed to import layer, ret=%d", ret);
507 return HWC2::Error::NoResources;
508 }
509 map.layers.emplace_back(std::move(layer));
510 }
511 if (map.layers.empty()) {
512 *retire_fence = -1;
513 return HWC2::Error::None;
514 }
515
516 std::unique_ptr<DrmDisplayComposition> composition =
517 compositor_.CreateComposition();
518 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
519
520 // TODO: Don't always assume geometry changed
521 int ret = composition->SetLayers(map.layers.data(), map.layers.size(), true);
522 if (ret) {
523 ALOGE("Failed to set layers in the composition ret=%d", ret);
524 return HWC2::Error::BadLayer;
525 }
526
527 std::vector<DrmPlane *> primary_planes(primary_planes_);
528 std::vector<DrmPlane *> overlay_planes(overlay_planes_);
529 ret = composition->Plan(compositor_.squash_state(), &primary_planes,
530 &overlay_planes);
531 if (ret) {
532 ALOGE("Failed to plan the composition ret=%d", ret);
533 return HWC2::Error::BadConfig;
534 }
535
536 // Disable the planes we're not using
537 for (auto i = primary_planes.begin(); i != primary_planes.end();) {
538 composition->AddPlaneDisable(*i);
539 i = primary_planes.erase(i);
540 }
541 for (auto i = overlay_planes.begin(); i != overlay_planes.end();) {
542 composition->AddPlaneDisable(*i);
543 i = overlay_planes.erase(i);
544 }
545
Robert Fossa1ade4e2017-09-27 19:28:15 +0200546 AddFenceToRetireFence(composition->take_out_fence());
547
Sean Pauled45a8e2017-02-28 13:17:34 -0500548 ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500549 if (ret) {
550 ALOGE("Failed to apply the frame composition ret=%d", ret);
551 return HWC2::Error::BadParameter;
552 }
553
Sean Paulac874152016-03-10 16:00:26 -0500554 // The retire fence returned here is for the last frame, so return it and
555 // promote the next retire fence
556 *retire_fence = retire_fence_.Release();
557 retire_fence_ = std::move(next_retire_fence_);
558
559 ++frame_no_;
560 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500561}
562
563HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
Sean Paulac874152016-03-10 16:00:26 -0500564 supported(__func__);
565 auto mode =
566 std::find_if(connector_->modes().begin(), connector_->modes().end(),
567 [config](DrmMode const &m) { return m.id() == config; });
568 if (mode == connector_->modes().end()) {
569 ALOGE("Could not find active mode for %d", config);
570 return HWC2::Error::BadConfig;
571 }
572
573 std::unique_ptr<DrmDisplayComposition> composition =
574 compositor_.CreateComposition();
575 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
576 int ret = composition->SetDisplayMode(*mode);
Sean Pauled45a8e2017-02-28 13:17:34 -0500577 ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500578 if (ret) {
579 ALOGE("Failed to queue dpms composition on %d", ret);
580 return HWC2::Error::BadConfig;
581 }
582 if (connector_->active_mode().id() == 0)
583 connector_->set_active_mode(*mode);
584
585 // Setup the client layer's dimensions
586 hwc_rect_t display_frame = {.left = 0,
587 .top = 0,
588 .right = static_cast<int>(mode->h_display()),
589 .bottom = static_cast<int>(mode->v_display())};
590 client_layer_.SetLayerDisplayFrame(display_frame);
591 hwc_frect_t source_crop = {.left = 0.0f,
592 .top = 0.0f,
593 .right = mode->h_display() + 0.0f,
594 .bottom = mode->v_display() + 0.0f};
595 client_layer_.SetLayerSourceCrop(source_crop);
596
597 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500598}
599
600HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target,
601 int32_t acquire_fence,
602 int32_t dataspace,
Rob Herring1b2685c2017-11-29 10:19:57 -0600603 hwc_region_t /*damage*/) {
Sean Paulac874152016-03-10 16:00:26 -0500604 supported(__func__);
605 UniqueFd uf(acquire_fence);
606
607 client_layer_.set_buffer(target);
608 client_layer_.set_acquire_fence(uf.get());
609 client_layer_.SetLayerDataspace(dataspace);
610 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500611}
612
613HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500614 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800615
616 if (mode != HAL_COLOR_MODE_NATIVE)
617 return HWC2::Error::Unsupported;
618
619 color_mode_ = mode;
620 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500621}
622
623HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix,
Sean Paulac874152016-03-10 16:00:26 -0500624 int32_t hint) {
625 supported(__func__);
626 // TODO: Force client composition if we get this
Sean Pauled2ec4b2016-03-10 15:35:40 -0500627 return unsupported(__func__, matrix, hint);
628}
629
630HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500631 int32_t release_fence) {
632 supported(__func__);
633 // TODO: Need virtual display support
Sean Pauled2ec4b2016-03-10 15:35:40 -0500634 return unsupported(__func__, buffer, release_fence);
635}
636
Sean Paulac874152016-03-10 16:00:26 -0500637HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) {
638 supported(__func__);
639 uint64_t dpms_value = 0;
640 auto mode = static_cast<HWC2::PowerMode>(mode_in);
641 switch (mode) {
642 case HWC2::PowerMode::Off:
643 dpms_value = DRM_MODE_DPMS_OFF;
644 break;
645 case HWC2::PowerMode::On:
646 dpms_value = DRM_MODE_DPMS_ON;
647 break;
648 default:
649 ALOGI("Power mode %d is unsupported\n", mode);
650 return HWC2::Error::Unsupported;
651 };
652
653 std::unique_ptr<DrmDisplayComposition> composition =
654 compositor_.CreateComposition();
655 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
656 composition->SetDpmsMode(dpms_value);
Sean Pauled45a8e2017-02-28 13:17:34 -0500657 int ret = compositor_.ApplyComposition(std::move(composition));
Sean Paulac874152016-03-10 16:00:26 -0500658 if (ret) {
659 ALOGE("Failed to apply the dpms composition ret=%d", ret);
660 return HWC2::Error::BadParameter;
661 }
662 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500663}
664
665HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Sean Paulac874152016-03-10 16:00:26 -0500666 supported(__func__);
667 vsync_worker_.VSyncControl(enabled);
668 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500669}
670
671HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types,
Sean Paulac874152016-03-10 16:00:26 -0500672 uint32_t *num_requests) {
673 supported(__func__);
674 *num_types = 0;
675 *num_requests = 0;
676 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
677 DrmHwcTwo::HwcLayer &layer = l.second;
678 switch (layer.sf_type()) {
679 case HWC2::Composition::SolidColor:
680 case HWC2::Composition::Cursor:
681 case HWC2::Composition::Sideband:
682 layer.set_validated_type(HWC2::Composition::Client);
683 ++*num_types;
684 break;
685 default:
686 layer.set_validated_type(layer.sf_type());
687 break;
688 }
689 }
Rob Herringee8f45b2017-06-09 15:15:55 -0500690 return *num_types ? HWC2::Error::HasChanges : HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500691}
692
693HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t x, int32_t y) {
Sean Paulac874152016-03-10 16:00:26 -0500694 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800695 cursor_x_ = x;
696 cursor_y_ = y;
697 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500698}
699
700HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500701 supported(__func__);
702 blending_ = static_cast<HWC2::BlendMode>(mode);
703 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500704}
705
706HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500707 int32_t acquire_fence) {
708 supported(__func__);
709 UniqueFd uf(acquire_fence);
710
711 // The buffer and acquire_fence are handled elsewhere
712 if (sf_type_ == HWC2::Composition::Client ||
713 sf_type_ == HWC2::Composition::Sideband ||
714 sf_type_ == HWC2::Composition::SolidColor)
715 return HWC2::Error::None;
716
717 set_buffer(buffer);
718 set_acquire_fence(uf.get());
719 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500720}
721
722HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) {
Sean Paulac874152016-03-10 16:00:26 -0500723 // TODO: Punt to client composition here?
Sean Pauled2ec4b2016-03-10 15:35:40 -0500724 return unsupported(__func__, color);
725}
726
727HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) {
Sean Paulac874152016-03-10 16:00:26 -0500728 sf_type_ = static_cast<HWC2::Composition>(type);
729 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500730}
731
732HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) {
Sean Paulac874152016-03-10 16:00:26 -0500733 supported(__func__);
734 dataspace_ = static_cast<android_dataspace_t>(dataspace);
735 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500736}
737
738HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
Sean Paulac874152016-03-10 16:00:26 -0500739 supported(__func__);
740 display_frame_ = frame;
741 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500742}
743
744HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) {
Sean Paulac874152016-03-10 16:00:26 -0500745 supported(__func__);
746 alpha_ = alpha;
747 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500748}
749
750HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream(
751 const native_handle_t *stream) {
Sean Paulac874152016-03-10 16:00:26 -0500752 supported(__func__);
753 // TODO: We don't support sideband
Sean Pauled2ec4b2016-03-10 15:35:40 -0500754 return unsupported(__func__, stream);
755}
756
757HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
Sean Paulac874152016-03-10 16:00:26 -0500758 supported(__func__);
759 source_crop_ = crop;
760 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500761}
762
763HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -0500764 supported(__func__);
765 // TODO: We don't use surface damage, marking as unsupported
766 unsupported(__func__, damage);
767 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500768}
769
770HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) {
Sean Paulac874152016-03-10 16:00:26 -0500771 supported(__func__);
772 transform_ = static_cast<HWC2::Transform>(transform);
773 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500774}
775
776HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) {
Sean Paulac874152016-03-10 16:00:26 -0500777 supported(__func__);
778 // TODO: We don't use this information, marking as unsupported
779 unsupported(__func__, visible);
780 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500781}
782
Sean Paulac874152016-03-10 16:00:26 -0500783HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) {
784 supported(__func__);
785 z_order_ = order;
786 return HWC2::Error::None;
787}
788
789void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) {
790 supported(__func__);
791 switch (blending_) {
792 case HWC2::BlendMode::None:
793 layer->blending = DrmHwcBlending::kNone;
794 break;
795 case HWC2::BlendMode::Premultiplied:
796 layer->blending = DrmHwcBlending::kPreMult;
797 break;
798 case HWC2::BlendMode::Coverage:
799 layer->blending = DrmHwcBlending::kCoverage;
800 break;
801 default:
802 ALOGE("Unknown blending mode b=%d", blending_);
803 layer->blending = DrmHwcBlending::kNone;
804 break;
805 }
806
807 OutputFd release_fence = release_fence_output();
808
809 layer->sf_handle = buffer_;
810 layer->acquire_fence = acquire_fence_.Release();
811 layer->release_fence = std::move(release_fence);
812 layer->SetDisplayFrame(display_frame_);
Stefan Schake025d0a62018-05-04 18:03:00 +0200813 layer->alpha = static_cast<uint16_t>(65535.0f * alpha_ + 0.5f);
Sean Paulac874152016-03-10 16:00:26 -0500814 layer->SetSourceCrop(source_crop_);
815 layer->SetTransform(static_cast<int32_t>(transform_));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500816}
817
818// static
819int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) {
820 unsupported(__func__);
821 return 0;
822}
823
824// static
825void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/,
Sean Paulac874152016-03-10 16:00:26 -0500826 uint32_t *out_count,
827 int32_t * /*out_capabilities*/) {
828 supported(__func__);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500829 *out_count = 0;
830}
831
832// static
Sean Paulac874152016-03-10 16:00:26 -0500833hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
834 struct hwc2_device * /*dev*/, int32_t descriptor) {
835 supported(__func__);
836 auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500837 switch (func) {
838 // Device functions
839 case HWC2::FunctionDescriptor::CreateVirtualDisplay:
840 return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
841 DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
842 &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
843 int32_t*, hwc2_display_t *>);
844 case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
845 return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
846 DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
847 &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
848 case HWC2::FunctionDescriptor::Dump:
849 return ToHook<HWC2_PFN_DUMP>(
850 DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump,
851 uint32_t *, char *>);
852 case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
853 return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
854 DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
855 &DrmHwcTwo::GetMaxVirtualDisplayCount>);
856 case HWC2::FunctionDescriptor::RegisterCallback:
857 return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
858 DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
859 &DrmHwcTwo::RegisterCallback, int32_t,
860 hwc2_callback_data_t, hwc2_function_pointer_t>);
861
862 // Display functions
863 case HWC2::FunctionDescriptor::AcceptDisplayChanges:
864 return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
865 DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
866 &HwcDisplay::AcceptDisplayChanges>);
867 case HWC2::FunctionDescriptor::CreateLayer:
868 return ToHook<HWC2_PFN_CREATE_LAYER>(
869 DisplayHook<decltype(&HwcDisplay::CreateLayer),
870 &HwcDisplay::CreateLayer, hwc2_layer_t *>);
871 case HWC2::FunctionDescriptor::DestroyLayer:
872 return ToHook<HWC2_PFN_DESTROY_LAYER>(
873 DisplayHook<decltype(&HwcDisplay::DestroyLayer),
874 &HwcDisplay::DestroyLayer, hwc2_layer_t>);
875 case HWC2::FunctionDescriptor::GetActiveConfig:
876 return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
877 DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
878 &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
879 case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
880 return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
881 DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
882 &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
883 hwc2_layer_t *, int32_t *>);
884 case HWC2::FunctionDescriptor::GetClientTargetSupport:
885 return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
886 DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
887 &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
888 int32_t, int32_t>);
889 case HWC2::FunctionDescriptor::GetColorModes:
890 return ToHook<HWC2_PFN_GET_COLOR_MODES>(
891 DisplayHook<decltype(&HwcDisplay::GetColorModes),
892 &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
893 case HWC2::FunctionDescriptor::GetDisplayAttribute:
894 return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(DisplayHook<
895 decltype(&HwcDisplay::GetDisplayAttribute),
896 &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, int32_t *>);
897 case HWC2::FunctionDescriptor::GetDisplayConfigs:
898 return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(DisplayHook<
899 decltype(&HwcDisplay::GetDisplayConfigs),
900 &HwcDisplay::GetDisplayConfigs, uint32_t *, hwc2_config_t *>);
901 case HWC2::FunctionDescriptor::GetDisplayName:
902 return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
903 DisplayHook<decltype(&HwcDisplay::GetDisplayName),
904 &HwcDisplay::GetDisplayName, uint32_t *, char *>);
905 case HWC2::FunctionDescriptor::GetDisplayRequests:
906 return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
907 DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
908 &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
909 hwc2_layer_t *, int32_t *>);
910 case HWC2::FunctionDescriptor::GetDisplayType:
911 return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
912 DisplayHook<decltype(&HwcDisplay::GetDisplayType),
913 &HwcDisplay::GetDisplayType, int32_t *>);
914 case HWC2::FunctionDescriptor::GetDozeSupport:
915 return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
916 DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
917 &HwcDisplay::GetDozeSupport, int32_t *>);
Sean Paulac874152016-03-10 16:00:26 -0500918 case HWC2::FunctionDescriptor::GetHdrCapabilities:
919 return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
920 DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
921 &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
922 float *, float *, float *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500923 case HWC2::FunctionDescriptor::GetReleaseFences:
924 return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
925 DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
926 &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
927 int32_t *>);
928 case HWC2::FunctionDescriptor::PresentDisplay:
929 return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
930 DisplayHook<decltype(&HwcDisplay::PresentDisplay),
931 &HwcDisplay::PresentDisplay, int32_t *>);
932 case HWC2::FunctionDescriptor::SetActiveConfig:
933 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
934 DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
935 &HwcDisplay::SetActiveConfig, hwc2_config_t>);
936 case HWC2::FunctionDescriptor::SetClientTarget:
937 return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(DisplayHook<
938 decltype(&HwcDisplay::SetClientTarget), &HwcDisplay::SetClientTarget,
939 buffer_handle_t, int32_t, int32_t, hwc_region_t>);
940 case HWC2::FunctionDescriptor::SetColorMode:
941 return ToHook<HWC2_PFN_SET_COLOR_MODE>(
942 DisplayHook<decltype(&HwcDisplay::SetColorMode),
943 &HwcDisplay::SetColorMode, int32_t>);
944 case HWC2::FunctionDescriptor::SetColorTransform:
945 return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
946 DisplayHook<decltype(&HwcDisplay::SetColorTransform),
947 &HwcDisplay::SetColorTransform, const float *, int32_t>);
948 case HWC2::FunctionDescriptor::SetOutputBuffer:
949 return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
950 DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
951 &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
952 case HWC2::FunctionDescriptor::SetPowerMode:
953 return ToHook<HWC2_PFN_SET_POWER_MODE>(
954 DisplayHook<decltype(&HwcDisplay::SetPowerMode),
955 &HwcDisplay::SetPowerMode, int32_t>);
956 case HWC2::FunctionDescriptor::SetVsyncEnabled:
957 return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
958 DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
959 &HwcDisplay::SetVsyncEnabled, int32_t>);
960 case HWC2::FunctionDescriptor::ValidateDisplay:
961 return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
962 DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
963 &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
964
965 // Layer functions
966 case HWC2::FunctionDescriptor::SetCursorPosition:
967 return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
968 LayerHook<decltype(&HwcLayer::SetCursorPosition),
969 &HwcLayer::SetCursorPosition, int32_t, int32_t>);
970 case HWC2::FunctionDescriptor::SetLayerBlendMode:
971 return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
972 LayerHook<decltype(&HwcLayer::SetLayerBlendMode),
973 &HwcLayer::SetLayerBlendMode, int32_t>);
974 case HWC2::FunctionDescriptor::SetLayerBuffer:
975 return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
976 LayerHook<decltype(&HwcLayer::SetLayerBuffer),
977 &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>);
978 case HWC2::FunctionDescriptor::SetLayerColor:
979 return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
980 LayerHook<decltype(&HwcLayer::SetLayerColor),
981 &HwcLayer::SetLayerColor, hwc_color_t>);
982 case HWC2::FunctionDescriptor::SetLayerCompositionType:
983 return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
984 LayerHook<decltype(&HwcLayer::SetLayerCompositionType),
985 &HwcLayer::SetLayerCompositionType, int32_t>);
986 case HWC2::FunctionDescriptor::SetLayerDataspace:
987 return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
988 LayerHook<decltype(&HwcLayer::SetLayerDataspace),
989 &HwcLayer::SetLayerDataspace, int32_t>);
990 case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
991 return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
992 LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame),
993 &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>);
994 case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
995 return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
996 LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha),
997 &HwcLayer::SetLayerPlaneAlpha, float>);
998 case HWC2::FunctionDescriptor::SetLayerSidebandStream:
999 return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(LayerHook<
1000 decltype(&HwcLayer::SetLayerSidebandStream),
1001 &HwcLayer::SetLayerSidebandStream, const native_handle_t *>);
1002 case HWC2::FunctionDescriptor::SetLayerSourceCrop:
1003 return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
1004 LayerHook<decltype(&HwcLayer::SetLayerSourceCrop),
1005 &HwcLayer::SetLayerSourceCrop, hwc_frect_t>);
1006 case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
1007 return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
1008 LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage),
1009 &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>);
1010 case HWC2::FunctionDescriptor::SetLayerTransform:
1011 return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
1012 LayerHook<decltype(&HwcLayer::SetLayerTransform),
1013 &HwcLayer::SetLayerTransform, int32_t>);
1014 case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
1015 return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
1016 LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion),
1017 &HwcLayer::SetLayerVisibleRegion, hwc_region_t>);
1018 case HWC2::FunctionDescriptor::SetLayerZOrder:
1019 return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
1020 LayerHook<decltype(&HwcLayer::SetLayerZOrder),
1021 &HwcLayer::SetLayerZOrder, uint32_t>);
Sean Paulac874152016-03-10 16:00:26 -05001022 case HWC2::FunctionDescriptor::Invalid:
Sean Pauled2ec4b2016-03-10 15:35:40 -05001023 default:
1024 return NULL;
1025 }
1026}
Sean Paulac874152016-03-10 16:00:26 -05001027
1028// static
1029int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
1030 struct hw_device_t **dev) {
1031 supported(__func__);
1032 if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
1033 ALOGE("Invalid module name- %s", name);
1034 return -EINVAL;
1035 }
1036
1037 std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo());
1038 if (!ctx) {
1039 ALOGE("Failed to allocate DrmHwcTwo");
1040 return -ENOMEM;
1041 }
1042
1043 HWC2::Error err = ctx->Init();
1044 if (err != HWC2::Error::None) {
1045 ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err);
1046 return -EINVAL;
1047 }
1048
1049 ctx->common.module = const_cast<hw_module_t *>(module);
1050 *dev = &ctx->common;
1051 ctx.release();
1052 return 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001053}
Sean Paulac874152016-03-10 16:00:26 -05001054}
1055
1056static struct hw_module_methods_t hwc2_module_methods = {
1057 .open = android::DrmHwcTwo::HookDevOpen,
1058};
1059
1060hw_module_t HAL_MODULE_INFO_SYM = {
1061 .tag = HARDWARE_MODULE_TAG,
1062 .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
1063 .id = HWC_HARDWARE_MODULE_ID,
1064 .name = "DrmHwcTwo module",
1065 .author = "The Android Open Source Project",
1066 .methods = &hwc2_module_methods,
1067 .dso = NULL,
1068 .reserved = {0},
1069};