Modern X Tech. Chinese Translation Project
[[composite_tutorial]]
Last edit on
Jul 10, 2006
2:58 AM
by Anonymous
http://ktown.kde.org/~fredrik/composite_howto.html
翻译人员:kidux
Composite tutorial
合成教程
Introduction
简介
About this tutorial
关于这篇教程
Now that composite has appeared in an X.Org release, a lot of people will be interested in using it, not just from a user point of view for transparency and eye candy, but also from a developers point of view, for accessing the contents of covered windows.
现在合成功能已经在x.org版本中崭露头角,很多人都对使用它感兴趣。不仅是从一个用户的角度来感受透明和养眼美色,同样是从一个开发者的角度来,怎么访问掩盖着的窗口的内容。
This tutorial is about using Composite and the Xrender extension for doing the latter. Tracking changes to window contents with Xdamage is tightly coupled to accessing window contents, so that's also covered in this tutorial.
这是关于合成的教程,后面也介绍了 Xrender 扩展,跟踪 与访问窗口内容是想联系的,所以在本篇教程里面也会涉及。
This tutorial is mainly aimed at those that are interested in using Composite for providing thumbnails in a desktop pager, or for those working on Expos?like features. But the concepts introduced here are applicable to Composite managers as well. This tutorial is not meant to be the one and only reference you'll ever need for everything having to do with the Composite extension however, but I've tried to cover all aspects of its usage for the above mentioned purposes. It should also help you avoid all the pitfalls you're likely to run into when using the Composite extension.
这篇讲座主要是针对那些对利用合成为桌面页提供一个缩略图感兴趣,或者为那些在Expos 风格感兴趣。但是这里介绍原理也适用于Composite managers 。这篇讲座不是你需要的对所有Composite 扩展都适用的参考,但是我试着去涉及上面讲过的它的用法所有的方向。它也将帮助你避免当你利用Composite extension 时可能撞上的陷阱。
You don't need to have any previous experience from using X directly from within a Qt application, but it helps if you have a general idea on how X works, and how an application communicates with an X server. Previous experience with Xlib programming helps too.
你不需要有任何早先的经验利用一个Qt程序直接利用X,但是如果你有关于X怎么工作的概念会有帮助,一个程序怎么随着一X服务器交流。早先的使用Xlib方面的经验也有帮助。
When a windows contents are made available by Composite
当窗口内容对合成可使用时
Before we begin I feel I need to clear up a misconception about when the contents of a window is made available by composite. A backing pixmap is allocated when the window is shown, and is deallocated when it becomes hidden. What this means in other words is that when a window is minimized, or not on the current desktop, the window contents aren't available.
在我们开始之前我感觉我需要消除一个关于当一个window 的contents 构造composite 可用的错觉。一个背景象素映射是当window 显示时分配,当隐藏的时候释放。意思是当那一个window 最小化时,或不在当前桌面,那window contents 是不可用的。
There are basically two reasons why composite works like this. The first is to minimize the amount of video ram needed at a given time by the backing store. The second is that with the traditional X design, drawing on a hidden window is effectively a NOOP. Clever applications and toolkits know this, so they'll never try to draw on a minimized window anyway.
主要地有二个原因解释composite 这么工作。第一个是最小化在一定时刻背景存储需要显示内存的数值。第二是因为传统的X设计,画一个隐藏的window 是一个实际的无操作。聪明的程序和工具箱知道这些,所以它们决不设法画一个最小化的window 。
This probably comes as a dissapointment nonetheless to those that are hoping that composite would enable them to e.g. hover over a taskbar button, and get a tooltip with a thumbnail of a minimized window or a window on another desktop (to see if the window has been updated).
这大概会让人失望,对那些希望composite 会使他们能够,例如:悬在一个任务条按钮上,得到一个最小化窗略图的tooltip或者一个窗在另一个桌面(看看是否window 已经更新)。
The best thing a taskbar/pager that wants to do this can do is to keep a cached thumbnail of the contents of the window before it was unmapped. Composite actually provides an easy way of doing that, as explained in this tutorial.
一个任务栏/页面最好的情况可以把window 的contents略图当它unmapped 之前保存在一个高速缓存 。Composite 有效的提供一个容易的做法,如这讲座所述。
Note that while the contents of a minimized window will never be available, the contents of a window on an inactive desktop may be, depending on the WM design. If the WM uses a virtual root window for each desktop, and don't unmap the inactive ones, then the contents of those windows on those desktops will still be available. KWin and Metacity aren't designed like that however.
注意当最小化window 的contents 永不可用的,可能是window 的contents 在一不活动桌面,视窗口管理的设计而定。如果窗口管理分别为桌面使用一个虚拟的根window ,不unmap 不活动的那些,然后在那些桌面windows 的contents 仍是可用的。然而KWin和Metacity不是象那样设计的。
Reasons for using Xrender to access the contents
使用xrender访问目录的原因
I'll also briefly explain the motivation for using Xrender to access the window contents. It is perfectly possible to create a GC for a window and use XCopyArea() to copy the contents of the window if you want to use the core protocol, but since the Composite extension exposes new visuals (ones with alpha channels e.g.), there's no guarantee that the format of the source drawable will match that of the destination. With the core protocol that situation will result in a match error, something that won't happen with the Xrender extension.
我也会简短的说明利用Xrender存取window window contents 的动机。完全地可能为一个window 创造一个GC和使用XCopyArea()拷贝这window 的contents, 如果你想使用核心协议,仅仅当Composite 扩展暴露新的图象时(例如带alpha 通道 )不能保证源的可画格式和那样的目标相配。核心协议不同情况将要导致一个匹配误差,用Xrender 扩展有些事情不会发生。
In addition the core protocol has no understanding of alpha channels, which means that it can't composite windows that use the new ARGB visual. When the source and destination have the same format, there's also no performance advantage to using the core protocol as of X11R6.8. That release is also the first to support the new Composite extension.
另外核心协议不知道到alpha 通道,意谓它不能合成使用使用新的ARGB 图象的windows 。当源和目标有一样格式,利用核心协议也没有性能利益,因为X11R6.8.版是第一个支持新的合成扩展的版本。
So in conclusion there are no drawbacks, and only advantages to choosing Xrender over the core protocol for these operations.
结论是没有缺点,使用Xrender而不用核心协议的唯一优势就是,Xrender在操作上的占强势。
[这句话是说,对这些操作而言,选择 Xrender 而不是核心协议都是优点,没有缺点,only advantages 是指"只有优点"。]
Checking if the X server supports the composite extension
检查 X 服务器是否支持合成扩展
The first you thing you need to do is to do a runtime check to make sure the X server you're connected to actually supports the composite extension. You'll need a compile time check too of course, but that'll only tell you that the composite lib is available, not that the X server the application will be using has the server side bits.
首先你需要做的是进行运行时检查来确定你连接到的Xserver是支持合成扩展的。你当然也需要核对编译时间,但是那样只告诉你合成 lib 是可用的,不是说Xserver 程序将用到服务器那面