Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2094330
  • 博文数量: 229
  • 博客积分: 7217
  • 博客等级: 上校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 17:23
个人简介

个人主页https://xugaoxiang.com,微信公众号: Dev_Club 或者搜索 程序员Club

文章分类

全部博文(229)

文章存档

2017年(1)

2016年(20)

2015年(23)

2013年(1)

2012年(23)

2011年(68)

2010年(62)

2009年(31)

分类: LINUX

2012-02-02 12:22:10

系统开机第一个程序的进程是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中)指定。

  1. int load_565rle_image(char *fn)
  2. {
  3.     struct FB fb;
  4.     struct stat s;
  5.     unsigned short *data, *bits, *ptr;
  6.     unsigned count, max;
  7.     int fd;

  8.     if (vt_set_mode(1))
  9.         return -1;

  10.     fd = open(fn, O_RDONLY);
  11.     if (fd < 0) {
  12.         ERROR("cannot open '%s'\n", fn);
  13.         goto fail_restore_text;
  14.     }

  15.     if (fstat(fd, &s) < 0) {
  16.         goto fail_close_file;
  17.     }

  18.     data = mmap(0, s.st_size, PROT_READ, MAP_SHARED, fd, 0);
  19.     if (data == MAP_FAILED)
  20.         goto fail_close_file;

  21.     if (fb_open(&fb))
  22.         goto fail_unmap_data;

  23.     max = fb_width(&fb) * fb_height(&fb);
  24.     ptr = data;
  25.     count = s.st_size;
  26.     bits = fb.bits;
  27.     while (count > 3) {
  28.         unsigned n = ptr[0];
  29.         if (n > max)
  30.             break;
  31.         android_memset16(bits, ptr[1], n << 1);
  32.         bits += n;
  33.         max -= n;
  34.         ptr += 2;
  35.         count -= 4;
  36.     }

  37.     munmap(data, s.st_size);
  38.     fb_update(&fb);
  39.     fb_close(&fb);
  40.     close(fd);
  41.     unlink(fn);
  42.     return 0;

  43. fail_unmap_data:
  44.     munmap(data, s.st_size);
  45. fail_close_file:
  46.     close(fd);
  47. fail_restore_text:
  48.     vt_set_mode(0);
  49.     return -1;
  50. }

如果是显示文本的话,则是和/dev/tty0打交道,而如果是图片的话,则是通过mmap将图片内容写到framebuffer的存储空间来完成。
  1. static int console_init_action(int nargs, char **args)
  2. {
  3.     int fd;
  4.     char tmp[PROP_VALUE_MAX];

  5.     if (console[0]) {
  6.         snprintf(tmp, sizeof(tmp), "/dev/%s", console);
  7.         console_name = strdup(tmp);
  8.     }

  9.     fd = open(console_name, O_RDWR);
  10.     if (fd >= 0)
  11.         have_console = 1;
  12.     close(fd);

  13.     if( load_565rle_image(INIT_IMAGE_FILE) ) {
  14.         fd = open("/dev/tty0", O_WRONLY);
  15.         if (fd >= 0) {
  16.             const char *msg;
  17.                 msg = "\n"
  18.             "\n"
  19.             "\n"
  20.             "\n"
  21.             "\n"
  22.             "\n"
  23.             "\n" // console is 40 cols x 30 lines
  24.             "\n"
  25.             "\n"
  26.             "\n"
  27.             "\n"
  28.             "\n"
  29.             "\n"
  30.             "\n"
  31.             " A N D R O I D ";
  32.             write(fd, msg, strlen(msg));
  33.             close(fd);
  34.         }
  35.     }
  36.     return 0;
  37. }

而开机的那段动画即晃动的android字样是由两幅图片组成,一张前景,一张背景,位于

代码位于frameworks/base/cmds/bootanimation/BootAnimation.cpp
  1. if(ForcePortraitLCD == true){
  2.         initTexture(&mAndroid[0], mAssets, "images/android-logo-mask-vertical.png");
  3.         initTexture(&mAndroid[1], mAssets, "images/android-logo-shine-vertical.png");
  4.     }else{
  5.         initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
  6.         initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
  7.     }



阅读(4892) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~