3

I am reading the layer contents to check whether its the same content as that rendered by the app on-screen. I am reading the contents before they are being composited by SurfaceFlinger. Here is the block of code in HWCLayerVersion1::setAcquireFenceFd() in HWComposer.cpp, to dump the layer content/pixels to a raw-file.

    getLayer()->acquireFenceFd = fenceFd;
    private_handle_t *hnd = (private_handle_t*)getLayer()->handle; // the handle of the layer

    /*code for checking layer contents*/
    if(private_handle_t::validate(getLayer()->handle)==0){
             ALOGD("beta: we are gonna read a valid buffer-> %08x", intptr_t(getLayer()->handle));
             char filename[64];
             memset(filename, 0, 64);
             int name = clock();
             sprintf(filename, "/data/dump.%08x.raw", intptr_t(getLayer()->handle));                
             if(getLayer()->acquireFenceFd >= 0){
                  int ret = sync_wait(getLayer()->acquireFenceFd, -1);
                  if(ret < 0){
                        ALOGD("beta: sync_wait failed");
                  } else{
                      FILE *file = fopen(filename,"w+");
                      //ALOGD("beta: writing pixels");
                      fwrite((void*)hnd->base, hnd->size, 1, file);
                      close(getLayer()->acquireFenceFd);
                      //getLayer()->acquireFenceFd = -1;
                  } 
              } else {
                   ALOGD("beta: fencefd not valid");
              }
    }

When I am reading the pixels using IrfanView with the appropriate attributes, the image only faintly resembles the actual content, but the colors are all smudged. What is the reason behind this? Is the buffer being rendered while I am reading the content? I'm totally new to AOSP, and any help would be appreciated.

sg1993
  • 335
  • 2
  • 19
  • What do you mean by "colors are all smudged"? Can you post good/bad sample images? (you'll probably need to do that on an external site and post a link -- I think you need higher rep to include them inline) What device are you testing on? – fadden Jun 12 '14 at 14:44
  • 1
    I'm so very sorry for posting this question. A few minutes after posting this, I tried a new resolution, and everything works! turns out I was not using the correct resolution in IrfanView. Wasted a whole day for no reason at all! One question though, is it necessary that I wait on the acquireFenceFd, because it seems to be working without it too? – sg1993 Jun 13 '14 at 04:28

1 Answers1

0

If your host (in case its an emulator) or device supports graphic acceleration , then yes, the buffer you are reading is not fully rendered yet. Latest Android releases support a sync mechanism which means that buffers (layers) can be acquired by the SurfaceFlinger while they are being rendered. They are protected by a fencing mechanism which ensures that a buffer that's not fully rendered will not be displayed.

EyalBellisha
  • 1,874
  • 19
  • 28
  • But sync_wait() should wait till the buffer is fully rendered, right? Or am I missing something? – sg1993 Jun 13 '14 at 04:22
  • if you can help would you help please about that problem : https://stackoverflow.com/questions/50705858/intent-does-not-work – Amin Jul 31 '19 at 08:19