我正在阅读图层内容以检查其内容是否与应用程序在屏幕上呈现的内容相同。我正在阅读内容,然后再由SurfaceFlinger合成它们。这是HWCLayerVersion1 :: setAcquireFenceFd () 在HWComposer.cpp中的代码块,用于将图层内容/像素转储到原始文件。
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");
}
}
当我使用具有适当属性的IrfanView读取像素时,图像仅与实际内容略有相似,但颜色都被弄脏了。这背后的原因是什么?在我阅读内容时是否正在渲染缓冲区?我对 AOSP 完全陌生,任何帮助将不胜感激。