Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android read fb0 always give me blackscreen

My device is Nexus 4 running Jelly Bean 4.2. I'm trying to record the screen and send it out. Most codes on internet do the cap by read /dev/graphics/fb0. It works fine in some devices and the older systems. But when I try it on my device, it fail. It only gives me blackscreen and all "0" in the raw data. I have run "adb root" to get the root permission, tried "chmod 777 fb0", "cat fb0 > /sdcard/fb0". Also I have tried codes like "mmap" and "memcpy" to get the data. But all fail. I have searched on internet and there seems no solution. And some threads said that the kernel may forbid you reading the fb0. Anyone have idea on that?

like image 239
user1659072 Avatar asked Jun 25 '13 18:06

user1659072


1 Answers

As the hardware advances, you're less and less likely to find an actual framebuffer with the screen contents in it.

As noted in the comments, adb uses the "screencap" command, which contacts surfaceflinger through a Binder call, falling back on /dev/graphcs/fb0 if that fails. The latter path is rarely used now.

If you really want to dig into how this works, you need to examine how surfaceflinger does composition, especially the hwcomposer HAL. The hardware composer takes multiple gralloc surfaces and composites them during scan-out. How this works differs from device to device; the hwcomposer implementation is usually done by the graphics chip manufacturer.

Screen shot generation, used by the app framework to generate the thumbnails for the "recent apps" feature, applies the same composition steps HWC does but exclusively with GLES. As of Android 4.2, the hardware composer isn't able to composite into a buffer.

Sometimes the hardware composer "punts", e.g. because there are more layers to composite than the hardware can handle. In that case, surfaceflinger reverts to GLES composition, and there will be a buffer somewhere that has the complete image; whether or not you'll find it by opening /dev/graphics/fb0 is a different matter.

Some starting points:

  • surfaceflinger
  • hwcomposer HAL interface
  • adb shell dumpsys SurfaceFlinger
like image 112
fadden Avatar answered Sep 29 '22 11:09

fadden