XRender创建离屏图片

5
我正在尝试创建一个复合窗口管理器。目前它可以工作,但是当一个窗口覆盖另一个窗口时,会出现闪烁的问题。我发现这是因为我创建了一个Picture,然后在其上绘制,导致它绘制到屏幕上。
我的期望行为是有一个离屏的Picture,我可以在其上绘图,然后使用XComposite将其绘制到屏幕上的窗口上。有没有办法创建一个与根窗口大小相同的离屏Picture
到目前为止(这段代码在一个无限循环中运行):
Window root, parent, *children;
uint children_count;
XQueryTree(disp, DefaultRootWindow(disp), &root, &parent, &children, &children_count);

// I'd like the following picture to be offscreen.
// I suspect that I have to put else something where rootPicture is
// Currently, when I draw to this picture, X11 renders it to the screen immediately, which is what I don't want.
Picture pictureBuf = XRenderCreatePicture(disp, /* rootPicture */, XRenderFindVisualFormat(disp, DefaultVisual(disp, DefaultScreen(disp))), CPSubwindowMode, &RootAttributes);

for (uint i = 0; i < children_count; i++) {
    // collapsed some stuff that doesn't matter
    Picture picture = XRenderCreatePicture(disp, children[i], pictureFormat, CPSubwindowMode, &pictureAttributes);

    // The following line should composite to an offscreen picture
    XRenderComposite(disp, hasAlpha ? PictOpOver : PictOpSrc, picture, None, pictureBuf, 0, 0, 0, 0, windowRect.x(), windowRect.y(), windowRect.width(), windowRect.height());
    // collapsed some stuff that doesn't matter
}

// The following line should composite from the offscreen picture to an onscreen picture
XRenderComposite(disp, PictOpSrc, pictureBuf, None, rootPicture, 0, 0, 0, 0, RootAttr.x, RootAttr.y, RootAttr.width, RootAttr.height);

你能不能在内存缓冲区中绘制并复制呢? - user3853544
@user3853544 这正是我想做的事情。不过我不知道该如何去做。 :) - Victor Tran
我从未使用过这个库,但通常它是按照以下方式进行的:SomeBitmapType img(width, height); 然后将其复制到您的图像中。 - user3853544
@user3853544 这个库似乎没有任何能够做到这一点的函数。Picture 是一个 XID 的别名,而 XID 本身是一个 unsigned long 的别名。 - Victor Tran
1个回答

1
我最近在研究类似的问题并想回复一下。以下代码片段展示了如何从现有窗口创建新的像素图,而无需直接绘制到该窗口。希望这可以帮到你。
Pixmap new_pixmap;
new_pixmap = XCompositeNameWindowPixmap( display, src_window);
Drawable draw = new_pixmap;
if (!draw) draw = src_window;
Picture origin;
origin = XRenderCreatePicture( display, draw, format, CPSubWindowMode, &attributes);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接