2012-09-16 19:39:40 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 17:06:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2012-09-16 19:39:40 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* KMS/DRM context, running without any window manager.
|
|
|
|
* Based on kmscube example by Rob Clark.
|
|
|
|
*/
|
2012-09-16 19:39:40 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2015-09-16 03:53:34 +00:00
|
|
|
#include <errno.h>
|
2012-09-18 19:51:50 +00:00
|
|
|
#include <unistd.h>
|
2015-09-16 03:53:34 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2012-09-18 19:51:50 +00:00
|
|
|
#include <sched.h>
|
2012-09-18 22:44:50 +00:00
|
|
|
#include <sys/time.h>
|
2015-09-16 03:53:34 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/poll.h>
|
2012-09-16 19:39:40 +00:00
|
|
|
|
|
|
|
#include <libdrm/drm.h>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
#include <gbm.h>
|
2015-09-16 03:53:34 +00:00
|
|
|
|
|
|
|
#include <file/dir_list.h>
|
2015-09-18 01:47:44 +00:00
|
|
|
#include <retro_file.h>
|
2015-09-16 03:53:34 +00:00
|
|
|
|
|
|
|
#include "../../driver.h"
|
|
|
|
#include "../../runloop.h"
|
2015-11-19 12:24:51 +00:00
|
|
|
#include "../common/egl_common.h"
|
2015-11-17 07:01:33 +00:00
|
|
|
#include "../common/gl_common.h"
|
2015-09-16 03:53:34 +00:00
|
|
|
#include "../video_monitor.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-04-30 08:00:52 +00:00
|
|
|
#ifndef EGL_OPENGL_ES3_BIT_KHR
|
|
|
|
#define EGL_OPENGL_ES3_BIT_KHR 0x0040
|
|
|
|
#endif
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
typedef struct gfx_ctx_drm_egl_data
|
|
|
|
{
|
2015-09-18 01:47:44 +00:00
|
|
|
RFILE *g_drm;
|
2014-10-24 03:19:48 +00:00
|
|
|
int g_drm_fd;
|
|
|
|
uint32_t g_crtc_id;
|
|
|
|
uint32_t g_connector_id;
|
|
|
|
unsigned g_fb_width;
|
|
|
|
unsigned g_fb_height;
|
|
|
|
|
|
|
|
drmModeModeInfo *g_drm_mode;
|
|
|
|
drmModeCrtcPtr g_orig_crtc;
|
|
|
|
drmModeRes *g_resources;
|
|
|
|
drmModeConnector *g_connector;
|
|
|
|
drmModeEncoder *g_encoder;
|
|
|
|
|
|
|
|
struct gbm_bo *g_bo;
|
|
|
|
struct gbm_bo *g_next_bo;
|
|
|
|
struct gbm_device *g_gbm_dev;
|
|
|
|
struct gbm_surface *g_gbm_surface;
|
|
|
|
} gfx_ctx_drm_egl_data_t;
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static enum gfx_ctx_api g_api;
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static unsigned g_major;
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static unsigned g_minor;
|
2012-09-16 20:36:43 +00:00
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
struct drm_fb
|
|
|
|
{
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
uint32_t fb_id;
|
|
|
|
};
|
|
|
|
|
2015-04-26 02:02:04 +00:00
|
|
|
static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
struct drm_fb *fb = (struct drm_fb*)data;
|
|
|
|
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)driver->video_context_data;
|
|
|
|
|
|
|
|
if (drm && fb->fb_id)
|
|
|
|
drmModeRmFB(drm->g_drm_fd, fb->fb_id);
|
|
|
|
|
|
|
|
free(fb);
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static struct drm_fb *drm_fb_get_from_bo(
|
2015-04-26 02:02:04 +00:00
|
|
|
gfx_ctx_drm_egl_data_t *drm,
|
|
|
|
struct gbm_bo *bo)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned width, height, stride, handle;
|
|
|
|
struct drm_fb *fb = (struct drm_fb*)gbm_bo_get_user_data(bo);
|
|
|
|
if (fb)
|
|
|
|
return fb;
|
|
|
|
|
|
|
|
fb = (struct drm_fb*)calloc(1, sizeof(*fb));
|
|
|
|
fb->bo = bo;
|
2014-10-08 16:09:01 +00:00
|
|
|
|
2015-04-26 02:02:04 +00:00
|
|
|
width = gbm_bo_get_width(bo);
|
|
|
|
height = gbm_bo_get_height(bo);
|
|
|
|
stride = gbm_bo_get_stride(bo);
|
|
|
|
handle = gbm_bo_get_handle(bo).u32;
|
|
|
|
|
|
|
|
RARCH_LOG("[KMS/EGL]: New FB: %ux%u (stride: %u).\n", width, height, stride);
|
|
|
|
|
|
|
|
ret = drmModeAddFB(drm->g_drm_fd, width, height, 24, 32, stride, handle, &fb->fb_id);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[KMS/EGL]: Failed to create FB: %s\n", strerror(errno));
|
|
|
|
free(fb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback);
|
|
|
|
return fb;
|
|
|
|
}
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_swap_interval(void *data, unsigned interval)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2015-11-19 14:32:02 +00:00
|
|
|
g_interval = interval;
|
2013-09-01 11:20:10 +00:00
|
|
|
if (interval > 1)
|
|
|
|
RARCH_WARN("[KMS/EGL]: Swap intervals > 1 currently not supported. Will use swap interval of 1.\n");
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_check_window(void *data, bool *quit,
|
2012-09-16 19:39:40 +00:00
|
|
|
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
|
|
|
{
|
2014-03-09 15:50:18 +00:00
|
|
|
(void)data;
|
2012-09-16 19:39:40 +00:00
|
|
|
(void)frame_count;
|
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
|
|
|
|
*resize = false;
|
2015-11-19 14:47:30 +00:00
|
|
|
*quit = g_egl_quit;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static bool waiting_for_flip;
|
2012-09-18 18:36:16 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static void page_flip_handler(int fd, unsigned frame,
|
|
|
|
unsigned sec, unsigned usec, void *data)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2015-11-19 16:02:02 +00:00
|
|
|
static unsigned first_page_flip;
|
|
|
|
static unsigned last_page_flip;
|
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
(void)fd;
|
2013-06-05 16:12:29 +00:00
|
|
|
(void)sec;
|
|
|
|
(void)usec;
|
2012-09-18 18:36:16 +00:00
|
|
|
|
|
|
|
if (!first_page_flip)
|
|
|
|
first_page_flip = frame;
|
|
|
|
|
|
|
|
if (last_page_flip)
|
|
|
|
{
|
|
|
|
unsigned missed = frame - last_page_flip - 1;
|
2013-06-05 16:12:29 +00:00
|
|
|
if (missed)
|
2012-09-20 17:54:46 +00:00
|
|
|
RARCH_LOG("[KMS/EGL]: Missed %u VBlank(s) (Frame: %u, DRM frame: %u).\n",
|
|
|
|
missed, frame - first_page_flip, frame);
|
2012-09-18 18:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
last_page_flip = frame;
|
2012-09-18 22:44:50 +00:00
|
|
|
*(bool*)data = false;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 15:46:38 +00:00
|
|
|
static bool wait_flip(gfx_ctx_drm_egl_data_t *drm, bool block)
|
2012-09-17 22:17:01 +00:00
|
|
|
{
|
2015-01-10 02:25:44 +00:00
|
|
|
int timeout = 0;
|
2012-09-16 19:39:40 +00:00
|
|
|
struct pollfd fds = {0};
|
2015-01-10 02:25:44 +00:00
|
|
|
drmEventContext evctx = {0};
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2015-11-19 16:02:02 +00:00
|
|
|
if (!waiting_for_flip)
|
|
|
|
return false;
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2015-11-19 16:02:02 +00:00
|
|
|
fds.fd = drm->g_drm_fd;
|
|
|
|
fds.events = POLLIN;
|
2012-09-16 19:39:40 +00:00
|
|
|
evctx.version = DRM_EVENT_CONTEXT_VERSION;
|
|
|
|
evctx.page_flip_handler = page_flip_handler;
|
2012-09-18 08:32:35 +00:00
|
|
|
|
2015-01-10 02:25:44 +00:00
|
|
|
if (block)
|
|
|
|
timeout = -1;
|
2012-09-16 19:39:40 +00:00
|
|
|
|
|
|
|
while (waiting_for_flip)
|
|
|
|
{
|
|
|
|
fds.revents = 0;
|
2015-01-10 02:25:44 +00:00
|
|
|
|
2012-09-18 08:32:35 +00:00
|
|
|
if (poll(&fds, 1, timeout) < 0)
|
2012-09-16 19:39:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (fds.revents & (POLLHUP | POLLERR))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (fds.revents & POLLIN)
|
2014-10-24 03:19:48 +00:00
|
|
|
drmHandleEvent(drm->g_drm_fd, &evctx);
|
2012-09-16 19:39:40 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-10 02:25:44 +00:00
|
|
|
if (waiting_for_flip)
|
2015-11-19 15:06:16 +00:00
|
|
|
return true;
|
2015-01-10 02:25:44 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* Page flip has taken place. */
|
2015-01-10 02:25:44 +00:00
|
|
|
|
|
|
|
/* This buffer is not on-screen anymore. Release it to GBM. */
|
|
|
|
gbm_surface_release_buffer(drm->g_gbm_surface, drm->g_bo);
|
2015-06-30 12:37:11 +00:00
|
|
|
/* This buffer is being shown now. */
|
|
|
|
drm->g_bo = drm->g_next_bo;
|
2015-11-19 15:06:16 +00:00
|
|
|
|
|
|
|
return false;
|
2012-09-17 22:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 16:02:02 +00:00
|
|
|
static bool queue_flip(gfx_ctx_drm_egl_data_t *drm)
|
2012-09-17 22:17:01 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
struct drm_fb *fb = NULL;
|
2012-09-17 22:17:01 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_next_bo = gbm_surface_lock_front_buffer(drm->g_gbm_surface);
|
|
|
|
|
|
|
|
fb = (struct drm_fb*)drm_fb_get_from_bo(drm, drm->g_next_bo);
|
|
|
|
|
2015-11-19 15:32:58 +00:00
|
|
|
if (drmModePageFlip(drm->g_drm_fd, drm->g_crtc_id, fb->fb_id,
|
2015-11-19 16:02:02 +00:00
|
|
|
DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Failed to queue page flip. */
|
|
|
|
return false;
|
2012-09-17 22:17:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_swap_buffers(void *data)
|
2012-09-17 22:17:01 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2014-10-24 03:19:48 +00:00
|
|
|
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->video_context_data;
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2015-11-19 13:38:55 +00:00
|
|
|
egl_swap_buffers(data);
|
2014-10-24 03:19:48 +00:00
|
|
|
|
|
|
|
/* I guess we have to wait for flip to have taken
|
2015-11-19 16:02:02 +00:00
|
|
|
* place before another flip can be queued up.
|
|
|
|
*
|
|
|
|
* If true, we are still waiting for a flip
|
|
|
|
* (nonblocking mode, so just drop the frame). */
|
|
|
|
if (wait_flip(drm, g_interval))
|
|
|
|
return;
|
2012-09-17 22:17:01 +00:00
|
|
|
|
2015-11-19 16:02:02 +00:00
|
|
|
waiting_for_flip = queue_flip(drm);
|
2012-09-17 22:17:01 +00:00
|
|
|
|
2015-11-19 15:06:16 +00:00
|
|
|
if (gbm_surface_has_free_buffers(drm->g_gbm_surface))
|
|
|
|
return;
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* We have to wait for this flip to finish.
|
|
|
|
* This shouldn't happen as we have triple buffered page-flips. */
|
2015-11-19 15:06:16 +00:00
|
|
|
RARCH_WARN("[KMS/EGL]: Triple buffering is not working correctly ...\n");
|
2015-11-19 15:46:38 +00:00
|
|
|
wait_flip(drm, true);
|
2012-09-16 20:56:58 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static void gfx_ctx_drm_egl_set_resize(void *data,
|
|
|
|
unsigned width, unsigned height)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-03-09 15:50:18 +00:00
|
|
|
(void)data;
|
2012-09-16 19:39:40 +00:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_update_window_title(void *data)
|
2013-06-05 16:12:29 +00:00
|
|
|
{
|
2015-06-13 00:10:06 +00:00
|
|
|
char buf[128] = {0};
|
|
|
|
char buf_fps[128] = {0};
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2015-01-18 19:03:33 +00:00
|
|
|
video_monitor_get_fps(buf, sizeof(buf),
|
2015-03-07 22:03:56 +00:00
|
|
|
buf_fps, sizeof(buf_fps));
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->fps_show)
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push( buf_fps, 1, 1, false);
|
2013-06-05 16:12:29 +00:00
|
|
|
}
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_get_video_size(void *data, unsigned *width, unsigned *height)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)driver->video_context_data;
|
2014-10-24 03:19:48 +00:00
|
|
|
|
|
|
|
if (!drm)
|
|
|
|
return;
|
|
|
|
|
2014-03-09 15:50:18 +00:00
|
|
|
(void)data;
|
2014-10-24 03:19:48 +00:00
|
|
|
*width = drm->g_fb_width;
|
|
|
|
*height = drm->g_fb_height;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
static void free_drm_resources(gfx_ctx_drm_egl_data_t *drm)
|
2014-04-05 20:11:19 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm)
|
|
|
|
return;
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (drm->g_gbm_surface)
|
|
|
|
gbm_surface_destroy(drm->g_gbm_surface);
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (drm->g_gbm_dev)
|
|
|
|
gbm_device_destroy(drm->g_gbm_dev);
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (drm->g_encoder)
|
|
|
|
drmModeFreeEncoder(drm->g_encoder);
|
|
|
|
|
|
|
|
if (drm->g_connector)
|
|
|
|
drmModeFreeConnector(drm->g_connector);
|
|
|
|
|
|
|
|
if (drm->g_resources)
|
|
|
|
drmModeFreeResources(drm->g_resources);
|
|
|
|
|
|
|
|
if (drm->g_orig_crtc)
|
|
|
|
drmModeFreeCrtc(drm->g_orig_crtc);
|
|
|
|
|
|
|
|
if (drm->g_drm_fd >= 0)
|
2015-09-18 01:47:44 +00:00
|
|
|
retro_fclose(drm->g_drm);
|
2014-10-24 03:19:48 +00:00
|
|
|
|
|
|
|
drm->g_gbm_surface = NULL;
|
|
|
|
drm->g_gbm_dev = NULL;
|
|
|
|
drm->g_encoder = NULL;
|
|
|
|
drm->g_connector = NULL;
|
|
|
|
drm->g_resources = NULL;
|
|
|
|
drm->g_orig_crtc = NULL;
|
|
|
|
drm->g_drm_fd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_drm_egl_destroy_resources(gfx_ctx_drm_egl_data_t *drm)
|
|
|
|
{
|
|
|
|
if (!drm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Make sure we acknowledge all page-flips. */
|
2015-11-19 16:02:02 +00:00
|
|
|
wait_flip(drm, true);
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2015-11-19 14:34:40 +00:00
|
|
|
egl_destroy(NULL);
|
2014-10-24 03:19:48 +00:00
|
|
|
|
|
|
|
/* Restore original CRTC. */
|
|
|
|
if (drm->g_orig_crtc)
|
|
|
|
{
|
|
|
|
drmModeSetCrtc(drm->g_drm_fd, drm->g_orig_crtc->crtc_id,
|
|
|
|
drm->g_orig_crtc->buffer_id,
|
|
|
|
drm->g_orig_crtc->x,
|
|
|
|
drm->g_orig_crtc->y,
|
|
|
|
&drm->g_connector_id, 1, &drm->g_orig_crtc->mode);
|
|
|
|
}
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
free_drm_resources(drm);
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2015-11-19 14:47:30 +00:00
|
|
|
drm->g_drm_mode = NULL;
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_crtc_id = 0;
|
|
|
|
drm->g_connector_id = 0;
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_fb_width = 0;
|
|
|
|
drm->g_fb_height = 0;
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_bo = NULL;
|
|
|
|
drm->g_next_bo = NULL;
|
2014-04-05 20:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_drm_egl_init(void *data)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2013-10-22 19:26:33 +00:00
|
|
|
int i;
|
2014-04-06 13:10:39 +00:00
|
|
|
unsigned monitor_index;
|
2015-06-13 00:10:06 +00:00
|
|
|
unsigned gpu_index = 0;
|
|
|
|
const char *gpu = NULL;
|
2014-10-24 03:19:48 +00:00
|
|
|
struct string_list *gpu_descriptors = NULL;
|
2015-06-13 00:10:06 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-03-20 21:08:36 +00:00
|
|
|
unsigned monitor = max(settings->video.monitor_index, 1);
|
2014-04-06 13:10:39 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)calloc(1, sizeof(gfx_ctx_drm_egl_data_t));
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm)
|
2015-03-16 17:14:32 +00:00
|
|
|
return false;
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2015-05-24 03:07:01 +00:00
|
|
|
drm->g_drm_fd = -1;
|
2015-08-30 18:04:40 +00:00
|
|
|
gpu_descriptors = dir_list_new("/dev/dri", NULL, false, false);
|
2014-04-05 20:11:19 +00:00
|
|
|
|
2014-04-05 13:57:33 +00:00
|
|
|
nextgpu:
|
2014-10-24 03:19:48 +00:00
|
|
|
free_drm_resources(drm);
|
2014-04-05 20:11:19 +00:00
|
|
|
|
|
|
|
if (!gpu_descriptors || gpu_index == gpu_descriptors->size)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-04-05 13:57:33 +00:00
|
|
|
RARCH_ERR("[KMS/EGL]: Couldn't find a suitable DRM device.\n");
|
2012-09-16 19:39:40 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2014-04-05 17:51:28 +00:00
|
|
|
gpu = gpu_descriptors->elems[gpu_index++].data;
|
2014-04-05 13:57:33 +00:00
|
|
|
|
2015-09-18 01:47:44 +00:00
|
|
|
drm->g_drm = retro_fopen(gpu, RFILE_MODE_READ_WRITE, -1);
|
|
|
|
if (!drm->g_drm)
|
2014-04-05 13:57:33 +00:00
|
|
|
{
|
|
|
|
RARCH_WARN("[KMS/EGL]: Couldn't open DRM device.\n");
|
|
|
|
goto nextgpu;
|
|
|
|
}
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2015-09-18 01:47:44 +00:00
|
|
|
drm->g_drm_fd = retro_get_fd(drm->g_drm);
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_resources = drmModeGetResources(drm->g_drm_fd);
|
|
|
|
if (!drm->g_resources)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-04-05 13:57:33 +00:00
|
|
|
RARCH_WARN("[KMS/EGL]: Couldn't get device resources.\n");
|
|
|
|
goto nextgpu;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* Enumerate all connectors. */
|
2014-04-06 13:10:39 +00:00
|
|
|
monitor_index = 0;
|
2014-10-24 03:19:48 +00:00
|
|
|
RARCH_LOG("[KMS/EGL]: Found %d connectors.\n",
|
|
|
|
drm->g_resources->count_connectors);
|
|
|
|
|
|
|
|
for (i = 0; i < drm->g_resources->count_connectors; i++)
|
2014-04-06 13:10:39 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
drmModeConnectorPtr conn = drmModeGetConnector(
|
|
|
|
drm->g_drm_fd, drm->g_resources->connectors[i]);
|
|
|
|
|
2014-04-06 13:10:39 +00:00
|
|
|
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;
|
2014-10-24 03:19:48 +00:00
|
|
|
for (i = 0; i < drm->g_resources->count_connectors; i++)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_connector = drmModeGetConnector(drm->g_drm_fd,
|
|
|
|
drm->g_resources->connectors[i]);
|
2013-02-15 10:12:33 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_connector)
|
2013-02-15 10:12:33 +00:00
|
|
|
continue;
|
2014-10-24 03:19:48 +00:00
|
|
|
if (drm->g_connector->connection == DRM_MODE_CONNECTED
|
|
|
|
&& drm->g_connector->count_modes > 0)
|
2014-04-06 13:10:39 +00:00
|
|
|
{
|
|
|
|
monitor_index++;
|
|
|
|
if (monitor_index == monitor)
|
|
|
|
break;
|
|
|
|
}
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drmModeFreeConnector(drm->g_connector);
|
|
|
|
drm->g_connector = NULL;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_connector)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-04-05 13:57:33 +00:00
|
|
|
RARCH_WARN("[KMS/EGL]: Couldn't get device connector.\n");
|
|
|
|
goto nextgpu;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
for (i = 0; i < drm->g_resources->count_encoders; i++)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_encoder = drmModeGetEncoder(drm->g_drm_fd,
|
|
|
|
drm->g_resources->encoders[i]);
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_encoder)
|
2013-02-15 10:12:33 +00:00
|
|
|
continue;
|
2014-10-24 03:19:48 +00:00
|
|
|
if (drm->g_encoder->encoder_id == drm->g_connector->encoder_id)
|
2013-02-15 10:12:33 +00:00
|
|
|
break;
|
2013-02-15 09:26:45 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drmModeFreeEncoder(drm->g_encoder);
|
|
|
|
drm->g_encoder = NULL;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_encoder)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-04-05 13:57:33 +00:00
|
|
|
RARCH_WARN("[KMS/EGL]: Couldn't find DRM encoder.\n");
|
|
|
|
goto nextgpu;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
for (i = 0; i < drm->g_connector->count_modes; i++)
|
2014-04-05 20:29:20 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
RARCH_LOG("[KMS/EGL]: Mode %d: (%s) %d x %d, %u Hz\n",
|
|
|
|
i,
|
|
|
|
drm->g_connector->modes[i].name,
|
|
|
|
drm->g_connector->modes[i].hdisplay,
|
|
|
|
drm->g_connector->modes[i].vdisplay,
|
|
|
|
drm->g_connector->modes[i].vrefresh);
|
2014-04-05 20:29:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_crtc_id = drm->g_encoder->crtc_id;
|
|
|
|
drm->g_orig_crtc = drmModeGetCrtc(drm->g_drm_fd, drm->g_crtc_id);
|
|
|
|
if (!drm->g_orig_crtc)
|
2013-02-15 10:12:33 +00:00
|
|
|
RARCH_WARN("[KMS/EGL]: Cannot find original CRTC.\n");
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_connector_id = drm->g_connector->connector_id;
|
|
|
|
|
|
|
|
/* First mode is assumed to be the "optimal"
|
|
|
|
* one for get_video_size() purposes. */
|
|
|
|
drm->g_fb_width = drm->g_connector->modes[0].hdisplay;
|
|
|
|
drm->g_fb_height = drm->g_connector->modes[0].vdisplay;
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_gbm_dev = gbm_create_device(drm->g_drm_fd);
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_gbm_dev)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-04-06 13:20:31 +00:00
|
|
|
RARCH_WARN("[KMS/EGL]: Couldn't create GBM device.\n");
|
2014-04-05 13:57:33 +00:00
|
|
|
goto nextgpu;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 17:59:31 +00:00
|
|
|
dir_list_free(gpu_descriptors);
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->video_context_data = drm;
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
2014-04-05 17:32:51 +00:00
|
|
|
dir_list_free(gpu_descriptors);
|
2014-10-24 03:19:48 +00:00
|
|
|
|
|
|
|
gfx_ctx_drm_egl_destroy_resources(drm);
|
|
|
|
|
|
|
|
if (drm)
|
|
|
|
free(drm);
|
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:54:29 +00:00
|
|
|
static EGLint *egl_fill_attribs(EGLint *attr)
|
|
|
|
{
|
|
|
|
switch (g_api)
|
|
|
|
{
|
|
|
|
#ifdef EGL_KHR_create_context
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
{
|
|
|
|
unsigned version = g_major * 1000 + g_minor;
|
2015-03-21 04:55:31 +00:00
|
|
|
bool core = version >= 3001;
|
2014-04-20 11:54:29 +00:00
|
|
|
#ifdef GL_DEBUG
|
2015-03-21 04:55:31 +00:00
|
|
|
bool debug = true;
|
2014-04-20 11:54:29 +00:00
|
|
|
#else
|
2015-05-20 17:56:12 +00:00
|
|
|
const struct retro_hw_render_callback *hw_render =
|
|
|
|
(const struct retro_hw_render_callback*)video_driver_callback();
|
|
|
|
bool debug = hw_render->debug_context;
|
2014-04-20 11:54:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (core)
|
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR;
|
|
|
|
*attr++ = g_major;
|
|
|
|
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
|
|
|
|
*attr++ = g_minor;
|
2014-10-24 03:19:48 +00:00
|
|
|
|
|
|
|
/* Technically, we don't have core/compat until 3.2.
|
|
|
|
* Version 3.1 is either compat or not depending
|
|
|
|
* on GL_ARB_compatibility. */
|
2014-04-20 11:54:29 +00:00
|
|
|
if (version >= 3002)
|
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
|
|
*attr++ = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
*attr++ = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
|
|
|
*attr++ = EGL_CONTEXT_CLIENT_VERSION;
|
|
|
|
*attr++ = g_major ? (EGLint)g_major : 2;
|
2014-05-03 13:21:14 +00:00
|
|
|
#ifdef EGL_KHR_create_context
|
|
|
|
if (g_minor > 0)
|
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
|
|
|
|
*attr++ = g_minor;
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-20 11:54:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*attr = EGL_NONE;
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2014-10-27 13:35:23 +00:00
|
|
|
#define DRM_EGL_ATTRIBS_BASE \
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, \
|
|
|
|
EGL_RED_SIZE, 1, \
|
|
|
|
EGL_GREEN_SIZE, 1, \
|
|
|
|
EGL_BLUE_SIZE, 1, \
|
|
|
|
EGL_ALPHA_SIZE, 0, \
|
|
|
|
EGL_DEPTH_SIZE, 0
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_drm_egl_set_video_mode(void *data,
|
2012-09-16 19:39:40 +00:00
|
|
|
unsigned width, unsigned height,
|
2012-11-20 22:23:18 +00:00
|
|
|
bool fullscreen)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2012-09-25 11:25:03 +00:00
|
|
|
static const EGLint egl_attribs_gl[] = {
|
2014-10-27 13:35:23 +00:00
|
|
|
DRM_EGL_ATTRIBS_BASE,
|
2012-09-25 11:25:03 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
EGL_NONE,
|
2012-09-24 23:26:22 +00:00
|
|
|
};
|
|
|
|
|
2012-09-25 11:25:03 +00:00
|
|
|
static const EGLint egl_attribs_gles[] = {
|
2014-10-27 13:35:23 +00:00
|
|
|
DRM_EGL_ATTRIBS_BASE,
|
2012-09-24 23:26:22 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2012-09-25 11:25:03 +00:00
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
2014-04-30 08:00:52 +00:00
|
|
|
#ifdef EGL_KHR_create_context
|
2013-12-13 13:19:25 +00:00
|
|
|
static const EGLint egl_attribs_gles3[] = {
|
2014-10-27 13:35:23 +00:00
|
|
|
DRM_EGL_ATTRIBS_BASE,
|
2013-12-13 13:19:25 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-09-25 11:25:03 +00:00
|
|
|
static const EGLint egl_attribs_vg[] = {
|
2014-10-27 13:35:23 +00:00
|
|
|
DRM_EGL_ATTRIBS_BASE,
|
2012-09-25 11:25:03 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
|
|
|
|
EGL_NONE,
|
2012-09-24 23:26:22 +00:00
|
|
|
};
|
|
|
|
|
2012-09-25 11:25:03 +00:00
|
|
|
const EGLint *attrib_ptr;
|
2015-01-10 02:25:44 +00:00
|
|
|
EGLint major, minor, n, egl_attribs[16], *attr;
|
|
|
|
float refresh_mod;
|
|
|
|
int i, ret = 0;
|
|
|
|
struct drm_fb *fb = NULL;
|
2015-03-20 21:08:36 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-10 02:25:44 +00:00
|
|
|
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->video_context_data;
|
2015-01-10 02:25:44 +00:00
|
|
|
|
|
|
|
if (!drm)
|
|
|
|
return false;
|
|
|
|
|
2015-11-19 14:55:57 +00:00
|
|
|
egl_install_sighandlers();
|
2015-01-10 02:25:44 +00:00
|
|
|
|
2012-09-25 11:25:03 +00:00
|
|
|
switch (g_api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
attrib_ptr = egl_attribs_gl;
|
|
|
|
break;
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
2014-04-30 08:00:52 +00:00
|
|
|
#ifdef EGL_KHR_create_context
|
2013-12-13 13:19:25 +00:00
|
|
|
if (g_major >= 3)
|
|
|
|
attrib_ptr = egl_attribs_gles3;
|
|
|
|
else
|
|
|
|
#endif
|
2012-09-25 11:25:03 +00:00
|
|
|
attrib_ptr = egl_attribs_gles;
|
|
|
|
break;
|
|
|
|
case GFX_CTX_OPENVG_API:
|
|
|
|
attrib_ptr = egl_attribs_vg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
attrib_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* If we use black frame insertion,
|
|
|
|
* we fake a 60 Hz monitor for 120 Hz one, etc, so try to match that. */
|
2015-03-20 21:08:36 +00:00
|
|
|
refresh_mod = settings->video.black_frame_insertion ? 0.5f : 1.0f;
|
2014-07-13 17:45:28 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* Find desired video mode, and use that.
|
|
|
|
* If not fullscreen, we get desired windowed size,
|
|
|
|
* which is not appropriate. */
|
2014-04-06 13:41:53 +00:00
|
|
|
if ((width == 0 && height == 0) || !fullscreen)
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_drm_mode = &drm->g_connector->modes[0];
|
2014-04-06 13:20:31 +00:00
|
|
|
else
|
|
|
|
{
|
2015-03-20 21:08:36 +00:00
|
|
|
/* Try to match settings->video.refresh_rate as closely as possible.
|
2014-10-24 03:19:48 +00:00
|
|
|
* Lower resolutions tend to have multiple supported
|
|
|
|
* refresh rates as well.
|
|
|
|
*/
|
2014-04-06 13:29:59 +00:00
|
|
|
float minimum_fps_diff = 0.0f;
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* Find best match. */
|
|
|
|
for (i = 0; i < drm->g_connector->count_modes; i++)
|
2014-04-06 13:20:31 +00:00
|
|
|
{
|
2015-06-29 19:52:55 +00:00
|
|
|
float diff;
|
2014-10-24 03:19:48 +00:00
|
|
|
if (width != drm->g_connector->modes[i].hdisplay ||
|
|
|
|
height != drm->g_connector->modes[i].vdisplay)
|
2014-04-06 13:29:59 +00:00
|
|
|
continue;
|
|
|
|
|
2015-06-29 19:52:55 +00:00
|
|
|
diff = fabsf(refresh_mod * drm->g_connector->modes[i].vrefresh
|
|
|
|
- settings->video.refresh_rate);
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_drm_mode || diff < minimum_fps_diff)
|
2014-04-06 13:20:31 +00:00
|
|
|
{
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_drm_mode = &drm->g_connector->modes[i];
|
2014-07-13 17:23:08 +00:00
|
|
|
minimum_fps_diff = diff;
|
2014-04-06 13:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_drm_mode)
|
2014-04-06 13:20:31 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[KMS/EGL]: Did not find suitable video mode for %u x %u.\n", width, height);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_fb_width = drm->g_drm_mode->hdisplay;
|
|
|
|
drm->g_fb_height = drm->g_drm_mode->vdisplay;
|
2014-04-06 13:20:31 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
/* Create GBM surface. */
|
|
|
|
drm->g_gbm_surface = gbm_surface_create(
|
|
|
|
drm->g_gbm_dev,
|
|
|
|
drm->g_fb_width,
|
|
|
|
drm->g_fb_height,
|
2014-04-06 13:20:31 +00:00
|
|
|
GBM_FORMAT_XRGB8888,
|
|
|
|
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm->g_gbm_surface)
|
2014-04-06 13:20:31 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[KMS/EGL]: Couldn't create GBM surface.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-11-19 16:52:13 +00:00
|
|
|
if (!egl_init_context((EGLNativeDisplayType)drm->g_gbm_dev, &major,
|
|
|
|
&minor, &n, attrib_ptr))
|
2015-11-19 17:01:37 +00:00
|
|
|
{
|
|
|
|
egl_report_error();
|
2012-09-24 23:26:22 +00:00
|
|
|
goto error;
|
2015-11-19 17:01:37 +00:00
|
|
|
}
|
2012-09-24 23:26:22 +00:00
|
|
|
|
2014-06-08 12:06:02 +00:00
|
|
|
attr = egl_fill_attribs(egl_attribs);
|
2014-04-20 11:54:29 +00:00
|
|
|
|
2015-11-19 13:09:51 +00:00
|
|
|
g_egl_ctx = eglCreateContext(g_egl_dpy, g_egl_config, EGL_NO_CONTEXT,
|
2014-04-20 11:54:29 +00:00
|
|
|
attr != egl_attribs ? egl_attribs : NULL);
|
|
|
|
|
2015-11-19 13:09:51 +00:00
|
|
|
if (g_egl_ctx == EGL_NO_CONTEXT)
|
2012-09-24 23:26:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-11-19 13:28:21 +00:00
|
|
|
if (g_use_hw_ctx)
|
2014-04-19 14:06:12 +00:00
|
|
|
{
|
2015-11-19 13:09:51 +00:00
|
|
|
g_egl_hw_ctx = eglCreateContext(g_egl_dpy, g_egl_config, g_egl_ctx,
|
2014-04-20 11:54:29 +00:00
|
|
|
attr != egl_attribs ? egl_attribs : NULL);
|
2015-11-19 13:09:51 +00:00
|
|
|
RARCH_LOG("[KMS/EGL]: Created shared context: %p.\n", (void*)g_egl_hw_ctx);
|
2014-04-19 14:06:12 +00:00
|
|
|
|
2015-11-19 13:09:51 +00:00
|
|
|
if (g_egl_hw_ctx == EGL_NO_CONTEXT)
|
2014-04-19 14:06:12 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-11-19 13:09:51 +00:00
|
|
|
g_egl_surf = eglCreateWindowSurface(g_egl_dpy,
|
|
|
|
g_egl_config, (EGLNativeWindowType)drm->g_gbm_surface, NULL);
|
|
|
|
if (!g_egl_surf)
|
2012-09-24 23:26:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-11-19 13:09:51 +00:00
|
|
|
if (!eglMakeCurrent(g_egl_dpy,
|
|
|
|
g_egl_surf, g_egl_surf, g_egl_ctx))
|
2012-09-24 23:26:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2015-11-19 13:38:55 +00:00
|
|
|
egl_swap_buffers(NULL);
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
drm->g_bo = gbm_surface_lock_front_buffer(drm->g_gbm_surface);
|
|
|
|
fb = drm_fb_get_from_bo(drm, drm->g_bo);
|
2012-09-16 19:39:40 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
ret = drmModeSetCrtc(drm->g_drm_fd,
|
|
|
|
drm->g_crtc_id, fb->fb_id, 0, 0, &drm->g_connector_id, 1, drm->g_drm_mode);
|
2012-09-16 19:39:40 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
2014-10-24 03:19:48 +00:00
|
|
|
gfx_ctx_drm_egl_destroy_resources(drm);
|
|
|
|
|
|
|
|
if (drm)
|
|
|
|
free(drm);
|
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_destroy(void *data)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2014-10-27 13:35:23 +00:00
|
|
|
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->video_context_data;
|
2014-04-19 14:06:12 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
if (!drm)
|
|
|
|
return;
|
2012-09-16 20:36:43 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
(void)data;
|
2012-09-16 20:36:43 +00:00
|
|
|
|
2014-10-24 03:19:48 +00:00
|
|
|
gfx_ctx_drm_egl_destroy_resources(drm);
|
2012-09-16 20:36:43 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->video_context_data)
|
|
|
|
free(driver->video_context_data);
|
|
|
|
driver->video_context_data = NULL;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_drm_egl_input_driver(void *data,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-03-09 15:50:18 +00:00
|
|
|
(void)data;
|
2014-01-24 09:23:48 +00:00
|
|
|
*input = NULL;
|
|
|
|
*input_data = NULL;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_drm_egl_has_focus(void *data)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2015-01-10 02:25:44 +00:00
|
|
|
return true;
|
2012-09-16 19:39:40 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool gfx_ctx_drm_egl_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_drm_egl_has_windowed(void *data)
|
2014-10-08 15:23:02 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_drm_egl_bind_api(void *data,
|
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2012-09-24 23:26:22 +00:00
|
|
|
{
|
2014-03-09 15:50:18 +00:00
|
|
|
(void)data;
|
2015-01-10 02:25:44 +00:00
|
|
|
|
2013-12-13 13:19:25 +00:00
|
|
|
g_major = major;
|
|
|
|
g_minor = minor;
|
2012-09-24 23:26:22 +00:00
|
|
|
g_api = api;
|
2015-01-10 02:25:44 +00:00
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
switch (api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2014-04-20 11:54:29 +00:00
|
|
|
#ifndef EGL_KHR_create_context
|
|
|
|
if ((major * 1000 + minor) >= 3001)
|
|
|
|
return false;
|
|
|
|
#endif
|
2012-09-24 23:26:22 +00:00
|
|
|
return eglBindAPI(EGL_OPENGL_API);
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
2014-04-20 11:54:29 +00:00
|
|
|
#ifndef EGL_KHR_create_context
|
2013-12-13 13:19:25 +00:00
|
|
|
if (major >= 3)
|
|
|
|
return false;
|
|
|
|
#endif
|
2012-09-24 23:26:22 +00:00
|
|
|
return eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
case GFX_CTX_OPENVG_API:
|
|
|
|
return eglBindAPI(EGL_OPENVG_API);
|
|
|
|
default:
|
2015-04-16 21:04:22 +00:00
|
|
|
break;
|
2012-09-24 23:26:22 +00:00
|
|
|
}
|
2015-04-09 03:29:24 +00:00
|
|
|
|
|
|
|
return false;
|
2012-09-24 23:26:22 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 14:06:12 +00:00
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_drm_egl = {
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_drm_egl_init,
|
|
|
|
gfx_ctx_drm_egl_destroy,
|
|
|
|
gfx_ctx_drm_egl_bind_api,
|
|
|
|
gfx_ctx_drm_egl_swap_interval,
|
|
|
|
gfx_ctx_drm_egl_set_video_mode,
|
|
|
|
gfx_ctx_drm_egl_get_video_size,
|
2015-02-24 20:36:23 +00:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-08 18:10:30 +00:00
|
|
|
NULL, /* get_metrics */
|
2015-02-24 18:58:14 +00:00
|
|
|
NULL,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_drm_egl_update_window_title,
|
|
|
|
gfx_ctx_drm_egl_check_window,
|
|
|
|
gfx_ctx_drm_egl_set_resize,
|
|
|
|
gfx_ctx_drm_egl_has_focus,
|
2015-01-18 21:32:14 +00:00
|
|
|
gfx_ctx_drm_egl_suppress_screensaver,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_drm_egl_has_windowed,
|
|
|
|
gfx_ctx_drm_egl_swap_buffers,
|
|
|
|
gfx_ctx_drm_egl_input_driver,
|
2015-11-19 12:24:51 +00:00
|
|
|
egl_get_proc_address,
|
2014-03-09 15:50:18 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2013-03-29 12:46:11 +00:00
|
|
|
NULL,
|
2013-02-23 13:49:49 +00:00
|
|
|
"kms-egl",
|
2015-11-19 13:32:39 +00:00
|
|
|
egl_bind_hw_render,
|
2012-09-24 23:26:22 +00:00
|
|
|
};
|