XGetImage需要大量的时间来运行

XGetImage需要3-4秒才能执行并完全冻结X11

Display *display; display = XOpenDisplay(NULL); if (!display) {fprintf(stderr, "unable to connect to display");return 7;} Window w; int x,y,i; unsigned m; Window root = XDefaultRootWindow(display); if (!root) {fprintf(stderr, "unable to open rootwindow");return 8;} //sleep(1); if(!XQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m)) { printf("unable to query pointer\n"); return 9;} XImage *image; XWindowAttributes attr; XGetWindowAttributes(display, root, &attr); image = XGetImage(display,root,0,0,attr.width,attr.height,AllPlanes,XYPixmap); XCloseDisplay(display); if (!image) {printf("unable to get image\n"); return 10;} 

在Xorg日志中:

 [ 13234.693] AUDIT: Thu Jan 7 20:12:13 2016: 3856: client 45 connected from local host ( uid=500 gid=500 pid=12993 ) Auth name: MIT-MAGIC-COOKIE-1 ID: 153 [ 13238.774] AUDIT: Thu Jan 7 20:12:18 2016: 3856: client 45 disconnected 

 time: real 0m4.080s user 0m0.002s sys 0m0.007s 

理想情况下,我希望这个函数在不到0.1秒的时间内运行

XYPixmap是一个非常专业的格式,没有太多的用途。 几乎总是应该使用ZPixmap

XYPixmap 平面地工作 。 这是什么意思? 取每个像素的位0,并将所有这些位紧紧地包装在一个unsigned int的数组中。 这就是你的飞机0.然后把每个像素的位1,并将所有这些位打包在一个数组中。 那是你的飞机1.然后把每一个像素的位2

  Framebuffer __________________________________________________________________ / Pixel 0 Pixel 1 Pixel 2 [0][1][2][3][4][5][6][7] [0][1][2][3][4][5][6][7] [0][1][2].... | | | | +------------------------+ | | | | | | +--------------------------------------------------+ | | | vvv [0][0][0]..... \ (Plane 0) | | [1][1][1].... | Result (Plane 1) | .... | [7][7][7].... | (Plane 7) | / 

如果你的framebuffer是这样存储的,大多数现代硬件就是这种情况,这是很多的操纵!

图片显示了8位像素,但对于其他任何深度都是一样的。

另一方面, ZPixmap将整个像素ZPixmap到一个数组中:

  Framebuffer __________________________________________________________________ / Pixel 0 Pixel 1 Pixel 2 [0][1][2][3][4][5][6][7] [0][1][2][3][4][5][6][7] [0][1][2].... | | | | | | | | | | | | | | | | | | | vvvvvvvvvvvvvvvvvvv [0][1][2][3][4][5][6][7] [0][1][2][3][4][5][6][7] [0][1][2].... \_____________________________________________________________________ Result 

这是简单的直接复制,应该是非常快的。