系统开机第一个程序的进程是init,它的源码位于system/core/init/init.c,其中函数load_565rle_image负责logo的显示,如果读取成功,就在/dev/graphics/fb0显示图片,如果读取失败,则将/dev/tty0设为文本模式,并打开/dev/tty0并输出android字样。之后会显示android开机动画(其实两张图片做成的效果),logo图片由INIT_IMAGE_FILE(在init.h中)指定。
- int load_565rle_image(char *fn)
-
{
-
struct FB fb;
-
struct stat s;
-
unsigned short *data, *bits, *ptr;
-
unsigned count, max;
-
int fd;
-
-
if (vt_set_mode(1))
-
return -1;
-
-
fd = open(fn, O_RDONLY);
-
if (fd < 0) {
-
ERROR("cannot open '%s'\n", fn);
-
goto fail_restore_text;
-
}
-
-
if (fstat(fd, &s) < 0) {
-
goto fail_close_file;
-
}
-
-
data = mmap(0, s.st_size, PROT_READ, MAP_SHARED, fd, 0);
-
if (data == MAP_FAILED)
-
goto fail_close_file;
-
-
if (fb_open(&fb))
-
goto fail_unmap_data;
-
-
max = fb_width(&fb) * fb_height(&fb);
-
ptr = data;
-
count = s.st_size;
-
bits = fb.bits;
-
while (count > 3) {
-
unsigned n = ptr[0];
-
if (n > max)
-
break;
-
android_memset16(bits, ptr[1], n << 1);
-
bits += n;
-
max -= n;
-
ptr += 2;
-
count -= 4;
-
}
-
-
munmap(data, s.st_size);
-
fb_update(&fb);
-
fb_close(&fb);
-
close(fd);
-
unlink(fn);
-
return 0;
-
-
fail_unmap_data:
-
munmap(data, s.st_size);
-
fail_close_file:
-
close(fd);
-
fail_restore_text:
-
vt_set_mode(0);
-
return -1;
-
}
如果是显示文本的话,则是和/dev/tty0打交道,而如果是图片的话,则是通过mmap将图片内容写到framebuffer的存储空间来完成。
- static int console_init_action(int nargs, char **args)
-
{
-
int fd;
-
char tmp[PROP_VALUE_MAX];
-
-
if (console[0]) {
-
snprintf(tmp, sizeof(tmp), "/dev/%s", console);
-
console_name = strdup(tmp);
-
}
-
-
fd = open(console_name, O_RDWR);
-
if (fd >= 0)
-
have_console = 1;
-
close(fd);
-
-
if( load_565rle_image(INIT_IMAGE_FILE) ) {
-
fd = open("/dev/tty0", O_WRONLY);
-
if (fd >= 0) {
-
const char *msg;
-
msg = "\n"
-
"\n"
-
"\n"
-
"\n"
-
"\n"
-
"\n"
-
"\n" // console is 40 cols x 30 lines
-
"\n"
-
"\n"
-
"\n"
-
"\n"
-
"\n"
-
"\n"
-
"\n"
-
" A N D R O I D ";
-
write(fd, msg, strlen(msg));
-
close(fd);
-
}
-
}
-
return 0;
-
}
而开机的那段动画即晃动的android字样是由两幅图片组成,一张前景,一张背景,位于
代码位于frameworks/base/cmds/bootanimation/BootAnimation.cpp
- if(ForcePortraitLCD == true){
-
initTexture(&mAndroid[0], mAssets, "images/android-logo-mask-vertical.png");
-
initTexture(&mAndroid[1], mAssets, "images/android-logo-shine-vertical.png");
-
}else{
-
initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
-
initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
-
}
阅读(4951) | 评论(0) | 转发(0) |