RetroArch/gfx/common/drm_common.c
2015-11-26 18:23:51 +01:00

88 lines
2.1 KiB
C

/* RetroArch - A frontend for libretro.
* copyright (c) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../verbosity.h"
#include "drm_common.h"
uint32_t g_connector_id;
int g_drm_fd;
uint32_t g_crtc_id;
drmModeCrtc *g_orig_crtc;
struct pollfd g_drm_fds;
drmModeRes *g_drm_resources;
drmModeConnector *g_drm_connector;
drmModeEncoder *g_drm_encoder;
drmModeModeInfo *g_drm_mode;
drmEventContext g_drm_evctx;
/* Restore the original CRTC. */
void drm_restore_crtc(void)
{
if (!g_orig_crtc)
return;
drmModeSetCrtc(g_drm_fd, g_orig_crtc->crtc_id,
g_orig_crtc->buffer_id,
g_orig_crtc->x,
g_orig_crtc->y,
&g_connector_id, 1, &g_orig_crtc->mode);
drmModeFreeCrtc(g_orig_crtc);
g_orig_crtc = NULL;
}
bool drm_get_encoder(int fd)
{
unsigned i;
for (i = 0; i < g_drm_resources->count_encoders; i++)
{
g_drm_encoder = drmModeGetEncoder(fd, g_drm_resources->encoders[i]);
if (!g_drm_encoder)
continue;
if (g_drm_encoder->encoder_id == g_drm_connector->encoder_id)
break;
drmModeFreeEncoder(g_drm_encoder);
g_drm_encoder = NULL;
}
if (!g_drm_encoder)
{
RARCH_WARN("[DRM]: Couldn't find DRM encoder.\n");
return false;
}
return true;
}
void drm_free(void)
{
if (g_drm_encoder)
drmModeFreeEncoder(g_drm_encoder);
if (g_drm_connector)
drmModeFreeConnector(g_drm_connector);
if (g_drm_resources)
drmModeFreeResources(g_drm_resources);
}