Create more DRM common functions

This commit is contained in:
twinaphex 2015-11-26 18:47:07 +01:00
parent 60ead8f6b1
commit 25680ec8a6
4 changed files with 105 additions and 105 deletions

View File

@ -13,6 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#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)

View File

@ -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

View File

@ -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;

View File

@ -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. */