Blame SOURCES/0001-Revert-throbgress-Remove-the-throbgress-plugin.patch

f67285
From ae48268a110722927cc9deb2f667f6327634436c Mon Sep 17 00:00:00 2001
f67285
From: Ray Strode <rstrode@redhat.com>
f67285
Date: Mon, 15 Jun 2020 10:22:20 -0400
f67285
Subject: [PATCH 1/2] Revert "throbgress: Remove the throbgress plugin"
f67285
f67285
This reverts commit a76638856d600496f8f69b308fbcf7d623430851.
f67285
---
f67285
 configure.ac                              |   1 +
f67285
 src/plugins/splash/Makefile.am            |   2 +-
f67285
 src/plugins/splash/throbgress/Makefile.am |  28 +
f67285
 src/plugins/splash/throbgress/plugin.c    | 980 ++++++++++++++++++++++
f67285
 4 files changed, 1010 insertions(+), 1 deletion(-)
f67285
 create mode 100644 src/plugins/splash/throbgress/Makefile.am
f67285
 create mode 100644 src/plugins/splash/throbgress/plugin.c
f67285
f67285
diff --git a/configure.ac b/configure.ac
f67285
index d34245a..970e19f 100644
f67285
--- a/configure.ac
f67285
+++ b/configure.ac
f67285
@@ -280,60 +280,61 @@ plymouththemedir=$datadir/plymouth/themes
f67285
 AS_AC_EXPAND(PLYMOUTH_THEME_PATH, $plymouththemedir)
f67285
 
f67285
 plymouthruntimethemedir=$plymouthruntimedir/themes
f67285
 AS_AC_EXPAND(PLYMOUTH_RUNTIME_THEME_PATH, $plymouthruntimethemedir)
f67285
 
f67285
 plymouthplugindir=$libdir/plymouth/
f67285
 AS_AC_EXPAND(PLYMOUTH_PLUGIN_PATH, $plymouthplugindir)
f67285
 
f67285
 plymouthpolicydir=$datadir/plymouth/
f67285
 AS_AC_EXPAND(PLYMOUTH_POLICY_DIR, $plymouthpolicydir)
f67285
 
f67285
 plymouthconfdir=$sysconfdir/plymouth/
f67285
 AS_AC_EXPAND(PLYMOUTH_CONF_DIR, $plymouthconfdir)
f67285
 
f67285
 AS_AC_EXPAND(PLYMOUTH_LIBDIR, $libdir)
f67285
 AS_AC_EXPAND(PLYMOUTH_LIBEXECDIR, $libexecdir)
f67285
 AS_AC_EXPAND(PLYMOUTH_DATADIR, $datadir)
f67285
 
f67285
 AC_CONFIG_FILES([Makefile po/Makefile.in
f67285
            src/libply/Makefile
f67285
            src/libply-splash-core/Makefile
f67285
            src/libply-splash-graphics/Makefile
f67285
            src/ply-splash-core.pc
f67285
            src/ply-splash-graphics.pc
f67285
            src/plugins/Makefile
f67285
            src/plugins/renderers/Makefile
f67285
            src/plugins/renderers/frame-buffer/Makefile
f67285
            src/plugins/renderers/drm/Makefile
f67285
            src/plugins/renderers/x11/Makefile
f67285
            src/plugins/splash/Makefile
f67285
+           src/plugins/splash/throbgress/Makefile
f67285
            src/plugins/splash/fade-throbber/Makefile
f67285
            src/plugins/splash/tribar/Makefile
f67285
            src/plugins/splash/text/Makefile
f67285
            src/plugins/splash/details/Makefile
f67285
            src/plugins/splash/space-flares/Makefile
f67285
            src/plugins/splash/two-step/Makefile
f67285
            src/plugins/splash/script/Makefile
f67285
            src/plugins/controls/Makefile
f67285
            src/plugins/controls/label/Makefile
f67285
            src/Makefile
f67285
            src/client/ply-boot-client.pc
f67285
            src/client/Makefile
f67285
            src/upstart-bridge/Makefile
f67285
            themes/Makefile
f67285
            themes/spinfinity/Makefile
f67285
            themes/fade-in/Makefile
f67285
            themes/tribar/Makefile
f67285
            themes/text/Makefile
f67285
            themes/details/Makefile
f67285
            themes/solar/Makefile
f67285
            themes/glow/Makefile
f67285
            themes/spinner/Makefile
f67285
            themes/script/Makefile
f67285
            themes/bgrt/Makefile
f67285
            images/Makefile
f67285
 	   scripts/plymouth-generate-initrd
f67285
 	   scripts/plymouth-populate-initrd
f67285
 	   scripts/plymouth-set-default-theme
f67285
            scripts/Makefile
f67285
            systemd-units/plymouth-halt.service
f67285
diff --git a/src/plugins/splash/Makefile.am b/src/plugins/splash/Makefile.am
f67285
index d167530..a19197b 100644
f67285
--- a/src/plugins/splash/Makefile.am
f67285
+++ b/src/plugins/splash/Makefile.am
f67285
@@ -1,2 +1,2 @@
f67285
-SUBDIRS = fade-throbber text details space-flares two-step script tribar
f67285
+SUBDIRS = throbgress fade-throbber text details space-flares two-step script tribar
f67285
 MAINTAINERCLEANFILES = Makefile.in
f67285
diff --git a/src/plugins/splash/throbgress/Makefile.am b/src/plugins/splash/throbgress/Makefile.am
f67285
new file mode 100644
f67285
index 0000000..2ac1b0c
f67285
--- /dev/null
f67285
+++ b/src/plugins/splash/throbgress/Makefile.am
f67285
@@ -0,0 +1,28 @@
f67285
+AM_CPPFLAGS = -I$(top_srcdir)                                                 \
f67285
+           -I$(srcdir)/../../../libply                                        \
f67285
+           -I$(srcdir)/../../../libply-splash-core                            \
f67285
+           -I$(srcdir)/../../../libply-splash-graphics                        \
f67285
+           -I$(srcdir)/../../..                                               \
f67285
+           -I$(srcdir)/../..                                                  \
f67285
+           -I$(srcdir)/..                                                     \
f67285
+           -I$(srcdir)
f67285
+
f67285
+plugindir = $(libdir)/plymouth
f67285
+plugin_LTLIBRARIES = throbgress.la
f67285
+
f67285
+throbgress_la_CFLAGS = $(PLYMOUTH_CFLAGS)                                    \
f67285
+                       -DPLYMOUTH_IMAGE_DIR=\"$(datadir)/plymouth/\"         \
f67285
+                       -DPLYMOUTH_TIME_DIR=\"$(localstatedir)/lib/plymouth/\"\
f67285
+                       -DPLYMOUTH_LOGO_FILE=\"$(logofile)\"                  \
f67285
+                       -DPLYMOUTH_BACKGROUND_COLOR=$(background_color)       \
f67285
+                       -DPLYMOUTH_BACKGROUND_END_COLOR=$(background_end_color)   \
f67285
+                       -DPLYMOUTH_BACKGROUND_START_COLOR=$(background_start_color)
f67285
+
f67285
+throbgress_la_LDFLAGS = -module -avoid-version -export-dynamic
f67285
+throbgress_la_LIBADD = $(PLYMOUTH_LIBS)                                      \
f67285
+                       ../../../libply/libply.la                             \
f67285
+                       ../../../libply-splash-core/libply-splash-core.la     \
f67285
+                       ../../../libply-splash-graphics/libply-splash-graphics.la
f67285
+throbgress_la_SOURCES = $(srcdir)/plugin.c
f67285
+
f67285
+MAINTAINERCLEANFILES = Makefile.in
f67285
diff --git a/src/plugins/splash/throbgress/plugin.c b/src/plugins/splash/throbgress/plugin.c
f67285
new file mode 100644
f67285
index 0000000..86be064
f67285
--- /dev/null
f67285
+++ b/src/plugins/splash/throbgress/plugin.c
f67285
@@ -0,0 +1,980 @@
f67285
+/* throbgress.c - boot splash plugin
f67285
+ *
f67285
+ * Copyright (C) 2007, 2008 Red Hat, Inc.
f67285
+ *
f67285
+ * This program is free software; you can redistribute it and/or modify
f67285
+ * it under the terms of the GNU General Public License as published by
f67285
+ * the Free Software Foundation; either version 2, or (at your option)
f67285
+ * any later version.
f67285
+ *
f67285
+ * This program is distributed in the hope that it will be useful,
f67285
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
f67285
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f67285
+ * GNU General Public License for more details.
f67285
+ *
f67285
+ * You should have received a copy of the GNU General Public License
f67285
+ * along with this program; if not, write to the Free Software
f67285
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
f67285
+ * 02111-1307, USA.
f67285
+ *
f67285
+ * Written by: Ray Strode <rstrode@redhat.com>
f67285
+ *             Will Woods <wwoods@redhat.com>
f67285
+ */
f67285
+#include "config.h"
f67285
+
f67285
+#include <assert.h>
f67285
+#include <errno.h>
f67285
+#include <fcntl.h>
f67285
+#include <math.h>
f67285
+#include <signal.h>
f67285
+#include <stdbool.h>
f67285
+#include <stdio.h>
f67285
+#include <stdint.h>
f67285
+#include <stdlib.h>
f67285
+#include <string.h>
f67285
+#include <sys/ioctl.h>
f67285
+#include <sys/stat.h>
f67285
+#include <sys/time.h>
f67285
+#include <sys/types.h>
f67285
+#include <values.h>
f67285
+#include <unistd.h>
f67285
+#include <wchar.h>
f67285
+
f67285
+#include "ply-boot-splash-plugin.h"
f67285
+#include "ply-buffer.h"
f67285
+#include "ply-entry.h"
f67285
+#include "ply-event-loop.h"
f67285
+#include "ply-key-file.h"
f67285
+#include "ply-label.h"
f67285
+#include "ply-list.h"
f67285
+#include "ply-progress-bar.h"
f67285
+#include "ply-logger.h"
f67285
+#include "ply-image.h"
f67285
+#include "ply-trigger.h"
f67285
+#include "ply-pixel-buffer.h"
f67285
+#include "ply-pixel-display.h"
f67285
+#include "ply-utils.h"
f67285
+
f67285
+#include "ply-throbber.h"
f67285
+
f67285
+#ifndef FRAMES_PER_SECOND
f67285
+#define FRAMES_PER_SECOND 30
f67285
+#endif
f67285
+
f67285
+#ifndef BAR_HEIGHT
f67285
+#define BAR_HEIGHT 16
f67285
+#endif
f67285
+
f67285
+typedef enum
f67285
+{
f67285
+        PLY_BOOT_SPLASH_DISPLAY_NORMAL,
f67285
+        PLY_BOOT_SPLASH_DISPLAY_QUESTION_ENTRY,
f67285
+        PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY
f67285
+} ply_boot_splash_display_type_t;
f67285
+
f67285
+typedef struct
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+        ply_pixel_display_t      *display;
f67285
+        ply_entry_t              *entry;
f67285
+        ply_throbber_t           *throbber;
f67285
+        ply_progress_bar_t       *progress_bar;
f67285
+        ply_label_t              *label;
f67285
+        ply_label_t              *message_label;
f67285
+        ply_rectangle_t           box_area, lock_area, logo_area, bar_area;
f67285
+} view_t;
f67285
+
f67285
+struct _ply_boot_splash_plugin
f67285
+{
f67285
+        ply_event_loop_t              *loop;
f67285
+        ply_boot_splash_mode_t         mode;
f67285
+        ply_image_t                   *logo_image;
f67285
+        ply_image_t                   *lock_image;
f67285
+        ply_image_t                   *box_image;
f67285
+        ply_list_t                    *views;
f67285
+
f67285
+        char                          *image_dir;
f67285
+        ply_boot_splash_display_type_t state;
f67285
+
f67285
+        uint32_t                       background_start_color;
f67285
+        uint32_t                       background_end_color;
f67285
+
f67285
+        ply_trigger_t                 *idle_trigger;
f67285
+
f67285
+        uint32_t                       root_is_mounted : 1;
f67285
+        uint32_t                       is_visible : 1;
f67285
+        uint32_t                       is_animating : 1;
f67285
+        uint32_t                       is_idle : 1;
f67285
+};
f67285
+
f67285
+ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void);
f67285
+static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin);
f67285
+
f67285
+static void become_idle (ply_boot_splash_plugin_t *plugin,
f67285
+                         ply_trigger_t            *idle_trigger);
f67285
+
f67285
+static view_t *
f67285
+view_new (ply_boot_splash_plugin_t *plugin,
f67285
+          ply_pixel_display_t      *display)
f67285
+{
f67285
+        view_t *view;
f67285
+
f67285
+        view = calloc (1, sizeof(view_t));
f67285
+        view->plugin = plugin;
f67285
+        view->display = display;
f67285
+
f67285
+        view->entry = ply_entry_new (plugin->image_dir);
f67285
+        view->throbber = ply_throbber_new (plugin->image_dir,
f67285
+                                           "throbber-");
f67285
+        view->progress_bar = ply_progress_bar_new ();
f67285
+        view->label = ply_label_new ();
f67285
+        view->message_label = ply_label_new ();
f67285
+
f67285
+        return view;
f67285
+}
f67285
+
f67285
+static void
f67285
+view_free (view_t *view)
f67285
+{
f67285
+        ply_entry_free (view->entry);
f67285
+        ply_throbber_free (view->throbber);
f67285
+        ply_progress_bar_free (view->progress_bar);
f67285
+        ply_label_free (view->label);
f67285
+        ply_label_free (view->message_label);
f67285
+
f67285
+        free (view);
f67285
+}
f67285
+
f67285
+static void
f67285
+free_views (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                view_free (view);
f67285
+                ply_list_remove_node (plugin->views, node);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+
f67285
+        ply_list_free (plugin->views);
f67285
+        plugin->views = NULL;
f67285
+}
f67285
+
f67285
+static bool
f67285
+view_load (view_t *view)
f67285
+{
f67285
+        ply_trace ("loading entry");
f67285
+        if (!ply_entry_load (view->entry))
f67285
+                return false;
f67285
+
f67285
+        ply_trace ("loading throbber");
f67285
+        if (!ply_throbber_load (view->throbber))
f67285
+                return false;
f67285
+
f67285
+        return true;
f67285
+}
f67285
+
f67285
+static bool
f67285
+load_views (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+        bool view_loaded;
f67285
+
f67285
+        view_loaded = false;
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                if (view_load (view))
f67285
+                        view_loaded = true;
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+
f67285
+        return view_loaded;
f67285
+}
f67285
+
f67285
+static void
f67285
+view_redraw (view_t *view)
f67285
+{
f67285
+        unsigned long screen_width, screen_height;
f67285
+
f67285
+        screen_width = ply_pixel_display_get_width (view->display);
f67285
+        screen_height = ply_pixel_display_get_height (view->display);
f67285
+
f67285
+        ply_pixel_display_draw_area (view->display, 0, 0,
f67285
+                                     screen_width, screen_height);
f67285
+}
f67285
+
f67285
+static void
f67285
+redraw_views (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                view_redraw (view);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+pause_views (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        ply_trace ("pausing views");
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                ply_pixel_display_pause_updates (view->display);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+unpause_views (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        ply_trace ("unpausing views");
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                ply_pixel_display_unpause_updates (view->display);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+view_start_animation (view_t *view)
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+
f67285
+        unsigned long screen_width, screen_height;
f67285
+        long width, height;
f67285
+
f67285
+        assert (view != NULL);
f67285
+
f67285
+        plugin = view->plugin;
f67285
+
f67285
+        assert (plugin != NULL);
f67285
+        assert (plugin->loop != NULL);
f67285
+
f67285
+        screen_width = ply_pixel_display_get_width (view->display);
f67285
+        screen_height = ply_pixel_display_get_height (view->display);
f67285
+
f67285
+        ply_pixel_display_draw_area (view->display, 0, 0,
f67285
+                                     screen_width, screen_height);
f67285
+
f67285
+        if (plugin->mode == PLY_BOOT_SPLASH_MODE_SHUTDOWN ||
f67285
+            plugin->mode == PLY_BOOT_SPLASH_MODE_REBOOT)
f67285
+                return;
f67285
+
f67285
+        plugin->is_idle = false;
f67285
+
f67285
+        width = ply_throbber_get_width (view->throbber);
f67285
+        height = ply_throbber_get_height (view->throbber);
f67285
+        ply_throbber_start (view->throbber,
f67285
+                            plugin->loop,
f67285
+                            view->display,
f67285
+                            screen_width / 2.0 - width / 2.0,
f67285
+                            view->logo_area.y + view->logo_area.height + height / 2);
f67285
+        ply_progress_bar_show (view->progress_bar,
f67285
+                               view->display,
f67285
+                               0,
f67285
+                               screen_height - BAR_HEIGHT,
f67285
+                               screen_width,
f67285
+                               BAR_HEIGHT);
f67285
+        view_redraw (view);
f67285
+}
f67285
+
f67285
+static void
f67285
+view_show_prompt (view_t     *view,
f67285
+                  const char *prompt)
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+        int x, y;
f67285
+        int entry_width, entry_height;
f67285
+
f67285
+        assert (view != NULL);
f67285
+
f67285
+        plugin = view->plugin;
f67285
+
f67285
+        if (ply_entry_is_hidden (view->entry)) {
f67285
+                unsigned long screen_width, screen_height;
f67285
+
f67285
+                screen_width = ply_pixel_display_get_width (view->display);
f67285
+                screen_height = ply_pixel_display_get_height (view->display);
f67285
+
f67285
+                view->box_area.width = ply_image_get_width (plugin->box_image);
f67285
+                view->box_area.height = ply_image_get_height (plugin->box_image);
f67285
+                view->box_area.x = screen_width / 2.0 - view->box_area.width / 2.0;
f67285
+                view->box_area.y = screen_height / 2.0 - view->box_area.height / 2.0;
f67285
+
f67285
+                view->lock_area.width = ply_image_get_width (plugin->lock_image);
f67285
+                view->lock_area.height = ply_image_get_height (plugin->lock_image);
f67285
+
f67285
+                entry_width = ply_entry_get_width (view->entry);
f67285
+                entry_height = ply_entry_get_height (view->entry);
f67285
+
f67285
+                x = screen_width / 2.0 - (view->lock_area.width + entry_width) / 2.0 + view->lock_area.width;
f67285
+                y = screen_height / 2.0 - entry_height / 2.0;
f67285
+
f67285
+                view->lock_area.x = screen_width / 2.0 - (view->lock_area.width + entry_width) / 2.0;
f67285
+                view->lock_area.y = screen_height / 2.0 - view->lock_area.height / 2.0;
f67285
+
f67285
+                ply_entry_show (view->entry, plugin->loop, view->display, x, y);
f67285
+        }
f67285
+
f67285
+        if (prompt != NULL) {
f67285
+                ply_label_set_text (view->label, prompt);
f67285
+
f67285
+                x = view->box_area.x + view->lock_area.width / 2;
f67285
+                y = view->box_area.y + view->box_area.height;
f67285
+
f67285
+                ply_label_show (view->label, view->display, x, y);
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+view_hide_prompt (view_t *view)
f67285
+{
f67285
+        assert (view != NULL);
f67285
+
f67285
+        ply_entry_hide (view->entry);
f67285
+        ply_label_hide (view->label);
f67285
+}
f67285
+
f67285
+static ply_boot_splash_plugin_t *
f67285
+create_plugin (ply_key_file_t *key_file)
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+        char *image_dir, *image_path;
f67285
+        char *color;
f67285
+
f67285
+        srand ((int) ply_get_timestamp ());
f67285
+        plugin = calloc (1, sizeof(ply_boot_splash_plugin_t));
f67285
+
f67285
+        plugin->logo_image = ply_image_new (PLYMOUTH_LOGO_FILE);
f67285
+        image_dir = ply_key_file_get_value (key_file, "throbgress", "ImageDir");
f67285
+
f67285
+        asprintf (&image_path, "%s/lock.png", image_dir);
f67285
+        plugin->lock_image = ply_image_new (image_path);
f67285
+        free (image_path);
f67285
+
f67285
+        asprintf (&image_path, "%s/box.png", image_dir);
f67285
+        plugin->box_image = ply_image_new (image_path);
f67285
+        free (image_path);
f67285
+
f67285
+        plugin->image_dir = image_dir;
f67285
+        plugin->views = ply_list_new ();
f67285
+
f67285
+        color = ply_key_file_get_value (key_file, "throbgress", "BackgroundStartColor");
f67285
+
f67285
+        if (color != NULL)
f67285
+                plugin->background_start_color = strtol (color, NULL, 0);
f67285
+        else
f67285
+                plugin->background_start_color = PLYMOUTH_BACKGROUND_START_COLOR;
f67285
+
f67285
+        free (color);
f67285
+
f67285
+        color = ply_key_file_get_value (key_file, "throbgress", "BackgroundEndColor");
f67285
+
f67285
+        if (color != NULL)
f67285
+                plugin->background_end_color = strtol (color, NULL, 0);
f67285
+        else
f67285
+                plugin->background_end_color = PLYMOUTH_BACKGROUND_END_COLOR;
f67285
+
f67285
+        free (color);
f67285
+
f67285
+        return plugin;
f67285
+}
f67285
+
f67285
+static void
f67285
+destroy_plugin (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        if (plugin == NULL)
f67285
+                return;
f67285
+
f67285
+        ply_trace ("destroying plugin");
f67285
+
f67285
+        if (plugin->loop != NULL) {
f67285
+                ply_event_loop_stop_watching_for_exit (plugin->loop, (ply_event_loop_exit_handler_t)
f67285
+                                                       detach_from_event_loop,
f67285
+                                                       plugin);
f67285
+                detach_from_event_loop (plugin);
f67285
+        }
f67285
+
f67285
+        ply_image_free (plugin->logo_image);
f67285
+        ply_image_free (plugin->box_image);
f67285
+        ply_image_free (plugin->lock_image);
f67285
+
f67285
+        free_views (plugin);
f67285
+
f67285
+        free (plugin);
f67285
+}
f67285
+
f67285
+static void
f67285
+draw_background (view_t             *view,
f67285
+                 ply_pixel_buffer_t *pixel_buffer,
f67285
+                 int                 x,
f67285
+                 int                 y,
f67285
+                 int                 width,
f67285
+                 int                 height)
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+        ply_rectangle_t area;
f67285
+
f67285
+        plugin = view->plugin;
f67285
+
f67285
+        area.x = x;
f67285
+        area.y = y;
f67285
+        area.width = width;
f67285
+        area.height = height;
f67285
+
f67285
+        if (plugin->background_start_color != plugin->background_end_color)
f67285
+                ply_pixel_buffer_fill_with_gradient (pixel_buffer, &area,
f67285
+                                                     plugin->background_start_color,
f67285
+                                                     plugin->background_end_color);
f67285
+        else
f67285
+                ply_pixel_buffer_fill_with_hex_color (pixel_buffer, &area,
f67285
+                                                      plugin->background_start_color);
f67285
+}
f67285
+
f67285
+static void
f67285
+draw_logo (view_t             *view,
f67285
+           ply_pixel_buffer_t *pixel_buffer)
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+        uint32_t *logo_data;
f67285
+        unsigned long screen_width, screen_height;
f67285
+        long width, height;
f67285
+
f67285
+        plugin = view->plugin;
f67285
+
f67285
+        screen_width = ply_pixel_display_get_width (view->display);
f67285
+        screen_height = ply_pixel_display_get_height (view->display);
f67285
+
f67285
+        width = ply_image_get_width (plugin->logo_image);
f67285
+        height = ply_image_get_height (plugin->logo_image);
f67285
+        logo_data = ply_image_get_data (plugin->logo_image);
f67285
+        view->logo_area.x = (screen_width / 2) - (width / 2);
f67285
+        view->logo_area.y = (screen_height / 2) - (height / 2);
f67285
+        view->logo_area.width = width;
f67285
+        view->logo_area.height = height;
f67285
+
f67285
+        ply_pixel_buffer_fill_with_argb32_data (pixel_buffer,
f67285
+                                                &view->logo_area,
f67285
+                                                logo_data);
f67285
+}
f67285
+
f67285
+static void
f67285
+start_animation (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        if (plugin->is_animating)
f67285
+                return;
f67285
+
f67285
+        ply_trace ("starting animation");
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                view_start_animation (view);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+
f67285
+        plugin->is_animating = true;
f67285
+
f67285
+        if (plugin->mode == PLY_BOOT_SPLASH_MODE_SHUTDOWN ||
f67285
+            plugin->mode == PLY_BOOT_SPLASH_MODE_REBOOT)
f67285
+                plugin->is_idle = true;
f67285
+}
f67285
+
f67285
+static void
f67285
+stop_animation (ply_boot_splash_plugin_t *plugin,
f67285
+                ply_trigger_t            *trigger)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        assert (plugin != NULL);
f67285
+        assert (plugin->loop != NULL);
f67285
+
f67285
+        if (!plugin->is_animating)
f67285
+                return;
f67285
+
f67285
+        ply_trace ("stopping animation%s",
f67285
+                   trigger != NULL ? " with trigger" : "");
f67285
+
f67285
+        plugin->is_animating = false;
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                ply_progress_bar_hide (view->progress_bar);
f67285
+                if (trigger != NULL)
f67285
+                        ply_trigger_ignore_next_pull (trigger);
f67285
+                ply_throbber_stop (view->throbber, trigger);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+
f67285
+        if (trigger != NULL)
f67285
+                ply_trigger_pull (trigger, NULL);
f67285
+}
f67285
+
f67285
+static void
f67285
+detach_from_event_loop (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        plugin->loop = NULL;
f67285
+}
f67285
+
f67285
+static void
f67285
+on_draw (view_t             *view,
f67285
+         ply_pixel_buffer_t *pixel_buffer,
f67285
+         int                 x,
f67285
+         int                 y,
f67285
+         int                 width,
f67285
+         int                 height)
f67285
+{
f67285
+        ply_boot_splash_plugin_t *plugin;
f67285
+
f67285
+        plugin = view->plugin;
f67285
+
f67285
+        draw_background (view, pixel_buffer, x, y, width, height);
f67285
+
f67285
+        if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_QUESTION_ENTRY ||
f67285
+            plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) {
f67285
+                uint32_t *box_data, *lock_data;
f67285
+
f67285
+                box_data = ply_image_get_data (plugin->box_image);
f67285
+                ply_pixel_buffer_fill_with_argb32_data (pixel_buffer,
f67285
+                                                        &view->box_area,
f67285
+                                                        box_data);
f67285
+                ply_entry_draw_area (view->entry, pixel_buffer, x, y, width, height);
f67285
+                ply_label_draw_area (view->label, pixel_buffer, x, y, width, height);
f67285
+                lock_data = ply_image_get_data (plugin->lock_image);
f67285
+                ply_pixel_buffer_fill_with_argb32_data (pixel_buffer,
f67285
+                                                        &view->lock_area,
f67285
+                                                        lock_data);
f67285
+        } else {
f67285
+                draw_logo (view, pixel_buffer);
f67285
+                ply_throbber_draw_area (view->throbber,
f67285
+                                        pixel_buffer, x, y, width, height);
f67285
+                ply_progress_bar_draw_area (view->progress_bar,
f67285
+                                            pixel_buffer, x, y, width, height);
f67285
+        }
f67285
+        ply_label_draw_area (view->message_label,
f67285
+                             pixel_buffer,
f67285
+                             x, y, width, height);
f67285
+}
f67285
+
f67285
+static void
f67285
+add_pixel_display (ply_boot_splash_plugin_t *plugin,
f67285
+                   ply_pixel_display_t      *display)
f67285
+{
f67285
+        view_t *view;
f67285
+
f67285
+        ply_trace ("adding pixel display to plugin");
f67285
+        view = view_new (plugin, display);
f67285
+
f67285
+        ply_pixel_display_set_draw_handler (view->display,
f67285
+                                            (ply_pixel_display_draw_handler_t)
f67285
+                                            on_draw, view);
f67285
+
f67285
+        if (plugin->is_visible) {
f67285
+                if (view_load (view))
f67285
+                        ply_list_append_data (plugin->views, view);
f67285
+                else
f67285
+                        view_free (view);
f67285
+        } else {
f67285
+                ply_list_append_data (plugin->views, view);
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+remove_pixel_display (ply_boot_splash_plugin_t *plugin,
f67285
+                      ply_pixel_display_t      *display)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        ply_trace ("removing pixel display from plugin");
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                view_t *view;
f67285
+                ply_list_node_t *next_node;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                if (view->display == display) {
f67285
+                        ply_pixel_display_set_draw_handler (view->display, NULL, NULL);
f67285
+                        view_free (view);
f67285
+                        ply_list_remove_node (plugin->views, node);
f67285
+                        return;
f67285
+                }
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static bool
f67285
+show_splash_screen (ply_boot_splash_plugin_t *plugin,
f67285
+                    ply_event_loop_t         *loop,
f67285
+                    ply_buffer_t             *boot_buffer,
f67285
+                    ply_boot_splash_mode_t    mode)
f67285
+{
f67285
+        assert (plugin != NULL);
f67285
+        assert (plugin->logo_image != NULL);
f67285
+
f67285
+        plugin->loop = loop;
f67285
+        plugin->mode = mode;
f67285
+
f67285
+        ply_trace ("loading logo image");
f67285
+        if (!ply_image_load (plugin->logo_image))
f67285
+                return false;
f67285
+
f67285
+        ply_trace ("loading lock image");
f67285
+        if (!ply_image_load (plugin->lock_image))
f67285
+                return false;
f67285
+
f67285
+        ply_trace ("loading box image");
f67285
+        if (!ply_image_load (plugin->box_image))
f67285
+                return false;
f67285
+
f67285
+        if (!load_views (plugin)) {
f67285
+                ply_trace ("couldn't load views");
f67285
+                return false;
f67285
+        }
f67285
+
f67285
+        ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t)
f67285
+                                       detach_from_event_loop,
f67285
+                                       plugin);
f67285
+
f67285
+        ply_trace ("starting boot animation");
f67285
+        start_animation (plugin);
f67285
+
f67285
+        plugin->is_visible = true;
f67285
+
f67285
+        return true;
f67285
+}
f67285
+
f67285
+static void
f67285
+update_status (ply_boot_splash_plugin_t *plugin,
f67285
+               const char               *status)
f67285
+{
f67285
+        assert (plugin != NULL);
f67285
+}
f67285
+
f67285
+static void
f67285
+on_boot_progress (ply_boot_splash_plugin_t *plugin,
f67285
+                  double                    duration,
f67285
+                  double                    percent_done)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+        double total_duration;
f67285
+
f67285
+        if (plugin->mode == PLY_BOOT_SPLASH_MODE_UPDATES ||
f67285
+            plugin->mode == PLY_BOOT_SPLASH_MODE_SYSTEM_UPGRADE ||
f67285
+            plugin->mode == PLY_BOOT_SPLASH_MODE_FIRMWARE_UPGRADE)
f67285
+                return;
f67285
+
f67285
+        total_duration = duration / percent_done;
f67285
+
f67285
+        /* Fun made-up smoothing function to make the growth asymptotic:
f67285
+         * fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */
f67285
+        percent_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - percent_done);
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                ply_progress_bar_set_percent_done (view->progress_bar, percent_done);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+hide_splash_screen (ply_boot_splash_plugin_t *plugin,
f67285
+                    ply_event_loop_t         *loop)
f67285
+{
f67285
+        assert (plugin != NULL);
f67285
+
f67285
+        ply_trace ("hiding splash");
f67285
+        if (plugin->loop != NULL) {
f67285
+                stop_animation (plugin, NULL);
f67285
+
f67285
+                ply_event_loop_stop_watching_for_exit (plugin->loop, (ply_event_loop_exit_handler_t)
f67285
+                                                       detach_from_event_loop,
f67285
+                                                       plugin);
f67285
+                detach_from_event_loop (plugin);
f67285
+        }
f67285
+
f67285
+        plugin->is_visible = false;
f67285
+}
f67285
+
f67285
+static void
f67285
+show_password_prompt (ply_boot_splash_plugin_t *plugin,
f67285
+                      const char               *text,
f67285
+                      int                       number_of_bullets)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        ply_trace ("showing password prompt");
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                view_show_prompt (view, text);
f67285
+                ply_entry_set_bullet_count (view->entry, number_of_bullets);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+show_prompt (ply_boot_splash_plugin_t *plugin,
f67285
+             const char               *prompt,
f67285
+             const char               *entry_text)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        ply_trace ("showing prompt");
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                view_show_prompt (view, prompt);
f67285
+                ply_entry_set_text (view->entry, entry_text);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+on_root_mounted (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_trace ("root filesystem mounted");
f67285
+        plugin->root_is_mounted = true;
f67285
+}
f67285
+
f67285
+static void
f67285
+become_idle (ply_boot_splash_plugin_t *plugin,
f67285
+             ply_trigger_t            *idle_trigger)
f67285
+{
f67285
+        ply_trace ("deactivation requested");
f67285
+        if (plugin->is_idle) {
f67285
+                ply_trace ("plugin is already idle");
f67285
+                ply_trigger_pull (idle_trigger, NULL);
f67285
+                return;
f67285
+        }
f67285
+
f67285
+        stop_animation (plugin, idle_trigger);
f67285
+        plugin->is_idle = true;
f67285
+}
f67285
+
f67285
+static void
f67285
+hide_prompt (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        ply_trace ("hiding prompt");
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+
f67285
+                view_hide_prompt (view);
f67285
+
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+
f67285
+static void
f67285
+show_message (ply_boot_splash_plugin_t *plugin,
f67285
+              const char               *message)
f67285
+{
f67285
+        ply_trace ("Showing message '%s'", message);
f67285
+        ply_list_node_t *node;
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+                ply_label_set_text (view->message_label, message);
f67285
+                ply_label_show (view->message_label, view->display, 10, 10);
f67285
+
f67285
+                ply_pixel_display_draw_area (view->display, 10, 10,
f67285
+                                             ply_label_get_width (view->message_label),
f67285
+                                             ply_label_get_height (view->message_label));
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+static void
f67285
+display_normal (ply_boot_splash_plugin_t *plugin)
f67285
+{
f67285
+        pause_views (plugin);
f67285
+        if (plugin->state != PLY_BOOT_SPLASH_DISPLAY_NORMAL)
f67285
+                hide_prompt (plugin);
f67285
+
f67285
+        plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL;
f67285
+        start_animation (plugin);
f67285
+        redraw_views (plugin);
f67285
+        unpause_views (plugin);
f67285
+}
f67285
+
f67285
+static void
f67285
+display_password (ply_boot_splash_plugin_t *plugin,
f67285
+                  const char               *prompt,
f67285
+                  int                       bullets)
f67285
+{
f67285
+        pause_views (plugin);
f67285
+        if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_NORMAL)
f67285
+                stop_animation (plugin, NULL);
f67285
+
f67285
+        plugin->state = PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY;
f67285
+        show_password_prompt (plugin, prompt, bullets);
f67285
+        redraw_views (plugin);
f67285
+        unpause_views (plugin);
f67285
+}
f67285
+
f67285
+static void
f67285
+display_question (ply_boot_splash_plugin_t *plugin,
f67285
+                  const char               *prompt,
f67285
+                  const char               *entry_text)
f67285
+{
f67285
+        pause_views (plugin);
f67285
+        if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_NORMAL)
f67285
+                stop_animation (plugin, NULL);
f67285
+
f67285
+        plugin->state = PLY_BOOT_SPLASH_DISPLAY_QUESTION_ENTRY;
f67285
+        show_prompt (plugin, prompt, entry_text);
f67285
+        redraw_views (plugin);
f67285
+        unpause_views (plugin);
f67285
+}
f67285
+
f67285
+static void
f67285
+display_message (ply_boot_splash_plugin_t *plugin,
f67285
+                 const char               *message)
f67285
+{
f67285
+        show_message (plugin, message);
f67285
+}
f67285
+
f67285
+static void
f67285
+system_update (ply_boot_splash_plugin_t *plugin,
f67285
+               int                       progress)
f67285
+{
f67285
+        ply_list_node_t *node;
f67285
+
f67285
+        if (plugin->mode != PLY_BOOT_SPLASH_MODE_UPDATES &&
f67285
+            plugin->mode != PLY_BOOT_SPLASH_MODE_SYSTEM_UPGRADE &&
f67285
+            plugin->mode != PLY_BOOT_SPLASH_MODE_FIRMWARE_UPGRADE)
f67285
+                return;
f67285
+
f67285
+        node = ply_list_get_first_node (plugin->views);
f67285
+        while (node != NULL) {
f67285
+                ply_list_node_t *next_node;
f67285
+                view_t *view;
f67285
+
f67285
+                view = ply_list_node_get_data (node);
f67285
+                next_node = ply_list_get_next_node (plugin->views, node);
f67285
+                ply_progress_bar_set_percent_done (view->progress_bar, (double) progress / 100.f);
f67285
+                node = next_node;
f67285
+        }
f67285
+}
f67285
+
f67285
+ply_boot_splash_plugin_interface_t *
f67285
+ply_boot_splash_plugin_get_interface (void)
f67285
+{
f67285
+        static ply_boot_splash_plugin_interface_t plugin_interface =
f67285
+        {
f67285
+                .create_plugin        = create_plugin,
f67285
+                .destroy_plugin       = destroy_plugin,
f67285
+                .add_pixel_display    = add_pixel_display,
f67285
+                .remove_pixel_display = remove_pixel_display,
f67285
+                .show_splash_screen   = show_splash_screen,
f67285
+                .update_status        = update_status,
f67285
+                .on_boot_progress     = on_boot_progress,
f67285
+                .hide_splash_screen   = hide_splash_screen,
f67285
+                .on_root_mounted      = on_root_mounted,
f67285
+                .become_idle          = become_idle,
f67285
+                .display_normal       = display_normal,
f67285
+                .display_password     = display_password,
f67285
+                .display_question     = display_question,
f67285
+                .display_message      = display_message,
f67285
+                .system_update        = system_update,
f67285
+        };
f67285
+
f67285
+        return &plugin_interface;
f67285
+}
f67285
+
f67285
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
f67285
-- 
f67285
2.21.0
f67285