blob: dac7ed4e189a71c48dd4558a25902529f2b90809 [file] [log] [blame]
Sean Paule0c4c3d2015-01-20 16:56:04 -05001/*
2 * Copyright (C) 2015 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 LOG_TAG "hwcomposer-drm"
18
19#include <fcntl.h>
20#include <errno.h>
21#include <sys/param.h>
Sean Paul9aa5ad32015-01-22 15:47:54 -050022#include <sys/resource.h>
23#include <pthread.h>
Sean Paul9b1bb842015-01-23 01:11:58 -050024#include <queue>
Sean Paule0c4c3d2015-01-20 16:56:04 -050025
26#include <cutils/log.h>
27
28#include <xf86drm.h>
29#include <xf86drmMode.h>
Sean Paule0c4c3d2015-01-20 16:56:04 -050030
31#include <hardware/hardware.h>
32#include <hardware/hwcomposer.h>
33
Sean Paul9aa5ad32015-01-22 15:47:54 -050034#include <sync/sync.h>
Sean Paulf1dc1912015-01-24 01:34:31 -050035#include <sw_sync.h>
Sean Paul9aa5ad32015-01-22 15:47:54 -050036
Sean Paulcd36a9e2015-01-22 18:01:18 -050037#include "drm_hwcomposer.h"
Sean Paule0c4c3d2015-01-20 16:56:04 -050038
39#define ARRAY_SIZE(arr) (int)(sizeof(arr) / sizeof((arr)[0]))
40
41#define HWCOMPOSER_DRM_DEVICE "/dev/dri/card0"
42#define MAX_NUM_DISPLAYS 3
43#define UM_PER_INCH 25400
44
45static const uint32_t panel_types[] = {
46 DRM_MODE_CONNECTOR_LVDS,
47 DRM_MODE_CONNECTOR_eDP,
48 DRM_MODE_CONNECTOR_DSI,
49};
50
Sean Paul9aa5ad32015-01-22 15:47:54 -050051struct hwc_worker {
52 pthread_t thread;
53 pthread_mutex_t lock;
54 pthread_cond_t cond;
55 bool exit;
56};
57
Sean Paule0c4c3d2015-01-20 16:56:04 -050058struct hwc_drm_display {
Sean Paul9aa5ad32015-01-22 15:47:54 -050059 struct hwc_context_t *ctx;
60 int display;
61
Sean Paule0c4c3d2015-01-20 16:56:04 -050062 uint32_t connector_id;
63
64 drmModeModeInfoPtr configs;
65 uint32_t num_configs;
66
67 int active_config;
68 uint32_t active_crtc;
Sean Pauleb9e75c2015-01-25 23:31:30 -050069 int active_pipe;
Sean Paul9aa5ad32015-01-22 15:47:54 -050070
71 struct hwc_worker set_worker;
72
Sean Paul9b1bb842015-01-23 01:11:58 -050073 std::queue<struct hwc_drm_bo> buf_queue;
Sean Paul9aa5ad32015-01-22 15:47:54 -050074 struct hwc_drm_bo front;
Sean Paulf1dc1912015-01-24 01:34:31 -050075
76 int timeline_fd;
77 unsigned timeline_next;
Sean Pauleb9e75c2015-01-25 23:31:30 -050078
79 struct hwc_worker vsync_worker;
80 bool enable_vsync_events;
Sean Paule0c4c3d2015-01-20 16:56:04 -050081};
82
83struct hwc_context_t {
84 hwc_composer_device_1_t device;
85
86 int fd;
Sean Paule0c4c3d2015-01-20 16:56:04 -050087
88 hwc_procs_t const *procs;
Sean Paulcd36a9e2015-01-22 18:01:18 -050089 struct hwc_import_context *import_ctx;
Sean Paule0c4c3d2015-01-20 16:56:04 -050090
91 struct hwc_drm_display displays[MAX_NUM_DISPLAYS];
92 int num_displays;
93};
94
95static int hwc_get_drm_display(struct hwc_context_t *ctx, int display,
96 struct hwc_drm_display **hd)
97{
98 if (display >= MAX_NUM_DISPLAYS) {
99 ALOGE("Requested display is out-of-bounds %d %d", display,
100 MAX_NUM_DISPLAYS);
101 return -EINVAL;
102 }
103 *hd = &ctx->displays[display];
104 return 0;
105}
106
107static int hwc_prepare_layer(hwc_layer_1_t *layer)
108{
109 /* TODO: We can't handle background right now, defer to sufaceFlinger */
110 if (layer->compositionType == HWC_BACKGROUND) {
111 layer->compositionType = HWC_FRAMEBUFFER;
112 ALOGV("Can't handle background layers yet");
113
114 /* TODO: Support sideband compositions */
115 } else if (layer->compositionType == HWC_SIDEBAND) {
116 layer->compositionType = HWC_FRAMEBUFFER;
117 ALOGV("Can't handle sideband content yet");
118 }
119
120 layer->hints = 0;
121
122 /* TODO: Handle cursor by setting compositionType=HWC_CURSOR_OVERLAY */
123 if (layer->flags & HWC_IS_CURSOR_LAYER) {
124 ALOGV("Can't handle async cursors yet");
125 }
126
127 /* TODO: Handle transformations */
128 if (layer->transform) {
129 ALOGV("Can't handle transformations yet");
130 }
131
132 /* TODO: Handle blending & plane alpha*/
133 if (layer->blending == HWC_BLENDING_PREMULT ||
134 layer->blending == HWC_BLENDING_COVERAGE) {
135 ALOGV("Can't handle blending yet");
136 }
137
138 /* TODO: Handle cropping & scaling */
139
140 return 0;
141}
142
143static int hwc_prepare(hwc_composer_device_1_t */* dev */, size_t num_displays,
144 hwc_display_contents_1_t** display_contents)
145{
146 int ret = 0, i, j;
147
148 /* TODO: Check flags for HWC_GEOMETRY_CHANGED */
149
150 for (i = 0; i < (int)num_displays && i < MAX_NUM_DISPLAYS; i++) {
151 for (j = 0; j < (int)display_contents[i]->numHwLayers; j++) {
152 ret = hwc_prepare_layer(
153 &display_contents[i]->hwLayers[j]);
154 if (ret) {
155 ALOGE("Failed to prepare layer %d:%d", j, i);
156 return ret;
157 }
158 }
159 }
160
161 return ret;
162}
163
Sean Paulcd36a9e2015-01-22 18:01:18 -0500164/*
165 * TODO: This hack allows us to use the importer's fd to drm to add and remove
166 * framebuffers. The reason it exists is because gralloc doesn't export its
167 * bo's, so we have to use its file descriptor to drm for some operations. Once
168 * gralloc behaves, we can remove this.
169 */
170static int hwc_get_fd_for_bo(struct hwc_context_t *ctx, struct hwc_drm_bo *bo)
171{
172 if (bo->importer_fd >= 0)
173 return bo->importer_fd;
174
175 return ctx->fd;
176}
177
Sean Paule0c4c3d2015-01-20 16:56:04 -0500178static bool hwc_mode_is_equal(drmModeModeInfoPtr a, drmModeModeInfoPtr b)
179{
180 return a->clock == b->clock &&
181 a->hdisplay == b->hdisplay &&
182 a->hsync_start == b->hsync_start &&
183 a->hsync_end == b->hsync_end &&
184 a->htotal == b->htotal &&
185 a->hskew == b->hskew &&
186 a->vdisplay == b->vdisplay &&
187 a->vsync_start == b->vsync_start &&
188 a->vsync_end == b->vsync_end &&
189 a->vtotal == b->vtotal &&
190 a->vscan == b->vscan &&
191 a->vrefresh == b->vrefresh &&
192 a->flags == b->flags &&
193 a->type == b->type &&
194 !strcmp(a->name, b->name);
195}
196
Sean Paul9aa5ad32015-01-22 15:47:54 -0500197static int hwc_modeset_required(struct hwc_drm_display *hd,
198 bool *modeset_required)
199{
200 drmModeCrtcPtr crtc;
201 drmModeModeInfoPtr m;
202
203 crtc = drmModeGetCrtc(hd->ctx->fd, hd->active_crtc);
204 if (!crtc) {
205 ALOGE("Failed to get crtc for display %d", hd->display);
206 return -ENODEV;
207 }
208
209 m = &hd->configs[hd->active_config];
210
211 /* Do a modeset if we haven't done one, or the mode has changed */
212 if (!crtc->mode_valid || !hwc_mode_is_equal(m, &crtc->mode))
213 *modeset_required = true;
214 else
215 *modeset_required = false;
216
217 drmModeFreeCrtc(crtc);
218
219 return 0;
220}
221
222static void hwc_flip_handler(int /* fd */, unsigned int /* sequence */,
223 unsigned int /* tv_sec */, unsigned int /* tv_usec */,
224 void */* user_data */)
225{
226}
227
Sean Paul9b1bb842015-01-23 01:11:58 -0500228static int hwc_flip(struct hwc_drm_display *hd, struct hwc_drm_bo *buf)
Sean Paul9aa5ad32015-01-22 15:47:54 -0500229{
230 fd_set fds;
231 drmEventContext event_context;
232 int ret;
233 bool modeset_required;
234
235 ret = hwc_modeset_required(hd, &modeset_required);
236 if (ret) {
237 ALOGE("Failed to determine if modeset is required %d", ret);
238 return ret;
239 }
240 if (modeset_required) {
Sean Paul9b1bb842015-01-23 01:11:58 -0500241 ret = drmModeSetCrtc(hd->ctx->fd, hd->active_crtc, buf->fb_id,
242 0, 0, &hd->connector_id, 1,
Sean Paul9aa5ad32015-01-22 15:47:54 -0500243 &hd->configs[hd->active_config]);
244 if (ret) {
245 ALOGE("Modeset failed for crtc %d",
246 hd->active_crtc);
247 return ret;
248 }
249 return 0;
250 }
251
252 FD_ZERO(&fds);
253 FD_SET(hd->ctx->fd, &fds);
254
255 event_context.version = DRM_EVENT_CONTEXT_VERSION;
256 event_context.page_flip_handler = hwc_flip_handler;
257
Sean Paul9b1bb842015-01-23 01:11:58 -0500258 ret = drmModePageFlip(hd->ctx->fd, hd->active_crtc, buf->fb_id,
Sean Paul9aa5ad32015-01-22 15:47:54 -0500259 DRM_MODE_PAGE_FLIP_EVENT, hd);
260 if (ret) {
261 ALOGE("Failed to flip buffer for crtc %d",
262 hd->active_crtc);
263 return ret;
264 }
265
266 do {
267 ret = select(hd->ctx->fd + 1, &fds, NULL, NULL, NULL);
268 } while (ret == -1 && errno == EINTR);
269
270 if (ret != 1) {
271 ALOGE("Failed waiting for flip to complete\n");
272 return -EINVAL;
273 }
274 drmHandleEvent(hd->ctx->fd, &event_context);
275
276 return 0;
277}
278
Sean Paul3bc48e82015-01-23 01:41:13 -0500279static int hwc_wait_and_set(struct hwc_drm_display *hd,
280 struct hwc_drm_bo *buf)
Sean Paul9aa5ad32015-01-22 15:47:54 -0500281{
282 int ret;
283
Sean Paul3bc48e82015-01-23 01:41:13 -0500284 ret = drmModeAddFB2(hwc_get_fd_for_bo(hd->ctx, buf), buf->width,
285 buf->height, buf->format, buf->gem_handles, buf->pitches,
286 buf->offsets, &buf->fb_id, 0);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500287 if (ret) {
288 ALOGE("could not create drm fb %d", ret);
289 return ret;
290 }
291
Sean Paul3bc48e82015-01-23 01:41:13 -0500292 if (buf->acquire_fence_fd >= 0) {
293 ret = sync_wait(buf->acquire_fence_fd, -1);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500294 if (ret) {
295 ALOGE("Failed to wait for acquire %d", ret);
296 return ret;
297 }
298 }
299
Sean Paul3bc48e82015-01-23 01:41:13 -0500300 ret = hwc_flip(hd, buf);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500301 if (ret) {
302 ALOGE("Failed to perform flip\n");
303 return ret;
304 }
305
306 if (hd->front.fb_id) {
Sean Paulcd36a9e2015-01-22 18:01:18 -0500307 ret = drmModeRmFB(hwc_get_fd_for_bo(hd->ctx, &hd->front),
308 hd->front.fb_id);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500309 if (ret) {
310 ALOGE("Failed to rm fb from front %d", ret);
311 return ret;
312 }
313 }
Sean Paul3bc48e82015-01-23 01:41:13 -0500314 hd->front = *buf;
315
Sean Paul9aa5ad32015-01-22 15:47:54 -0500316 return ret;
317}
318
319static void *hwc_set_worker(void *arg)
320{
321 struct hwc_drm_display *hd = (struct hwc_drm_display *)arg;
322 int ret;
323
324 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
325
Sean Paul9aa5ad32015-01-22 15:47:54 -0500326 do {
Sean Paul3bc48e82015-01-23 01:41:13 -0500327 struct hwc_drm_bo buf;
328
329 ret = pthread_mutex_lock(&hd->set_worker.lock);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500330 if (ret) {
Sean Paul3bc48e82015-01-23 01:41:13 -0500331 ALOGE("Failed to lock set lock %d", ret);
332 return NULL;
Sean Paul9aa5ad32015-01-22 15:47:54 -0500333 }
334
Sean Paul3bc48e82015-01-23 01:41:13 -0500335 if (hd->set_worker.exit)
336 goto out;
337
338 if (hd->buf_queue.empty()) {
339 ret = pthread_cond_wait(&hd->set_worker.cond,
340 &hd->set_worker.lock);
341 if (ret) {
342 ALOGE("Failed to wait on condition %d", ret);
343 goto out;
344 }
345 }
346
347 buf = hd->buf_queue.front();
348 hd->buf_queue.pop();
349
350 ret = pthread_mutex_unlock(&hd->set_worker.lock);
351 if (ret) {
352 ALOGE("Failed to unlock set lock %d", ret);
353 return NULL;
354 }
355
356 ret = hwc_wait_and_set(hd, &buf);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500357 if (ret)
358 ALOGE("Failed to wait and set %d", ret);
Sean Paulf1dc1912015-01-24 01:34:31 -0500359
360 ret = sw_sync_timeline_inc(hd->timeline_fd, 1);
361 if (ret)
362 ALOGE("Failed to increment sync timeline %d", ret);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500363 } while (true);
364
Sean Paul3bc48e82015-01-23 01:41:13 -0500365out:
Sean Paul9aa5ad32015-01-22 15:47:54 -0500366 ret = pthread_mutex_unlock(&hd->set_worker.lock);
Sean Paul3bc48e82015-01-23 01:41:13 -0500367 if (ret)
368 ALOGE("Failed to unlock set lock while exiting %d", ret);
Sean Paul9aa5ad32015-01-22 15:47:54 -0500369
370 return NULL;
371}
372
Sean Paule0c4c3d2015-01-20 16:56:04 -0500373static int hwc_set_display(hwc_context_t *ctx, int display,
374 hwc_display_contents_1_t* display_contents)
375{
376 struct hwc_drm_display *hd = NULL;
Sean Paule0c4c3d2015-01-20 16:56:04 -0500377 hwc_layer_1_t *layer = NULL;
Sean Paul9b1bb842015-01-23 01:11:58 -0500378 struct hwc_drm_bo buf;
Sean Paule0c4c3d2015-01-20 16:56:04 -0500379 int ret, i;
Sean Paul9aa5ad32015-01-22 15:47:54 -0500380 uint32_t fb_id;
Sean Paule0c4c3d2015-01-20 16:56:04 -0500381
Sean Paul9b1bb842015-01-23 01:11:58 -0500382 memset(&buf, 0, sizeof(buf));
383
Sean Paule0c4c3d2015-01-20 16:56:04 -0500384 ret = hwc_get_drm_display(ctx, display, &hd);
385 if (ret)
386 return ret;
387
388 if (!hd->active_crtc) {
389 ALOGE("There is no active crtc for display %d", display);
390 return -ENOENT;
391 }
392
393 /*
394 * TODO: We can only support one hw layer atm, so choose either the
395 * first one or the framebuffer target.
396 */
397 if (!display_contents->numHwLayers) {
398 return 0;
399 } else if (display_contents->numHwLayers == 1) {
400 layer = &display_contents->hwLayers[0];
401 } else {
402 for (i = 0; i < (int)display_contents->numHwLayers; i++) {
403 layer = &display_contents->hwLayers[i];
404 if (layer->compositionType == HWC_FRAMEBUFFER_TARGET)
405 break;
406 }
407 if (i == (int)display_contents->numHwLayers) {
408 ALOGE("Could not find a suitable layer for display %d",
409 display);
410 }
411 }
412
Sean Paul3bc48e82015-01-23 01:41:13 -0500413 ret = hwc_create_bo_from_import(ctx->fd, ctx->import_ctx, layer->handle,
414 &buf);
415 if (ret) {
416 ALOGE("Failed to import handle to drm bo %d", ret);
417 return ret;
418 }
419 buf.acquire_fence_fd = layer->acquireFenceFd;
Sean Paul3bc48e82015-01-23 01:41:13 -0500420
Sean Paul9aa5ad32015-01-22 15:47:54 -0500421 ret = pthread_mutex_lock(&hd->set_worker.lock);
Sean Paule0c4c3d2015-01-20 16:56:04 -0500422 if (ret) {
Sean Paul9aa5ad32015-01-22 15:47:54 -0500423 ALOGE("Failed to lock set lock in set() %d", ret);
424 return ret;
425 }
Sean Paulf1dc1912015-01-24 01:34:31 -0500426
427 /*
428 * TODO: Retire and release can use the same sync point here b/c hwc is
429 * restricted to one layer. Once that is no longer true, this will need
430 * to change
431 */
432 hd->timeline_next++;
433 display_contents->retireFenceFd = sw_sync_fence_create(hd->timeline_fd,
434 "drm_hwc_retire", hd->timeline_next);
435 layer->releaseFenceFd = sw_sync_fence_create(hd->timeline_fd,
436 "drm_hwc_release", hd->timeline_next);
Sean Paul9b1bb842015-01-23 01:11:58 -0500437 hd->buf_queue.push(buf);
438
Sean Paul9aa5ad32015-01-22 15:47:54 -0500439 ret = pthread_cond_signal(&hd->set_worker.cond);
440 if (ret) {
441 ALOGE("Failed to signal set worker %d", ret);
442 goto out;
443 }
444
445 ret = pthread_mutex_unlock(&hd->set_worker.lock);
446 if (ret) {
447 ALOGE("Failed to unlock set lock in set() %d", ret);
448 return ret;
449 }
450
451 return ret;
452
Sean Paule0c4c3d2015-01-20 16:56:04 -0500453out:
Sean Paul9aa5ad32015-01-22 15:47:54 -0500454 if (pthread_mutex_unlock(&hd->set_worker.lock))
455 ALOGE("Failed to unlock set lock in set error handler");
456
Sean Paule0c4c3d2015-01-20 16:56:04 -0500457 return ret;
458}
459
460static int hwc_set(hwc_composer_device_1_t *dev, size_t num_displays,
461 hwc_display_contents_1_t** display_contents)
462{
463 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
464 int ret = 0, i;
465
Sean Paule0c4c3d2015-01-20 16:56:04 -0500466 for (i = 0; i < (int)num_displays && i < MAX_NUM_DISPLAYS; i++) {
Sean Paule0c4c3d2015-01-20 16:56:04 -0500467 ret = hwc_set_display(ctx, i, display_contents[i]);
468 }
469
470 return ret;
471}
472
Sean Pauleb9e75c2015-01-25 23:31:30 -0500473static int hwc_wait_for_vsync(struct hwc_drm_display *hd)
Sean Paule0c4c3d2015-01-20 16:56:04 -0500474{
Sean Pauleb9e75c2015-01-25 23:31:30 -0500475 drmVBlank vblank;
476 int ret;
477 uint32_t high_crtc;
478 int64_t timestamp;
479
480 if (hd->active_pipe == -1)
481 return -EINVAL;
482
483 memset(&vblank, 0, sizeof(vblank));
484
485 high_crtc = (hd->active_pipe << DRM_VBLANK_HIGH_CRTC_SHIFT);
486 vblank.request.type = (drmVBlankSeqType)(DRM_VBLANK_RELATIVE |
487 (high_crtc & DRM_VBLANK_HIGH_CRTC_MASK));
488 vblank.request.sequence = 1;
489
490 ret = drmWaitVBlank(hd->ctx->fd, &vblank);
491 if (ret) {
492 ALOGE("Failed to wait for vblank %d", ret);
493 return ret;
494 }
495
496 if (hd->ctx->procs->vsync) {
497 timestamp = vblank.reply.tval_sec * 1000 * 1000 * 1000 +
498 vblank.reply.tval_usec * 1000;
499 hd->ctx->procs->vsync(hd->ctx->procs, hd->display, timestamp);
500 }
501
502 return 0;
503}
504
505static void *hwc_vsync_worker(void *arg)
506{
507 struct hwc_drm_display *hd = (struct hwc_drm_display *)arg;
508 struct hwc_worker *w = &hd->vsync_worker;
Sean Paule0c4c3d2015-01-20 16:56:04 -0500509 int ret;
510
Sean Pauleb9e75c2015-01-25 23:31:30 -0500511 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
512
513 do {
514 ret = pthread_mutex_lock(&w->lock);
515 if (ret) {
516 ALOGE("Failed to lock vsync lock %d", ret);
517 return NULL;
518 }
519
520 if (hd->active_pipe == -1) {
521 ALOGE("Pipe is no longer active, disable events");
522 hd->enable_vsync_events = false;
523 }
524
525 if (!hd->enable_vsync_events) {
526 ret = pthread_cond_wait(&w->cond, &w->lock);
527 if (ret) {
528 ALOGE("Failed to wait on vsync cond %d", ret);
529 break;
530 }
531 }
532
533 if (w->exit)
534 break;
535
536 ret = pthread_mutex_unlock(&w->lock);
537 if (ret) {
538 ALOGE("Failed to unlock vsync lock %d", ret);
539 return NULL;
540 }
541
542 if (!hd->enable_vsync_events)
543 continue;
544
545 ret = hwc_wait_for_vsync(hd);
546 if (ret)
547 ALOGE("Failed to wait for vsync %d", ret);
548
549 } while (true);
550
551out:
552 ret = pthread_mutex_unlock(&hd->set_worker.lock);
553 if (ret)
554 ALOGE("Failed to unlock set lock while exiting %d", ret);
555
556 return NULL;
557}
558
559static int hwc_event_control(struct hwc_composer_device_1* dev, int display,
560 int event, int enabled)
561{
562 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
563 struct hwc_drm_display *hd = NULL;
564 int ret;
565
566 ret = hwc_get_drm_display(ctx, display, &hd);
567 if (ret)
568 return ret;
569
570 if (event != HWC_EVENT_VSYNC || (enabled != 0 && enabled != 1))
571 return -EINVAL;
572
573 if (hd->active_pipe == -1) {
574 ALOGD("Can't service events for display %d, no pipe", display);
575 return -EINVAL;
576 }
577
578 ret = pthread_mutex_lock(&hd->vsync_worker.lock);
579 if (ret) {
580 ALOGE("Failed to lock vsync lock %d", ret);
581 return ret;
582 }
583
584 hd->enable_vsync_events = !!enabled;
585
586 ret = pthread_cond_signal(&hd->vsync_worker.cond);
587 if (ret) {
588 ALOGE("Failed to signal vsync thread %d", ret);
589 goto out;
590 }
591
592 ret = pthread_mutex_unlock(&hd->vsync_worker.lock);
593 if (ret) {
594 ALOGE("Failed to unlock vsync lock %d", ret);
595 return ret;
596 }
597
Sean Paule0c4c3d2015-01-20 16:56:04 -0500598 return 0;
Sean Pauleb9e75c2015-01-25 23:31:30 -0500599
600out:
601 if (pthread_mutex_unlock(&hd->vsync_worker.lock))
602 ALOGE("Failed to unlock vsync worker in error path");
603
604 return ret;
Sean Paule0c4c3d2015-01-20 16:56:04 -0500605}
606
607static int hwc_set_power_mode(struct hwc_composer_device_1* dev, int display,
608 int mode)
609{
610 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
611 struct hwc_drm_display *hd = NULL;
612 drmModeConnectorPtr c;
613 int ret, i;
614 uint32_t dpms_prop = 0;
615 uint64_t dpms_value = 0;
616
617 ret = hwc_get_drm_display(ctx, display, &hd);
618 if (ret)
619 return ret;
620
621 c = drmModeGetConnector(ctx->fd, hd->connector_id);
622 if (!c) {
623 ALOGE("Failed to get connector %d", display);
624 return -ENODEV;
625 }
626
627 for (i = 0; !dpms_prop && i < c->count_props; i++) {
628 drmModePropertyPtr p;
629
630 p = drmModeGetProperty(ctx->fd, c->props[i]);
631 if (!p)
632 continue;
633
634 if (!strcmp(p->name, "DPMS"))
635 dpms_prop = c->props[i];
636
637 drmModeFreeProperty(p);
638 }
639 if (!dpms_prop) {
640 ALOGE("Failed to get DPMS property from display %d", display);
641 ret = -ENOENT;
642 goto out;
643 }
644
645 switch(mode) {
646 case HWC_POWER_MODE_OFF:
647 dpms_value = DRM_MODE_DPMS_OFF;
648 break;
649
650 /* We can't support dozing right now, so go full on */
651 case HWC_POWER_MODE_DOZE:
652 case HWC_POWER_MODE_DOZE_SUSPEND:
653 case HWC_POWER_MODE_NORMAL:
654 dpms_value = DRM_MODE_DPMS_ON;
655 break;
656 };
657
658 ret = drmModeConnectorSetProperty(ctx->fd, c->connector_id,
659 dpms_prop, dpms_value);
660 if (ret) {
661 ALOGE("Failed to set DPMS property for display %d", display);
662 goto out;
663 }
664
665out:
666 drmModeFreeConnector(c);
667 return ret;
668}
669
670static int hwc_query(struct hwc_composer_device_1 */* dev */, int what,
671 int *value)
672{
673 switch(what) {
674 case HWC_BACKGROUND_LAYER_SUPPORTED:
675 *value = 0; /* TODO: We should do this */
676 break;
677 case HWC_VSYNC_PERIOD:
678 ALOGW("Query for deprecated vsync value, returning 60Hz");
679 *value = 1000 * 1000 * 1000 / 60;
680 break;
681 case HWC_DISPLAY_TYPES_SUPPORTED:
682 *value = HWC_DISPLAY_PRIMARY | HWC_DISPLAY_EXTERNAL;
683 break;
684 }
685 return 0;
686}
687
688static void hwc_register_procs(struct hwc_composer_device_1* dev,
689 hwc_procs_t const* procs)
690{
691 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
692
693 ctx->procs = procs;
694}
695
696static int hwc_get_display_configs(struct hwc_composer_device_1* dev,
697 int display, uint32_t* configs, size_t* numConfigs)
698{
699 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
700 struct hwc_drm_display *hd = NULL;
701 drmModeConnectorPtr c;
702 int ret = 0, i;
703
704 if (!*numConfigs)
705 return 0;
706
707 ret = hwc_get_drm_display(ctx, display, &hd);
708 if (ret)
709 return ret;
710
711 c = drmModeGetConnector(ctx->fd, hd->connector_id);
712 if (!c) {
713 ALOGE("Failed to get connector %d", display);
714 return -ENODEV;
715 }
716
717 if (hd->configs)
718 free(hd->configs);
719
720 hd->active_config = -1;
721 hd->configs = (drmModeModeInfoPtr)calloc(c->count_modes,
722 sizeof(*hd->configs));
723 if (!hd->configs) {
724 ALOGE("Failed to allocate config list for display %d", display);
725 ret = -ENOMEM;
726 hd->num_configs = 0;
727 goto out;
728 }
729
730 for (i = 0; i < c->count_modes; i++) {
731 drmModeModeInfoPtr m = &hd->configs[i];
732
733 memcpy(m, &c->modes[i], sizeof(*m));
734
735 if (i < (int)*numConfigs)
736 configs[i] = i;
737 }
738
739 hd->num_configs = c->count_modes;
740 *numConfigs = MIN(c->count_modes, *numConfigs);
741
742out:
743 drmModeFreeConnector(c);
744 return ret;
745}
746
747static int hwc_check_config_valid(struct hwc_context_t *ctx,
748 drmModeConnectorPtr connector, int display,
749 int config_idx)
750{
751 struct hwc_drm_display *hd = NULL;
752 drmModeModeInfoPtr m = NULL;
753 int ret = 0, i;
754
755 ret = hwc_get_drm_display(ctx, display, &hd);
756 if (ret)
757 return ret;
758
759 /* Make sure the requested config is still valid for the display */
760 for (i = 0; i < connector->count_modes; i++) {
761 if (hwc_mode_is_equal(&connector->modes[i],
762 &hd->configs[config_idx])) {
763 m = &hd->configs[config_idx];
764 break;
765 }
766 }
767 if (!m)
768 return -ENOENT;
769
770 return 0;
771}
772
773static int hwc_get_display_attributes(struct hwc_composer_device_1* dev,
774 int display, uint32_t config, const uint32_t* attributes,
775 int32_t* values)
776{
777 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
778 struct hwc_drm_display *hd = NULL;
779 drmModeConnectorPtr c;
780 drmModeModeInfoPtr m;
781 int ret, i;
782
783 ret = hwc_get_drm_display(ctx, display, &hd);
784 if (ret)
785 return ret;
786
787 if (config >= hd->num_configs) {
788 ALOGE("Requested config is out-of-bounds %d %d", config,
789 hd->num_configs);
790 return -EINVAL;
791 }
792
793 c = drmModeGetConnector(ctx->fd, hd->connector_id);
794 if (!c) {
795 ALOGE("Failed to get connector %d", display);
796 return -ENODEV;
797 }
798
799 ret = hwc_check_config_valid(ctx, c, display, (int)config);
800 if (ret) {
801 ALOGE("Provided config is no longer valid %u", config);
802 goto out;
803 }
804
805 m = &hd->configs[config];
806 for (i = 0; attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; i++) {
807 switch(attributes[i]) {
808 case HWC_DISPLAY_VSYNC_PERIOD:
809 values[i] = 1000 * 1000 * 1000 / m->vrefresh;
810 break;
811 case HWC_DISPLAY_WIDTH:
812 values[i] = m->hdisplay;
813 break;
814 case HWC_DISPLAY_HEIGHT:
815 values[i] = m->vdisplay;
816 break;
817 case HWC_DISPLAY_DPI_X:
818 /* Dots per 1000 inches */
819 values[i] = c->mmWidth ?
820 (m->hdisplay * UM_PER_INCH) / c->mmWidth : 0;
821 break;
822 case HWC_DISPLAY_DPI_Y:
823 /* Dots per 1000 inches */
824 values[i] = c->mmHeight ?
825 (m->vdisplay * UM_PER_INCH) / c->mmHeight : 0;
826 break;
827 }
828 }
829
830out:
831 drmModeFreeConnector(c);
832 return ret;
833}
834
835static int hwc_get_active_config(struct hwc_composer_device_1* dev, int display)
836{
837 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
838 struct hwc_drm_display *hd = NULL;
839 drmModeConnectorPtr c;
840 int ret;
841
842 ret = hwc_get_drm_display(ctx, display, &hd);
843 if (ret)
844 return ret;
845
846 if (hd->active_config < 0)
847 return -1;
848
849 c = drmModeGetConnector(ctx->fd, hd->connector_id);
850 if (!c) {
851 ALOGE("Failed to get connector %d", display);
852 return -ENODEV;
853 }
854
855 ret = hwc_check_config_valid(ctx, c, display, hd->active_config);
856 if (ret) {
857 ALOGE("Config is no longer valid %d", hd->active_config);
858 ret = -1;
859 goto out;
860 }
861
862 ret = hd->active_config;
863
864out:
865 drmModeFreeConnector(c);
866 return ret;
867}
868
869static bool hwc_crtc_is_bound(struct hwc_context_t *ctx, uint32_t crtc_id)
870{
871 int i;
872
873 for (i = 0; i < MAX_NUM_DISPLAYS; i++) {
874 if (ctx->displays[i].active_crtc == crtc_id)
875 return true;
876 }
877 return false;
878}
879
880static int hwc_try_encoder(struct hwc_context_t *ctx, drmModeResPtr r,
881 uint32_t encoder_id, uint32_t *crtc_id)
882{
883 drmModeEncoderPtr e;
884 int ret, i;
885
886 e = drmModeGetEncoder(ctx->fd, encoder_id);
887 if (!e) {
888 ALOGE("Failed to get encoder for connector %d", encoder_id);
889 return -ENODEV;
890 }
891
892 /* First try to use the currently-bound crtc */
893 if (e->crtc_id) {
894 if (!hwc_crtc_is_bound(ctx, e->crtc_id)) {
895 *crtc_id = e->crtc_id;
896 ret = 0;
897 goto out;
898 }
899 }
900
901 /* Try to find a possible crtc which will work */
902 for (i = 0; i < r->count_crtcs; i++) {
903 if (!(e->possible_crtcs & (1 << i)))
904 continue;
905
906 /* We've already tried this earlier */
907 if (e->crtc_id == r->crtcs[i])
908 continue;
909
910 if (!hwc_crtc_is_bound(ctx, r->crtcs[i])) {
911 *crtc_id = r->crtcs[i];
912 ret = 0;
913 goto out;
914 }
915 }
916
917 /* We can't use the encoder, but nothing went wrong, try another one */
918 ret = -EAGAIN;
919
920out:
921 drmModeFreeEncoder(e);
922 return ret;
923}
924
925static int hwc_set_active_config(struct hwc_composer_device_1* dev, int display,
926 int index)
927{
928 struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
929 struct hwc_drm_display *hd = NULL;
930 drmModeResPtr r = NULL;
931 drmModeConnectorPtr c;
932 uint32_t crtc_id = 0;
933 int ret, i;
934 bool new_crtc, new_encoder;
935
936 ret = hwc_get_drm_display(ctx, display, &hd);
937 if (ret)
938 return ret;
939
940 c = drmModeGetConnector(ctx->fd, hd->connector_id);
941 if (!c) {
942 ALOGE("Failed to get connector %d", display);
943 return -ENODEV;
944 }
945
946 if (c->connection == DRM_MODE_DISCONNECTED) {
947 ALOGE("Tried to configure a disconnected display %d", display);
948 ret = -ENODEV;
949 goto out;
950 }
951
952 ret = hwc_check_config_valid(ctx, c, display, index);
953 if (ret) {
954 ALOGE("Provided config is no longer valid %u", index);
955 ret = -ENOENT;
956 goto out;
957 }
958
959 r = drmModeGetResources(ctx->fd);
960 if (!r) {
961 ALOGE("Failed to get drm resources");
962 goto out;
963 }
964
965 /* We no longer have an active_crtc */
966 hd->active_crtc = 0;
Sean Pauleb9e75c2015-01-25 23:31:30 -0500967 hd->active_pipe = -1;
Sean Paule0c4c3d2015-01-20 16:56:04 -0500968
969 /* First, try to use the currently-connected encoder */
970 if (c->encoder_id) {
971 ret = hwc_try_encoder(ctx, r, c->encoder_id, &crtc_id);
972 if (ret && ret != -EAGAIN) {
973 ALOGE("Encoder try failed %d", ret);
974 goto out;
975 }
976 }
977
978 /* We couldn't find a crtc with the attached encoder, try the others */
979 if (!crtc_id) {
980 for (i = 0; i < c->count_encoders; i++) {
981 ret = hwc_try_encoder(ctx, r, c->encoders[i], &crtc_id);
982 if (!ret) {
983 break;
984 } else if (ret != -EAGAIN) {
985 ALOGE("Encoder try failed %d", ret);
986 goto out;
987 }
988 }
989 if (!crtc_id) {
990 ALOGE("Couldn't find valid crtc to modeset");
991 ret = -EINVAL;
992 goto out;
993 }
994 }
995
996 hd->active_crtc = crtc_id;
997 hd->active_config = index;
998
Sean Pauleb9e75c2015-01-25 23:31:30 -0500999 /* Find the pipe corresponding to the crtc_id */
1000 for (i = 0; i < r->count_crtcs; i++) {
1001 /* We've already tried this earlier */
1002 if (r->crtcs[i] == crtc_id) {
1003 hd->active_pipe = i;
1004 break;
1005 }
1006 }
1007 /* This should never happen... hehehe */
1008 if (hd->active_pipe == -1) {
1009 ALOGE("Active crtc was not found in resources!!");
1010 ret = -ENODEV;
1011 goto out;
1012 }
1013
Sean Paule0c4c3d2015-01-20 16:56:04 -05001014 /* TODO: Once we have atomic, set the crtc timing info here */
1015
1016out:
1017 if (r)
1018 drmModeFreeResources(r);
1019
1020 drmModeFreeConnector(c);
1021 return ret;
1022}
1023
Sean Paul9aa5ad32015-01-22 15:47:54 -05001024static int hwc_destroy_worker(struct hwc_worker *worker)
1025{
1026 int ret;
1027
1028 ret = pthread_mutex_lock(&worker->lock);
1029 if (ret) {
1030 ALOGE("Failed to lock in destroy() %d", ret);
1031 return ret;
1032 }
1033
1034 worker->exit = true;
1035
1036 ret |= pthread_cond_signal(&worker->cond);
1037 if (ret)
1038 ALOGE("Failed to signal cond in destroy() %d", ret);
1039
1040 ret |= pthread_mutex_unlock(&worker->lock);
1041 if (ret)
1042 ALOGE("Failed to unlock in destroy() %d", ret);
1043
1044 ret |= pthread_join(worker->thread, NULL);
1045 if (ret && ret != ESRCH)
1046 ALOGE("Failed to join thread in destroy() %d", ret);
1047
1048 return ret;
1049}
1050
1051static void hwc_destroy_display(struct hwc_drm_display *hd)
1052{
1053 int ret;
1054
1055 if (hwc_destroy_worker(&hd->set_worker))
1056 ALOGE("Destroy set worker failed");
Sean Pauleb9e75c2015-01-25 23:31:30 -05001057
1058 if (hwc_destroy_worker(&hd->vsync_worker))
1059 ALOGE("Destroy vsync worker failed");
Sean Paul9aa5ad32015-01-22 15:47:54 -05001060}
1061
Sean Paule0c4c3d2015-01-20 16:56:04 -05001062static int hwc_device_close(struct hw_device_t *dev)
1063{
1064 struct hwc_context_t *ctx = (struct hwc_context_t *)dev;
Sean Paulcd36a9e2015-01-22 18:01:18 -05001065 int ret, i;
Sean Paule0c4c3d2015-01-20 16:56:04 -05001066
Sean Paul9aa5ad32015-01-22 15:47:54 -05001067 for (i = 0; i < MAX_NUM_DISPLAYS; i++)
1068 hwc_destroy_display(&ctx->displays[i]);
1069
1070 drmClose(ctx->fd);
Sean Paulcd36a9e2015-01-22 18:01:18 -05001071
1072 ret = hwc_import_destroy(ctx->import_ctx);
1073 if (ret)
1074 ALOGE("Could not destroy import %d", ret);
1075
Sean Paule0c4c3d2015-01-20 16:56:04 -05001076 free(ctx);
1077
1078 return 0;
1079}
1080
Sean Paul9aa5ad32015-01-22 15:47:54 -05001081static int hwc_initialize_worker(struct hwc_drm_display *hd,
1082 struct hwc_worker *worker, void *(*routine)(void*))
1083{
1084 int ret;
1085
1086 ret = pthread_cond_init(&worker->cond, NULL);
1087 if (ret) {
1088 ALOGE("Failed to create worker condition %d", ret);
1089 return ret;
1090 }
1091
1092 ret = pthread_mutex_init(&worker->lock, NULL);
1093 if (ret) {
1094 ALOGE("Failed to initialize worker lock %d", ret);
1095 goto err_cond;
1096 }
1097
1098 worker->exit = false;
1099
1100 ret = pthread_create(&worker->thread, NULL, routine, hd);
1101 if (ret) {
1102 ALOGE("Could not create worker thread %d", ret);
1103 goto err_lock;
1104 }
1105 return 0;
1106
1107err_lock:
1108 pthread_mutex_destroy(&worker->lock);
1109err_cond:
1110 pthread_cond_destroy(&worker->cond);
1111 return ret;
1112}
1113
Sean Paule0c4c3d2015-01-20 16:56:04 -05001114static int hwc_initialize_display(struct hwc_context_t *ctx, int display,
1115 uint32_t connector_id)
1116{
1117 struct hwc_drm_display *hd = NULL;
1118 int ret;
1119
1120 ret = hwc_get_drm_display(ctx, display, &hd);
1121 if (ret)
1122 return ret;
1123
Sean Paul9aa5ad32015-01-22 15:47:54 -05001124 hd->ctx = ctx;
1125 hd->display = display;
Sean Paule0c4c3d2015-01-20 16:56:04 -05001126 hd->active_config = -1;
Sean Pauleb9e75c2015-01-25 23:31:30 -05001127 hd->active_pipe = -1;
Sean Paule0c4c3d2015-01-20 16:56:04 -05001128 hd->connector_id = connector_id;
1129
Sean Paulf1dc1912015-01-24 01:34:31 -05001130 ret = sw_sync_timeline_create();
1131 if (ret < 0) {
1132 ALOGE("Failed to create sw sync timeline %d", ret);
1133 return ret;
1134 }
1135 hd->timeline_fd = ret;
1136
Sean Paul9aa5ad32015-01-22 15:47:54 -05001137 ret = hwc_initialize_worker(hd, &hd->set_worker, hwc_set_worker);
1138 if (ret) {
1139 ALOGE("Failed to create set worker %d\n", ret);
1140 return ret;
1141 }
1142
Sean Pauleb9e75c2015-01-25 23:31:30 -05001143 ret = hwc_initialize_worker(hd, &hd->vsync_worker, hwc_vsync_worker);
1144 if (ret) {
1145 ALOGE("Failed to create vsync worker %d", ret);
1146 goto err;
1147 }
1148
Sean Paule0c4c3d2015-01-20 16:56:04 -05001149 return 0;
Sean Pauleb9e75c2015-01-25 23:31:30 -05001150
1151err:
1152 if (hwc_destroy_worker(&hd->set_worker))
1153 ALOGE("Failed to destroy set worker");
1154
1155 return ret;
Sean Paule0c4c3d2015-01-20 16:56:04 -05001156}
1157
1158static int hwc_enumerate_displays(struct hwc_context_t *ctx)
1159{
1160 struct hwc_drm_display *panel_hd;
1161 drmModeResPtr res;
1162 drmModeConnectorPtr *conn_list;
1163 int ret = 0, i, j;
1164
1165 res = drmModeGetResources(ctx->fd);
1166 if (!res) {
1167 ALOGE("Failed to get drm resources");
1168 return -ENODEV;
1169 }
1170
1171 conn_list = (drmModeConnector **)calloc(res->count_connectors,
1172 sizeof(*conn_list));
1173 if (!conn_list) {
1174 ALOGE("Failed to allocate connector list");
1175 ret = -ENOMEM;
1176 goto out;
1177 }
1178
1179 for (i = 0; i < res->count_connectors; i++) {
1180 conn_list[i] = drmModeGetConnector(ctx->fd, res->connectors[i]);
1181 if (!conn_list[i]) {
1182 ALOGE("Failed to get connector %d", res->connectors[i]);
1183 ret = -ENODEV;
1184 goto out;
1185 }
1186 }
1187
1188 ctx->num_displays = 0;
1189
1190 /* Find a connected, panel type connector for display 0 */
1191 for (i = 0; i < res->count_connectors; i++) {
1192 drmModeConnectorPtr c = conn_list[i];
1193
1194 for (j = 0; j < ARRAY_SIZE(panel_types); j++) {
1195 if (c->connector_type == panel_types[j] &&
1196 c->connection == DRM_MODE_CONNECTED)
1197 break;
1198 }
1199 if (j == ARRAY_SIZE(panel_types))
1200 continue;
1201
1202 hwc_initialize_display(ctx, ctx->num_displays, c->connector_id);
1203 ctx->num_displays++;
1204 break;
1205 }
1206
1207 ret = hwc_get_drm_display(ctx, 0, &panel_hd);
1208 if (ret)
1209 goto out;
1210
1211 /* Fill in the other displays */
1212 for (i = 0; i < res->count_connectors; i++) {
1213 drmModeConnectorPtr c = conn_list[i];
1214
1215 if (panel_hd->connector_id == c->connector_id)
1216 continue;
1217
1218 hwc_initialize_display(ctx, ctx->num_displays, c->connector_id);
1219 ctx->num_displays++;
1220 }
1221
1222out:
1223 for (i = 0; i < res->count_connectors; i++) {
1224 if (conn_list[i])
1225 drmModeFreeConnector(conn_list[i]);
1226 }
1227 free(conn_list);
1228
1229 if (res)
1230 drmModeFreeResources(res);
1231
1232 return ret;
1233}
1234
1235static int hwc_device_open(const struct hw_module_t* module, const char* name,
1236 struct hw_device_t** dev)
1237{
1238 int ret = 0;
1239 struct hwc_context_t *ctx;
1240
1241 if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
1242 ALOGE("Invalid module name- %s", name);
1243 return -EINVAL;
1244 }
1245
Sean Paul9b1bb842015-01-23 01:11:58 -05001246 ctx = new hwc_context_t();
Sean Paule0c4c3d2015-01-20 16:56:04 -05001247 if (!ctx) {
1248 ALOGE("Failed to allocate hwc context");
1249 return -ENOMEM;
1250 }
1251
Sean Paulcd36a9e2015-01-22 18:01:18 -05001252 ret = hwc_import_init(&ctx->import_ctx);
Sean Paule0c4c3d2015-01-20 16:56:04 -05001253 if (ret) {
Sean Paulcd36a9e2015-01-22 18:01:18 -05001254 ALOGE("Failed to initialize import context");
Sean Paule0c4c3d2015-01-20 16:56:04 -05001255 goto out;
1256 }
1257
1258 /* TODO: Use drmOpenControl here instead */
1259 ctx->fd = open(HWCOMPOSER_DRM_DEVICE, O_RDWR);
1260 if (ctx->fd < 0) {
1261 ALOGE("Failed to open dri- %s", strerror(-errno));
1262 goto out;
1263 }
1264
1265 ret = drmSetMaster(ctx->fd);
1266 if (ret) {
1267 ALOGE("Failed to set hwcomposer as drm master %d", ret);
1268 goto out;
1269 }
1270
1271 ret = hwc_enumerate_displays(ctx);
1272 if (ret) {
1273 ALOGE("Failed to enumerate displays: %s", strerror(ret));
1274 goto out;
1275 }
1276
1277 ctx->device.common.tag = HARDWARE_DEVICE_TAG;
1278 ctx->device.common.version = HWC_DEVICE_API_VERSION_1_4;
1279 ctx->device.common.module = const_cast<hw_module_t*>(module);
1280 ctx->device.common.close = hwc_device_close;
1281
1282 ctx->device.prepare = hwc_prepare;
1283 ctx->device.set = hwc_set;
1284 ctx->device.eventControl = hwc_event_control;
1285 ctx->device.setPowerMode = hwc_set_power_mode;
1286 ctx->device.query = hwc_query;
1287 ctx->device.registerProcs = hwc_register_procs;
1288 ctx->device.getDisplayConfigs = hwc_get_display_configs;
1289 ctx->device.getDisplayAttributes = hwc_get_display_attributes;
1290 ctx->device.getActiveConfig = hwc_get_active_config;
1291 ctx->device.setActiveConfig = hwc_set_active_config;
1292 ctx->device.setCursorPositionAsync = NULL; /* TODO: Add cursor */
1293
1294 *dev = &ctx->device.common;
1295
1296 return 0;
1297out:
1298 if (ctx->fd >= 0)
1299 close(ctx->fd);
1300
1301 free(ctx);
1302 return ret;
1303}
1304
1305static struct hw_module_methods_t hwc_module_methods = {
1306 open: hwc_device_open
1307};
1308
1309hwc_module_t HAL_MODULE_INFO_SYM = {
1310 common: {
1311 tag: HARDWARE_MODULE_TAG,
1312 version_major: 1,
1313 version_minor: 0,
1314 id: HWC_HARDWARE_MODULE_ID,
1315 name: "DRM hwcomposer module",
1316 author: "The Android Open Source Project",
1317 methods: &hwc_module_methods,
1318 dso: NULL,
1319 reserved: { 0 },
1320 }
1321};