minigbm: add minigbm_create_default_device helper
Variants of minigbm_create_default_device are open-coded in multiple places. This should be used wherever minigbm can be assumed. BUG=none TEST=manual check that the function works Change-Id: I3ad9897355ab72080fdca329674df09087b9adfd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4163418 Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Tested-by: Chia-I Wu <olv@google.com> Commit-Queue: Chia-I Wu <olv@google.com>
This commit is contained in:
parent
afa4dedecd
commit
52fca9c2cd
3 changed files with 69 additions and 1 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include "gbm.h"
|
||||
#include "minigbm_helpers.h"
|
||||
#include "util.h"
|
||||
|
||||
|
|
@ -312,3 +313,60 @@ PUBLIC int gbm_detect_device_info_path(unsigned int detect_flags, const char *de
|
|||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct gbm_device *
|
||||
try_drm_devices(drmDevicePtr *devs, int dev_count, int type, int *out_fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dev_count; i++) {
|
||||
drmDevicePtr dev = devs[i];
|
||||
int fd;
|
||||
|
||||
if (!(dev->available_nodes & (1 << type)))
|
||||
continue;
|
||||
|
||||
fd = open(dev->nodes[type], O_RDWR | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
struct gbm_device *gbm = gbm_create_device(fd);
|
||||
if (gbm) {
|
||||
*out_fd = fd;
|
||||
return gbm;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PUBLIC struct gbm_device *
|
||||
minigbm_create_default_device(int *out_fd)
|
||||
{
|
||||
struct gbm_device *gbm;
|
||||
drmDevicePtr devs[64];
|
||||
int dev_count;
|
||||
int fd;
|
||||
|
||||
/* try gbm_get_default_device_fd first */
|
||||
fd = gbm_get_default_device_fd();
|
||||
if (fd >= 0) {
|
||||
gbm = gbm_create_device(fd);
|
||||
if (gbm) {
|
||||
*out_fd = fd;
|
||||
return gbm;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
dev_count = drmGetDevices2(0, devs, sizeof(devs) / sizeof(devs[0]));
|
||||
|
||||
/* try render nodes and then primary nodes */
|
||||
gbm = try_drm_devices(devs, dev_count, DRM_NODE_RENDER, out_fd);
|
||||
if (!gbm)
|
||||
gbm = try_drm_devices(devs, dev_count, DRM_NODE_PRIMARY, out_fd);
|
||||
|
||||
drmFreeDevices(devs, dev_count);
|
||||
|
||||
return gbm;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue