XFCE下Screen Tearing问题的解决

来源:互联网 发布:北大青鸟java多少钱 编辑:程序博客网 时间:2024/05/01 03:25

Screen tearing 是什么?从字面意思看,就是屏幕撕裂,让人联想到显示器的硬件问题,其实不然,它是一种常见的显示问题,就是我们常说的锯齿、狗牙之类。看看下面这张图片就明白了,图上#1和#2处都产生了撕裂。这是从维基百科上摘过来的,一幅图片被撕裂成了3段,看起来是从某段视频中截取的。

这种现象通常是由于显卡驱动没装造成的,在Linux桌面环境中非常常见,特别是在拖动窗口、调整窗口大小、播放视频时经常发生。维基上对此现象解释得非常清楚,并且还给出了解决方案。

Screen tearing is a visual artifact in video display where a display device shows information from two or more frames in a single screen draw.

The artifact occurs when the video feed to the device isn't in sync with the display's refresh. This can be due to non-matching refresh rates—in which case the tear line moves as the phase difference changes (with speed proportional to difference of frame rates). It can also occur simply from lack of sync between two equal frame rates, in which case the tear line is at a fixed location that corresponds to the phase difference. During video motion, screen tearing creates a torn look as edges of objects (such as a wall or a tree) fail to line up.——Wikipedia

如上所述,Screen tearing是因为显卡与显视器的刷新频率不同步造成显示器同时将多个帧显示在了同一画面中了。解决方案很显然,就是调整显卡和显示器的刷新频率,使其同步即可。现在的显卡大都可以自动调整刷新频率,与显示器保持一持,这可以通过开启VSync选项来启用。

但是在XFCE下,开启显卡VSync后,Screen tearing并没有好转。经过多次Google,发现问题出在了XFCE默认窗口管理器XFWM上,它没有采用显卡的加速功能,而是简单地采用了CPU直接渲染,难怪开启显卡的VSync不能解决问题!找到了原因,也就有了解决方案,那就是换个可以使用显卡加速的窗口管理器,Google发现只有Emerald和Mutter有这功能,但Mutter只能集成在Gnome3中使用,因此选择Emerald。

安装Emerald具体的方法不同发行版不同,就不多讲了,需要帮助的可以查看该发行版的软件包管理文档。装上Emerald后,必须在Compiz(Emerald是它的一个组成部分)的CCSM中设置好Window Decoration才能让通过命令emerald --replace来让Emerald管理窗口。这样,在CCSM中选上VSync选项就把Screen Tearing问题消灭了。当然,前提是显卡驱动已经装好,并且支持OpenGL才行。

我用的是Gentoo,具体的步骤如下:

$ emerge emerald compiz ccsm
# 在ccsm中设置VSync和Window Decoration
$ emerald --replace &
#选择或DIY窗口修饰主题
$ emerald-theme-manager 

我只在XFCE下测试了,实际上本方法可以作为一个通用的解决方案,在其它桌面环境应该也是可用的。