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.