From 749edc154668a05461890dd10007519b4806e13a Mon Sep 17 00:00:00 2001 From: kernelkinetic <67117582+kernelkinetic@users.noreply.github.com> Date: Sat, 26 Sep 2020 10:33:54 +0200 Subject: [PATCH] replaced SetGraphicDeviceName() by DEFAULT_GRAPHIC_DEVICE_DRM --- src/core.c | 42 +++++++++--------------------------------- src/raylib.h | 1 - 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/core.c b/src/core.c index 388fb15bd..f08124f5a 100644 --- a/src/core.c +++ b/src/core.c @@ -350,7 +350,6 @@ typedef struct CoreData { #endif #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) || defined(PLATFORM_UWP) #if defined(PLATFORM_DRM) - const char *card; // /dev/dri/... file name int fd; // /dev/dri/... file descriptor drmModeConnector *connector; // Direct Rendering Manager (DRM) mode connector int modeIndex; // index of the used mode of connector->modes @@ -3053,7 +3052,6 @@ static bool InitGraphicsDevice(int width, int height) #endif #if defined(PLATFORM_DRM) - CORE.Window.card = NULL; CORE.Window.fd = -1; CORE.Window.connector = NULL; CORE.Window.modeIndex = -1; @@ -3063,37 +3061,22 @@ static bool InitGraphicsDevice(int width, int height) CORE.Window.prevBO = NULL; CORE.Window.prevFB = 0; - if ((NULL != CORE.Window.card) && ('\0' != CORE.Window.card[0])) +#if defined(DEFAULT_GRAPHIC_DEVICE_DRM) + CORE.Window.fd = open(DEFAULT_GRAPHIC_DEVICE_DRM, O_RDWR); +#else + TRACELOG(LOG_INFO, "DISPLAY: no graphic card set, trying card1"); + CORE.Window.fd = open("/dev/dri/card1", O_RDWR); // VideoCore VI (Raspberry Pi 4) + if (-1 == CORE.Window.fd) { - char *base = "/dev/dri/"; - const int len = strlen(base) + strlen(CORE.Window.card); - char *path = malloc(len); - if (!path) { - TRACELOG(LOG_WARNING, "DISPLAY: failed to get memory for path"); - return false; - } - path[0] = '\0'; - strncpy(path, base, len - 1); - strncat(path, CORE.Window.card, len - strlen(base)); - CORE.Window.fd = open(path, O_RDWR); - free(path); - } - else - { - TRACELOG(LOG_INFO, "DISPLAY: no graphic card set, trying card1"); - CORE.Window.fd = open("/dev/dri/card1", O_RDWR); // VideoCore VI (Raspberry Pi 4) - if (-1 == CORE.Window.fd) - { - TRACELOG(LOG_INFO, "DISPLAY: failed to open graphic card1, trying card0"); - CORE.Window.fd = open("/dev/dri/card0", O_RDWR); // VideoCore IV (Raspberry Pi 1-3) - } + TRACELOG(LOG_INFO, "DISPLAY: failed to open graphic card1, trying card0"); + CORE.Window.fd = open("/dev/dri/card0", O_RDWR); // VideoCore IV (Raspberry Pi 1-3) } +#endif if (-1 == CORE.Window.fd) { TRACELOG(LOG_WARNING, "DISPLAY: failed to open graphic card"); return false; } - drmModeRes *res = drmModeGetResources(CORE.Window.fd); if (!res) @@ -5759,13 +5742,6 @@ void UWPGestureTouch(int pointer, float x, float y, bool touch) #endif // PLATFORM_UWP -void SetGraphicDeviceName(const char *name) -{ -#if defined(PLATFORM_DRM) - if ((name != NULL) && (name[0] != 0)) CORE.Window.card = name; -#endif -} - #if defined(PLATFORM_DRM) static int FindMatchingConnectorMode(const drmModeConnector *connector, const drmModeModeInfo *mode) diff --git a/src/raylib.h b/src/raylib.h index e1de52de5..dfdea6381 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -866,7 +866,6 @@ extern "C" { // Prevents name mangling of functions //------------------------------------------------------------------------------------ // Window-related functions -RLAPI void SetGraphicDeviceName(const char *name); // Set the name of the graphic device to use RLAPI void InitWindow(int width, int height, const char *title); // Initialize window and OpenGL context RLAPI bool WindowShouldClose(void); // Check if KEY_ESCAPE pressed or Close icon pressed RLAPI void CloseWindow(void); // Close window and unload OpenGL context