我目前正在尝试使用Xlib记录X11显示器的屏幕。我编写了一段简单的代码来衡量捕获的性能。 (为了方便阅读,我删除了计时和错误检查代码)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xdamage.h>
int main( int argc, char* argv[] )
{
Display* d = XOpenDisplay( 0 );
int xDamageEventBase, xDamageErrorBase;
XDamageQueryExtension( d, &xDamageEventBase, &xDamageErrorBase );
Window rootWindow = DefaultRootWindow( d );
Damage damage = XDamageCreate( d, rootWindow, XDamageReportNonEmpty );
XserverRegion damageParts = XFixesCreateRegion( d, 0, 0 );
XEvent e;
while ( 1 )
{
XNextEvent( d, &e );
if ( e.type == xDamageEventBase + XDamageNotify ) {
XDamageSubtract( d, damage, None, damageParts );
int partCount;
XRectangle* parts = XFixesFetchRegion ( d, damageParts, &partCount );
for ( int i = 0; i < partCount; ++i ) {
XImage* image = XGetImage( d, rootWindow, parts[i].x, parts[i].y,
parts[i].width, parts[i].height, AllPlanes, ZPixmap );
XDestroyImage( image );
}
XFree( parts );
}
}
return 0;
}
将上述代码与需要大量更新的应用程序并行运行几分钟(即全屏视频重放),并显示以下消息,以终止该消息:
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
xcapture: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)
该应用程序显然不是多线程的。据我对协议和Xlib的了解,我没有做任何非法的事情。我有限的调试Xlib / xcb的实验表明,断言是在16位事件序列计数器回绕时触发的,但是我对xlib的内部知识知之甚少,无法知道更多信息。谁能对此有任何启发?我做错什么了吗?这是Xlib错误吗?有空的时候,我将尝试使用纯xcb加载它并查看它是否为