From 25680ec8a63bd098d9a0b721ce7cc67f9853058b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 26 Nov 2015 18:47:07 +0100 Subject: [PATCH] Create more DRM common functions --- gfx/common/drm_common.c | 91 +++++++++++++++++++++++++++++++ gfx/common/drm_common.h | 6 ++ gfx/drivers/exynos_gfx.c | 39 ++----------- gfx/drivers_context/drm_egl_ctx.c | 74 +------------------------ 4 files changed, 105 insertions(+), 105 deletions(-) diff --git a/gfx/common/drm_common.c b/gfx/common/drm_common.c index 1e6eae672a..791a99a18a 100644 --- a/gfx/common/drm_common.c +++ b/gfx/common/drm_common.c @@ -13,6 +13,7 @@ * If not, see . */ +#include "../../configuration.h" #include "../../verbosity.h" #include "drm_common.h" @@ -48,6 +49,77 @@ void drm_restore_crtc(void) g_orig_crtc = NULL; } +bool drm_get_resources(int fd) +{ + g_drm_resources = drmModeGetResources(fd); + if (!g_drm_resources) + { + RARCH_WARN("[DRM]: Couldn't get device resources.\n"); + return false; + } + + return true; +} + +bool drm_get_connector(int fd) +{ + unsigned i; + unsigned monitor_index = 0; + settings_t *settings = config_get_ptr(); + unsigned monitor = max(settings->video.monitor_index, 1); + + /* Enumerate all connectors. */ + + RARCH_LOG("[DRM]: Found %d connectors.\n", g_drm_resources->count_connectors); + + for (i = 0; i < g_drm_resources->count_connectors; i++) + { + drmModeConnectorPtr conn = drmModeGetConnector( + fd, g_drm_resources->connectors[i]); + + if (conn) + { + bool connected = conn->connection == DRM_MODE_CONNECTED; + RARCH_LOG("[DRM]: Connector %d connected: %s\n", i, connected ? "yes" : "no"); + RARCH_LOG("[DRM]: Connector %d has %d modes.\n", i, conn->count_modes); + if (connected && conn->count_modes > 0) + { + monitor_index++; + RARCH_LOG("[DRM]: Connector %d assigned to monitor index: #%u.\n", i, monitor_index); + } + drmModeFreeConnector(conn); + } + } + + monitor_index = 0; + + for (i = 0; i < g_drm_resources->count_connectors; i++) + { + g_drm_connector = drmModeGetConnector(fd, + g_drm_resources->connectors[i]); + + if (!g_drm_connector) + continue; + if (g_drm_connector->connection == DRM_MODE_CONNECTED + && g_drm_connector->count_modes > 0) + { + monitor_index++; + if (monitor_index == monitor) + break; + } + + drmModeFreeConnector(g_drm_connector); + g_drm_connector = NULL; + } + + if (!g_drm_connector) + { + RARCH_WARN("[DRM]: Couldn't get device connector.\n"); + return false; + } + return true; +} + bool drm_get_encoder(int fd) { unsigned i; @@ -72,9 +144,28 @@ bool drm_get_encoder(int fd) return false; } + for (i = 0; i < g_drm_connector->count_modes; i++) + { + RARCH_LOG("[DRM]: Mode %d: (%s) %d x %d, %u Hz\n", + i, + g_drm_connector->modes[i].name, + g_drm_connector->modes[i].hdisplay, + g_drm_connector->modes[i].vdisplay, + g_drm_connector->modes[i].vrefresh); + } + return true; } +void drm_setup(int fd) +{ + g_crtc_id = g_drm_encoder->crtc_id; + g_connector_id = g_drm_connector->connector_id; + g_orig_crtc = drmModeGetCrtc(fd, g_crtc_id); + if (!g_orig_crtc) + RARCH_WARN("[DRM]: Cannot find original CRTC.\n"); +} + void drm_free(void) { if (g_drm_encoder) diff --git a/gfx/common/drm_common.h b/gfx/common/drm_common.h index dfac7de40a..ed24b1fc58 100644 --- a/gfx/common/drm_common.h +++ b/gfx/common/drm_common.h @@ -48,6 +48,12 @@ bool drm_get_encoder(int fd); /* Restore the original CRTC. */ void drm_restore_crtc(void); +bool drm_get_resources(int fd); + +bool drm_get_connector(int id); + +void drm_setup(int fd); + void drm_free(void); #ifdef __cplusplus diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 756455b5f9..433e11ce68 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -564,38 +564,14 @@ static int exynos_open(struct exynos_data *pdata) return -1; } - g_drm_resources = drmModeGetResources(fd); - if (!g_drm_resources) - { - RARCH_ERR("[video_exynos]: failed to get DRM resources\n"); + if (!drm_get_resources(fd)) goto fail; - } - for (i = 0; i < g_drm_resources->count_connectors; ++i) - { - if (settings->video.monitor_index != 0 && - settings->video.monitor_index - 1 != i) - continue; - - g_drm_connector = drmModeGetConnector(fd, g_drm_resources->connectors[i]); - if (!drm->connecto) - continue; - - if (g_drm_connector->connection == DRM_MODE_CONNECTED && - g_drm_connector->count_modes > 0) - break; - - drmModeFreeConnector(g_drm_connector); - g_drm_connector = NULL; - } - - if (i == g_drm_resources->count_connectors) - { - RARCH_ERR("[video_exynos]: no currently active connector found.\n"); + if (!drm_get_decoder(fd)) goto fail; - } - drm_get_encoder(fd); + if (!drm_get_encoder(fd)) + goto fail; /* Setup the flip handler. */ g_drm_fds.fd = fd; @@ -669,12 +645,7 @@ static int exynos_init(struct exynos_data *pdata, unsigned bpp) goto fail; } - g_crtc_id = g_drm_encoder->crtc_id; - g_connector_id = g_drm_connector->connector_id; - g_orig_crtc = drmModeGetCrtc(g_drm_fd, g_crtc_id); - - if (!g_orig_crtc) - RARCH_WARN("[video_exynos]: cannot find original crtc\n"); + drm_setup(g_drm_fd); pdata->width = g_drm_mode->hdisplay; pdata->height = g_drm_mode->vdisplay; diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index e9d011849e..376d8df136 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -339,8 +339,6 @@ static bool gfx_ctx_drm_egl_init(void *data) unsigned gpu_index = 0; const char *gpu = NULL; struct string_list *gpu_descriptors = NULL; - settings_t *settings = config_get_ptr(); - unsigned monitor = max(settings->video.monitor_index, 1); gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)calloc(1, sizeof(gfx_ctx_drm_egl_data_t)); if (!drm) @@ -369,82 +367,16 @@ nextgpu: fd = retro_get_fd(drm->g_drm); - g_drm_resources = drmModeGetResources(fd); - if (!g_drm_resources) - { - RARCH_WARN("[DRM]: Couldn't get device resources.\n"); + if (!drm_get_resources(fd)) goto nextgpu; - } - /* Enumerate all connectors. */ - monitor_index = 0; - RARCH_LOG("[KMS/EGL]: Found %d connectors.\n", - g_drm_resources->count_connectors); - - for (i = 0; i < g_drm_resources->count_connectors; i++) - { - drmModeConnectorPtr conn = drmModeGetConnector( - fd, g_drm_resources->connectors[i]); - - if (conn) - { - bool connected = conn->connection == DRM_MODE_CONNECTED; - RARCH_LOG("[KMS/EGL]: Connector %d connected: %s\n", i, connected ? "yes" : "no"); - RARCH_LOG("[KMS/EGL]: Connector %d has %d modes.\n", i, conn->count_modes); - if (connected && conn->count_modes > 0) - { - monitor_index++; - RARCH_LOG("[KMS/EGL]: Connector %d assigned to monitor index: #%u.\n", i, monitor_index); - } - drmModeFreeConnector(conn); - } - } - - monitor_index = 0; - for (i = 0; i < g_drm_resources->count_connectors; i++) - { - g_drm_connector = drmModeGetConnector(fd, - g_drm_resources->connectors[i]); - - if (!g_drm_connector) - continue; - if (g_drm_connector->connection == DRM_MODE_CONNECTED - && g_drm_connector->count_modes > 0) - { - monitor_index++; - if (monitor_index == monitor) - break; - } - - drmModeFreeConnector(g_drm_connector); - g_drm_connector = NULL; - } - - if (!g_drm_connector) - { - RARCH_WARN("[KMS/EGL]: Couldn't get device connector.\n"); + if (!drm_get_connector(fd)) goto nextgpu; - } if (!drm_get_encoder(fd)) goto nextgpu; - for (i = 0; i < g_drm_connector->count_modes; i++) - { - RARCH_LOG("[KMS/EGL]: Mode %d: (%s) %d x %d, %u Hz\n", - i, - g_drm_connector->modes[i].name, - g_drm_connector->modes[i].hdisplay, - g_drm_connector->modes[i].vdisplay, - g_drm_connector->modes[i].vrefresh); - } - - g_crtc_id = g_drm_encoder->crtc_id; - g_orig_crtc = drmModeGetCrtc(fd, g_crtc_id); - if (!g_orig_crtc) - RARCH_WARN("[KMS/EGL]: Cannot find original CRTC.\n"); - - g_connector_id = g_drm_connector->connector_id; + drm_setup(fd); /* First mode is assumed to be the "optimal" * one for get_video_size() purposes. */