summaryrefslogtreecommitdiff
path: root/Source/3rdParty/SDL2/src/video/kmsdrm
diff options
context:
space:
mode:
Diffstat (limited to 'Source/3rdParty/SDL2/src/video/kmsdrm')
-rw-r--r--Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c10
-rw-r--r--Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c24
-rw-r--r--Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c87
-rw-r--r--Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h1
4 files changed, 99 insertions, 23 deletions
diff --git a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c
index e23dd13..0474089 100644
--- a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c
+++ b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c
@@ -487,12 +487,12 @@ KMSDRM_MoveCursor(SDL_Cursor * cursor)
That's why we move the cursor graphic ONLY. */
if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
- drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
- ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y);
+ drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
+ ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y);
- if (ret) {
- SDL_SetError("drmModeMoveCursor() failed.");
- }
+ if (ret) {
+ SDL_SetError("drmModeMoveCursor() failed.");
+ }
}
}
diff --git a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c
index 7a0b079..fc6304d 100644
--- a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c
+++ b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -50,23 +50,23 @@ KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) {
KMSDRM_FBInfo *fb_info;
if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
- SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup");
- return SDL_FALSE;
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup");
+ return SDL_FALSE;
}
- wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
- if (wdata->next_bo == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup");
- return SDL_FALSE;
+ wdata->crtc_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
+ if (wdata->crtc_bo == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup");
+ return SDL_FALSE;
}
- fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
+ fb_info = KMSDRM_FBFromBO(_this, wdata->crtc_bo);
if (fb_info == NULL) {
- return SDL_FALSE;
+ return SDL_FALSE;
}
if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
- 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) {
+ 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) {
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC to a GBM buffer");
return SDL_FALSE;
@@ -153,14 +153,14 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
} else {
/* Queue page flip at vsync */
- /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
+ /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
or FlipPage won't work in some cases. */
- if (!wdata->crtc_ready) {
+ if (!wdata->crtc_ready) {
if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing vsync-ed pageflips");
return 0;
}
- }
+ }
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
diff --git a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 7855eed..bacbe0c 100644
--- a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -41,20 +41,27 @@
#include "SDL_kmsdrmopengles.h"
#include "SDL_kmsdrmmouse.h"
#include "SDL_kmsdrmdyn.h"
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
-#define KMSDRM_DRI_CARD_0 "/dev/dri/card0"
+#define KMSDRM_DRI_PATH "/dev/dri/"
static int
-KMSDRM_Available(void)
+check_modestting(int devindex)
{
- int available = 0;
+ SDL_bool available = SDL_FALSE;
+ char device[512];
+ int drm_fd;
+
+ SDL_snprintf(device, sizeof (device), "%scard%d", KMSDRM_DRI_PATH, devindex);
- int drm_fd = open(KMSDRM_DRI_CARD_0, O_RDWR | O_CLOEXEC);
+ drm_fd = open(device, O_RDWR | O_CLOEXEC);
if (drm_fd >= 0) {
if (SDL_KMSDRM_LoadSymbols()) {
drmModeRes *resources = KMSDRM_drmModeGetResources(drm_fd);
if (resources != NULL) {
- available = 1;
+ available = SDL_TRUE;
KMSDRM_drmModeFreeResources(resources);
}
SDL_KMSDRM_UnloadSymbols();
@@ -65,6 +72,66 @@ KMSDRM_Available(void)
return available;
}
+static int get_dricount(void)
+{
+ int devcount = 0;
+ struct dirent *res;
+ struct stat sb;
+ DIR *folder;
+
+ if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
+ && S_ISDIR(sb.st_mode))) {
+ printf("The path %s cannot be opened or is not available\n",
+ KMSDRM_DRI_PATH);
+ return 0;
+ }
+
+ if (access(KMSDRM_DRI_PATH, F_OK) == -1) {
+ printf("The path %s cannot be opened\n",
+ KMSDRM_DRI_PATH);
+ return 0;
+ }
+
+ folder = opendir(KMSDRM_DRI_PATH);
+ if (folder) {
+ while ((res = readdir(folder))) {
+ if (res->d_type == DT_CHR) {
+ devcount++;
+ }
+ }
+ closedir(folder);
+ }
+
+ return devcount;
+}
+
+static int
+get_driindex(void)
+{
+ const int devcount = get_dricount();
+ int i;
+
+ for (i = 0; i < devcount; i++) {
+ if (check_modestting(i)) {
+ return i;
+ }
+ }
+
+ return -ENOENT;
+}
+
+static int
+KMSDRM_Available(void)
+{
+ int ret = -ENOENT;
+
+ ret = get_driindex();
+ if (ret >= 0)
+ return 1;
+
+ return ret;
+}
+
static void
KMSDRM_Destroy(SDL_VideoDevice * device)
{
@@ -83,7 +150,11 @@ KMSDRM_Create(int devindex)
SDL_VideoDevice *device;
SDL_VideoData *vdata;
- if (devindex < 0 || devindex > 99) {
+ if (!devindex || (devindex > 99)) {
+ devindex = get_driindex();
+ }
+
+ if (devindex < 0) {
SDL_SetError("devindex (%d) must be between 0 and 99.\n", devindex);
return NULL;
}
@@ -566,6 +637,10 @@ KMSDRM_DestroyWindow(_THIS, SDL_Window * window)
if(data) {
/* Wait for any pending page flips and unlock buffer */
KMSDRM_WaitPageFlip(_this, data, -1);
+ if (data->crtc_bo != NULL) {
+ KMSDRM_gbm_surface_release_buffer(data->gs, data->crtc_bo);
+ data->crtc_bo = NULL;
+ }
if (data->next_bo != NULL) {
KMSDRM_gbm_surface_release_buffer(data->gs, data->next_bo);
data->next_bo = NULL;
diff --git a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 5f00f0e..34f0b10 100644
--- a/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/Source/3rdParty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -62,6 +62,7 @@ typedef struct SDL_WindowData
struct gbm_surface *gs;
struct gbm_bo *current_bo;
struct gbm_bo *next_bo;
+ struct gbm_bo *crtc_bo;
SDL_bool waiting_for_flip;
SDL_bool crtc_ready;
SDL_bool double_buffer;