diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index 2a5974511c..a8362461f4 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -40,6 +39,7 @@ #include #include +#include #include "../../driver.h" #include "../../runloop.h" @@ -57,6 +57,7 @@ typedef struct gfx_ctx_drm_egl_data { bool g_use_hw_ctx; + RFILE *g_drm; int g_drm_fd; uint32_t g_crtc_id; uint32_t g_connector_id; @@ -356,7 +357,7 @@ static void free_drm_resources(gfx_ctx_drm_egl_data_t *drm) drmModeFreeCrtc(drm->g_orig_crtc); if (drm->g_drm_fd >= 0) - close(drm->g_drm_fd); + retro_fclose(drm->g_drm); drm->g_gbm_surface = NULL; drm->g_gbm_dev = NULL; @@ -457,13 +458,15 @@ nextgpu: } gpu = gpu_descriptors->elems[gpu_index++].data; - drm->g_drm_fd = open(gpu, O_RDWR); - if (drm->g_drm_fd < 0) + drm->g_drm = retro_fopen(gpu, RFILE_MODE_READ_WRITE, -1); + if (!drm->g_drm) { RARCH_WARN("[KMS/EGL]: Couldn't open DRM device.\n"); goto nextgpu; } + drm->g_drm_fd = retro_get_fd(drm->g_drm); + drm->g_resources = drmModeGetResources(drm->g_drm_fd); if (!drm->g_resources) { diff --git a/libretro-common/file/retro_file.c b/libretro-common/file/retro_file.c index 0a91b31850..a335a052f5 100644 --- a/libretro-common/file/retro_file.c +++ b/libretro-common/file/retro_file.c @@ -53,6 +53,17 @@ struct RFILE #endif }; +int retro_get_fd(RFILE *stream) +{ + if (!stream) + return -1; +#if defined(HAVE_BUFFERED_IO) + return fileno(stream->fd); +#else + return stream->fd; +#endif +} + RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len) { RFILE *stream = (RFILE*)calloc(1, sizeof(*stream)); diff --git a/libretro-common/include/retro_file.h b/libretro-common/include/retro_file.h index cf535da63f..81e0b22a8f 100644 --- a/libretro-common/include/retro_file.h +++ b/libretro-common/include/retro_file.h @@ -55,6 +55,8 @@ void retro_fclose(RFILE *stream); bool retro_fmemcpy(const char *path, char *s, size_t len, ssize_t *bytes_written); +int retro_get_fd(RFILE *stream); + #ifdef __cplusplus } #endif