歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android教程:開機Logo

Android系統開機第一個程序的進程是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. }
Copyright © Linux教程網 All Rights Reserved