简体   繁体   English

X11窗口在获取事件之前不会刷新

[英]X11 window does not get refreshed until it gets an event

In my application ( cairo and X11 ), the user can issue a command whereby the drawing is enlarged. 在我的应用程序( cairoX11 )中,用户可以发出一个命令,从而放大绘图。 To be able to grab the entire drawing as a pattern, I enlarge the drawing surface to match the current scale (the drawing is just a graph, so this can be afforded as far as memory is concerned). 为了能够将整个图形作为图案抓取,我将绘图表面放大以匹配当前比例(图形只是一个图形,因此就内存而言,这可以提供)。 Beginning with a certain scale though, the X11 window refuses to refresh until it gets an event (eg loss of focus, which is not even handled in my application). 不过,从一定比例开始,X11窗口将拒绝刷新,直到它收到事件为止(例如,失去焦点,这在我的应用程序中甚至没有处理)。

I tried refreshing the window using both XFlush() and XSync() . 我尝试使用XFlush()XSync()刷新窗口。

Does this look like a bug in the windowing system? 这看起来像窗口系统中的错误吗? If not, what should I do? 如果没有,我该怎么办? Everything works perfectly with smaller scales. 一切都适用于较小的尺度。

EDIT 1 : After much work with gdb , I found that the problem is not with the window not refreshing. 编辑1 :经过gdb大量工作后,我发现问题出在窗口不刷新。 Rather, at a certain point a call to XNextEvent() causes the window to become all black. 相反,在某个时候,对XNextEvent()的调用会导致窗口变为全黑。

EDIT2 : It looks like calls to XNextEvent() actually cause the window to be refreshed! EDIT2 :似乎对XNextEvent()调用实际上导致刷新窗口! And here is the code that caused the problem: 这是导致问题的代码:

struct PatternLock {
    PatternLock(Graphics &g)
        : g_(g) {
        p_ = cairo_get_source(g_.cr);
        cairo_pattern_reference(p_);
    }

    ~PatternLock() {
        // The commented lines caused the problem. How come?
        // cairo_set_source_rgb(g_.cr, 0, 0, 0);
        // cairo_paint(g_.cr);
        cairo_set_source(g_.cr, p_);
        cairo_paint(g_.cr);
        cairo_pattern_destroy(p_);
    }

private:
    Graphics &g_;
    cairo_pattern_t *p_;
};

Suppose the we have this code for moving the drawing: 假设我们有用于移动图形的以下代码:

{
    PatternLock lock{g};
    ... // Change of transformation matrix
}

It somehow happen that the effect of the commented lines in the destructor of PatternLock becomes visible (hence the black screen), but the effect of the following lines does not. 它在某种程度上发生了PatternLock的析构函数中注释行的效果变得可见(因此黑屏),但以下行的效果不会。 I realize that the commented code is actually unneeded. 我意识到评论的代码实际上是不需要的。 But still, how does this happen? 但是,这怎么会发生?

If my memory serves me correct, there's a limit to Drawables (eg Windows and Pixmaps) of 4096x4096 pixels. 如果我的记忆对我有用,那么对于4096x4096像素的Drawables(例如Windows和Pixmaps)是有限制的。 You should check the return values of your calls to XCreatePixmap() etc. 您应该检查调用XCreatePixmap()等的返回值。

Either way, just enlarging the pixmap to draw your drawing is Bad Design (tm), and will inevitably lead to a very slow program. 无论哪种方式,只是放大像素图来绘制你的绘图是Bad Design(tm),并且将不可避免地导致一个非常慢的程序。 Learn how to deal with zoom and pan (tip: work from the center of your viewport, not the corners). 了解如何处理缩放和平移(提示:从视口中心工作,而不是角落)。 Assuming your drawing is vector-based (ie lines and curves) you can optimize painting a lot at high zoom factors. 假设您的绘图是基于矢量的(即线条和曲线),您可以在高缩放系数下优化绘画。

If you must grab a complete graph at a resolutions larger than 4096 pixels you must implement tiling, which isn't that hard if you have zoom and pan already. 如果必须以大于4096像素的分辨率抓取完整的图形,则必须实现平铺,如果已经具有缩放和平移,这并不难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM