KMSDRM: Add hint to enable the backend without DRM master In some cases, it can be useful to have the KMSDRM backend even if it cannot be used for rendering. An app may want to use SDL for input processing while using another rendering API (such as an MMAL overlay on Raspberry Pi) or using its own code to render to DRM overlays that SDL doesn't support. This also moves the check for DRM master to an earlier point where we can fail initialization of the backend, rather than allowing the backend to initialize then failing the creation of a window later.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 5c320dc..6b3f469 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1325,6 +1325,29 @@ extern "C" {
#define SDL_HINT_VIDEO_DOUBLE_BUFFER "SDL_VIDEO_DOUBLE_BUFFER"
/**
+ * \brief Determines whether SDL enforces that DRM master is required in order
+ * to initialize the KMSDRM video backend.
+ *
+ * The DRM subsystem has a concept of a "DRM master" which is a DRM client that
+ * has the ability to set planes, set cursor, etc. When SDL is DRM master, it
+ * can draw to the screen using the SDL rendering APIs. Without DRM master, SDL
+ * is still able to process input and query attributes of attached displays,
+ * but it cannot change display state or draw to the screen directly.
+ *
+ * In some cases, it can be useful to have the KMSDRM backend even if it cannot
+ * be used for rendering. An app may want to use SDL for input processing while
+ * using another rendering API (such as an MMAL overlay on Raspberry Pi) or
+ * using its own code to render to DRM overlays that SDL doesn't support.
+ *
+ * This hint must be set before initializing the video subsystem.
+ *
+ * This variable can be set to the following values:
+ * "0" - SDL will allow usage of the KMSDRM backend without DRM master
+ * "1" - SDL Will require DRM master to use the KMSDRM backend (default)
+ */
+#define SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER "SDL_KMSDRM_REQUIRE_DRM_MASTER"
+
+/**
* \brief A variable controlling what driver to use for OpenGL ES contexts.
*
* On some platforms, currently Windows and X11, OpenGL drivers may support
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index b0967d1..b52b545 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -100,6 +100,14 @@ check_modestting(int devindex)
}
if (conn->connection == DRM_MODE_CONNECTED && conn->count_modes) {
+ if (SDL_GetHintBoolean(SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER, SDL_TRUE)) {
+ /* Skip this device if we can't obtain DRM master */
+ KMSDRM_drmSetMaster(drm_fd);
+ if (KMSDRM_drmAuthMagic(drm_fd, 0) == -EACCES) {
+ continue;
+ }
+ }
+
available = SDL_TRUE;
break;
}
@@ -773,12 +781,6 @@ KMSDRM_GBMInit (_THIS, SDL_DisplayData *dispdata)
/* Set the FD we just opened as current DRM master. */
KMSDRM_drmSetMaster(viddata->drm_fd);
- /* Check if we are the current DRM master. */
- if (KMSDRM_drmAuthMagic(viddata->drm_fd, 0) == -EACCES) {
- ret = SDL_SetError("DRM device is claimed by another program as master.");
- return ret;
- }
-
/* Create the GBM device. */
viddata->gbm_dev = KMSDRM_gbm_create_device(viddata->drm_fd);
if (!viddata->gbm_dev) {