blob: e57d8421131c1ae916b0c6f17279043d8fc6e8ed [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
29#include <cutils/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
73 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
74 (const hw_module_t **)&gralloc_);
75 if (ret) {
76 ALOGE("Failed to open gralloc module %d", ret);
77 return HWC2::Error::NoResources;
78 }
79
80 displays_.emplace(std::piecewise_construct,
81 std::forward_as_tuple(HWC_DISPLAY_PRIMARY),
82 std::forward_as_tuple(&drm_, importer_, gralloc_,
83 HWC_DISPLAY_PRIMARY,
84 HWC2::DisplayType::Physical));
85
86 DrmCrtc *crtc = drm_.GetCrtcForDisplay(static_cast<int>(HWC_DISPLAY_PRIMARY));
87 if (!crtc) {
88 ALOGE("Failed to get crtc for display %d",
89 static_cast<int>(HWC_DISPLAY_PRIMARY));
90 return HWC2::Error::BadDisplay;
91 }
92
93 std::vector<DrmPlane *> display_planes;
94 for (auto &plane : drm_.planes()) {
95 if (plane->GetCrtcSupported(*crtc))
96 display_planes.push_back(plane.get());
97 }
98 displays_.at(HWC_DISPLAY_PRIMARY).Init(&display_planes);
99 return HWC2::Error::None;
100}
101
Sean Pauled2ec4b2016-03-10 15:35:40 -0500102template <typename... Args>
103static inline HWC2::Error unsupported(char const *func, Args... /*args*/) {
104 ALOGV("Unsupported function: %s", func);
105 return HWC2::Error::Unsupported;
106}
107
Sean Paulac874152016-03-10 16:00:26 -0500108static inline void supported(char const *func) {
109 ALOGV("Supported function: %s", func);
110}
111
Sean Pauled2ec4b2016-03-10 15:35:40 -0500112HWC2::Error DrmHwcTwo::CreateVirtualDisplay(uint32_t width, uint32_t height,
113 int32_t *format,
114 hwc2_display_t *display) {
115 // TODO: Implement virtual display
Sean Paulac874152016-03-10 16:00:26 -0500116 return unsupported(__func__, width, height, format, display);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500117}
118
119HWC2::Error DrmHwcTwo::DestroyVirtualDisplay(hwc2_display_t display) {
Sean Paulac874152016-03-10 16:00:26 -0500120 // TODO: Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500121 return unsupported(__func__, display);
122}
123
124void DrmHwcTwo::Dump(uint32_t *size, char *buffer) {
Sean Paulac874152016-03-10 16:00:26 -0500125 // TODO: Implement dump
Sean Pauled2ec4b2016-03-10 15:35:40 -0500126 unsupported(__func__, size, buffer);
127}
128
129uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() {
Sean Paulac874152016-03-10 16:00:26 -0500130 // TODO: Implement virtual display
Sean Pauled2ec4b2016-03-10 15:35:40 -0500131 unsupported(__func__);
132 return 0;
133}
134
135HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor,
Sean Paulac874152016-03-10 16:00:26 -0500136 hwc2_callback_data_t data,
137 hwc2_function_pointer_t function) {
138 supported(__func__);
139 auto callback = static_cast<HWC2::Callback>(descriptor);
140 callbacks_.emplace(callback, HwcCallback(data, function));
141
142 switch (callback) {
143 case HWC2::Callback::Hotplug: {
144 auto hotplug = reinterpret_cast<HWC2_PFN_HOTPLUG>(function);
145 hotplug(data, HWC_DISPLAY_PRIMARY,
146 static_cast<int32_t>(HWC2::Connection::Connected));
147 break;
148 }
149 case HWC2::Callback::Vsync: {
150 for (std::pair<const hwc2_display_t, DrmHwcTwo::HwcDisplay> &d :
151 displays_)
152 d.second.RegisterVsyncCallback(data, function);
153 break;
154 }
155 default:
156 break;
157 }
158 return HWC2::Error::None;
159}
160
161DrmHwcTwo::HwcDisplay::HwcDisplay(DrmResources *drm,
162 std::shared_ptr<Importer> importer,
163 const gralloc_module_t *gralloc,
164 hwc2_display_t handle, HWC2::DisplayType type)
165 : drm_(drm),
166 importer_(importer),
167 gralloc_(gralloc),
168 handle_(handle),
169 type_(type) {
170 supported(__func__);
171}
172
173HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) {
174 supported(__func__);
175 planner_ = Planner::CreateInstance(drm_);
176 if (!planner_) {
177 ALOGE("Failed to create planner instance for composition");
178 return HWC2::Error::NoResources;
179 }
180
181 int display = static_cast<int>(handle_);
182 int ret = compositor_.Init(drm_, display);
183 if (ret) {
184 ALOGE("Failed display compositor init for display %d (%d)", display, ret);
185 return HWC2::Error::NoResources;
186 }
187
188 // Split up the given display planes into primary and overlay to properly
189 // interface with the composition
190 char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
191 property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
192 bool use_overlay_planes = atoi(use_overlay_planes_prop);
193 for (auto &plane : *planes) {
194 if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
195 primary_planes_.push_back(plane);
196 else if (use_overlay_planes && (plane)->type() == DRM_PLANE_TYPE_OVERLAY)
197 overlay_planes_.push_back(plane);
198 }
199
200 crtc_ = drm_->GetCrtcForDisplay(display);
201 if (!crtc_) {
202 ALOGE("Failed to get crtc for display %d", display);
203 return HWC2::Error::BadDisplay;
204 }
205
206 connector_ = drm_->GetConnectorForDisplay(display);
207 if (!connector_) {
208 ALOGE("Failed to get connector for display %d", display);
209 return HWC2::Error::BadDisplay;
210 }
211
212 // Fetch the number of modes from the display
213 uint32_t num_configs;
214 HWC2::Error err = GetDisplayConfigs(&num_configs, NULL);
215 if (err != HWC2::Error::None || !num_configs)
216 return err;
217
218 // Grab the first mode, we'll choose this as the active mode
219 // TODO: Should choose the preferred mode here
220 hwc2_config_t default_config;
221 num_configs = 1;
222 err = GetDisplayConfigs(&num_configs, &default_config);
223 if (err != HWC2::Error::None)
224 return err;
225
226 ret = vsync_worker_.Init(drm_, display);
227 if (ret) {
228 ALOGE("Failed to create event worker for d=%d %d\n", display, ret);
229 return HWC2::Error::BadDisplay;
230 }
231
232 return SetActiveConfig(default_config);
233}
234
235HWC2::Error DrmHwcTwo::HwcDisplay::RegisterVsyncCallback(
236 hwc2_callback_data_t data, hwc2_function_pointer_t func) {
237 supported(__func__);
238 auto callback = std::make_shared<DrmVsyncCallback>(data, func);
239 int ret = vsync_worker_.RegisterCallback(std::move(callback));
240 if (ret) {
241 ALOGE("Failed to register callback d=%" PRIu64 " ret=%d", handle_, ret);
242 return HWC2::Error::BadDisplay;
243 }
244 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500245}
246
247HWC2::Error DrmHwcTwo::HwcDisplay::AcceptDisplayChanges() {
Sean Paulac874152016-03-10 16:00:26 -0500248 supported(__func__);
249 uint32_t num_changes = 0;
250 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_)
251 l.second.accept_type_change();
252 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500253}
254
255HWC2::Error DrmHwcTwo::HwcDisplay::CreateLayer(hwc2_layer_t *layer) {
Sean Paulac874152016-03-10 16:00:26 -0500256 supported(__func__);
257 layers_.emplace(static_cast<hwc2_layer_t>(layer_idx_), HwcLayer());
258 *layer = static_cast<hwc2_layer_t>(layer_idx_);
259 ++layer_idx_;
260 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500261}
262
263HWC2::Error DrmHwcTwo::HwcDisplay::DestroyLayer(hwc2_layer_t layer) {
Sean Paulac874152016-03-10 16:00:26 -0500264 supported(__func__);
265 layers_.erase(layer);
266 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500267}
268
269HWC2::Error DrmHwcTwo::HwcDisplay::GetActiveConfig(hwc2_config_t *config) {
Sean Paulac874152016-03-10 16:00:26 -0500270 supported(__func__);
271 DrmMode const &mode = connector_->active_mode();
272 if (mode.id() == 0)
273 return HWC2::Error::BadConfig;
274
275 *config = mode.id();
276 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500277}
278
279HWC2::Error DrmHwcTwo::HwcDisplay::GetChangedCompositionTypes(
280 uint32_t *num_elements, hwc2_layer_t *layers, int32_t *types) {
Sean Paulac874152016-03-10 16:00:26 -0500281 supported(__func__);
282 uint32_t num_changes = 0;
283 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
284 if (l.second.type_changed()) {
285 if (layers && num_changes < *num_elements)
286 layers[num_changes] = l.first;
287 if (types && num_changes < *num_elements)
288 types[num_changes] = static_cast<int32_t>(l.second.validated_type());
289 ++num_changes;
290 }
291 }
292 if (!layers && !types)
293 *num_elements = num_changes;
294 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500295}
296
297HWC2::Error DrmHwcTwo::HwcDisplay::GetClientTargetSupport(uint32_t width,
Sean Paulac874152016-03-10 16:00:26 -0500298 uint32_t height,
299 int32_t /*format*/,
300 int32_t dataspace) {
301 supported(__func__);
302 std::pair<uint32_t, uint32_t> min = drm_->min_resolution();
303 std::pair<uint32_t, uint32_t> max = drm_->max_resolution();
304
305 if (width < min.first || height < min.second)
306 return HWC2::Error::Unsupported;
307
308 if (width > max.first || height > max.second)
309 return HWC2::Error::Unsupported;
310
311 if (dataspace != HAL_DATASPACE_UNKNOWN &&
312 dataspace != HAL_DATASPACE_STANDARD_UNSPECIFIED)
313 return HWC2::Error::Unsupported;
314
315 // TODO: Validate format can be handled by either GL or planes
316 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500317}
318
319HWC2::Error DrmHwcTwo::HwcDisplay::GetColorModes(uint32_t *num_modes,
Sean Paulac874152016-03-10 16:00:26 -0500320 int32_t *modes) {
321 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800322 if (!modes)
323 *num_modes = 1;
324
325 if (modes)
326 *modes = HAL_COLOR_MODE_NATIVE;
327
328 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500329}
330
331HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
Sean Paulac874152016-03-10 16:00:26 -0500332 int32_t attribute_in,
333 int32_t *value) {
334 supported(__func__);
335 auto mode =
336 std::find_if(connector_->modes().begin(), connector_->modes().end(),
337 [config](DrmMode const &m) { return m.id() == config; });
338 if (mode == connector_->modes().end()) {
339 ALOGE("Could not find active mode for %d", config);
340 return HWC2::Error::BadConfig;
341 }
342
343 static const int32_t kUmPerInch = 25400;
344 uint32_t mm_width = connector_->mm_width();
345 uint32_t mm_height = connector_->mm_height();
346 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
347 switch (attribute) {
348 case HWC2::Attribute::Width:
349 *value = mode->h_display();
350 break;
351 case HWC2::Attribute::Height:
352 *value = mode->v_display();
353 break;
354 case HWC2::Attribute::VsyncPeriod:
355 // in nanoseconds
356 *value = 1000 * 1000 * 1000 / mode->v_refresh();
357 break;
358 case HWC2::Attribute::DpiX:
359 // Dots per 1000 inches
360 *value = mm_width ? (mode->h_display() * kUmPerInch) / mm_width : -1;
361 break;
362 case HWC2::Attribute::DpiY:
363 // Dots per 1000 inches
364 *value = mm_height ? (mode->v_display() * kUmPerInch) / mm_height : -1;
365 break;
366 default:
367 *value = -1;
368 return HWC2::Error::BadConfig;
369 }
370 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500371}
372
373HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
374 hwc2_config_t *configs) {
Sean Paulac874152016-03-10 16:00:26 -0500375 supported(__func__);
376 // Since this callback is normally invoked twice (once to get the count, and
377 // once to populate configs), we don't really want to read the edid
378 // redundantly. Instead, only update the modes on the first invocation. While
379 // it's possible this will result in stale modes, it'll all come out in the
380 // wash when we try to set the active config later.
381 if (!configs) {
382 int ret = connector_->UpdateModes();
383 if (ret) {
384 ALOGE("Failed to update display modes %d", ret);
385 return HWC2::Error::BadDisplay;
386 }
387 }
388
389 auto num_modes = static_cast<uint32_t>(connector_->modes().size());
390 if (!configs) {
391 *num_configs = num_modes;
392 return HWC2::Error::None;
393 }
394
395 uint32_t idx = 0;
396 for (const DrmMode &mode : connector_->modes()) {
397 if (idx >= *num_configs)
398 break;
399 configs[idx++] = mode.id();
400 }
401 *num_configs = idx;
402 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500403}
404
405HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
Sean Paulac874152016-03-10 16:00:26 -0500406 supported(__func__);
407 std::ostringstream stream;
408 stream << "display-" << connector_->id();
409 std::string string = stream.str();
410 size_t length = string.length();
411 if (!name) {
412 *size = length;
413 return HWC2::Error::None;
414 }
415
416 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
417 strncpy(name, string.c_str(), *size);
418 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500419}
420
Sean Paulac874152016-03-10 16:00:26 -0500421HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
422 uint32_t *num_elements,
423 hwc2_layer_t *layers,
424 int32_t *layer_requests) {
425 supported(__func__);
426 // TODO: I think virtual display should request
427 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
428 unsupported(__func__, display_requests, num_elements, layers, layer_requests);
429 *num_elements = 0;
430 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500431}
432
433HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayType(int32_t *type) {
Sean Paulac874152016-03-10 16:00:26 -0500434 supported(__func__);
435 *type = static_cast<int32_t>(type_);
436 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500437}
438
439HWC2::Error DrmHwcTwo::HwcDisplay::GetDozeSupport(int32_t *support) {
Sean Paulac874152016-03-10 16:00:26 -0500440 supported(__func__);
441 *support = 0;
442 return HWC2::Error::None;
443}
444
445HWC2::Error DrmHwcTwo::HwcDisplay::GetHdrCapabilities(
446 uint32_t *num_types, int32_t */*types*/, float */*max_luminance*/,
447 float */*max_average_luminance*/, float */*min_luminance*/) {
448 supported(__func__);
449 *num_types = 0;
450 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500451}
452
453HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
Sean Paulac874152016-03-10 16:00:26 -0500454 hwc2_layer_t *layers,
455 int32_t *fences) {
456 supported(__func__);
457 uint32_t num_layers = 0;
458
459 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
460 ++num_layers;
461 if (layers == NULL || fences == NULL) {
462 continue;
463 } else if (num_layers > *num_elements) {
464 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
465 return HWC2::Error::None;
466 }
467
468 layers[num_layers - 1] = l.first;
469 fences[num_layers - 1] = l.second.take_release_fence();
470 }
471 *num_elements = num_layers;
472 return HWC2::Error::None;
473}
474
475void DrmHwcTwo::HwcDisplay::AddFenceToRetireFence(int fd) {
476 supported(__func__);
477 if (fd < 0)
478 return;
479
480 if (next_retire_fence_.get() >= 0) {
481 int old_fence = next_retire_fence_.get();
482 next_retire_fence_.Set(sync_merge("dc_retire", old_fence, fd));
483 } else {
484 next_retire_fence_.Set(dup(fd));
485 }
Sean Pauled2ec4b2016-03-10 15:35:40 -0500486}
487
488HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) {
Sean Paulac874152016-03-10 16:00:26 -0500489 supported(__func__);
490 std::vector<DrmCompositionDisplayLayersMap> layers_map;
491 layers_map.emplace_back();
492 DrmCompositionDisplayLayersMap &map = layers_map.back();
493
494 map.display = static_cast<int>(handle_);
495 map.geometry_changed = true; // TODO: Fix this
496
497 // order the layers by z-order
498 bool use_client_layer = false;
499 uint32_t client_z_order = 0;
500 std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
501 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
502 switch (l.second.validated_type()) {
503 case HWC2::Composition::Device:
504 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
505 break;
506 case HWC2::Composition::Client:
507 // Place it at the z_order of the highest client layer
508 use_client_layer = true;
509 client_z_order = std::max(client_z_order, l.second.z_order());
510 break;
511 default:
512 continue;
513 }
514 }
515 if (use_client_layer)
516 z_map.emplace(std::make_pair(client_z_order, &client_layer_));
517
518 // now that they're ordered by z, add them to the composition
519 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
520 DrmHwcLayer layer;
521 l.second->PopulateDrmLayer(&layer);
522 int ret = layer.ImportBuffer(importer_.get(), gralloc_);
523 if (ret) {
524 ALOGE("Failed to import layer, ret=%d", ret);
525 return HWC2::Error::NoResources;
526 }
527 map.layers.emplace_back(std::move(layer));
528 }
529 if (map.layers.empty()) {
530 *retire_fence = -1;
531 return HWC2::Error::None;
532 }
533
534 std::unique_ptr<DrmDisplayComposition> composition =
535 compositor_.CreateComposition();
536 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
537
538 // TODO: Don't always assume geometry changed
539 int ret = composition->SetLayers(map.layers.data(), map.layers.size(), true);
540 if (ret) {
541 ALOGE("Failed to set layers in the composition ret=%d", ret);
542 return HWC2::Error::BadLayer;
543 }
544
545 std::vector<DrmPlane *> primary_planes(primary_planes_);
546 std::vector<DrmPlane *> overlay_planes(overlay_planes_);
547 ret = composition->Plan(compositor_.squash_state(), &primary_planes,
548 &overlay_planes);
549 if (ret) {
550 ALOGE("Failed to plan the composition ret=%d", ret);
551 return HWC2::Error::BadConfig;
552 }
553
554 // Disable the planes we're not using
555 for (auto i = primary_planes.begin(); i != primary_planes.end();) {
556 composition->AddPlaneDisable(*i);
557 i = primary_planes.erase(i);
558 }
559 for (auto i = overlay_planes.begin(); i != overlay_planes.end();) {
560 composition->AddPlaneDisable(*i);
561 i = overlay_planes.erase(i);
562 }
563
564 ret = compositor_.QueueComposition(std::move(composition));
565 if (ret) {
566 ALOGE("Failed to apply the frame composition ret=%d", ret);
567 return HWC2::Error::BadParameter;
568 }
569
570 // Now that the release fences have been generated by the compositor, make
571 // sure they're managed properly
572 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
573 l.second->manage_release_fence();
574 AddFenceToRetireFence(l.second->release_fence());
575 }
576
577 // The retire fence returned here is for the last frame, so return it and
578 // promote the next retire fence
579 *retire_fence = retire_fence_.Release();
580 retire_fence_ = std::move(next_retire_fence_);
581
582 ++frame_no_;
583 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500584}
585
586HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
Sean Paulac874152016-03-10 16:00:26 -0500587 supported(__func__);
588 auto mode =
589 std::find_if(connector_->modes().begin(), connector_->modes().end(),
590 [config](DrmMode const &m) { return m.id() == config; });
591 if (mode == connector_->modes().end()) {
592 ALOGE("Could not find active mode for %d", config);
593 return HWC2::Error::BadConfig;
594 }
595
596 std::unique_ptr<DrmDisplayComposition> composition =
597 compositor_.CreateComposition();
598 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
599 int ret = composition->SetDisplayMode(*mode);
600 ret = compositor_.QueueComposition(std::move(composition));
601 if (ret) {
602 ALOGE("Failed to queue dpms composition on %d", ret);
603 return HWC2::Error::BadConfig;
604 }
605 if (connector_->active_mode().id() == 0)
606 connector_->set_active_mode(*mode);
607
608 // Setup the client layer's dimensions
609 hwc_rect_t display_frame = {.left = 0,
610 .top = 0,
611 .right = static_cast<int>(mode->h_display()),
612 .bottom = static_cast<int>(mode->v_display())};
613 client_layer_.SetLayerDisplayFrame(display_frame);
614 hwc_frect_t source_crop = {.left = 0.0f,
615 .top = 0.0f,
616 .right = mode->h_display() + 0.0f,
617 .bottom = mode->v_display() + 0.0f};
618 client_layer_.SetLayerSourceCrop(source_crop);
619
620 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500621}
622
623HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target,
624 int32_t acquire_fence,
625 int32_t dataspace,
626 hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -0500627 supported(__func__);
628 UniqueFd uf(acquire_fence);
629
630 client_layer_.set_buffer(target);
631 client_layer_.set_acquire_fence(uf.get());
632 client_layer_.SetLayerDataspace(dataspace);
633 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500634}
635
636HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500637 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800638
639 if (mode != HAL_COLOR_MODE_NATIVE)
640 return HWC2::Error::Unsupported;
641
642 color_mode_ = mode;
643 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500644}
645
646HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix,
Sean Paulac874152016-03-10 16:00:26 -0500647 int32_t hint) {
648 supported(__func__);
649 // TODO: Force client composition if we get this
Sean Pauled2ec4b2016-03-10 15:35:40 -0500650 return unsupported(__func__, matrix, hint);
651}
652
653HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500654 int32_t release_fence) {
655 supported(__func__);
656 // TODO: Need virtual display support
Sean Pauled2ec4b2016-03-10 15:35:40 -0500657 return unsupported(__func__, buffer, release_fence);
658}
659
Sean Paulac874152016-03-10 16:00:26 -0500660HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) {
661 supported(__func__);
662 uint64_t dpms_value = 0;
663 auto mode = static_cast<HWC2::PowerMode>(mode_in);
664 switch (mode) {
665 case HWC2::PowerMode::Off:
666 dpms_value = DRM_MODE_DPMS_OFF;
667 break;
668 case HWC2::PowerMode::On:
669 dpms_value = DRM_MODE_DPMS_ON;
670 break;
671 default:
672 ALOGI("Power mode %d is unsupported\n", mode);
673 return HWC2::Error::Unsupported;
674 };
675
676 std::unique_ptr<DrmDisplayComposition> composition =
677 compositor_.CreateComposition();
678 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
679 composition->SetDpmsMode(dpms_value);
680 int ret = compositor_.QueueComposition(std::move(composition));
681 if (ret) {
682 ALOGE("Failed to apply the dpms composition ret=%d", ret);
683 return HWC2::Error::BadParameter;
684 }
685 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500686}
687
688HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Sean Paulac874152016-03-10 16:00:26 -0500689 supported(__func__);
690 vsync_worker_.VSyncControl(enabled);
691 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500692}
693
694HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types,
Sean Paulac874152016-03-10 16:00:26 -0500695 uint32_t *num_requests) {
696 supported(__func__);
697 *num_types = 0;
698 *num_requests = 0;
699 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
700 DrmHwcTwo::HwcLayer &layer = l.second;
701 switch (layer.sf_type()) {
702 case HWC2::Composition::SolidColor:
703 case HWC2::Composition::Cursor:
704 case HWC2::Composition::Sideband:
705 layer.set_validated_type(HWC2::Composition::Client);
706 ++*num_types;
707 break;
708 default:
709 layer.set_validated_type(layer.sf_type());
710 break;
711 }
712 }
713 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500714}
715
716HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t x, int32_t y) {
Sean Paulac874152016-03-10 16:00:26 -0500717 supported(__func__);
Kalyan Kondapallyda5839c2016-11-10 10:59:50 -0800718 cursor_x_ = x;
719 cursor_y_ = y;
720 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500721}
722
723HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500724 supported(__func__);
725 blending_ = static_cast<HWC2::BlendMode>(mode);
726 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500727}
728
729HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500730 int32_t acquire_fence) {
731 supported(__func__);
732 UniqueFd uf(acquire_fence);
733
734 // The buffer and acquire_fence are handled elsewhere
735 if (sf_type_ == HWC2::Composition::Client ||
736 sf_type_ == HWC2::Composition::Sideband ||
737 sf_type_ == HWC2::Composition::SolidColor)
738 return HWC2::Error::None;
739
740 set_buffer(buffer);
741 set_acquire_fence(uf.get());
742 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500743}
744
745HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) {
Sean Paulac874152016-03-10 16:00:26 -0500746 // TODO: Punt to client composition here?
Sean Pauled2ec4b2016-03-10 15:35:40 -0500747 return unsupported(__func__, color);
748}
749
750HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) {
Sean Paulac874152016-03-10 16:00:26 -0500751 sf_type_ = static_cast<HWC2::Composition>(type);
752 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500753}
754
755HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) {
Sean Paulac874152016-03-10 16:00:26 -0500756 supported(__func__);
757 dataspace_ = static_cast<android_dataspace_t>(dataspace);
758 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500759}
760
761HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
Sean Paulac874152016-03-10 16:00:26 -0500762 supported(__func__);
763 display_frame_ = frame;
764 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500765}
766
767HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) {
Sean Paulac874152016-03-10 16:00:26 -0500768 supported(__func__);
769 alpha_ = alpha;
770 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500771}
772
773HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream(
774 const native_handle_t *stream) {
Sean Paulac874152016-03-10 16:00:26 -0500775 supported(__func__);
776 // TODO: We don't support sideband
Sean Pauled2ec4b2016-03-10 15:35:40 -0500777 return unsupported(__func__, stream);
778}
779
780HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
Sean Paulac874152016-03-10 16:00:26 -0500781 supported(__func__);
782 source_crop_ = crop;
783 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500784}
785
786HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -0500787 supported(__func__);
788 // TODO: We don't use surface damage, marking as unsupported
789 unsupported(__func__, damage);
790 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500791}
792
793HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) {
Sean Paulac874152016-03-10 16:00:26 -0500794 supported(__func__);
795 transform_ = static_cast<HWC2::Transform>(transform);
796 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500797}
798
799HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) {
Sean Paulac874152016-03-10 16:00:26 -0500800 supported(__func__);
801 // TODO: We don't use this information, marking as unsupported
802 unsupported(__func__, visible);
803 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500804}
805
Sean Paulac874152016-03-10 16:00:26 -0500806HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) {
807 supported(__func__);
808 z_order_ = order;
809 return HWC2::Error::None;
810}
811
812void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) {
813 supported(__func__);
814 switch (blending_) {
815 case HWC2::BlendMode::None:
816 layer->blending = DrmHwcBlending::kNone;
817 break;
818 case HWC2::BlendMode::Premultiplied:
819 layer->blending = DrmHwcBlending::kPreMult;
820 break;
821 case HWC2::BlendMode::Coverage:
822 layer->blending = DrmHwcBlending::kCoverage;
823 break;
824 default:
825 ALOGE("Unknown blending mode b=%d", blending_);
826 layer->blending = DrmHwcBlending::kNone;
827 break;
828 }
829
830 OutputFd release_fence = release_fence_output();
831
832 layer->sf_handle = buffer_;
833 layer->acquire_fence = acquire_fence_.Release();
834 layer->release_fence = std::move(release_fence);
835 layer->SetDisplayFrame(display_frame_);
836 layer->alpha = static_cast<uint8_t>(255.0f * alpha_ + 0.5f);
837 layer->SetSourceCrop(source_crop_);
838 layer->SetTransform(static_cast<int32_t>(transform_));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500839}
840
841// static
842int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) {
843 unsupported(__func__);
844 return 0;
845}
846
847// static
848void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/,
Sean Paulac874152016-03-10 16:00:26 -0500849 uint32_t *out_count,
850 int32_t * /*out_capabilities*/) {
851 supported(__func__);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500852 *out_count = 0;
853}
854
855// static
Sean Paulac874152016-03-10 16:00:26 -0500856hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
857 struct hwc2_device * /*dev*/, int32_t descriptor) {
858 supported(__func__);
859 auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500860 switch (func) {
861 // Device functions
862 case HWC2::FunctionDescriptor::CreateVirtualDisplay:
863 return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
864 DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
865 &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
866 int32_t*, hwc2_display_t *>);
867 case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
868 return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
869 DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
870 &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
871 case HWC2::FunctionDescriptor::Dump:
872 return ToHook<HWC2_PFN_DUMP>(
873 DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump,
874 uint32_t *, char *>);
875 case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
876 return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
877 DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
878 &DrmHwcTwo::GetMaxVirtualDisplayCount>);
879 case HWC2::FunctionDescriptor::RegisterCallback:
880 return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
881 DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
882 &DrmHwcTwo::RegisterCallback, int32_t,
883 hwc2_callback_data_t, hwc2_function_pointer_t>);
884
885 // Display functions
886 case HWC2::FunctionDescriptor::AcceptDisplayChanges:
887 return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
888 DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
889 &HwcDisplay::AcceptDisplayChanges>);
890 case HWC2::FunctionDescriptor::CreateLayer:
891 return ToHook<HWC2_PFN_CREATE_LAYER>(
892 DisplayHook<decltype(&HwcDisplay::CreateLayer),
893 &HwcDisplay::CreateLayer, hwc2_layer_t *>);
894 case HWC2::FunctionDescriptor::DestroyLayer:
895 return ToHook<HWC2_PFN_DESTROY_LAYER>(
896 DisplayHook<decltype(&HwcDisplay::DestroyLayer),
897 &HwcDisplay::DestroyLayer, hwc2_layer_t>);
898 case HWC2::FunctionDescriptor::GetActiveConfig:
899 return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
900 DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
901 &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
902 case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
903 return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
904 DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
905 &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
906 hwc2_layer_t *, int32_t *>);
907 case HWC2::FunctionDescriptor::GetClientTargetSupport:
908 return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
909 DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
910 &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
911 int32_t, int32_t>);
912 case HWC2::FunctionDescriptor::GetColorModes:
913 return ToHook<HWC2_PFN_GET_COLOR_MODES>(
914 DisplayHook<decltype(&HwcDisplay::GetColorModes),
915 &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
916 case HWC2::FunctionDescriptor::GetDisplayAttribute:
917 return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(DisplayHook<
918 decltype(&HwcDisplay::GetDisplayAttribute),
919 &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, int32_t *>);
920 case HWC2::FunctionDescriptor::GetDisplayConfigs:
921 return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(DisplayHook<
922 decltype(&HwcDisplay::GetDisplayConfigs),
923 &HwcDisplay::GetDisplayConfigs, uint32_t *, hwc2_config_t *>);
924 case HWC2::FunctionDescriptor::GetDisplayName:
925 return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
926 DisplayHook<decltype(&HwcDisplay::GetDisplayName),
927 &HwcDisplay::GetDisplayName, uint32_t *, char *>);
928 case HWC2::FunctionDescriptor::GetDisplayRequests:
929 return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
930 DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
931 &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
932 hwc2_layer_t *, int32_t *>);
933 case HWC2::FunctionDescriptor::GetDisplayType:
934 return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
935 DisplayHook<decltype(&HwcDisplay::GetDisplayType),
936 &HwcDisplay::GetDisplayType, int32_t *>);
937 case HWC2::FunctionDescriptor::GetDozeSupport:
938 return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
939 DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
940 &HwcDisplay::GetDozeSupport, int32_t *>);
Sean Paulac874152016-03-10 16:00:26 -0500941 case HWC2::FunctionDescriptor::GetHdrCapabilities:
942 return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
943 DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
944 &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
945 float *, float *, float *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500946 case HWC2::FunctionDescriptor::GetReleaseFences:
947 return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
948 DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
949 &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
950 int32_t *>);
951 case HWC2::FunctionDescriptor::PresentDisplay:
952 return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
953 DisplayHook<decltype(&HwcDisplay::PresentDisplay),
954 &HwcDisplay::PresentDisplay, int32_t *>);
955 case HWC2::FunctionDescriptor::SetActiveConfig:
956 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
957 DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
958 &HwcDisplay::SetActiveConfig, hwc2_config_t>);
959 case HWC2::FunctionDescriptor::SetClientTarget:
960 return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(DisplayHook<
961 decltype(&HwcDisplay::SetClientTarget), &HwcDisplay::SetClientTarget,
962 buffer_handle_t, int32_t, int32_t, hwc_region_t>);
963 case HWC2::FunctionDescriptor::SetColorMode:
964 return ToHook<HWC2_PFN_SET_COLOR_MODE>(
965 DisplayHook<decltype(&HwcDisplay::SetColorMode),
966 &HwcDisplay::SetColorMode, int32_t>);
967 case HWC2::FunctionDescriptor::SetColorTransform:
968 return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
969 DisplayHook<decltype(&HwcDisplay::SetColorTransform),
970 &HwcDisplay::SetColorTransform, const float *, int32_t>);
971 case HWC2::FunctionDescriptor::SetOutputBuffer:
972 return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
973 DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
974 &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
975 case HWC2::FunctionDescriptor::SetPowerMode:
976 return ToHook<HWC2_PFN_SET_POWER_MODE>(
977 DisplayHook<decltype(&HwcDisplay::SetPowerMode),
978 &HwcDisplay::SetPowerMode, int32_t>);
979 case HWC2::FunctionDescriptor::SetVsyncEnabled:
980 return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
981 DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
982 &HwcDisplay::SetVsyncEnabled, int32_t>);
983 case HWC2::FunctionDescriptor::ValidateDisplay:
984 return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
985 DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
986 &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
987
988 // Layer functions
989 case HWC2::FunctionDescriptor::SetCursorPosition:
990 return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
991 LayerHook<decltype(&HwcLayer::SetCursorPosition),
992 &HwcLayer::SetCursorPosition, int32_t, int32_t>);
993 case HWC2::FunctionDescriptor::SetLayerBlendMode:
994 return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
995 LayerHook<decltype(&HwcLayer::SetLayerBlendMode),
996 &HwcLayer::SetLayerBlendMode, int32_t>);
997 case HWC2::FunctionDescriptor::SetLayerBuffer:
998 return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
999 LayerHook<decltype(&HwcLayer::SetLayerBuffer),
1000 &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>);
1001 case HWC2::FunctionDescriptor::SetLayerColor:
1002 return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
1003 LayerHook<decltype(&HwcLayer::SetLayerColor),
1004 &HwcLayer::SetLayerColor, hwc_color_t>);
1005 case HWC2::FunctionDescriptor::SetLayerCompositionType:
1006 return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
1007 LayerHook<decltype(&HwcLayer::SetLayerCompositionType),
1008 &HwcLayer::SetLayerCompositionType, int32_t>);
1009 case HWC2::FunctionDescriptor::SetLayerDataspace:
1010 return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
1011 LayerHook<decltype(&HwcLayer::SetLayerDataspace),
1012 &HwcLayer::SetLayerDataspace, int32_t>);
1013 case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
1014 return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
1015 LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame),
1016 &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>);
1017 case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
1018 return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
1019 LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha),
1020 &HwcLayer::SetLayerPlaneAlpha, float>);
1021 case HWC2::FunctionDescriptor::SetLayerSidebandStream:
1022 return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(LayerHook<
1023 decltype(&HwcLayer::SetLayerSidebandStream),
1024 &HwcLayer::SetLayerSidebandStream, const native_handle_t *>);
1025 case HWC2::FunctionDescriptor::SetLayerSourceCrop:
1026 return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
1027 LayerHook<decltype(&HwcLayer::SetLayerSourceCrop),
1028 &HwcLayer::SetLayerSourceCrop, hwc_frect_t>);
1029 case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
1030 return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
1031 LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage),
1032 &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>);
1033 case HWC2::FunctionDescriptor::SetLayerTransform:
1034 return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
1035 LayerHook<decltype(&HwcLayer::SetLayerTransform),
1036 &HwcLayer::SetLayerTransform, int32_t>);
1037 case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
1038 return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
1039 LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion),
1040 &HwcLayer::SetLayerVisibleRegion, hwc_region_t>);
1041 case HWC2::FunctionDescriptor::SetLayerZOrder:
1042 return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
1043 LayerHook<decltype(&HwcLayer::SetLayerZOrder),
1044 &HwcLayer::SetLayerZOrder, uint32_t>);
Sean Paulac874152016-03-10 16:00:26 -05001045 case HWC2::FunctionDescriptor::Invalid:
Sean Pauled2ec4b2016-03-10 15:35:40 -05001046 default:
1047 return NULL;
1048 }
1049}
Sean Paulac874152016-03-10 16:00:26 -05001050
1051// static
1052int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
1053 struct hw_device_t **dev) {
1054 supported(__func__);
1055 if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
1056 ALOGE("Invalid module name- %s", name);
1057 return -EINVAL;
1058 }
1059
1060 std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo());
1061 if (!ctx) {
1062 ALOGE("Failed to allocate DrmHwcTwo");
1063 return -ENOMEM;
1064 }
1065
1066 HWC2::Error err = ctx->Init();
1067 if (err != HWC2::Error::None) {
1068 ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err);
1069 return -EINVAL;
1070 }
1071
1072 ctx->common.module = const_cast<hw_module_t *>(module);
1073 *dev = &ctx->common;
1074 ctx.release();
1075 return 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001076}
Sean Paulac874152016-03-10 16:00:26 -05001077}
1078
1079static struct hw_module_methods_t hwc2_module_methods = {
1080 .open = android::DrmHwcTwo::HookDevOpen,
1081};
1082
1083hw_module_t HAL_MODULE_INFO_SYM = {
1084 .tag = HARDWARE_MODULE_TAG,
1085 .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
1086 .id = HWC_HARDWARE_MODULE_ID,
1087 .name = "DrmHwcTwo module",
1088 .author = "The Android Open Source Project",
1089 .methods = &hwc2_module_methods,
1090 .dso = NULL,
1091 .reserved = {0},
1092};