0

I'm working on a project that involves reading the content of a layer that is to be composited by the surfaceflinger.

I specifically need to check whether the layer to be composited is all 1-bits 0r all 0-bits.

This is to apply some optimizations before composition by the SurfaceFlinger.

I tracked the creation of the buffers via adb-logcat(by adding my own log messages) but couldn't find a way to read the actual contents of the layer.

Could anyone tell me if this is even possible, and if it is, how?

sg1993
  • 335
  • 2
  • 19

1 Answers1

0

In general, it's not. For example, if the layer is displaying DRM-protected video, it's impossible to read the data.

For unprotected layers, you can read the pixel values out with glReadPixels() -- there's some code in SurfaceFlinger's screenshot code that can be enabled to check for blank screenshots -- but this is going to be slow.

Bear in mind that not all layers are RGB. If the layer is YUV, an "all zero" layer would actually be a dull green.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • I was tracking the buffer allocation(using adb logcat) and found out that a buffer handle(of type private_handle_t) is returned, this handle also has a base-address. Can I read the buffer contents using this? And if yes, since each layer is ends up on a buffer, can't the layer-content be read as well before composition? Please correct me if I am wrong. – sg1993 Jun 06 '14 at 19:50
  • Before you can access it, you have to lock it. Locking it may involve a memcpy from elsewhere, cache flushes, or other activity, and may fail if the buffer is DRM-protected (because it's living in trusted memory that the CPU can't touch). As mentioned above you may also need to check the gralloc buffer format to understand what you're looking at. Assuming the buffer contains renderer output, you will also need to ensure that the relevant fence has signaled completion. See also http://source.android.com/devices/graphics.html . – fadden Jun 06 '14 at 21:13