compositeproto.txt revision ea1d6981
117ca54c3Smrg		         Composite Extension
217ca54c3Smrg			     Version 0.4
317ca54c3Smrg			      2007-7-3
417ca54c3Smrg			    Keith Packard
517ca54c3Smrg			  keithp@keithp.com
617ca54c3Smrg			    Deron Johnson
717ca54c3Smrg     		        deron.johnson@sun.com
817ca54c3Smrg
917ca54c3Smrg1. Introduction
1017ca54c3Smrg
1117ca54c3SmrgMany user interface operations would benefit from having pixel contents of
1217ca54c3Smrgwindow hierarchies available without respect to sibling and antecedent
1317ca54c3Smrgclipping. In addition, placing control over the composition of these pixel
1417ca54c3Smrgcontents into a final screen image in an external application will enable
1517ca54c3Smrga flexible system for dynamic application content presentation.
1617ca54c3Smrg
1717ca54c3Smrg2. Acknowledgements
1817ca54c3Smrg
1917ca54c3SmrgThis small extension has been brewing for several years, contributors to
2017ca54c3Smrgboth early prototypes and the final design include:
2117ca54c3Smrg
2217ca54c3Smrg +	Bill Haneman for motivating the ability to magnify occluded windows
2317ca54c3Smrg 	with his work on accessibility
2417ca54c3Smrg
2517ca54c3Smrg +	Carsten Haitzler for Enlightenment, the original eye-candy window
2617ca54c3Smrg 	manager which demonstrated that clever hacks are an awfully
2717ca54c3Smrg	close substitute for changes in the underlying system.
2817ca54c3Smrg
2917ca54c3Smrg +	Jim Gettys for key insights into the relationship between damage
3017ca54c3Smrg 	events and per-window pixmap usage
3117ca54c3Smrg
3217ca54c3Smrg +	Mike Harris and Owen Taylor for figuring out what to call it.
3317ca54c3Smrg
3417ca54c3Smrg +	Deron Johnson for the Looking Glass implementation and
3517ca54c3Smrg 	a prototype of the coordinate transformation mechanism.
3617ca54c3Smrg
3717ca54c3Smrg +	Ryan Lortie for helping figure out reasonable parent clipping
3817ca54c3Smrg	semantics in the presence of manual redirected children.
3917ca54c3Smrg
4017ca54c3Smrg3. Architecture
4117ca54c3Smrg
4217ca54c3SmrgThe composite extension provides three related mechanisms:
4317ca54c3Smrg
4417ca54c3Smrg 1.	Per-hierarchy storage. The rendering of an entire hierarchy of windows
4517ca54c3Smrg 	is redirected to off-screen storage. The pixels of that hierarchy
4617ca54c3Smrg	are available whenever it is viewable. Storage is automatically
4717ca54c3Smrg	reallocated when the top level window changes size. Contents beyond
4817ca54c3Smrg	the geometry of the top window are not preserved.
4917ca54c3Smrg
5017ca54c3Smrg 2.	Automatic shadow update. When a hierarchy is rendered off-screen,
5117ca54c3Smrg 	the X server provides an automatic mechanism for presenting those
5217ca54c3Smrg	contents within the parent window. The implementation is free to
5317ca54c3Smrg	make this update lag behind actual rendering operations by an
5417ca54c3Smrg	unspecified amount of time. This automatic update mechanism may
5517ca54c3Smrg	be disabled so that the parent window contents can be completely
5617ca54c3Smrg	determined by an external application.
5717ca54c3Smrg
5817ca54c3Smrg 3.	External parent - child pointer coordinate transformation.
5917ca54c3Smrg 	When a hierarchy is under manual compositing, the relationship
6017ca54c3Smrg	of coordinates within the parent to those in the child may
6117ca54c3Smrg	not be known within the X server. This mechanism provides
6217ca54c3Smrg	for redirection of these transformations through a client.
6317ca54c3Smrg
6417ca54c3SmrgPer-hierarchy storage may be created for individual windows or for all
6517ca54c3Smrgchildren of a window. Manual shadow update may be selected by only a single
6617ca54c3Smrgapplication for each window; manual update may also be selected on a
6717ca54c3Smrgper-window basis or for each child of a window. Detecting when to update
6817ca54c3Smrgmay be done with the Damage extension.
6917ca54c3Smrg
7017ca54c3SmrgThe off-screen storage includes the window contents, its borders and the
7117ca54c3Smrgcontents of all descendants.
7217ca54c3Smrg
7317ca54c3Smrg3.1 NameWindowPixmap
7417ca54c3Smrg
7517ca54c3SmrgVersion 0.2 of the protocol introduces a mechanism for associating an XID
7617ca54c3Smrgwith the off-screen pixmap used to store these contents. This can be used
7717ca54c3Smrgto hold onto window contents after the window is unmapped (and hence animate
7817ca54c3Smrgit's disappearance), and also to access the border of the window, which is
7917ca54c3Smrgnot reachable through the Window ID itself. A new pixmap is created each
8017ca54c3Smrgtime the window is mapped or resized; as these events are nicely signalled
8117ca54c3Smrgwith existing events, no additional notification is needed. The old pixmap
8217ca54c3Smrgwill remain allocated as long as the Pixmap ID is left valid, it is
8317ca54c3Smrgimportant that the client use the FreePixmap request when it is done with
8417ca54c3Smrgthe contents and to create a new name for the newly allocated pixmap.
8517ca54c3Smrg
8617ca54c3SmrgIn automatic update mode, the X server is itself responsible for presenting
8717ca54c3Smrgthe child window contents within the parent. It seems reasonable, then, for
8817ca54c3Smrgrendering to the parent window to be clipped so as not to interfere with any
8917ca54c3Smrgchild window content. In an environment with a mixture of manual and
9017ca54c3Smrgautomatic updating windows, rendering to the parent in the area nominally
9117ca54c3Smrgoccupied by a manual update window should be able to affect parent pixel
9217ca54c3Smrgvalues in those areas, but such rendering should be clipped to automatic
9317ca54c3Smrgupdate windows, and presumably to other manual update windows managed by
9417ca54c3Smrgother applications. In any of these cases, it should be easy to ensure that
9517ca54c3Smrgrendering has no effect on any non-redirected windows.
9617ca54c3Smrg
9717ca54c3SmrgInstead of attempting to define new clipping modes for rendering, the
9817ca54c3SmrgComposite extension instead defines ClipByChildren rendering to the parent
9917ca54c3Smrgto exclude regions occupied by redirected windows (either automatic or
10017ca54c3Smrgmanual). The CreateRegionFromBorderClip request can be used along with
10117ca54c3SmrgIncludeInferiors clipping modes to restrict manual shadow updates to the
10217ca54c3Smrgapporpriate region of the screen. Bracketing operations with
10317ca54c3SmrgGrabServer/UngrabServer will permit atomic sequences that can update the
10417ca54c3Smrgscreen without artifact. As all of these operations are asynchronous,
10517ca54c3Smrgnetwork latency should not adversely affect update latency.
10617ca54c3Smrg
10717ca54c3Smrg3.2 Composite Overlay Window
10817ca54c3Smrg
10917ca54c3SmrgVersion 0.3 of the protocol adds the Composite Overlay Window, which
11017ca54c3Smrgprovides compositing managers with a surface on which to draw without
11117ca54c3Smrginterference. This window is always above normal windows and is always
11217ca54c3Smrgbelow the screen saver window. It is an InputOutput window whose width
11317ca54c3Smrgand height are the screen dimensions. Its visual is the root visual
11417ca54c3Smrgand its border width is zero.  Attempts to redirect it using the
11517ca54c3Smrgcomposite extension are ignored.  This window does not appear in the
11617ca54c3Smrgreply of the QueryTree request. It is also an override redirect window.
11717ca54c3SmrgThese last two features make it invisible to window managers and other X11
11817ca54c3Smrgclients. The only way to access the XID of this window is via the
11917ca54c3SmrgCompositeGetOverlayWindow request. Initially, the Composite Overlay
12017ca54c3SmrgWindow is unmapped.
12117ca54c3Smrg
12217ca54c3SmrgCompositeGetOverlayWindow returns the XID of the Composite Overlay
12317ca54c3SmrgWindow. If the window has not yet been mapped, it is mapped by this
12417ca54c3Smrgrequest. When all clients who have called this request have terminated
12517ca54c3Smrgtheir X11 connections the window is unmapped.
12617ca54c3Smrg
12717ca54c3SmrgComposite managers may render directly to the Composite Overlay
12817ca54c3SmrgWindow, or they may reparent other windows to be children of this
12917ca54c3Smrgwindow and render to these. Multiple clients may render to the
13017ca54c3SmrgComposite Overlay Window, create child windows of it, reshape it, and
13117ca54c3Smrgredefine its input region, but the specific arbitration rules followed
13217ca54c3Smrgby these clients is not defined by this specification; these policies
13317ca54c3Smrgshould be defined by the clients themselves.
13417ca54c3Smrg
13517ca54c3Smrg3.3 Clipping semantics redefined
13617ca54c3Smrg
13717ca54c3SmrgVersion 0.4 of the protocol changes the semantics of clipping in the
13817ca54c3Smrgpresence of manual redirect children. In version 0.3, a parent was always
13917ca54c3Smrgclipped to child windows, independent of the kind of redirection going on.
14017ca54c3SmrgWith version 0.4, the parent is no longer clipped to child windows which are
14117ca54c3Smrgmanually redirected. This means the parent can draw in the child region without using
14217ca54c3SmrgIncludeInferiors mode, and (perhaps more importantly), it will receive
14317ca54c3Smrgexpose events in those regions caused by other actions. This new behaviour
14417ca54c3Smrgis not selectable.
14517ca54c3Smrg
14617ca54c3Smrg4. Errors
14717ca54c3Smrg
14817ca54c3SmrgThe composite extension does not define any new errors.
14917ca54c3Smrg
15017ca54c3Smrg5. Types
15117ca54c3Smrg
15217ca54c3Smrg	UPDATETYPE	{ Automatic, Manual }
15317ca54c3Smrg
15417ca54c3Smrg	CompositeCoordinate
15517ca54c3Smrg		child:			Window
15617ca54c3Smrg		x, y:			CARD16
15717ca54c3Smrg
15817ca54c3Smrg7. Extension Initialization
15917ca54c3Smrg
16017ca54c3SmrgThe client must negotiate the version of the extension before executing
16117ca54c3Smrgextension requests. Otherwise, the server will return BadRequest for any
16217ca54c3Smrgoperations other than QueryVersion.
16317ca54c3Smrg
16417ca54c3Smrg    QueryVersion
16517ca54c3Smrg
16617ca54c3Smrg		client-major-version:		CARD32
16717ca54c3Smrg		client-minor-version:		CARD32
16817ca54c3Smrg
16917ca54c3Smrg		->
17017ca54c3Smrg
17117ca54c3Smrg		major-version:			CARD32
17217ca54c3Smrg		minor-version:			CARD32
17317ca54c3Smrg
17417ca54c3Smrg	The client sends the highest supported version to the server and
17517ca54c3Smrg	the server sends the highest version it supports, but no higher than
17617ca54c3Smrg	the requested version. Major versions changes can introduce
17717ca54c3Smrg	incompatibilities in existing functionality, minor version
17817ca54c3Smrg	changes introduce only backward compatible changes. It is
17917ca54c3Smrg	the client's responsibility to ensure that the server supports
18017ca54c3Smrg	a version which is compatible with its expectations. Servers
18117ca54c3Smrg	are encouraged to support multiple versions of the extension.
18217ca54c3Smrg
18317ca54c3Smrg8. Hierarchy Redirection
18417ca54c3Smrg
18517ca54c3Smrg    RedirectWindow
18617ca54c3Smrg
18717ca54c3Smrg		window:				Window
18817ca54c3Smrg		update:				UPDATETYPE
18917ca54c3Smrg
19017ca54c3Smrg		errors: Window, Access, Match
19117ca54c3Smrg
19217ca54c3Smrg	The hierarchy starting at 'window' is directed to off-screen
19317ca54c3Smrg	storage. 'update' specifies whether the contents are mirrored to 
19417ca54c3Smrg	the parent window automatically or not. Only one client may specify 
19517ca54c3Smrg	an update type of Manual, another attempt will result in an
19617ca54c3Smrg	Access error. When all clients enabling redirection terminate,
19717ca54c3Smrg	the redirection will automatically be disabled.
19817ca54c3Smrg
19917ca54c3Smrg	The root window may not be redirected. Doing so results in a Match
20017ca54c3Smrg	error.
20117ca54c3Smrg
20217ca54c3Smrg    RedirectSubwindows
20317ca54c3Smrg
20417ca54c3Smrg		window:				Window
20517ca54c3Smrg		update				UPDATETYPE
20617ca54c3Smrg
20717ca54c3Smrg		errors: Window, Access
20817ca54c3Smrg
20917ca54c3Smrg	Hierarchies starting at all current and future children of window
21017ca54c3Smrg	will be redirected as in RedirectWindow. If update is Manual,
21117ca54c3Smrg	then painting of the window background during window manipulation
21217ca54c3Smrg	and ClearArea requests is inhibited.
21317ca54c3Smrg
21417ca54c3Smrg    UnredirectWindow:
21517ca54c3Smrg
21617ca54c3Smrg		window:				Window
217ea1d6981Smrg		update:				UPDATETYPE
21817ca54c3Smrg
21917ca54c3Smrg		errors: Window, Value
22017ca54c3Smrg
22117ca54c3Smrg	Redirection of the specified window will be terminated. If
22217ca54c3Smrg	the specified window was not selected for redirection by the
223ea1d6981Smrg	current client, or if the update type does not match the
224ea1d6981Smrg	current client's previously requested update type, a 'Value'
225ea1d6981Smrg	error results.
22617ca54c3Smrg
227ea1d6981Smrg    UnredirectSubwindows:
22817ca54c3Smrg
22917ca54c3Smrg		window:				Window
230ea1d6981Smrg		update:				UPDATETYPE
23117ca54c3Smrg
23217ca54c3Smrg		errors: Window, Value
23317ca54c3Smrg
23417ca54c3Smrg	Redirection of all children of window will be terminated. If
23517ca54c3Smrg	the specified window was not selected for sub-redirection by the
236ea1d6981Smrg	current client, or if the update type does not match the
237ea1d6981Smrg	current client's previously requested update type, a 'Value'
238ea1d6981Smrg	error results.
23917ca54c3Smrg
24017ca54c3Smrg9. Clip lists
24117ca54c3Smrg
24217ca54c3Smrg    CreateRegionFromBorderClip
24317ca54c3Smrg
24417ca54c3Smrg		region:				Region
24517ca54c3Smrg		window:				Window
24617ca54c3Smrg
24717ca54c3Smrg		errors: Window, IDChoice
24817ca54c3Smrg
24917ca54c3Smrg	This request creates a region containing the "usual" border clip
25017ca54c3Smrg	value; that is the area of the window clipped against siblings and
25117ca54c3Smrg	the parent. This region can be used to restrict rendering to
25217ca54c3Smrg	suitable areas while updating only a single window. The region
25317ca54c3Smrg	is copied at the moment the request is executed; future changes
25417ca54c3Smrg	to the window hierarchy will not be reflected in this region.
25517ca54c3Smrg
25617ca54c3Smrg10. Associating a Pixmap ID with the off-screen storage (0.2 and later)
25717ca54c3Smrg
25817ca54c3Smrg    NameWindowPixmap
25917ca54c3Smrg
26017ca54c3Smrg		window:				Window
26117ca54c3Smrg		pixmap:				Pixmap
26217ca54c3Smrg
26317ca54c3Smrg		errors: Window, Match, IDChoice
26417ca54c3Smrg
26517ca54c3Smrg	This request makes 'pixmap' a reference to the off-screen storage
26617ca54c3Smrg	for 'window'. This pixmap will remain allocated until freed, even
26717ca54c3Smrg	if 'window' is unmapped, reconfigured or destroyed. However,
26817ca54c3Smrg	'window' will get a new pixmap allocated each time it is
26917ca54c3Smrg	mapped or resized, so this request will need to be reinvoked for
27017ca54c3Smrg	the client to continue to refer to the storage holding the current
27117ca54c3Smrg	window contents. Generates a 'Match' error if 'window' is not
27217ca54c3Smrg	redirected or is not visible.
27317ca54c3Smrg
27417ca54c3Smrg11. Composite Overlay Window (0.3 and later)
27517ca54c3Smrg
27617ca54c3Smrg    CompositeGetOverlayWindow
27717ca54c3Smrg
27817ca54c3Smrg	        window:				Window
27917ca54c3Smrg
28017ca54c3Smrg	        ->
28117ca54c3Smrg
28217ca54c3Smrg	        overlayWin:			Window
28317ca54c3Smrg
28417ca54c3Smrg    This request returns the XID of the Composite Overlay Window for 
28517ca54c3Smrg    the screen specified by the argument 'window'. This request 
28617ca54c3Smrg    indicates that the client wishes to use the Composite Overlay 
28717ca54c3Smrg    Window of this screen. If this Composite Overlay Window has not 
28817ca54c3Smrg    yet been mapped, it is mapped by this request.
28917ca54c3Smrg
29017ca54c3Smrg    The Composite Overlay Window for a particular screen will be 
29117ca54c3Smrg    unmapped when all clients who have invoked this request have 
29217ca54c3Smrg    also invoked CompositeReleaseOverlayWindow for that screen. Also,
29317ca54c3Smrg    CompositeReleaseOverlayWindow for a screen will be implicitly 
29417ca54c3Smrg    called when a client using the Composite Overlay Window on that 
29517ca54c3Smrg    screen terminates its X11 connection.
29617ca54c3Smrg
29717ca54c3Smrg
29817ca54c3Smrg    CompositeReleaseOverlayWindow
29917ca54c3Smrg
30017ca54c3Smrg		window:				Window
30117ca54c3Smrg
30217ca54c3Smrg    This request specifies that the client is no longer using the 
30317ca54c3Smrg    Composite Overlay Window on the screen specified by the 
30417ca54c3Smrg    argument 'window'. A screen's Composite Overlay Window is 
30517ca54c3Smrg    unmapped when there are no longer any clients using it.
306