DisplayServer (Linux): support --ds-force-drm sysfs-only

This commit is contained in:
李通洲 2023-12-11 13:25:58 +08:00
parent f20b6d4387
commit a28dc8a9bf
7 changed files with 81 additions and 13 deletions

View File

@ -3,6 +3,7 @@
Features:
* Improve performance of detecting rpm and pkg package count (Packages, Linux / FreeBSD)
* Support Apple M3X temperature detection (CPU / GPU, macOS)
* `--ds-force-drm` support a new option `sysfs-only`
# 2.3.4

View File

@ -251,9 +251,24 @@
"description": "Set the path to the file containing OS information. Linux only"
},
"dsForceDrm": {
"type": "boolean",
"description": "Force display detection to use `/sys/class/drm`. Linux only",
"default": false
"description": "Force display detection to use DRM. Linux only",
"oneOf": [
{
"type": "bool",
"const": false,
"description": "Try `libdrm` first, then `sysfs` if libdrm failed"
},
{
"type": "string",
"description": "Use `/sys/class/drm` only.",
"const": "sysfs-only"
},
{
"type": "bool",
"const": true,
"description": "Don't force using DRM"
}
]
},
"wmiTimeout": {
"type": "integer",

View File

@ -124,9 +124,14 @@
"desc": "Set if only DRM should be used to detect displays",
"remark": "Use this option if you encountered problems with other detection method. Linux only",
"arg": {
"type": "bool",
"type": "enum",
"optional": true,
"default": false
"default": "false",
"enum": {
"true": "Try `libdrm` first, then `sysfs` if libdrm failed",
"sysfs-only": "Use `/sys/class/drm` only",
"false": "Don't force using DRM"
}
}
}
],

View File

@ -10,7 +10,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
ffStrbufInit(&ds->dePrettyName);
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4);
if (!instance.config.general.dsForceDrm)
if (instance.config.general.dsForceDrm == FF_DS_FORCE_DRM_TYPE_FALSE)
{
//We try wayland as our preferred display server, as it supports the most features.
//This method can't detect the name of our WM / DE

View File

@ -285,8 +285,11 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
void ffdsConnectDrm(FFDisplayServerResult* result)
{
#ifdef FF_HAVE_DRM
if (drmConnectLibdrm(result) == NULL)
return;
if (instance.config.general.dsForceDrm != FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY)
{
if (drmConnectLibdrm(result) == NULL)
return;
}
#endif
drmParseSysfs(result);

View File

@ -30,7 +30,24 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va
else if (ffStrEqualsIgnCase(key, "osFile"))
ffStrbufSetS(&options->osFile, yyjson_get_str(val));
else if (ffStrEqualsIgnCase(key, "dsForceDrm"))
options->dsForceDrm = yyjson_get_bool(val);
{
if (yyjson_is_str(val))
{
int value;
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
{ "sysfs-only", FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY },
{ "false", FF_DS_FORCE_DRM_TYPE_FALSE },
{ "true", FF_DS_FORCE_DRM_TYPE_TRUE },
{},
});
if (error)
return "Invalid enum value of `dsForceDrm`";
else
options->dsForceDrm = (FFDsForceDrmType) value;
}
else
options->dsForceDrm = yyjson_get_bool(val) ? FF_DS_FORCE_DRM_TYPE_TRUE : FF_DS_FORCE_DRM_TYPE_FALSE;
}
#elif defined(_WIN32)
else if (ffStrEqualsIgnCase(key, "wmiTimeout"))
options->wmiTimeout = (int32_t) yyjson_get_int(val);
@ -65,7 +82,14 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key
else if (ffStrEqualsIgnCase(key, "--os-file"))
ffOptionParseString(key, value, &options->osFile);
else if(ffStrEqualsIgnCase(key, "--ds-force-drm"))
options->dsForceDrm = ffOptionParseBoolean(value);
{
if (ffOptionParseBoolean(value))
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_TRUE;
else if (ffStrEqualsIgnCase(value, "sysfs-only"))
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY;
else
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE;
}
#elif defined(_WIN32)
else if (ffStrEqualsIgnCase(key, "--wmi-timeout"))
options->wmiTimeout = ffOptionParseInt32(key, value);
@ -86,7 +110,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options)
options->escapeBedrock = true;
ffStrbufInit(&options->playerName);
ffStrbufInit(&options->osFile);
options->dsForceDrm = false;
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE;
#elif defined(_WIN32)
options->wmiTimeout = 5000;
#endif
@ -125,7 +149,20 @@ void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_do
yyjson_mut_obj_add_strbuf(doc, obj, "osFile", &options->osFile);
if (options->dsForceDrm != defaultOptions.dsForceDrm)
yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", options->dsForceDrm);
{
switch (options->dsForceDrm)
{
case FF_DS_FORCE_DRM_TYPE_FALSE:
yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", false);
break;
case FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY:
yyjson_mut_obj_add_str(doc, obj, "dsForceDrm", "sysfs-only");
break;
case FF_DS_FORCE_DRM_TYPE_TRUE:
yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", true);
break;
}
}
#elif defined(_WIN32)

View File

@ -2,6 +2,13 @@
#include "util/FFstrbuf.h"
typedef enum FFDsForceDrmType
{
FF_DS_FORCE_DRM_TYPE_FALSE = 0, // Disable
FF_DS_FORCE_DRM_TYPE_TRUE = 1, // Try `libdrm`, then `sysfs` if libdrm failed
FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY, // Use `/sys/class/drm` only
} FFDsForceDrmType;
typedef struct FFOptionsGeneral
{
bool multithreading;
@ -12,7 +19,7 @@ typedef struct FFOptionsGeneral
FFstrbuf playerName;
FFstrbuf osFile;
bool escapeBedrock;
bool dsForceDrm;
FFDsForceDrmType dsForceDrm;
#elif defined(_WIN32)
int32_t wmiTimeout;
#endif