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

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