mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-08 13:38:45 +02:00
Split out progress bar into its own file
Other splash screens might want to use it.
This commit is contained in:
parent
7200c851ea
commit
19a6f20290
4 changed files with 279 additions and 29 deletions
|
|
@ -6,7 +6,7 @@ INCLUDES = -I$(top_srcdir) \
|
|||
lib_LTLIBRARIES = libplybootsplash.la
|
||||
|
||||
libplybootsplashdir = $(includedir)/plymouth-1/plybootsplash
|
||||
libplybootsplash_HEADERS = ply-answer.h ply-entry.h ply-text-pulser.h ply-throbber.h ply-window.h ply-label.h ply-boot-splash-plugin.h ply-label-plugin.h
|
||||
libplybootsplash_HEADERS = ply-answer.h ply-entry.h ply-progress-bar.h ply-text-pulser.h ply-throbber.h ply-window.h ply-label.h ply-boot-splash-plugin.h ply-label-plugin.h
|
||||
|
||||
libplybootsplash_la_CFLAGS = $(PLYMOUTH_CFLAGS) \
|
||||
-DPLYMOUTH_BACKGROUND_COLOR=$(background_color) \
|
||||
|
|
@ -22,6 +22,7 @@ libplybootsplash_la_SOURCES = \
|
|||
ply-answer.c \
|
||||
ply-entry.c \
|
||||
ply-label.c \
|
||||
ply-progress-bar.c \
|
||||
ply-throbber.c \
|
||||
ply-text-pulser.c \
|
||||
ply-window.c
|
||||
|
|
|
|||
200
src/libplybootsplash/ply-progress-bar.c
Normal file
200
src/libplybootsplash/ply-progress-bar.c
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/* progress_bar.c - boot progress_bar
|
||||
*
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by: Ray Strode <rstrode@redhat.com>
|
||||
* Will Woods <wwoods@redhat.com>
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <values.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "ply-progress-bar.h"
|
||||
#include "ply-event-loop.h"
|
||||
#include "ply-array.h"
|
||||
#include "ply-logger.h"
|
||||
#include "ply-frame-buffer.h"
|
||||
#include "ply-image.h"
|
||||
#include "ply-utils.h"
|
||||
#include "ply-window.h"
|
||||
|
||||
#include <linux/kd.h>
|
||||
|
||||
#ifndef FRAMES_PER_SECOND
|
||||
#define FRAMES_PER_SECOND 30
|
||||
#endif
|
||||
|
||||
#ifndef BAR_HEIGHT
|
||||
#define BAR_HEIGHT 16
|
||||
#endif
|
||||
|
||||
struct _ply_progress_bar
|
||||
{
|
||||
ply_window_t *window;
|
||||
ply_frame_buffer_t *frame_buffer;
|
||||
ply_frame_buffer_area_t area;
|
||||
|
||||
double percent_done;
|
||||
|
||||
uint32_t is_hidden : 1;
|
||||
};
|
||||
|
||||
ply_progress_bar_t *
|
||||
ply_progress_bar_new (void)
|
||||
{
|
||||
ply_progress_bar_t *progress_bar;
|
||||
|
||||
progress_bar = calloc (1, sizeof (ply_progress_bar_t));
|
||||
|
||||
progress_bar->is_hidden = true;
|
||||
progress_bar->percent_done = 0.0;
|
||||
progress_bar->area.x = 0;
|
||||
progress_bar->area.y = 0;
|
||||
progress_bar->area.width = 0;
|
||||
progress_bar->area.height = BAR_HEIGHT;
|
||||
|
||||
return progress_bar;
|
||||
}
|
||||
|
||||
void
|
||||
ply_progress_bar_free (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
if (progress_bar == NULL)
|
||||
return;
|
||||
free (progress_bar);
|
||||
}
|
||||
|
||||
static void
|
||||
erase_progress_bar_area (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
ply_window_erase_area (progress_bar->window,
|
||||
progress_bar->area.x, progress_bar->area.y,
|
||||
progress_bar->area.width, progress_bar->area.height);
|
||||
}
|
||||
|
||||
static void
|
||||
ply_progress_bar_update_area (ply_progress_bar_t *progress_bar,
|
||||
long x,
|
||||
long y)
|
||||
{
|
||||
|
||||
long width, height;
|
||||
double fraction;
|
||||
|
||||
ply_frame_buffer_get_size (progress_bar->frame_buffer, &progress_bar->area);
|
||||
|
||||
progress_bar->area.x = x;
|
||||
progress_bar->area.y = y;
|
||||
progress_bar->area.height = BAR_HEIGHT;
|
||||
|
||||
progress_bar->area.width = (long) (progress_bar->area.width * progress_bar->percent_done);
|
||||
}
|
||||
|
||||
void
|
||||
ply_progress_bar_draw (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
|
||||
if (progress_bar->is_hidden)
|
||||
return;
|
||||
|
||||
ply_frame_buffer_pause_updates (progress_bar->frame_buffer);
|
||||
erase_progress_bar_area (progress_bar);
|
||||
ply_progress_bar_update_area (progress_bar, progress_bar->area.x, progress_bar->area.y);
|
||||
ply_frame_buffer_fill_with_hex_color (progress_bar->frame_buffer,
|
||||
&progress_bar->area,
|
||||
0xffffff); /* white */
|
||||
ply_frame_buffer_unpause_updates (progress_bar->frame_buffer);
|
||||
}
|
||||
|
||||
void
|
||||
ply_progress_bar_show (ply_progress_bar_t *progress_bar,
|
||||
ply_window_t *window,
|
||||
long x,
|
||||
long y)
|
||||
{
|
||||
assert (progress_bar != NULL);
|
||||
|
||||
progress_bar->window = window;
|
||||
progress_bar->frame_buffer = ply_window_get_frame_buffer (window);;
|
||||
|
||||
ply_progress_bar_update_area (progress_bar, x, y);
|
||||
|
||||
progress_bar->is_hidden = false;
|
||||
ply_progress_bar_draw (progress_bar);
|
||||
}
|
||||
|
||||
void
|
||||
ply_progress_bar_hide (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
erase_progress_bar_area (progress_bar);
|
||||
|
||||
progress_bar->frame_buffer = NULL;
|
||||
progress_bar->window = NULL;
|
||||
|
||||
progress_bar->is_hidden = true;
|
||||
}
|
||||
|
||||
bool
|
||||
ply_progress_bar_is_hidden (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
return progress_bar->is_hidden;
|
||||
}
|
||||
|
||||
long
|
||||
ply_progress_bar_get_width (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
return progress_bar->area.width;
|
||||
}
|
||||
|
||||
long
|
||||
ply_progress_bar_get_height (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
return progress_bar->area.height;
|
||||
}
|
||||
|
||||
void
|
||||
ply_progress_bar_set_percent_done (ply_progress_bar_t *progress_bar,
|
||||
double percent_done)
|
||||
{
|
||||
progress_bar->percent_done = percent_done;
|
||||
}
|
||||
|
||||
double
|
||||
ply_progress_bar_get_percent_done (ply_progress_bar_t *progress_bar)
|
||||
{
|
||||
return progress_bar->percent_done;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
|
||||
57
src/libplybootsplash/ply-progress-bar.h
Normal file
57
src/libplybootsplash/ply-progress-bar.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* ply-progress-bar.h - simple text bar field
|
||||
*
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written By: Ray Strode <rstrode@redhat.com>
|
||||
* Will Woods <wwoods@redhat.com>
|
||||
*/
|
||||
#ifndef PLY_PROGRESS_BAR_H
|
||||
#define PLY_PROGRESS_BAR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ply-event-loop.h"
|
||||
#include "ply-frame-buffer.h"
|
||||
#include "ply-window.h"
|
||||
|
||||
typedef struct _ply_progress_bar ply_progress_bar_t;
|
||||
|
||||
#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
|
||||
ply_progress_bar_t *ply_progress_bar_new (void);
|
||||
void ply_progress_bar_free (ply_progress_bar_t *bar);
|
||||
|
||||
void ply_progress_bar_show (ply_progress_bar_t *bar,
|
||||
ply_window_t *window,
|
||||
long x,
|
||||
long y);
|
||||
void ply_progress_bar_hide (ply_progress_bar_t *bar);
|
||||
void ply_progress_bar_draw (ply_progress_bar_t *bar);
|
||||
bool ply_progress_bar_is_hidden (ply_progress_bar_t *bar);
|
||||
|
||||
long ply_progress_bar_get_width (ply_progress_bar_t *bar);
|
||||
long ply_progress_bar_get_height (ply_progress_bar_t *bar);
|
||||
|
||||
void ply_progress_bar_set_percent_done (ply_progress_bar_t *bar,
|
||||
double percent_done);
|
||||
double ply_progress_bar_get_percent_done (ply_progress_bar_t *bar);
|
||||
#endif
|
||||
|
||||
#endif /* PLY_PROGRESS_BAR_H */
|
||||
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
|
||||
|
|
@ -47,6 +47,7 @@
|
|||
#include "ply-event-loop.h"
|
||||
#include "ply-label.h"
|
||||
#include "ply-list.h"
|
||||
#include "ply-progress-bar.h"
|
||||
#include "ply-logger.h"
|
||||
#include "ply-frame-buffer.h"
|
||||
#include "ply-image.h"
|
||||
|
|
@ -84,6 +85,7 @@ struct _ply_boot_splash_plugin
|
|||
ply_entry_t *entry;
|
||||
ply_throbber_t *throbber;
|
||||
ply_label_t *label;
|
||||
ply_progress_bar_t *progress_bar;
|
||||
|
||||
double boot_duration;
|
||||
double start_time;
|
||||
|
|
@ -114,6 +116,7 @@ create_plugin (void)
|
|||
plugin->throbber = ply_throbber_new (PLYMOUTH_IMAGE_DIR "spinfinity",
|
||||
"throbber-");
|
||||
plugin->label = ply_label_new ();
|
||||
plugin->progress_bar = ply_progress_bar_new ();
|
||||
|
||||
plugin->start_time = ply_get_timestamp ();
|
||||
plugin->boot_duration = DEFAULT_BOOT_DURATION;
|
||||
|
|
@ -163,6 +166,7 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
|
|||
ply_entry_free (plugin->entry);
|
||||
ply_throbber_free (plugin->throbber);
|
||||
ply_label_free (plugin->label);
|
||||
ply_progress_bar_free (plugin->progress_bar);
|
||||
|
||||
ply_trace ("writing boot_duration");
|
||||
/* At this point we should have a real rootfs */
|
||||
|
|
@ -220,41 +224,23 @@ draw_logo (ply_boot_splash_plugin_t *plugin)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_bar (ply_boot_splash_plugin_t *plugin)
|
||||
animate_bar (ply_boot_splash_plugin_t *plugin)
|
||||
{
|
||||
long width, height;
|
||||
double fraction;
|
||||
double duration;
|
||||
double percent_done;
|
||||
|
||||
height = BAR_HEIGHT; /* TODO: configurable */
|
||||
assert (plugin != NULL);
|
||||
assert (plugin->loop != NULL);
|
||||
|
||||
ply_frame_buffer_get_size (plugin->frame_buffer, &plugin->bar_area);
|
||||
plugin->bar_area.x = 0; /* possibly unnecessary, but hey.. can't hurt */
|
||||
plugin->bar_area.y = plugin->bar_area.height - BAR_HEIGHT;
|
||||
plugin->bar_area.height = BAR_HEIGHT;
|
||||
duration = ply_get_timestamp () - plugin->start_time;
|
||||
|
||||
/* Fun made-up smoothing function to make the growth asymptotic:
|
||||
* fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */
|
||||
fraction = 1.0-pow(2.0,-pow(ply_get_timestamp () - plugin->start_time,1.45)/plugin->boot_duration);
|
||||
percent_done = 1.0 - pow (2.0, -pow (duration, 1.45) / plugin->boot_duration);
|
||||
|
||||
width = (long) (plugin->bar_area.width * fraction);
|
||||
if (width < 0)
|
||||
width = 0;
|
||||
if (width < plugin->bar_area.width)
|
||||
plugin->bar_area.width = width;
|
||||
ply_frame_buffer_pause_updates (plugin->frame_buffer);
|
||||
draw_background (plugin, &plugin->bar_area);
|
||||
ply_frame_buffer_fill_with_hex_color (plugin->frame_buffer,
|
||||
&plugin->bar_area,
|
||||
0xffffff); /* white */
|
||||
ply_frame_buffer_unpause_updates (plugin->frame_buffer);
|
||||
}
|
||||
ply_progress_bar_set_percent_done (plugin->progress_bar, percent_done);
|
||||
ply_progress_bar_draw (plugin->progress_bar);
|
||||
|
||||
static void
|
||||
animate_bar (ply_boot_splash_plugin_t *plugin)
|
||||
{
|
||||
assert (plugin != NULL);
|
||||
assert (plugin->loop != NULL);
|
||||
draw_bar (plugin);
|
||||
ply_event_loop_watch_for_timeout(plugin->loop,
|
||||
1.0 / FRAMES_PER_SECOND,
|
||||
(ply_event_loop_timeout_handler_t)
|
||||
|
|
@ -282,6 +268,9 @@ start_animation (ply_boot_splash_plugin_t *plugin)
|
|||
plugin->window,
|
||||
area.width / 2.0 - width / 2.0,
|
||||
plugin->logo_area.y + plugin->logo_area.height + height / 2);
|
||||
ply_progress_bar_show (plugin->progress_bar,
|
||||
plugin->window,
|
||||
0, area.height - ply_progress_bar_get_height (plugin->progress_bar));
|
||||
animate_bar (plugin);
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +380,10 @@ on_draw (ply_boot_splash_plugin_t *plugin,
|
|||
ply_label_draw (plugin->label);
|
||||
}
|
||||
else
|
||||
draw_logo (plugin);
|
||||
{
|
||||
draw_logo (plugin);
|
||||
ply_progress_bar_draw (plugin->progress_bar);
|
||||
}
|
||||
ply_frame_buffer_unpause_updates (plugin->frame_buffer);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue