Skip to content

Commit

Permalink
drm, launcher: Allow passing parameters at platform setup time
Browse files Browse the repository at this point in the history
Add a new --platform-params/-O command line option and have its value
passed down to cog_platform_setup() to allow passing an arbitrary string
to the platform module initialization. While at it, allow setting both
the rotation and renderer properties of CogDrmPlatform this way, which
is in particular important for the renderer property because it is
construct-only and there is no suitable mechanism to set construct-only
properties for CogPlatform subclasses at the moment.
  • Loading branch information
aperezdc committed Dec 8, 2021
1 parent 887c878 commit 583c528
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 31 deletions.
5 changes: 4 additions & 1 deletion launcher/cog-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static struct {
};
GStrv arguments;
char *background_color;
char *platform_params;
union {
char *platform_name;
};
Expand Down Expand Up @@ -219,7 +220,7 @@ platform_setup(CogLauncher *self)
}
g_clear_pointer(&s_options.platform_name, g_free);

if (!cog_platform_setup(platform, self->shell, "", &error)) {
if (!cog_platform_setup(platform, self->shell, s_options.platform_params ?: "", &error)) {
g_warning("Platform setup failed: %s", error->message);
return FALSE;
}
Expand Down Expand Up @@ -1000,6 +1001,8 @@ static GOptionEntry s_cli_options[] = {
{"bg-color", 'b', 0, G_OPTION_ARG_STRING, &s_options.background_color,
"Background color, as a CSS name or in #RRGGBBAA hex syntax (default: white)", "BG_COLOR"},
{"platform", 'P', 0, G_OPTION_ARG_STRING, &s_options.platform_name, "Platform plug-in to use.", "NAME"},
{"platform-params", 'O', 0, G_OPTION_ARG_STRING, &s_options.platform_params,
"Comma separated list of platform parameters.", "PARAMS"},
{"web-extensions-dir", '\0', 0, G_OPTION_ARG_STRING, &s_options.web_extensions_dir,
"Load Web Extensions from given directory.", "PATH"},
{"ignore-tls-errors", '\0', 0, G_OPTION_ARG_NONE, &s_options.ignore_tls_errors,
Expand Down
91 changes: 61 additions & 30 deletions platform/drm/cog-platform-drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,47 +204,78 @@ static struct {
} wpe_view_data;

static void
init_config(CogDrmPlatform *self, CogShell *shell)
init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
{
drm_data.device_scale = cog_shell_get_device_scale_factor (shell);
g_debug ("init_config: overriding device_scale value, using %.2f from shell",
drm_data.device_scale);

GKeyFile *key_file = cog_shell_get_config_file (shell);
if (!key_file)
return;

{
g_autoptr(GError) lookup_error = NULL;
gboolean value = g_key_file_get_boolean (key_file,
"drm", "disable-atomic-modesetting",
&lookup_error);
if (!lookup_error) {
drm_data.atomic_modesetting = !value;
g_debug ("init_config: atomic modesetting reconfigured to value '%s'",
drm_data.atomic_modesetting ? "true" : "false");
if (key_file) {
{
g_autoptr(GError) lookup_error = NULL;

gboolean value = g_key_file_get_boolean(key_file, "drm", "disable-atomic-modesetting", &lookup_error);
if (!lookup_error) {
drm_data.atomic_modesetting = !value;
g_debug("init_config: atomic modesetting reconfigured to value '%s'",
drm_data.atomic_modesetting ? "true" : "false");
}
}
}

{
g_autoptr(GError) lookup_error = NULL;
gdouble value = g_key_file_get_double (key_file,
"drm", "device-scale-factor",
&lookup_error);
if (!lookup_error) {
drm_data.device_scale = value;
g_debug("init_config: overriding device_scale value, using %.2f from config", drm_data.device_scale);
{
g_autoptr(GError) lookup_error = NULL;

gdouble value = g_key_file_get_double(key_file, "drm", "device-scale-factor", &lookup_error);
if (!lookup_error) {
drm_data.device_scale = value;
g_debug("init_config: overriding device_scale value, using %.2f from config", drm_data.device_scale);
}
}

{
g_autofree char *value = g_key_file_get_string(key_file, "drm", "renderer", NULL);
if (g_strcmp0(value, "gles") == 0)
self->use_gles = true;
else if (g_strcmp0(value, "modeset") != 0)
self->use_gles = false;
else if (value)
g_warning("Invalid renderer '%s', using default.", value);
}
}

{
g_autofree char *value = g_key_file_get_string(key_file, "drm", "renderer", NULL);
if (g_strcmp0(value, "gles") == 0)
self->use_gles = true;
else if (g_strcmp0(value, "modeset") != 0)
self->use_gles = false;
else if (value)
g_warning("Invalid renderer '%s', using default.", value);
if (params_string) {
g_auto(GStrv) params = g_strsplit(params_string, ",", 0);
for (unsigned i = 0; params[i]; i++) {
g_auto(GStrv) kv = g_strsplit(params[i], "=", 2);
if (g_strv_length(kv) != 2) {
g_warning("Invalid parameter syntax '%s'.", params[i]);
continue;
}

const char *k = g_strstrip(kv[0]);
const char *v = g_strstrip(kv[1]);

if (g_strcmp0(k, "renderer") == 0) {
if (g_strcmp0(v, "modeset") == 0)
self->use_gles = false;
else if (g_strcmp0(v, "gles") == 0)
self->use_gles = true;
else
g_warning("Invalid value '%s' for parameter '%s'.", v, k);
} else if (g_strcmp0(k, "rotation") == 0) {
char *endp = NULL;
const char *str = v ? v : "";
uint64_t val = g_ascii_strtoull(str, &endp, 10);
if (val > 3 || *endp != '\0')
g_warning("Invalid value '%s' for parameter '%s'.", v, k);
else
self->rotation = val;
} else {
g_warning("Invalid parameter '%s'.", k);
}
}
}
}

Expand Down Expand Up @@ -1208,7 +1239,7 @@ cog_drm_platform_setup(CogPlatform *platform, CogShell *shell, const char *param

CogDrmPlatform *self = COG_DRM_PLATFORM(platform);

init_config(COG_DRM_PLATFORM(platform), shell);
init_config(COG_DRM_PLATFORM(platform), shell, params);

if (!wpe_loader_init ("libWPEBackend-fdo-1.0.so")) {
g_set_error_literal (error,
Expand Down

0 comments on commit 583c528

Please sign in to comment.