5/24/2012

How to capture framebuffer in Android

Answer : It can be done by accessing /dev/graphics/fb0.

1. Using adb command.
>adb shell
#cat /dev/graphics/fb0 > /data/dump
#exit
>adb pull /data/dump
This command dumps the frame buffer data in raw format (ex. RGB565) into the file.


2. Similar method can be adapted in source code level.
1) Open the device
fb_fd = open("/dev/graphics/fb0", O_RDONLY)
2) Get the framebuffer pointer
fb_ptr = mmap(0, fb_size_total, PROT_READ, MAP_SHARED, fb_fd, 0)
3) Get the frame buffer offset
ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo)
page_offset = fb_width * vinfo.yoffset * bytes_per_pixel
4) Copy frame buffer to user memory.
memcpy(fb_data, fb_ptr + page_offset, fb_size)
5) Unmap framebuffer.
munmap(fb_ptr, fb_size_total)

No comments:

Post a Comment