From: Ray Strode Date: Sat, 30 Nov 2013 04:02:34 +0000 (-0500) Subject: renderer: use enum for selecting renderer type, not plugin path X-Git-Tag: 0.9.0~65^2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67addd18e3cd04be2955435d06ae8b5b1fc03b18;p=thirdparty%2Fplymouth.git renderer: use enum for selecting renderer type, not plugin path ply_renderer_new takes a path to a renderer plugin, or NULL to try each one in turn. It's cleaner to abstract the path behind an enum type, so this commit makes that change. Now it will be possible to instantiate specific renderers without hardcoding the paths to plugins in more than one place. --- diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 93d93450..7e69675f 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -914,7 +914,7 @@ main (int argc, return errno; } - renderer = ply_renderer_new (NULL, terminal); + renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, terminal); free(tty_name); if (!ply_renderer_open (renderer)) diff --git a/src/libply-splash-core/ply-renderer.c b/src/libply-splash-core/ply-renderer.c index 3559e013..39fbf9ab 100644 --- a/src/libply-splash-core/ply-renderer.c +++ b/src/libply-splash-core/ply-renderer.c @@ -49,7 +49,7 @@ struct _ply_renderer const ply_renderer_plugin_interface_t *plugin_interface; ply_renderer_backend_t *backend; - char *plugin_path; + ply_renderer_type_t type; char *device_name; ply_terminal_t *terminal; @@ -63,16 +63,15 @@ typedef const ply_renderer_plugin_interface_t * static void ply_renderer_unload_plugin (ply_renderer_t *renderer); ply_renderer_t * -ply_renderer_new (const char *plugin_path, - const char *device_name, - ply_terminal_t *terminal) +ply_renderer_new (ply_renderer_type_t renderer_type, + const char *device_name, + ply_terminal_t *terminal) { ply_renderer_t *renderer; renderer = calloc (1, sizeof (struct _ply_renderer)); - if (plugin_path != NULL) - renderer->plugin_path = strdup (plugin_path); + renderer->type = renderer_type; if (device_name != NULL) renderer->device_name = strdup (device_name); @@ -95,7 +94,6 @@ ply_renderer_free (ply_renderer_t *renderer) } free (renderer->device_name); - free (renderer->plugin_path); free (renderer); } @@ -258,29 +256,28 @@ ply_renderer_open (ply_renderer_t *renderer) { int i; - /* FIXME: at some point we may want to make this - * part more dynamic (so you don't have to edit this - * list to add a new renderer) - */ - const char *known_plugins[] = + struct { - PLYMOUTH_PLUGIN_PATH "renderers/x11.so", - PLYMOUTH_PLUGIN_PATH "renderers/drm.so", - PLYMOUTH_PLUGIN_PATH "renderers/frame-buffer.so", - NULL + ply_renderer_type_t type; + const char *path; + } known_plugins[] = + { + { PLY_RENDERER_TYPE_X11, PLYMOUTH_PLUGIN_PATH "renderers/x11.so" }, + { PLY_RENDERER_TYPE_DRM, PLYMOUTH_PLUGIN_PATH "renderers/drm.so" }, + { PLY_RENDERER_TYPE_FRAME_BUFFER, PLYMOUTH_PLUGIN_PATH "renderers/frame-buffer.so" }, + { PLY_RENDERER_TYPE_NONE, NULL } }; - if (renderer->plugin_path != NULL) + for (i = 0; known_plugins[i].type != PLY_RENDERER_TYPE_NONE; i++) { - return ply_renderer_open_plugin (renderer, renderer->plugin_path); + if (renderer->type == known_plugins[i].type || + renderer->type == PLY_RENDERER_TYPE_AUTO) + { + if (ply_renderer_open_plugin (renderer, known_plugins[i].path)) + return true; + } } - for (i = 0; known_plugins[i] != NULL; i++) - { - if (ply_renderer_open_plugin (renderer, known_plugins[i])) - return true; - } - ply_trace ("could not find suitable rendering plugin"); return false; } diff --git a/src/libply-splash-core/ply-renderer.h b/src/libply-splash-core/ply-renderer.h index 4b3bd1a3..75c39fab 100644 --- a/src/libply-splash-core/ply-renderer.h +++ b/src/libply-splash-core/ply-renderer.h @@ -35,12 +35,21 @@ typedef struct _ply_renderer ply_renderer_t; typedef struct _ply_renderer_head ply_renderer_head_t; typedef struct _ply_renderer_input_source ply_renderer_input_source_t; +typedef enum +{ + PLY_RENDERER_TYPE_NONE = -1, + PLY_RENDERER_TYPE_AUTO, + PLY_RENDERER_TYPE_DRM, + PLY_RENDERER_TYPE_FRAME_BUFFER, + PLY_RENDERER_TYPE_X11 +} ply_renderer_type_t; + typedef void (* ply_renderer_input_source_handler_t) (void *user_data, ply_buffer_t *key_buffer, ply_renderer_input_source_t *input_source); #ifndef PLY_HIDE_FUNCTION_DECLARATIONS -ply_renderer_t *ply_renderer_new (const char *plugin_path, +ply_renderer_t *ply_renderer_new (ply_renderer_type_t renderer_type, const char *device_name, ply_terminal_t *terminal); void ply_renderer_free (ply_renderer_t *renderer); diff --git a/src/main.c b/src/main.c index 4dceb9ab..6ef7bff2 100644 --- a/src/main.c +++ b/src/main.c @@ -1577,7 +1577,7 @@ add_default_displays_and_keyboard (state_t *state) state->local_console_terminal = ply_terminal_new (state->default_tty); - renderer = ply_renderer_new (NULL, NULL, state->local_console_terminal); + renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, state->local_console_terminal); if (!ply_renderer_open (renderer)) {