From 3a13a52b1c6ef577bb41e256c28538a9b37f012d Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Mon, 14 Jan 2019 08:19:29 +0800 Subject: [PATCH] gralloc_drm: open the DRM device of the primary framebuffer With the new added drmOpenByFB function in libdrm, it's easy to find the correct DRM device of the primary framebuffer. --- gralloc_drm.c | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/gralloc_drm.c b/gralloc_drm.c index 4dad064..4577427 100644 --- a/gralloc_drm.c +++ b/gralloc_drm.c @@ -107,49 +107,20 @@ init_drv_from_fd(int fd) return drv; } -static const char *fbdrv_map[][2] = { - { "amdgpudrmfb", "amdgpu" }, - { "inteldrmfb", "i915" }, - { "nouveaufb", "nouveau" }, - { "radeondrmfb", "radeon" }, - { "svgadrmfb", "vmwgfx" }, - { "virtiodrmfb", "virtio_gpu" }, -}; - /* * Create a DRM device object. */ struct gralloc_drm_t *gralloc_drm_create(void) { struct gralloc_drm_t *drm; - FILE *fb; - unsigned card, ret = 0; - char buf[64]; - - if ((fb = fopen("/proc/fb", "r"))) { - ret = fscanf(fb, "%u %s", &card, buf); - fclose(fb); - } - if (ret != 2) { - ALOGE("failed to open /proc/fb"); - return NULL; - } drm = calloc(1, sizeof(*drm)); if (!drm) return NULL; - drm->fd = -1; - for (card = 0; card < sizeof(fbdrv_map) / sizeof(const char *) / 2; ++card) { - if (!strcmp(buf, fbdrv_map[card][0])) { - drm->fd = drmOpen(fbdrv_map[card][1], NULL); - ALOGD("drmOpen %s: %d", fbdrv_map[card][1], drm->fd); - break; - } - } - + drm->fd = drmOpenByFB(0, DRM_NODE_PRIMARY); if (drm->fd < 0) { - ALOGE("failed to open driver for %s", buf); + ALOGE("failed to open DRM device of fb0"); } else { drm->drv = init_drv_from_fd(drm->fd); } -- 2.11.0