OSDN Git Service

gralloc_drm: open the DRM device of the primary framebuffer android-x86-8.1-r1
authorChih-Wei Huang <cwhuang@linux.org.tw>
Mon, 14 Jan 2019 00:19:29 +0000 (08:19 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Mon, 14 Jan 2019 00:19:29 +0000 (08:19 +0800)
With the new added drmOpenByFB function in libdrm, it's easy to find
the correct DRM device of the primary framebuffer.

gralloc_drm.c

index 4dad064..4577427 100644 (file)
@@ -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);
        }