开机动画的自定义
开机动画通过plymouth实现的,我们的需求是:开机时播放1遍动画,然后显示最后一帧直到GUI界面显示。
这个库没有文档说明支持哪些配置字段,所以有2个思路:
- 找一些开源的plymouth theme,看别人是怎么写配置的
- 看源码
最终问题的解决是通过看源码。
plymouth 简介
每一个plymouth主题主要由2个部分组成:
- 图片序列
- 配置文件
例如:
动画的实现原理就是连续渲染图片序列。plymouth有2种不同的动画:
- progress
- throbber (或者animation)
这两种动画类型对应着不同的图片序列前缀,以arch-glow-theme 为例:
根据源码中的写法,animation是throbber的替代,为了兼容而保留着throbber.
关键代码
// src/plugins/splash/two-step/plugin.c/view_load_end_animation(view_t *)
...
ply_trace ("now trying more general prefix: animation-");
view->end_animation = ply_animation_new (plugin->animation_dir,
"animation-");
if (ply_animation_load (view->end_animation))
return;
ply_animation_free (view->end_animation);
ply_trace ("now trying old compat prefix: throbber-");
view->end_animation = ply_animation_new (plugin->animation_dir,
"throbber-");
if (ply_animation_load (view->end_animation)) {
/* files named throbber- are for end animation, so
* there's no throbber */
ply_throbber_free (view->throbber);
view->throbber = NULL;
return;
}
...
plymouth在播放动画时会前后播放代表不同阶段的动画:
// src/plugins/splash/two-step/plugin.c/view_load(view_t *)
...
if (view->progress_animation != NULL) {
ply_trace ("loading progress animation");
if (!ply_progress_animation_load (view->progress_animation)) {
ply_trace ("optional progress animation wouldn't load");
ply_progress_animation_free (view->progress_animation);
view->progress_animation = NULL;
}
} else {
ply_trace ("this theme has no progress animation");
}
if (view->throbber != NULL) {
ply_trace ("loading throbber");
if (!ply_throbber_load (view->throbber)) {
ply_trace ("optional throbber was not loaded");
ply_throbber_free (view->throbber);
view->throbber = NULL;
}
} else {
ply_trace ("this theme has no throbber\\n");
}
...
回到我们的需求,为了只播放一次,所以只保留throbber图片序列,为了在动画结束后显示最后一帧,配置文件设置 UseEndAnimation=true
(该字段默认就是true, 所以不用特意写)。
以上内容仅供参考,如有不准确的地方还请指正。