c++ - XRender 创建离屏图片

标签 c++ x11 xlib

我正在尝试创建一个合成窗口管理器。到目前为止它可以工作,但是当一个窗口覆盖另一个窗口时,它会像疯了似的闪烁。我发现是因为我在创建一个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);

最佳答案

我最近在研究类似的事情,并想我会回复。下面的代码片段显示了如何在不直接绘制到该窗口的情况下从现有窗口创建新的像素图。希望这会有所帮助。

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);

关于c++ - XRender 创建离屏图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41649971/

相关文章:

java - 如何在 Fedora 16 上通过守护进程登录 X Window

linux - Motif:如何在没有用户干预的情况下自动移动滚动条

c - 如何优雅地退出 X11 事件循环?

c++ - 是否可以在一个 visual studio c++ 项目中使用同名源文件?

c++ - 如何检查我的代码是否在 GCC 中重新编译?

c++ - 从一个范围映射到另一个范围时避免重复值

linux - 在 GLX 中使用 X11 转发时遇到问题

捕获全局鼠标按下和释放

c++ - X损坏 : get event on window content changes

c++ - 什么是模板<typename T, T t> 习语?