blob: 138f5faa783e6859b1a4cf64222258d24051bc03 [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__);
322 // TODO: android_color_mode_t isn't defined yet!
Sean Pauled2ec4b2016-03-10 15:35:40 -0500323 return unsupported(__func__, num_modes, modes);
324}
325
326HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
Sean Paulac874152016-03-10 16:00:26 -0500327 int32_t attribute_in,
328 int32_t *value) {
329 supported(__func__);
330 auto mode =
331 std::find_if(connector_->modes().begin(), connector_->modes().end(),
332 [config](DrmMode const &m) { return m.id() == config; });
333 if (mode == connector_->modes().end()) {
334 ALOGE("Could not find active mode for %d", config);
335 return HWC2::Error::BadConfig;
336 }
337
338 static const int32_t kUmPerInch = 25400;
339 uint32_t mm_width = connector_->mm_width();
340 uint32_t mm_height = connector_->mm_height();
341 auto attribute = static_cast<HWC2::Attribute>(attribute_in);
342 switch (attribute) {
343 case HWC2::Attribute::Width:
344 *value = mode->h_display();
345 break;
346 case HWC2::Attribute::Height:
347 *value = mode->v_display();
348 break;
349 case HWC2::Attribute::VsyncPeriod:
350 // in nanoseconds
351 *value = 1000 * 1000 * 1000 / mode->v_refresh();
352 break;
353 case HWC2::Attribute::DpiX:
354 // Dots per 1000 inches
355 *value = mm_width ? (mode->h_display() * kUmPerInch) / mm_width : -1;
356 break;
357 case HWC2::Attribute::DpiY:
358 // Dots per 1000 inches
359 *value = mm_height ? (mode->v_display() * kUmPerInch) / mm_height : -1;
360 break;
361 default:
362 *value = -1;
363 return HWC2::Error::BadConfig;
364 }
365 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500366}
367
368HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
369 hwc2_config_t *configs) {
Sean Paulac874152016-03-10 16:00:26 -0500370 supported(__func__);
371 // Since this callback is normally invoked twice (once to get the count, and
372 // once to populate configs), we don't really want to read the edid
373 // redundantly. Instead, only update the modes on the first invocation. While
374 // it's possible this will result in stale modes, it'll all come out in the
375 // wash when we try to set the active config later.
376 if (!configs) {
377 int ret = connector_->UpdateModes();
378 if (ret) {
379 ALOGE("Failed to update display modes %d", ret);
380 return HWC2::Error::BadDisplay;
381 }
382 }
383
384 auto num_modes = static_cast<uint32_t>(connector_->modes().size());
385 if (!configs) {
386 *num_configs = num_modes;
387 return HWC2::Error::None;
388 }
389
390 uint32_t idx = 0;
391 for (const DrmMode &mode : connector_->modes()) {
392 if (idx >= *num_configs)
393 break;
394 configs[idx++] = mode.id();
395 }
396 *num_configs = idx;
397 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500398}
399
400HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayName(uint32_t *size, char *name) {
Sean Paulac874152016-03-10 16:00:26 -0500401 supported(__func__);
402 std::ostringstream stream;
403 stream << "display-" << connector_->id();
404 std::string string = stream.str();
405 size_t length = string.length();
406 if (!name) {
407 *size = length;
408 return HWC2::Error::None;
409 }
410
411 *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
412 strncpy(name, string.c_str(), *size);
413 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500414}
415
Sean Paulac874152016-03-10 16:00:26 -0500416HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
417 uint32_t *num_elements,
418 hwc2_layer_t *layers,
419 int32_t *layer_requests) {
420 supported(__func__);
421 // TODO: I think virtual display should request
422 // HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
423 unsupported(__func__, display_requests, num_elements, layers, layer_requests);
424 *num_elements = 0;
425 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500426}
427
428HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayType(int32_t *type) {
Sean Paulac874152016-03-10 16:00:26 -0500429 supported(__func__);
430 *type = static_cast<int32_t>(type_);
431 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500432}
433
434HWC2::Error DrmHwcTwo::HwcDisplay::GetDozeSupport(int32_t *support) {
Sean Paulac874152016-03-10 16:00:26 -0500435 supported(__func__);
436 *support = 0;
437 return HWC2::Error::None;
438}
439
440HWC2::Error DrmHwcTwo::HwcDisplay::GetHdrCapabilities(
441 uint32_t *num_types, int32_t */*types*/, float */*max_luminance*/,
442 float */*max_average_luminance*/, float */*min_luminance*/) {
443 supported(__func__);
444 *num_types = 0;
445 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500446}
447
448HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
Sean Paulac874152016-03-10 16:00:26 -0500449 hwc2_layer_t *layers,
450 int32_t *fences) {
451 supported(__func__);
452 uint32_t num_layers = 0;
453
454 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
455 ++num_layers;
456 if (layers == NULL || fences == NULL) {
457 continue;
458 } else if (num_layers > *num_elements) {
459 ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
460 return HWC2::Error::None;
461 }
462
463 layers[num_layers - 1] = l.first;
464 fences[num_layers - 1] = l.second.take_release_fence();
465 }
466 *num_elements = num_layers;
467 return HWC2::Error::None;
468}
469
470void DrmHwcTwo::HwcDisplay::AddFenceToRetireFence(int fd) {
471 supported(__func__);
472 if (fd < 0)
473 return;
474
475 if (next_retire_fence_.get() >= 0) {
476 int old_fence = next_retire_fence_.get();
477 next_retire_fence_.Set(sync_merge("dc_retire", old_fence, fd));
478 } else {
479 next_retire_fence_.Set(dup(fd));
480 }
Sean Pauled2ec4b2016-03-10 15:35:40 -0500481}
482
483HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) {
Sean Paulac874152016-03-10 16:00:26 -0500484 supported(__func__);
485 std::vector<DrmCompositionDisplayLayersMap> layers_map;
486 layers_map.emplace_back();
487 DrmCompositionDisplayLayersMap &map = layers_map.back();
488
489 map.display = static_cast<int>(handle_);
490 map.geometry_changed = true; // TODO: Fix this
491
492 // order the layers by z-order
493 bool use_client_layer = false;
494 uint32_t client_z_order = 0;
495 std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
496 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
497 switch (l.second.validated_type()) {
498 case HWC2::Composition::Device:
499 z_map.emplace(std::make_pair(l.second.z_order(), &l.second));
500 break;
501 case HWC2::Composition::Client:
502 // Place it at the z_order of the highest client layer
503 use_client_layer = true;
504 client_z_order = std::max(client_z_order, l.second.z_order());
505 break;
506 default:
507 continue;
508 }
509 }
510 if (use_client_layer)
511 z_map.emplace(std::make_pair(client_z_order, &client_layer_));
512
513 // now that they're ordered by z, add them to the composition
514 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
515 DrmHwcLayer layer;
516 l.second->PopulateDrmLayer(&layer);
517 int ret = layer.ImportBuffer(importer_.get(), gralloc_);
518 if (ret) {
519 ALOGE("Failed to import layer, ret=%d", ret);
520 return HWC2::Error::NoResources;
521 }
522 map.layers.emplace_back(std::move(layer));
523 }
524 if (map.layers.empty()) {
525 *retire_fence = -1;
526 return HWC2::Error::None;
527 }
528
529 std::unique_ptr<DrmDisplayComposition> composition =
530 compositor_.CreateComposition();
531 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
532
533 // TODO: Don't always assume geometry changed
534 int ret = composition->SetLayers(map.layers.data(), map.layers.size(), true);
535 if (ret) {
536 ALOGE("Failed to set layers in the composition ret=%d", ret);
537 return HWC2::Error::BadLayer;
538 }
539
540 std::vector<DrmPlane *> primary_planes(primary_planes_);
541 std::vector<DrmPlane *> overlay_planes(overlay_planes_);
542 ret = composition->Plan(compositor_.squash_state(), &primary_planes,
543 &overlay_planes);
544 if (ret) {
545 ALOGE("Failed to plan the composition ret=%d", ret);
546 return HWC2::Error::BadConfig;
547 }
548
549 // Disable the planes we're not using
550 for (auto i = primary_planes.begin(); i != primary_planes.end();) {
551 composition->AddPlaneDisable(*i);
552 i = primary_planes.erase(i);
553 }
554 for (auto i = overlay_planes.begin(); i != overlay_planes.end();) {
555 composition->AddPlaneDisable(*i);
556 i = overlay_planes.erase(i);
557 }
558
559 ret = compositor_.QueueComposition(std::move(composition));
560 if (ret) {
561 ALOGE("Failed to apply the frame composition ret=%d", ret);
562 return HWC2::Error::BadParameter;
563 }
564
565 // Now that the release fences have been generated by the compositor, make
566 // sure they're managed properly
567 for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
568 l.second->manage_release_fence();
569 AddFenceToRetireFence(l.second->release_fence());
570 }
571
572 // The retire fence returned here is for the last frame, so return it and
573 // promote the next retire fence
574 *retire_fence = retire_fence_.Release();
575 retire_fence_ = std::move(next_retire_fence_);
576
577 ++frame_no_;
578 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500579}
580
581HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
Sean Paulac874152016-03-10 16:00:26 -0500582 supported(__func__);
583 auto mode =
584 std::find_if(connector_->modes().begin(), connector_->modes().end(),
585 [config](DrmMode const &m) { return m.id() == config; });
586 if (mode == connector_->modes().end()) {
587 ALOGE("Could not find active mode for %d", config);
588 return HWC2::Error::BadConfig;
589 }
590
591 std::unique_ptr<DrmDisplayComposition> composition =
592 compositor_.CreateComposition();
593 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
594 int ret = composition->SetDisplayMode(*mode);
595 ret = compositor_.QueueComposition(std::move(composition));
596 if (ret) {
597 ALOGE("Failed to queue dpms composition on %d", ret);
598 return HWC2::Error::BadConfig;
599 }
600 if (connector_->active_mode().id() == 0)
601 connector_->set_active_mode(*mode);
602
603 // Setup the client layer's dimensions
604 hwc_rect_t display_frame = {.left = 0,
605 .top = 0,
606 .right = static_cast<int>(mode->h_display()),
607 .bottom = static_cast<int>(mode->v_display())};
608 client_layer_.SetLayerDisplayFrame(display_frame);
609 hwc_frect_t source_crop = {.left = 0.0f,
610 .top = 0.0f,
611 .right = mode->h_display() + 0.0f,
612 .bottom = mode->v_display() + 0.0f};
613 client_layer_.SetLayerSourceCrop(source_crop);
614
615 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500616}
617
618HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target,
619 int32_t acquire_fence,
620 int32_t dataspace,
621 hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -0500622 supported(__func__);
623 UniqueFd uf(acquire_fence);
624
625 client_layer_.set_buffer(target);
626 client_layer_.set_acquire_fence(uf.get());
627 client_layer_.SetLayerDataspace(dataspace);
628 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500629}
630
631HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500632 supported(__func__);
633 // TODO: android_color_mode_t isn't defined yet!
Sean Pauled2ec4b2016-03-10 15:35:40 -0500634 return unsupported(__func__, mode);
635}
636
637HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix,
Sean Paulac874152016-03-10 16:00:26 -0500638 int32_t hint) {
639 supported(__func__);
640 // TODO: Force client composition if we get this
Sean Pauled2ec4b2016-03-10 15:35:40 -0500641 return unsupported(__func__, matrix, hint);
642}
643
644HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500645 int32_t release_fence) {
646 supported(__func__);
647 // TODO: Need virtual display support
Sean Pauled2ec4b2016-03-10 15:35:40 -0500648 return unsupported(__func__, buffer, release_fence);
649}
650
Sean Paulac874152016-03-10 16:00:26 -0500651HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) {
652 supported(__func__);
653 uint64_t dpms_value = 0;
654 auto mode = static_cast<HWC2::PowerMode>(mode_in);
655 switch (mode) {
656 case HWC2::PowerMode::Off:
657 dpms_value = DRM_MODE_DPMS_OFF;
658 break;
659 case HWC2::PowerMode::On:
660 dpms_value = DRM_MODE_DPMS_ON;
661 break;
662 default:
663 ALOGI("Power mode %d is unsupported\n", mode);
664 return HWC2::Error::Unsupported;
665 };
666
667 std::unique_ptr<DrmDisplayComposition> composition =
668 compositor_.CreateComposition();
669 composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
670 composition->SetDpmsMode(dpms_value);
671 int ret = compositor_.QueueComposition(std::move(composition));
672 if (ret) {
673 ALOGE("Failed to apply the dpms composition ret=%d", ret);
674 return HWC2::Error::BadParameter;
675 }
676 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500677}
678
679HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
Sean Paulac874152016-03-10 16:00:26 -0500680 supported(__func__);
681 vsync_worker_.VSyncControl(enabled);
682 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500683}
684
685HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types,
Sean Paulac874152016-03-10 16:00:26 -0500686 uint32_t *num_requests) {
687 supported(__func__);
688 *num_types = 0;
689 *num_requests = 0;
690 for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
691 DrmHwcTwo::HwcLayer &layer = l.second;
692 switch (layer.sf_type()) {
693 case HWC2::Composition::SolidColor:
694 case HWC2::Composition::Cursor:
695 case HWC2::Composition::Sideband:
696 layer.set_validated_type(HWC2::Composition::Client);
697 ++*num_types;
698 break;
699 default:
700 layer.set_validated_type(layer.sf_type());
701 break;
702 }
703 }
704 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500705}
706
707HWC2::Error DrmHwcTwo::HwcLayer::SetCursorPosition(int32_t x, int32_t y) {
Sean Paulac874152016-03-10 16:00:26 -0500708 supported(__func__);
709 // TODO: Implement proper cursor support
Sean Pauled2ec4b2016-03-10 15:35:40 -0500710 return unsupported(__func__, x, y);
711}
712
713HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) {
Sean Paulac874152016-03-10 16:00:26 -0500714 supported(__func__);
715 blending_ = static_cast<HWC2::BlendMode>(mode);
716 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500717}
718
719HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
Sean Paulac874152016-03-10 16:00:26 -0500720 int32_t acquire_fence) {
721 supported(__func__);
722 UniqueFd uf(acquire_fence);
723
724 // The buffer and acquire_fence are handled elsewhere
725 if (sf_type_ == HWC2::Composition::Client ||
726 sf_type_ == HWC2::Composition::Sideband ||
727 sf_type_ == HWC2::Composition::SolidColor)
728 return HWC2::Error::None;
729
730 set_buffer(buffer);
731 set_acquire_fence(uf.get());
732 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500733}
734
735HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) {
Sean Paulac874152016-03-10 16:00:26 -0500736 // TODO: Punt to client composition here?
Sean Pauled2ec4b2016-03-10 15:35:40 -0500737 return unsupported(__func__, color);
738}
739
740HWC2::Error DrmHwcTwo::HwcLayer::SetLayerCompositionType(int32_t type) {
Sean Paulac874152016-03-10 16:00:26 -0500741 sf_type_ = static_cast<HWC2::Composition>(type);
742 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500743}
744
745HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDataspace(int32_t dataspace) {
Sean Paulac874152016-03-10 16:00:26 -0500746 supported(__func__);
747 dataspace_ = static_cast<android_dataspace_t>(dataspace);
748 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500749}
750
751HWC2::Error DrmHwcTwo::HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
Sean Paulac874152016-03-10 16:00:26 -0500752 supported(__func__);
753 display_frame_ = frame;
754 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500755}
756
757HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) {
Sean Paulac874152016-03-10 16:00:26 -0500758 supported(__func__);
759 alpha_ = alpha;
760 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500761}
762
763HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream(
764 const native_handle_t *stream) {
Sean Paulac874152016-03-10 16:00:26 -0500765 supported(__func__);
766 // TODO: We don't support sideband
Sean Pauled2ec4b2016-03-10 15:35:40 -0500767 return unsupported(__func__, stream);
768}
769
770HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
Sean Paulac874152016-03-10 16:00:26 -0500771 supported(__func__);
772 source_crop_ = crop;
773 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500774}
775
776HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
Sean Paulac874152016-03-10 16:00:26 -0500777 supported(__func__);
778 // TODO: We don't use surface damage, marking as unsupported
779 unsupported(__func__, damage);
780 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500781}
782
783HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) {
Sean Paulac874152016-03-10 16:00:26 -0500784 supported(__func__);
785 transform_ = static_cast<HWC2::Transform>(transform);
786 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500787}
788
789HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) {
Sean Paulac874152016-03-10 16:00:26 -0500790 supported(__func__);
791 // TODO: We don't use this information, marking as unsupported
792 unsupported(__func__, visible);
793 return HWC2::Error::None;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500794}
795
Sean Paulac874152016-03-10 16:00:26 -0500796HWC2::Error DrmHwcTwo::HwcLayer::SetLayerZOrder(uint32_t order) {
797 supported(__func__);
798 z_order_ = order;
799 return HWC2::Error::None;
800}
801
802void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) {
803 supported(__func__);
804 switch (blending_) {
805 case HWC2::BlendMode::None:
806 layer->blending = DrmHwcBlending::kNone;
807 break;
808 case HWC2::BlendMode::Premultiplied:
809 layer->blending = DrmHwcBlending::kPreMult;
810 break;
811 case HWC2::BlendMode::Coverage:
812 layer->blending = DrmHwcBlending::kCoverage;
813 break;
814 default:
815 ALOGE("Unknown blending mode b=%d", blending_);
816 layer->blending = DrmHwcBlending::kNone;
817 break;
818 }
819
820 OutputFd release_fence = release_fence_output();
821
822 layer->sf_handle = buffer_;
823 layer->acquire_fence = acquire_fence_.Release();
824 layer->release_fence = std::move(release_fence);
825 layer->SetDisplayFrame(display_frame_);
826 layer->alpha = static_cast<uint8_t>(255.0f * alpha_ + 0.5f);
827 layer->SetSourceCrop(source_crop_);
828 layer->SetTransform(static_cast<int32_t>(transform_));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500829}
830
831// static
832int DrmHwcTwo::HookDevClose(hw_device_t * /*dev*/) {
833 unsupported(__func__);
834 return 0;
835}
836
837// static
838void DrmHwcTwo::HookDevGetCapabilities(hwc2_device_t * /*dev*/,
Sean Paulac874152016-03-10 16:00:26 -0500839 uint32_t *out_count,
840 int32_t * /*out_capabilities*/) {
841 supported(__func__);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500842 *out_count = 0;
843}
844
845// static
Sean Paulac874152016-03-10 16:00:26 -0500846hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
847 struct hwc2_device * /*dev*/, int32_t descriptor) {
848 supported(__func__);
849 auto func = static_cast<HWC2::FunctionDescriptor>(descriptor);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500850 switch (func) {
851 // Device functions
852 case HWC2::FunctionDescriptor::CreateVirtualDisplay:
853 return ToHook<HWC2_PFN_CREATE_VIRTUAL_DISPLAY>(
854 DeviceHook<int32_t, decltype(&DrmHwcTwo::CreateVirtualDisplay),
855 &DrmHwcTwo::CreateVirtualDisplay, uint32_t, uint32_t,
856 int32_t*, hwc2_display_t *>);
857 case HWC2::FunctionDescriptor::DestroyVirtualDisplay:
858 return ToHook<HWC2_PFN_DESTROY_VIRTUAL_DISPLAY>(
859 DeviceHook<int32_t, decltype(&DrmHwcTwo::DestroyVirtualDisplay),
860 &DrmHwcTwo::DestroyVirtualDisplay, hwc2_display_t>);
861 case HWC2::FunctionDescriptor::Dump:
862 return ToHook<HWC2_PFN_DUMP>(
863 DeviceHook<void, decltype(&DrmHwcTwo::Dump), &DrmHwcTwo::Dump,
864 uint32_t *, char *>);
865 case HWC2::FunctionDescriptor::GetMaxVirtualDisplayCount:
866 return ToHook<HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT>(
867 DeviceHook<uint32_t, decltype(&DrmHwcTwo::GetMaxVirtualDisplayCount),
868 &DrmHwcTwo::GetMaxVirtualDisplayCount>);
869 case HWC2::FunctionDescriptor::RegisterCallback:
870 return ToHook<HWC2_PFN_REGISTER_CALLBACK>(
871 DeviceHook<int32_t, decltype(&DrmHwcTwo::RegisterCallback),
872 &DrmHwcTwo::RegisterCallback, int32_t,
873 hwc2_callback_data_t, hwc2_function_pointer_t>);
874
875 // Display functions
876 case HWC2::FunctionDescriptor::AcceptDisplayChanges:
877 return ToHook<HWC2_PFN_ACCEPT_DISPLAY_CHANGES>(
878 DisplayHook<decltype(&HwcDisplay::AcceptDisplayChanges),
879 &HwcDisplay::AcceptDisplayChanges>);
880 case HWC2::FunctionDescriptor::CreateLayer:
881 return ToHook<HWC2_PFN_CREATE_LAYER>(
882 DisplayHook<decltype(&HwcDisplay::CreateLayer),
883 &HwcDisplay::CreateLayer, hwc2_layer_t *>);
884 case HWC2::FunctionDescriptor::DestroyLayer:
885 return ToHook<HWC2_PFN_DESTROY_LAYER>(
886 DisplayHook<decltype(&HwcDisplay::DestroyLayer),
887 &HwcDisplay::DestroyLayer, hwc2_layer_t>);
888 case HWC2::FunctionDescriptor::GetActiveConfig:
889 return ToHook<HWC2_PFN_GET_ACTIVE_CONFIG>(
890 DisplayHook<decltype(&HwcDisplay::GetActiveConfig),
891 &HwcDisplay::GetActiveConfig, hwc2_config_t *>);
892 case HWC2::FunctionDescriptor::GetChangedCompositionTypes:
893 return ToHook<HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES>(
894 DisplayHook<decltype(&HwcDisplay::GetChangedCompositionTypes),
895 &HwcDisplay::GetChangedCompositionTypes, uint32_t *,
896 hwc2_layer_t *, int32_t *>);
897 case HWC2::FunctionDescriptor::GetClientTargetSupport:
898 return ToHook<HWC2_PFN_GET_CLIENT_TARGET_SUPPORT>(
899 DisplayHook<decltype(&HwcDisplay::GetClientTargetSupport),
900 &HwcDisplay::GetClientTargetSupport, uint32_t, uint32_t,
901 int32_t, int32_t>);
902 case HWC2::FunctionDescriptor::GetColorModes:
903 return ToHook<HWC2_PFN_GET_COLOR_MODES>(
904 DisplayHook<decltype(&HwcDisplay::GetColorModes),
905 &HwcDisplay::GetColorModes, uint32_t *, int32_t *>);
906 case HWC2::FunctionDescriptor::GetDisplayAttribute:
907 return ToHook<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>(DisplayHook<
908 decltype(&HwcDisplay::GetDisplayAttribute),
909 &HwcDisplay::GetDisplayAttribute, hwc2_config_t, int32_t, int32_t *>);
910 case HWC2::FunctionDescriptor::GetDisplayConfigs:
911 return ToHook<HWC2_PFN_GET_DISPLAY_CONFIGS>(DisplayHook<
912 decltype(&HwcDisplay::GetDisplayConfigs),
913 &HwcDisplay::GetDisplayConfigs, uint32_t *, hwc2_config_t *>);
914 case HWC2::FunctionDescriptor::GetDisplayName:
915 return ToHook<HWC2_PFN_GET_DISPLAY_NAME>(
916 DisplayHook<decltype(&HwcDisplay::GetDisplayName),
917 &HwcDisplay::GetDisplayName, uint32_t *, char *>);
918 case HWC2::FunctionDescriptor::GetDisplayRequests:
919 return ToHook<HWC2_PFN_GET_DISPLAY_REQUESTS>(
920 DisplayHook<decltype(&HwcDisplay::GetDisplayRequests),
921 &HwcDisplay::GetDisplayRequests, int32_t *, uint32_t *,
922 hwc2_layer_t *, int32_t *>);
923 case HWC2::FunctionDescriptor::GetDisplayType:
924 return ToHook<HWC2_PFN_GET_DISPLAY_TYPE>(
925 DisplayHook<decltype(&HwcDisplay::GetDisplayType),
926 &HwcDisplay::GetDisplayType, int32_t *>);
927 case HWC2::FunctionDescriptor::GetDozeSupport:
928 return ToHook<HWC2_PFN_GET_DOZE_SUPPORT>(
929 DisplayHook<decltype(&HwcDisplay::GetDozeSupport),
930 &HwcDisplay::GetDozeSupport, int32_t *>);
Sean Paulac874152016-03-10 16:00:26 -0500931 case HWC2::FunctionDescriptor::GetHdrCapabilities:
932 return ToHook<HWC2_PFN_GET_HDR_CAPABILITIES>(
933 DisplayHook<decltype(&HwcDisplay::GetHdrCapabilities),
934 &HwcDisplay::GetHdrCapabilities, uint32_t *, int32_t *,
935 float *, float *, float *>);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500936 case HWC2::FunctionDescriptor::GetReleaseFences:
937 return ToHook<HWC2_PFN_GET_RELEASE_FENCES>(
938 DisplayHook<decltype(&HwcDisplay::GetReleaseFences),
939 &HwcDisplay::GetReleaseFences, uint32_t *, hwc2_layer_t *,
940 int32_t *>);
941 case HWC2::FunctionDescriptor::PresentDisplay:
942 return ToHook<HWC2_PFN_PRESENT_DISPLAY>(
943 DisplayHook<decltype(&HwcDisplay::PresentDisplay),
944 &HwcDisplay::PresentDisplay, int32_t *>);
945 case HWC2::FunctionDescriptor::SetActiveConfig:
946 return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
947 DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
948 &HwcDisplay::SetActiveConfig, hwc2_config_t>);
949 case HWC2::FunctionDescriptor::SetClientTarget:
950 return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(DisplayHook<
951 decltype(&HwcDisplay::SetClientTarget), &HwcDisplay::SetClientTarget,
952 buffer_handle_t, int32_t, int32_t, hwc_region_t>);
953 case HWC2::FunctionDescriptor::SetColorMode:
954 return ToHook<HWC2_PFN_SET_COLOR_MODE>(
955 DisplayHook<decltype(&HwcDisplay::SetColorMode),
956 &HwcDisplay::SetColorMode, int32_t>);
957 case HWC2::FunctionDescriptor::SetColorTransform:
958 return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
959 DisplayHook<decltype(&HwcDisplay::SetColorTransform),
960 &HwcDisplay::SetColorTransform, const float *, int32_t>);
961 case HWC2::FunctionDescriptor::SetOutputBuffer:
962 return ToHook<HWC2_PFN_SET_OUTPUT_BUFFER>(
963 DisplayHook<decltype(&HwcDisplay::SetOutputBuffer),
964 &HwcDisplay::SetOutputBuffer, buffer_handle_t, int32_t>);
965 case HWC2::FunctionDescriptor::SetPowerMode:
966 return ToHook<HWC2_PFN_SET_POWER_MODE>(
967 DisplayHook<decltype(&HwcDisplay::SetPowerMode),
968 &HwcDisplay::SetPowerMode, int32_t>);
969 case HWC2::FunctionDescriptor::SetVsyncEnabled:
970 return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
971 DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
972 &HwcDisplay::SetVsyncEnabled, int32_t>);
973 case HWC2::FunctionDescriptor::ValidateDisplay:
974 return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
975 DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
976 &HwcDisplay::ValidateDisplay, uint32_t *, uint32_t *>);
977
978 // Layer functions
979 case HWC2::FunctionDescriptor::SetCursorPosition:
980 return ToHook<HWC2_PFN_SET_CURSOR_POSITION>(
981 LayerHook<decltype(&HwcLayer::SetCursorPosition),
982 &HwcLayer::SetCursorPosition, int32_t, int32_t>);
983 case HWC2::FunctionDescriptor::SetLayerBlendMode:
984 return ToHook<HWC2_PFN_SET_LAYER_BLEND_MODE>(
985 LayerHook<decltype(&HwcLayer::SetLayerBlendMode),
986 &HwcLayer::SetLayerBlendMode, int32_t>);
987 case HWC2::FunctionDescriptor::SetLayerBuffer:
988 return ToHook<HWC2_PFN_SET_LAYER_BUFFER>(
989 LayerHook<decltype(&HwcLayer::SetLayerBuffer),
990 &HwcLayer::SetLayerBuffer, buffer_handle_t, int32_t>);
991 case HWC2::FunctionDescriptor::SetLayerColor:
992 return ToHook<HWC2_PFN_SET_LAYER_COLOR>(
993 LayerHook<decltype(&HwcLayer::SetLayerColor),
994 &HwcLayer::SetLayerColor, hwc_color_t>);
995 case HWC2::FunctionDescriptor::SetLayerCompositionType:
996 return ToHook<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>(
997 LayerHook<decltype(&HwcLayer::SetLayerCompositionType),
998 &HwcLayer::SetLayerCompositionType, int32_t>);
999 case HWC2::FunctionDescriptor::SetLayerDataspace:
1000 return ToHook<HWC2_PFN_SET_LAYER_DATASPACE>(
1001 LayerHook<decltype(&HwcLayer::SetLayerDataspace),
1002 &HwcLayer::SetLayerDataspace, int32_t>);
1003 case HWC2::FunctionDescriptor::SetLayerDisplayFrame:
1004 return ToHook<HWC2_PFN_SET_LAYER_DISPLAY_FRAME>(
1005 LayerHook<decltype(&HwcLayer::SetLayerDisplayFrame),
1006 &HwcLayer::SetLayerDisplayFrame, hwc_rect_t>);
1007 case HWC2::FunctionDescriptor::SetLayerPlaneAlpha:
1008 return ToHook<HWC2_PFN_SET_LAYER_PLANE_ALPHA>(
1009 LayerHook<decltype(&HwcLayer::SetLayerPlaneAlpha),
1010 &HwcLayer::SetLayerPlaneAlpha, float>);
1011 case HWC2::FunctionDescriptor::SetLayerSidebandStream:
1012 return ToHook<HWC2_PFN_SET_LAYER_SIDEBAND_STREAM>(LayerHook<
1013 decltype(&HwcLayer::SetLayerSidebandStream),
1014 &HwcLayer::SetLayerSidebandStream, const native_handle_t *>);
1015 case HWC2::FunctionDescriptor::SetLayerSourceCrop:
1016 return ToHook<HWC2_PFN_SET_LAYER_SOURCE_CROP>(
1017 LayerHook<decltype(&HwcLayer::SetLayerSourceCrop),
1018 &HwcLayer::SetLayerSourceCrop, hwc_frect_t>);
1019 case HWC2::FunctionDescriptor::SetLayerSurfaceDamage:
1020 return ToHook<HWC2_PFN_SET_LAYER_SURFACE_DAMAGE>(
1021 LayerHook<decltype(&HwcLayer::SetLayerSurfaceDamage),
1022 &HwcLayer::SetLayerSurfaceDamage, hwc_region_t>);
1023 case HWC2::FunctionDescriptor::SetLayerTransform:
1024 return ToHook<HWC2_PFN_SET_LAYER_TRANSFORM>(
1025 LayerHook<decltype(&HwcLayer::SetLayerTransform),
1026 &HwcLayer::SetLayerTransform, int32_t>);
1027 case HWC2::FunctionDescriptor::SetLayerVisibleRegion:
1028 return ToHook<HWC2_PFN_SET_LAYER_VISIBLE_REGION>(
1029 LayerHook<decltype(&HwcLayer::SetLayerVisibleRegion),
1030 &HwcLayer::SetLayerVisibleRegion, hwc_region_t>);
1031 case HWC2::FunctionDescriptor::SetLayerZOrder:
1032 return ToHook<HWC2_PFN_SET_LAYER_Z_ORDER>(
1033 LayerHook<decltype(&HwcLayer::SetLayerZOrder),
1034 &HwcLayer::SetLayerZOrder, uint32_t>);
Sean Paulac874152016-03-10 16:00:26 -05001035 case HWC2::FunctionDescriptor::Invalid:
Sean Pauled2ec4b2016-03-10 15:35:40 -05001036 default:
1037 return NULL;
1038 }
1039}
Sean Paulac874152016-03-10 16:00:26 -05001040
1041// static
1042int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
1043 struct hw_device_t **dev) {
1044 supported(__func__);
1045 if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
1046 ALOGE("Invalid module name- %s", name);
1047 return -EINVAL;
1048 }
1049
1050 std::unique_ptr<DrmHwcTwo> ctx(new DrmHwcTwo());
1051 if (!ctx) {
1052 ALOGE("Failed to allocate DrmHwcTwo");
1053 return -ENOMEM;
1054 }
1055
1056 HWC2::Error err = ctx->Init();
1057 if (err != HWC2::Error::None) {
1058 ALOGE("Failed to initialize DrmHwcTwo err=%d\n", err);
1059 return -EINVAL;
1060 }
1061
1062 ctx->common.module = const_cast<hw_module_t *>(module);
1063 *dev = &ctx->common;
1064 ctx.release();
1065 return 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -05001066}
Sean Paulac874152016-03-10 16:00:26 -05001067}
1068
1069static struct hw_module_methods_t hwc2_module_methods = {
1070 .open = android::DrmHwcTwo::HookDevOpen,
1071};
1072
1073hw_module_t HAL_MODULE_INFO_SYM = {
1074 .tag = HARDWARE_MODULE_TAG,
1075 .module_api_version = HARDWARE_MODULE_API_VERSION(2, 0),
1076 .id = HWC_HARDWARE_MODULE_ID,
1077 .name = "DrmHwcTwo module",
1078 .author = "The Android Open Source Project",
1079 .methods = &hwc2_module_methods,
1080 .dso = NULL,
1081 .reserved = {0},
1082};