[Xquartz-changes] xserver: Branch 'master' - 73 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Wed Dec 8 13:41:39 PST 2010


 COPYING                                                             |    4 
 Xext/Makefile.am                                                    |    3 
 Xext/sync.c                                                         |  899 +++++++---
 Xext/syncsdk.h                                                      |   47 
 Xext/syncsrv.h                                                      |   37 
 Xi/exevents.c                                                       |    6 
 composite/compalloc.c                                               |    2 
 composite/compext.c                                                 |    2 
 composite/compinit.c                                                |    2 
 composite/compint.h                                                 |    2 
 composite/compoverlay.c                                             |    2 
 composite/compwindow.c                                              |    2 
 config/hal.c                                                        |   13 
 config/udev.c                                                       |   14 
 configure.ac                                                        |   33 
 dix/Xserver-dtrace.h.in                                             |    2 
 dix/Xserver.d                                                       |    2 
 dix/deprecated.c                                                    |   30 
 dix/devices.c                                                       |   17 
 dix/dispatch.c                                                      |    2 
 dix/dixfonts.c                                                      |    4 
 dix/eventconvert.c                                                  |    8 
 dix/events.c                                                        |    2 
 dix/privates.c                                                      |    1 
 dix/resource.c                                                      |    2 
 doc/.gitignore                                                      |    2 
 doc/Makefile.am                                                     |   27 
 doc/Xserver.man.pre                                                 |  584 ------
 doc/man/Makefile.am                                                 |   20 
 doc/man/Xserver.man                                                 |  584 ++++++
 doc/xml/Xserver-spec.xml                                            |  104 -
 fb/fbcmap_mi.c                                                      |    2 
 hw/dmx/Makefile.am                                                  |    2 
 hw/dmx/dmx.c                                                        |   10 
 hw/dmx/dmxextension.c                                               |   14 
 hw/dmx/dmxgcops.c                                                   |   10 
 hw/dmx/dmxpict.c                                                    |   54 
 hw/dmx/dmxwindow.c                                                  |   10 
 hw/dmx/glxProxy/glxcmds.c                                           |  182 +-
 hw/dmx/glxProxy/glxext.c                                            |    6 
 hw/xfree86/common/Makefile.am                                       |    4 
 hw/xfree86/common/xf86AutoConfig.c                                  |   22 
 hw/xfree86/common/xf86Config.c                                      |   18 
 hw/xfree86/common/xf86Configure.c                                   |   33 
 hw/xfree86/common/xf86Helper.c                                      |   21 
 hw/xfree86/common/xf86Init.c                                        |    3 
 hw/xfree86/common/xf86Mode.c                                        |    6 
 hw/xfree86/common/xf86Module.h                                      |    2 
 hw/xfree86/common/xf86Option.c                                      |    5 
 hw/xfree86/common/xf86ShowOpts.c                                    |   10 
 hw/xfree86/common/xf86Xinput.c                                      |    5 
 hw/xfree86/common/xf86Xinput.h                                      |    1 
 hw/xfree86/common/xf86pciBus.c                                      |    6 
 hw/xfree86/common/xf86sbusBus.c                                     |    6 
 hw/xfree86/dixmods/extmod/modinit.c                                 |    5 
 hw/xfree86/doc/devel/Registry                                       |    1 
 hw/xfree86/doc/man/xorg.conf.man.pre                                |   48 
 hw/xfree86/dri/dri.c                                                |    7 
 hw/xfree86/loader/loadmod.c                                         |   18 
 hw/xfree86/loader/sdksyms.sh                                        |    5 
 hw/xfree86/modes/xf86Crtc.c                                         |  151 +
 hw/xfree86/modes/xf86Crtc.h                                         |  119 +
 hw/xfree86/modes/xf86Cursors.c                                      |    4 
 hw/xfree86/modes/xf86Modes.c                                        |    4 
 hw/xfree86/modes/xf86RandR12.c                                      |  387 +++-
 hw/xfree86/modes/xf86Rotate.c                                       |   44 
 hw/xfree86/modes/xf86cvt.c                                          |   10 
 hw/xfree86/os-support/solaris/solaris-amd64.S                       |    2 
 hw/xfree86/os-support/solaris/solaris-ia32.S                        |    2 
 hw/xfree86/os-support/solaris/solaris-sparcv8plus.S                 |    2 
 hw/xfree86/os-support/solaris/sun_VTsw.c                            |    2 
 hw/xfree86/os-support/solaris/sun_agp.c                             |    4 
 hw/xfree86/os-support/solaris/sun_apm.c                             |    2 
 hw/xfree86/os-support/solaris/sun_bell.c                            |    2 
 hw/xfree86/os-support/solaris/sun_init.c                            |    7 
 hw/xfree86/os-support/solaris/sun_vid.c                             |    7 
 hw/xfree86/parser/Flags.c                                           |   13 
 hw/xfree86/parser/Makefile.am                                       |    1 
 hw/xfree86/parser/Pointer.c                                         |   16 
 hw/xfree86/ramdac/Makefile.am                                       |    4 
 hw/xfree86/utils/cvt/Makefile.am                                    |    7 
 hw/xfree86/utils/cvt/cvt.c                                          |   18 
 hw/xfree86/utils/gtf/Makefile.am                                    |    2 
 hw/xfree86/vbe/vbeModes.c                                           |    4 
 hw/xfree86/xaa/Makefile.am                                          |   52 
 hw/xquartz/Makefile.am                                              |    2 
 hw/xquartz/X11Application.h                                         |    1 
 hw/xquartz/X11Application.m                                         |    2 
 hw/xquartz/X11Controller.h                                          |    1 
 hw/xquartz/X11Controller.m                                          |    4 
 hw/xquartz/bundle/Resources/English.lproj/main.nib/designable.nib   |  320 ++-
 hw/xquartz/bundle/Resources/English.lproj/main.nib/keyedobjects.nib |binary
 hw/xquartz/quartz.c                                                 |   11 
 hw/xquartz/quartz.h                                                 |    1 
 hw/xquartz/quartzAudio.c                                            |  329 ---
 hw/xquartz/quartzAudio.h                                            |   37 
 hw/xquartz/quartzKeyboard.c                                         |    1 
 hw/xquartz/quartzStartup.c                                          |    4 
 hw/xwin/win.h                                                       |    7 
 hw/xwin/windialogs.c                                                |    5 
 hw/xwin/winerror.c                                                  |   24 
 include/Makefile.am                                                 |    1 
 include/Xprintf.h                                                   |   69 
 include/dix-config.h.in                                             |    3 
 include/os.h                                                        |   15 
 include/privates.h                                                  |    1 
 include/protocol-versions.h                                         |    6 
 mi/micmap.c                                                         |    2 
 mi/mieq.c                                                           |    8 
 miext/Makefile.am                                                   |    4 
 miext/sync/Makefile.am                                              |   14 
 miext/sync/misync.c                                                 |  201 ++
 miext/sync/misync.h                                                 |   77 
 miext/sync/misyncstr.h                                              |   86 
 os/access.c                                                         |    2 
 os/log.c                                                            |   31 
 os/xprintf.c                                                        |  170 +
 randr/Makefile.am                                                   |    6 
 randr/mirrcrtc.c                                                    |  174 +
 randr/randr.c                                                       |   15 
 randr/randrstr.h                                                    |  207 ++
 randr/rrcrtc.c                                                      |  562 +++++-
 randr/rrdispatch.c                                                  |    6 
 randr/rrinfo.c                                                      |    2 
 randr/rrpixmap.c                                                    |  154 +
 randr/rrscreen.c                                                    |   32 
 randr/rrsdispatch.c                                                 |  132 +
 randr/rrsprite.c                                                    |  104 +
 randr/rrtransform.c                                                 |   64 
 randr/rrtransform.h                                                 |   15 
 render/render.c                                                     |    8 
 xfixes/cursor.c                                                     |    2 
 xfixes/xfixes.c                                                     |    2 
 xfixes/xfixesint.h                                                  |    2 
 xkb/ddxList.c                                                       |   43 
 xkb/ddxLoad.c                                                       |   19 
 136 files changed, 4725 insertions(+), 2104 deletions(-)

New commits:
commit 27ef6565ff03288256c18da026a71345729bdc72
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Dec 8 13:27:41 2010 -0800

    XQuartz: Just NSBeep() for XBell()
    
    The CoreAudio path uses deprecated API and has reported crashes that
    I don't know how to fix.  NSBeep() does the job just fine.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 721d272..96b1fb0 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -30,7 +30,6 @@ libXquartz_la_SOURCES = \
 	keysym2ucs.c \
 	pseudoramiX.c \
 	quartz.c \
-	quartzAudio.c \
 	quartzCocoa.m \
 	quartzKeyboard.c \
 	quartzStartup.c \
@@ -47,7 +46,6 @@ EXTRA_DIST = \
 	keysym2ucs.h \
 	pseudoramiX.h \
 	quartz.h \
-	quartzAudio.h \
 	quartzCommon.h \
 	quartzKeyboard.h \
 	quartzRandR.h \
diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index 4621284..b3ad19b 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -77,7 +77,6 @@ void X11ApplicationMain(int argc, char **argv, char **envp);
 
 #define PREFS_APPSMENU              "apps_menu"
 #define PREFS_FAKEBUTTONS           "enable_fake_buttons"
-#define PREFS_SYSBEEP               "enable_system_beep"
 #define PREFS_KEYEQUIVS             "enable_key_equivalents"
 #define PREFS_FULLSCREEN_HOTKEYS    "fullscreen_hotkeys"
 #define PREFS_FULLSCREEN_MENU       "fullscreen_menu"
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index c3563b6..b855c83 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -718,8 +718,6 @@ static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
     NSString *nsstr;
     const char *tem;
 	
-    XQuartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
-                                       default:XQuartzUseSysBeep];
     XQuartzRootlessDefault = [self prefs_get_boolean:@PREFS_ROOTLESS
                                            default:XQuartzRootlessDefault];
     XQuartzFullscreenMenu = [self prefs_get_boolean:@PREFS_FULLSCREEN_MENU
diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index 65a09b8..9edaacd 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -65,7 +65,6 @@ typedef unsigned int NSUInteger;
     IBOutlet NSButton *fake_buttons;
     IBOutlet NSButton *enable_fullscreen;
     IBOutlet NSButton *enable_fullscreen_menu;
-    IBOutlet NSButton *use_sysbeep;
     IBOutlet NSButton *enable_keyequivs;
     IBOutlet NSButton *sync_keymap;
     IBOutlet NSButton *option_sends_alt;
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 13b6366..2edfb18 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -637,9 +637,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
     if(sender == fake_buttons) {
         darwinFakeButtons = [fake_buttons intValue];
         [NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
-    } else if(sender == use_sysbeep) {
-        XQuartzUseSysBeep = [use_sysbeep intValue];
-        [NSApp prefs_set_boolean:@PREFS_SYSBEEP value:XQuartzUseSysBeep];
     } else if(sender == enable_keyequivs) {
         XQuartzEnableKeyEquivalents =  [enable_keyequivs intValue];
         [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:XQuartzEnableKeyEquivalents];
@@ -701,7 +698,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
     BOOL pbproxy_active = [NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
     
     [fake_buttons setIntValue:darwinFakeButtons];
-    [use_sysbeep setIntValue:XQuartzUseSysBeep];
     [enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents];
     [sync_keymap setIntValue:darwinSyncKeymap];
     [option_sends_alt setIntValue:XQuartzOptionSendsAlt];
diff --git a/hw/xquartz/bundle/Resources/English.lproj/main.nib/designable.nib b/hw/xquartz/bundle/Resources/English.lproj/main.nib/designable.nib
index 7609393..bbf7eda 100644
--- a/hw/xquartz/bundle/Resources/English.lproj/main.nib/designable.nib
+++ b/hw/xquartz/bundle/Resources/English.lproj/main.nib/designable.nib
@@ -2,19 +2,22 @@
 <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
 	<data>
 		<int key="IBDocument.SystemTarget">1040</int>
-		<string key="IBDocument.SystemVersion">10D573</string>
-		<string key="IBDocument.InterfaceBuilderVersion">761</string>
-		<string key="IBDocument.AppKitVersion">1038.29</string>
-		<string key="IBDocument.HIToolboxVersion">460.00</string>
+		<string key="IBDocument.SystemVersion">10J541</string>
+		<string key="IBDocument.InterfaceBuilderVersion">850</string>
+		<string key="IBDocument.AppKitVersion">1038.35</string>
+		<string key="IBDocument.HIToolboxVersion">462.00</string>
 		<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
 			<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
-			<string key="NS.object.0">761</string>
+			<string key="NS.object.0">850</string>
 		</object>
 		<array class="NSMutableArray" key="IBDocument.EditedObjectIDs"/>
 		<array key="IBDocument.PluginDependencies">
 			<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 		</array>
-		<dictionary class="NSMutableDictionary" key="IBDocument.Metadata"/>
+		<object class="NSMutableDictionary" key="IBDocument.Metadata">
+			<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+			<integer value="1" key="NS.object.0"/>
+		</object>
 		<array class="NSMutableArray" key="IBDocument.RootObjects" id="904585544">
 			<object class="NSCustomObject" id="815810918">
 				<object class="NSMutableString" key="NSClassName">
@@ -388,7 +391,7 @@
 										<characters key="NS.bytes">1</characters>
 									</object>
 									<object class="NSView" key="NSView" id="596750588">
-										<reference key="NSNextResponder" ref="448510093"/>
+										<nil key="NSNextResponder"/>
 										<int key="NSvFlags">256</int>
 										<array class="NSMutableArray" key="NSSubviews">
 											<object class="NSButton" id="119157981">
@@ -396,7 +399,6 @@
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{18, 210}, {402, 18}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSButtonCell" key="NSCell" id="990762273">
 													<int key="NSCellFlags">67239424</int>
@@ -424,7 +426,6 @@
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{36, 60}, {385, 31}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="391919450">
 													<int key="NSCellFlags">67239424</int>
@@ -461,7 +462,6 @@
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{36, 162}, {385, 42}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="649334366">
 													<int key="NSCellFlags">67239424</int>
@@ -479,7 +479,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{18, 97}, {402, 18}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSButtonCell" key="NSCell" id="940564599">
 													<int key="NSCellFlags">67239424</int>
@@ -501,7 +500,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{36, 126}, {385, 14}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="666057093">
 													<int key="NSCellFlags">67239424</int>
@@ -518,7 +516,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{18, 146}, {402, 18}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSButtonCell" key="NSCell" id="967619578">
 													<int key="NSCellFlags">67239424</int>
@@ -540,7 +537,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{36, -1}, {385, 31}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="617441821">
 													<int key="NSCellFlags">67239424</int>
@@ -557,7 +553,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{18, 36}, {402, 18}}</string>
 												<reference key="NSSuperview" ref="596750588"/>
-												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSButtonCell" key="NSCell" id="67728988">
 													<int key="NSCellFlags">67239424</int>
@@ -576,8 +571,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 											</object>
 										</array>
 										<string key="NSFrame">{{10, 33}, {438, 246}}</string>
-										<reference key="NSSuperview" ref="448510093"/>
-										<reference key="NSWindow"/>
 									</object>
 									<string key="NSLabel">Input</string>
 									<reference key="NSColor" ref="57160303"/>
@@ -588,51 +581,15 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 										<characters key="NS.bytes">2</characters>
 									</object>
 									<object class="NSView" key="NSView" id="515308735">
-										<nil key="NSNextResponder"/>
+										<reference key="NSNextResponder" ref="448510093"/>
 										<int key="NSvFlags">256</int>
 										<array class="NSMutableArray" key="NSSubviews">
-											<object class="NSButton" id="418227126">
-												<reference key="NSNextResponder" ref="515308735"/>
-												<int key="NSvFlags">256</int>
-												<string key="NSFrame">{{18, 63}, {402, 18}}</string>
-												<reference key="NSSuperview" ref="515308735"/>
-												<bool key="NSEnabled">YES</bool>
-												<object class="NSButtonCell" key="NSCell" id="1016069354">
-													<int key="NSCellFlags">67239424</int>
-													<int key="NSCellFlags2">0</int>
-													<string key="NSContents">Use system alert effect</string>
-													<reference key="NSSupport" ref="463863101"/>
-													<reference key="NSControlView" ref="418227126"/>
-													<int key="NSButtonFlags">1211912703</int>
-													<int key="NSButtonFlags2">2</int>
-													<reference key="NSAlternateImage" ref="391434389"/>
-													<string key="NSAlternateContents"/>
-													<string key="NSKeyEquivalent"/>
-													<int key="NSPeriodicDelay">200</int>
-													<int key="NSPeriodicInterval">25</int>
-												</object>
-											</object>
-											<object class="NSTextField" id="1039016593">
-												<reference key="NSNextResponder" ref="515308735"/>
-												<int key="NSvFlags">256</int>
-												<string key="NSFrame">{{36, 29}, {385, 28}}</string>
-												<reference key="NSSuperview" ref="515308735"/>
-												<bool key="NSEnabled">YES</bool>
-												<object class="NSTextFieldCell" key="NSCell" id="624655599">
-													<int key="NSCellFlags">67239424</int>
-													<int key="NSCellFlags2">4194304</int>
-													<string key="NSContents">X11 beeps will use the standard system alert, as defined in the Sound Effects system preferences panel.</string>
-													<reference key="NSSupport" ref="26"/>
-													<reference key="NSControlView" ref="1039016593"/>
-													<reference key="NSBackgroundColor" ref="57160303"/>
-													<reference key="NSTextColor" ref="930815747"/>
-												</object>
-											</object>
 											<object class="NSPopUpButton" id="709074847">
 												<reference key="NSNextResponder" ref="515308735"/>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{74, 202}, {128, 26}}</string>
 												<reference key="NSSuperview" ref="515308735"/>
+												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSPopUpButtonCell" key="NSCell" id="633115429">
 													<int key="NSCellFlags">-2076049856</int>
@@ -723,6 +680,7 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{17, 205}, {55, 20}}</string>
 												<reference key="NSSuperview" ref="515308735"/>
+												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="930265681">
 													<int key="NSCellFlags">67239424</int>
@@ -739,6 +697,7 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{36, 183}, {392, 14}}</string>
 												<reference key="NSSuperview" ref="515308735"/>
+												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="311969422">
 													<int key="NSCellFlags">67239424</int>
@@ -755,6 +714,7 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{18, 149}, {409, 23}}</string>
 												<reference key="NSSuperview" ref="515308735"/>
+												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSButtonCell" key="NSCell" id="631531164">
 													<int key="NSCellFlags">67239424</int>
@@ -776,6 +736,7 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{37, 83}, {409, 23}}</string>
 												<reference key="NSSuperview" ref="515308735"/>
+												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSButtonCell" key="NSCell" id="917248662">
 													<int key="NSCellFlags">67239424</int>
@@ -797,6 +758,7 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 												<int key="NSvFlags">256</int>
 												<string key="NSFrame">{{36, 112}, {385, 31}}</string>
 												<reference key="NSSuperview" ref="515308735"/>
+												<reference key="NSWindow"/>
 												<bool key="NSEnabled">YES</bool>
 												<object class="NSTextFieldCell" key="NSCell" id="761107402">
 													<int key="NSCellFlags">67239424</int>
@@ -810,6 +772,8 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 											</object>
 										</array>
 										<string key="NSFrame">{{10, 33}, {438, 246}}</string>
+										<reference key="NSSuperview" ref="448510093"/>
+										<reference key="NSWindow"/>
 									</object>
 									<string key="NSLabel">Output</string>
 									<reference key="NSColor" ref="57160303"/>
@@ -1212,13 +1176,13 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 									<reference key="NSTabView" ref="448510093"/>
 								</object>
 							</array>
-							<reference key="NSSelectedTabViewItem" ref="287591690"/>
+							<reference key="NSSelectedTabViewItem" ref="960678392"/>
 							<reference key="NSFont" ref="463863101"/>
 							<int key="NSTvFlags">0</int>
 							<bool key="NSAllowTruncatedLabels">YES</bool>
 							<bool key="NSDrawsBackground">YES</bool>
 							<array class="NSMutableArray" key="NSSubviews">
-								<reference ref="596750588"/>
+								<reference ref="515308735"/>
 							</array>
 						</object>
 					</array>
@@ -1734,14 +1698,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBOutletConnection" key="connection">
-						<string key="label">use_sysbeep</string>
-						<reference key="source" ref="485884620"/>
-						<reference key="destination" ref="418227126"/>
-					</object>
-					<int key="connectionID">390</int>
-				</object>
-				<object class="IBConnectionRecord">
-					<object class="IBOutletConnection" key="connection">
 						<string key="label">fake_buttons</string>
 						<reference key="source" ref="485884620"/>
 						<reference key="destination" ref="119157981"/>
@@ -1792,14 +1748,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 					<object class="IBActionConnection" key="connection">
 						<string key="label">prefs_changed:</string>
 						<reference key="source" ref="485884620"/>
-						<reference key="destination" ref="418227126"/>
-					</object>
-					<int key="connectionID">397</int>
-				</object>
-				<object class="IBConnectionRecord">
-					<object class="IBActionConnection" key="connection">
-						<string key="label">prefs_changed:</string>
-						<reference key="source" ref="485884620"/>
 						<reference key="destination" ref="709074847"/>
 					</object>
 					<int key="connectionID">398</int>
@@ -2547,28 +2495,10 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 							<reference ref="477203622"/>
 							<reference ref="57246850"/>
 							<reference ref="298603383"/>
-							<reference ref="418227126"/>
-							<reference ref="1039016593"/>
 						</array>
 						<reference key="parent" ref="960678392"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">371</int>
-						<reference key="object" ref="418227126"/>
-						<array class="NSMutableArray" key="children">
-							<reference ref="1016069354"/>
-						</array>
-						<reference key="parent" ref="515308735"/>
-					</object>
-					<object class="IBObjectRecord">
-						<int key="objectID">372</int>
-						<reference key="object" ref="1039016593"/>
-						<array class="NSMutableArray" key="children">
-							<reference ref="624655599"/>
-						</array>
-						<reference key="parent" ref="515308735"/>
-					</object>
-					<object class="IBObjectRecord">
 						<int key="objectID">382</int>
 						<reference key="object" ref="709074847"/>
 						<array class="NSMutableArray" key="children">
@@ -2761,16 +2691,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 						<reference key="parent" ref="179949713"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">100371</int>
-						<reference key="object" ref="1016069354"/>
-						<reference key="parent" ref="418227126"/>
-					</object>
-					<object class="IBObjectRecord">
-						<int key="objectID">100372</int>
-						<reference key="object" ref="624655599"/>
-						<reference key="parent" ref="1039016593"/>
-					</object>
-					<object class="IBObjectRecord">
 						<int key="objectID">100382</int>
 						<reference key="object" ref="633115429"/>
 						<array class="NSMutableArray" key="children">
@@ -3249,8 +3169,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 				<string key="100368.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="100369.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="100370.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<string key="100371.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<string key="100372.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="100374.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="100375.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="100376.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3443,10 +3361,6 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 				<integer value="1" key="369.ImportedFromIB2"/>
 				<string key="370.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<integer value="1" key="370.ImportedFromIB2"/>
-				<string key="371.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<integer value="1" key="371.ImportedFromIB2"/>
-				<string key="372.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<integer value="1" key="372.ImportedFromIB2"/>
 				<string key="374.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<integer value="1" key="374.ImportedFromIB2"/>
 				<string key="375.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3582,6 +3496,76 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 						<string key="x11_help:">id</string>
 						<string key="zoom_window:">id</string>
 					</dictionary>
+					<dictionary class="NSMutableDictionary" key="actionInfosByName">
+						<object class="IBActionInfo" key="apps_table_delete:">
+							<string key="name">apps_table_delete:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="apps_table_done:">
+							<string key="name">apps_table_done:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="apps_table_duplicate:">
+							<string key="name">apps_table_duplicate:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="apps_table_new:">
+							<string key="name">apps_table_new:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="apps_table_show:">
+							<string key="name">apps_table_show:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="bring_to_front:">
+							<string key="name">bring_to_front:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="close_window:">
+							<string key="name">close_window:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="enable_fullscreen_changed:">
+							<string key="name">enable_fullscreen_changed:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="minimize_window:">
+							<string key="name">minimize_window:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="next_window:">
+							<string key="name">next_window:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="prefs_changed:">
+							<string key="name">prefs_changed:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="prefs_show:">
+							<string key="name">prefs_show:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="previous_window:">
+							<string key="name">previous_window:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="quit:">
+							<string key="name">quit:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="toggle_fullscreen:">
+							<string key="name">toggle_fullscreen:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="x11_help:">
+							<string key="name">x11_help:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+						<object class="IBActionInfo" key="zoom_window:">
+							<string key="name">zoom_window:</string>
+							<string key="candidateClassName">id</string>
+						</object>
+					</dictionary>
 					<dictionary class="NSMutableDictionary" key="outlets">
 						<string key="apps_separator">NSMenuItem</string>
 						<string key="apps_table">NSTableView</string>
@@ -3614,6 +3598,128 @@ IG9yIHJpZ2h0IG1vdXNlIGJ1dHRvbnMuCg</string>
 						<string key="window_separator">NSMenuItem</string>
 						<string key="x11_about_item">NSMenuItem</string>
 					</dictionary>
+					<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+						<object class="IBToOneOutletInfo" key="apps_separator">
+							<string key="name">apps_separator</string>
+							<string key="candidateClassName">NSMenuItem</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="apps_table">
+							<string key="name">apps_table</string>
+							<string key="candidateClassName">NSTableView</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="click_through">
+							<string key="name">click_through</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="copy_menu_item">
+							<string key="name">copy_menu_item</string>
+							<string key="candidateClassName">NSMenuItem</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="depth">
+							<string key="name">depth</string>
+							<string key="candidateClassName">NSPopUpButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="dock_apps_menu">
+							<string key="name">dock_apps_menu</string>
+							<string key="candidateClassName">NSMenu</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="dock_menu">
+							<string key="name">dock_menu</string>
+							<string key="candidateClassName">NSMenu</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="dock_window_separator">
+							<string key="name">dock_window_separator</string>
+							<string key="candidateClassName">NSMenuItem</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="enable_auth">
+							<string key="name">enable_auth</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="enable_fullscreen">
+							<string key="name">enable_fullscreen</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="enable_fullscreen_menu">
+							<string key="name">enable_fullscreen_menu</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="enable_keyequivs">
+							<string key="name">enable_keyequivs</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="enable_tcp">
+							<string key="name">enable_tcp</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="fake_buttons">
+							<string key="name">fake_buttons</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="focus_follows_mouse">
+							<string key="name">focus_follows_mouse</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="focus_on_new_window">
+							<string key="name">focus_on_new_window</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="option_sends_alt">
+							<string key="name">option_sends_alt</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="prefs_panel">
+							<string key="name">prefs_panel</string>
+							<string key="candidateClassName">NSPanel</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_clipboard_to_pasteboard">
+							<string key="name">sync_clipboard_to_pasteboard</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_keymap">
+							<string key="name">sync_keymap</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_pasteboard">
+							<string key="name">sync_pasteboard</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_pasteboard_to_clipboard">
+							<string key="name">sync_pasteboard_to_clipboard</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_pasteboard_to_primary">
+							<string key="name">sync_pasteboard_to_primary</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_primary_immediately">
+							<string key="name">sync_primary_immediately</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_text1">
+							<string key="name">sync_text1</string>
+							<string key="candidateClassName">NSTextField</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="sync_text2">
+							<string key="name">sync_text2</string>
+							<string key="candidateClassName">NSTextField</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="toggle_fullscreen_item">
+							<string key="name">toggle_fullscreen_item</string>
+							<string key="candidateClassName">NSMenuItem</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="use_sysbeep">
+							<string key="name">use_sysbeep</string>
+							<string key="candidateClassName">NSButton</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="window_separator">
+							<string key="name">window_separator</string>
+							<string key="candidateClassName">NSMenuItem</string>
+						</object>
+						<object class="IBToOneOutletInfo" key="x11_about_item">
+							<string key="name">x11_about_item</string>
+							<string key="candidateClassName">NSMenuItem</string>
+						</object>
+					</dictionary>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBDocumentRelativeSource</string>
 						<string key="minorKey">../../../X11Controller.h</string>
diff --git a/hw/xquartz/bundle/Resources/English.lproj/main.nib/keyedobjects.nib b/hw/xquartz/bundle/Resources/English.lproj/main.nib/keyedobjects.nib
index 888424d..836d595 100644
Binary files a/hw/xquartz/bundle/Resources/English.lproj/main.nib/keyedobjects.nib and b/hw/xquartz/bundle/Resources/English.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 26b2c1f..6c185a8 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -80,7 +80,6 @@ Bool XQuartzRootlessDefault = TRUE;
 Bool XQuartzIsRootless = TRUE;
 Bool XQuartzServerVisible = FALSE;
 Bool XQuartzFullscreenMenu = FALSE;
-Bool XQuartzUseSysBeep = FALSE;
 
 /*
 ===========================================================================
@@ -446,3 +445,13 @@ void QuartzCopyDisplayIDs(ScreenPtr pScreen,
     memcpy(pQuartzScreen->displayIDs, displayIDs, size);
     pQuartzScreen->displayCount = displayCount;
 }
+
+void NSBeep(void);
+void DDXRingBell(
+    int volume,         // volume is % of max
+    int pitch,          // pitch is Hz
+    int duration)       // duration is milliseconds
+{
+    if (volume)
+        NSBeep();
+}
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index 7efb7e0..b83391d 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -123,7 +123,6 @@ extern Bool XQuartzIsRootless;       /* Is our current mode rootless (or FS)? */
 extern Bool XQuartzFullscreenMenu;   /* Show the menu bar (autohide) while in FS */
 extern Bool XQuartzFullscreenDisableHotkeys;
 extern Bool XQuartzOptionSendsAlt;   /* Alt or Mode_switch? */
-extern Bool XQuartzUseSysBeep;       /* Sys beep or our own? */
 
 Bool QuartzAddScreen(int index, ScreenPtr pScreen);
 Bool QuartzSetupScreen(int index, ScreenPtr pScreen);
diff --git a/hw/xquartz/quartzAudio.c b/hw/xquartz/quartzAudio.c
deleted file mode 100644
index d0f7c53..0000000
--- a/hw/xquartz/quartzAudio.c
+++ /dev/null
@@ -1,329 +0,0 @@
-//
-// QuartzAudio.m
-//
-// X Window bell support using CoreAudio or AppKit.
-// Greg Parker  gparker at cs.stanford.edu  19 Feb 2001
-//
-// Info about sine wave sound playback:
-// CoreAudio code derived from macosx-dev posting by Tim Wood
-//  http://www.omnigroup.com/mailman/archive/macosx-dev/2000-May/002004.html
-// Smoothing transitions between sounds
-//  http://www.wam.umd.edu/~mphoenix/dss/dss.html
-//
-/*
- * Copyright (c) 2001 Greg Parker. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#include "sanitizedCarbon.h"
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartz.h"
-#include "quartzAudio.h"
-
-#include <CoreAudio/CoreAudio.h>
-#include <pthread.h>
-#include <AvailabilityMacros.h>
-
-#include "inputstr.h"
-#include <X11/extensions/XI.h>
-#include <assert.h>
-
-void NSBeep(void);
-
-typedef struct QuartzAudioRec {
-    double frequency;
-    double amplitude;
-
-    UInt32 curFrame;
-    UInt32 remainingFrames;
-    UInt32 totalFrames;
-    double sampleRate;
-    UInt32 fadeLength;
-
-    UInt32 bufferByteCount;
-    Boolean playing;
-    pthread_mutex_t lock;
-
-    // used to fade out interrupted sound and avoid 'pop'
-    double prevFrequency;
-    double prevAmplitude;
-    UInt32 prevFrame; 
-} QuartzAudioRec;
-
-static AudioDeviceID quartzAudioDevice = kAudioDeviceUnknown;
-static QuartzAudioRec data;
-
-
-/*
- * QuartzAudioEnvelope
- *  Fade sound in and out to avoid pop.
- *  Sounds with shorter duration will never reach full amplitude. Deal.
- */
-static double QuartzAudioEnvelope(
-    UInt32 curFrame,
-    UInt32 totalFrames,
-    UInt32 fadeLength )
-{
-    double fadeFrames = min(fadeLength, totalFrames / 2);
-    if (fadeFrames < 1) return 0;
-
-    if (curFrame < fadeFrames) {
-        return curFrame / fadeFrames;
-    } else if (curFrame > totalFrames - fadeFrames) {
-        return (totalFrames-curFrame) / fadeFrames;
-    } else {
-        return 1.0;
-    }
-}
-
-
-/*
- * QuartzFillBuffer
- *  Fill this buffer with data and update the data position.
- *  FIXME: this is ugly
- */
-static void QuartzFillBuffer(
-    AudioBuffer *audiobuffer,
-    QuartzAudioRec *data )
-{
-    float *buffer, *b;
-    unsigned int frame, frameCount;
-    unsigned int bufferFrameCount;
-    float multiplier, v;
-    int i;
-    
-    buffer = (float *)audiobuffer->mData;
-    bufferFrameCount = audiobuffer->mDataByteSize / (sizeof(float) * audiobuffer->mNumberChannels);
-
-    frameCount = min(bufferFrameCount, data->remainingFrames);
-
-    // Fade out previous sine wave, if any.
-    b = buffer;
-    if (data->prevFrame) {
-        multiplier = 2*M_PI*(data->prevFrequency/data->sampleRate);
-        for (frame = 0; frame < data->fadeLength; frame++) {
-            v = data->prevAmplitude *
-                QuartzAudioEnvelope(frame+data->fadeLength,
-                                    2*data->fadeLength,
-                                    data->fadeLength) *
-                sin(multiplier * (data->prevFrame+frame));
-            for (i = 0; i < audiobuffer->mNumberChannels; i++) {
-                *b++ = v;
-            }
-        }
-        // no more prev fade
-        data->prevFrame = 0;
-
-        // adjust for space eaten by prev fade
-        b += audiobuffer->mNumberChannels*frame;
-        bufferFrameCount -= frame;
-        frameCount = min(bufferFrameCount, data->remainingFrames);
-    }
-
-    // Write a sine wave with the specified frequency and amplitude
-    multiplier = 2*M_PI*(data->frequency/data->sampleRate);
-    for (frame = 0; frame < frameCount; frame++) {
-        v = data->amplitude * 
-            QuartzAudioEnvelope(data->curFrame+frame, data->totalFrames,
-                                data->fadeLength) *
-            sin(multiplier * (data->curFrame+frame));
-        for (i = 0; i < audiobuffer->mNumberChannels; i++) {
-            *b++ = v;
-        }
-    }
-
-    // Zero out the rest of the buffer, if any
-    memset(b, 0, sizeof(float) * audiobuffer->mNumberChannels *
-           (bufferFrameCount-frame));
-
-    data->curFrame += frameCount;
-    data->remainingFrames -= frameCount;
-    if (data->remainingFrames == 0) {
-        data->playing = FALSE;
-        data->curFrame = 0;
-    }
-}
-
-
-/*
- * QuartzAudioIOProc
- *  Callback function for audio playback.
- *  FIXME: use inOutputTime to correct for skipping
- */
-static OSStatus 
-QuartzAudioIOProc(
-    AudioDeviceID inDevice, 
-    const AudioTimeStamp *inNow, 
-    const AudioBufferList *inInputData, 
-    const AudioTimeStamp *inInputTime, 
-    AudioBufferList *outOutputData, 
-    const AudioTimeStamp *inOutputTime, 
-    void *inClientData )
-{
-    QuartzAudioRec *data = (QuartzAudioRec *)inClientData;
-    int i;
-    Boolean wasPlaying;
-
-    pthread_mutex_lock(&data->lock);
-    wasPlaying = data->playing;
-    for (i = 0; i < outOutputData->mNumberBuffers; i++) {
-        if (data->playing) {
-            QuartzFillBuffer(outOutputData->mBuffers+i, data); 
-        }
-        else {
-            memset(outOutputData->mBuffers[i].mData, 0, 
-                   outOutputData->mBuffers[i].mDataByteSize);
-        }
-    }
-    if (wasPlaying  &&  !data->playing) {
-        OSStatus err;
-        err = AudioDeviceStop(inDevice, QuartzAudioIOProc);
-        if(err != noErr)
-            fprintf(stderr, "Error stopping audio device: %ld\n", (long int)err);
-    }
-    pthread_mutex_unlock(&data->lock);
-    return 0;
-}
-
-
-/*
- * DDXRingBell
- * Play a tone using the CoreAudio API
- */
-void DDXRingBell(
-    int volume,         // volume is % of max
-    int pitch,          // pitch is Hz
-    int duration )      // duration is milliseconds
-{
-    if (XQuartzUseSysBeep) {
-        if (volume)
-            NSBeep();
-        return;
-    }
-        
-    if (quartzAudioDevice == kAudioDeviceUnknown) return;
-
-    pthread_mutex_lock(&data.lock);
-
-    // fade previous sound, if any
-    data.prevFrequency = data.frequency;
-    data.prevAmplitude = data.amplitude;
-    data.prevFrame = data.curFrame;
-
-    // set new sound
-    data.frequency = pitch;
-    data.amplitude = volume / 100.0;
-    data.curFrame = 0;
-    data.totalFrames = (int)(data.sampleRate * duration / 1000.0);
-    data.remainingFrames = data.totalFrames;
-
-    if (! data.playing) {
-        OSStatus status;
-        status = AudioDeviceStart(quartzAudioDevice, QuartzAudioIOProc);
-        if (status) {
-            ErrorF("DDXRingBell: AudioDeviceStart returned %ld\n", (long)status);
-        } else {
-            data.playing = TRUE;
-        }
-    }
-    pthread_mutex_unlock(&data.lock);
-}
-
-/*
- * QuartzAudioInit
- *  Prepare to play the bell with the CoreAudio API
- */
-void QuartzAudioInit(void) 
-{
-    UInt32 propertySize;
-    OSStatus status;
-    AudioDeviceID outputDevice;
-    double sampleRate;
-    AudioObjectPropertyAddress devicePropertyAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
-    AudioObjectPropertyAddress sampleRatePropertyAddress = { kAudioDevicePropertyNominalSampleRate, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
-    
-    // Get the default output device
-    propertySize = sizeof(outputDevice);
-    status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &devicePropertyAddress,
-                                        0, NULL,
-                                        &propertySize, &outputDevice);
-    if (status) {
-        ErrorF("QuartzAudioInit: AudioObjectGetPropertyData(output device) returned %ld\n",
-               (long)status);
-        return;
-    }
-    if (outputDevice == kAudioDeviceUnknown) {
-        ErrorF("QuartzAudioInit: No audio output devices available.\n");
-        return;
-    }
-
-    // Get the basic device description
-    sampleRate = 0.;
-    propertySize = sizeof(sampleRate);
-    status = AudioObjectGetPropertyData(outputDevice, &sampleRatePropertyAddress,
-                                        0, NULL,
-                                        &propertySize, &sampleRate);
-    if (status) {
-        ErrorF("QuartzAudioInit: AudioObjectGetPropertyData(sample rate) returned %ld\n",
-               (long)status);
-        return;
-    }
-
-    // Fill in the playback data
-    data.frequency = 0;
-    data.amplitude = 0;
-    data.curFrame = 0;
-    data.remainingFrames = 0; 
-    data.sampleRate = sampleRate;
-    // data.bufferByteCount = bufferByteCount;
-    data.playing = FALSE;
-    data.prevAmplitude = 0;
-    data.prevFrame = 0;
-    data.prevFrequency = 0;
-    data.fadeLength = data.sampleRate / 200;
-    pthread_mutex_init(&data.lock, NULL); // fixme error check
-
-    // fixme assert fadeLength<framesPerBuffer
-
-    // Prepare for playback
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
-    {
-    AudioDeviceIOProcID sInputIOProcID = NULL;
-    status = AudioDeviceCreateIOProcID( outputDevice, QuartzAudioIOProc, &data, &sInputIOProcID );
-    }
-#else
-    status = AudioDeviceAddIOProc(outputDevice, QuartzAudioIOProc, &data);
-#endif
-    if (status) {
-        ErrorF("QuartzAudioInit: AddIOProc returned %ld\n", (long)status);
-        return;
-    }
-
-    // success!
-    quartzAudioDevice = outputDevice;
-}
diff --git a/hw/xquartz/quartzAudio.h b/hw/xquartz/quartzAudio.h
deleted file mode 100644
index 2a78b39..0000000
--- a/hw/xquartz/quartzAudio.h
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-// QuartzAudio.h
-//
-// X Window bell support using CoreAudio or AppKit.
-// Greg Parker   gparker at cs.stanford.edu   19 Feb 2001
-/*
- * Copyright (c) 2001 Greg Parker. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifndef _QUARTZAUDIO_H
-#define _QUARTZAUDIO_H
-
-void QuartzAudioInit(void);
-
-#endif
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index f54c686..54f709a 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -53,7 +53,6 @@
 #include "darwinEvents.h"
 
 #include "quartzKeyboard.h"
-#include "quartzAudio.h"
 
 #include "X11Application.h"
 
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index ba92ece..36c8182 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -40,7 +40,6 @@
 #include "X11Controller.h"
 #include "darwin.h"
 #include "darwinEvents.h"
-#include "quartzAudio.h"
 #include "quartz.h"
 #include "opaque.h"
 #include "micmap.h"
@@ -117,9 +116,6 @@ int server_main(int argc, char **argv, char **envp) {
         }
     }
 
-    /* Create the audio mutex */
-    QuartzAudioInit();
-
     X11ControllerMain(argc, argv, envp);
     exit(0);
 }
commit 2c70b650b342378898064cf27e2f95c4b2e53d24
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Dec 8 18:54:30 2010 +0000

    Fix Xwin build after af0f9f91
    
    Fix damage to XWIN_LIBS in commit af0f9f913398d34a885c3fb4e8d40c1a7e2b3ee9
    "Move some sync code to miext", which broke the XWin build
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index d2318da..38158f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1888,7 +1888,7 @@ if test "x$XWIN" = xyes; then
 			XWIN_SYS_LIBS=-lwinsock2
 			;;
 	esac
-	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $CONFIG_LIB $RANDR_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
+	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
 	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS"
 	AC_SUBST(XWIN_LIBS)
 	AC_SUBST(XWIN_SERVER_NAME)
commit 519d243f0c8e3c80226701f71d2cfa62e42dbff7
Merge: 9f9c732... 446482e...
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Dec 7 13:39:58 2010 -0800

    Merge remote branch 'alanc/master'

commit 446482efaa3d266266e2a143492a3ec0523622bd
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Nov 28 09:41:17 2010 -0800

    Convert cvt code to use XNFasprintf()
    
    Requires linking xprintf.c into standalone cvt utility
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
index 1da5fe5..244f3b9 100644
--- a/hw/xfree86/modes/xf86cvt.c
+++ b/hw/xfree86/modes/xf86cvt.c
@@ -279,15 +279,7 @@ xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
     if (Interlaced)
         Mode->VTotal *= 2;
 
-    {
-        char  Name[256];
-        Name[0] = 0;
-
-        snprintf(Name, 256, "%dx%d", HDisplay, VDisplay);
-
-        Mode->name = xnfalloc(strlen(Name) + 1);
-        memcpy(Mode->name, Name, strlen(Name) + 1);
-    }
+    XNFasprintf(&Mode->name, "%dx%d", HDisplay, VDisplay);
 
     if (Reduced)
         Mode->Flags |= V_PHSYNC | V_NVSYNC;
diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am
index 0658682..ba02145 100644
--- a/hw/xfree86/utils/cvt/Makefile.am
+++ b/hw/xfree86/utils/cvt/Makefile.am
@@ -27,7 +27,10 @@ INCLUDES = $(XORG_INCS) \
 	   -I$(top_srcdir)/hw/xfree86/parser
 
 # gah
-cvt_SOURCES = cvt.c $(top_srcdir)/hw/xfree86/modes/xf86cvt.c
+cvt_SOURCES = cvt.c \
+	$(top_srcdir)/hw/xfree86/modes/xf86cvt.c \
+	$(top_srcdir)/os/xprintf.c
+
 cvt_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
 man1_MANS = cvt.man
diff --git a/hw/xfree86/utils/cvt/cvt.c b/hw/xfree86/utils/cvt/cvt.c
index cf0a479..fff500b 100644
--- a/hw/xfree86/utils/cvt/cvt.c
+++ b/hw/xfree86/utils/cvt/cvt.c
@@ -25,6 +25,24 @@
 
 #include "xf86.h"
 
+/* Error implementation used by the server code we built in */
+void
+Error(const char *str)
+{
+    perror(str);
+}
+
+/* FatalError implementation used by the server code we built in */
+void
+FatalError(const char *f, ...)
+{
+    va_list args;
+    va_start(args, f);
+    vfprintf(stderr, f, args);
+    va_end(args);
+    exit(1);
+}
+
 /* xnfalloc implementation used by the server code we built in */
 pointer
 XNFalloc(unsigned long n)
commit d2c42b102707db6c1ca9dccc4de9210a43650cb1
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 23:10:46 2010 -0800

    Replace alloc+strcpy+strcat with asprintf() & XNFasprintf() calls
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/dix/devices.c b/dix/devices.c
index 708860a..6c0dc42 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2524,9 +2524,11 @@ AllocDevicePair (ClientPtr client, char* name,
     if (!pointer)
         return BadAlloc;
 
-    pointer->name = calloc(strlen(name) + strlen(" pointer") + 1, sizeof(char));
-    strcpy(pointer->name, name);
-    strcat(pointer->name, " pointer");
+    if (asprintf(&pointer->name, "%s pointer", name) == -1) {
+        pointer->name = NULL;
+        RemoveDevice(pointer, FALSE);
+        return BadAlloc;
+    }
 
     pointer->public.processInputProc = ProcessOtherEvent;
     pointer->public.realInputProc = ProcessOtherEvent;
@@ -2547,9 +2549,12 @@ AllocDevicePair (ClientPtr client, char* name,
         return BadAlloc;
     }
 
-    keyboard->name = calloc(strlen(name) + strlen(" keyboard") + 1, sizeof(char));
-    strcpy(keyboard->name, name);
-    strcat(keyboard->name, " keyboard");
+    if (asprintf(&keyboard->name, "%s keyboard", name) == -1) {
+        keyboard->name = NULL;
+        RemoveDevice(keyboard, FALSE);
+        RemoveDevice(pointer, FALSE);
+        return BadAlloc;
+    }
 
     keyboard->public.processInputProc = ProcessOtherEvent;
     keyboard->public.realInputProc = ProcessOtherEvent;
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 5f3b8e8..49d8fa8 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -208,9 +208,7 @@ xf86ValidateFontPath(char *path)
 	continue;
       }
       else {
-	p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
-	strcpy(p1, dir_elem);
-	strcat(p1, DIR_FILE);
+	XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE);
 	flag = stat(p1, &stat_buf);
 	if (flag == 0)
 	  if (!S_ISREG(stat_buf.st_mode))
diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index af39b2b..d49aa31 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -638,13 +638,10 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
 	    newn = n + 2;
 	} else {
 	    free(n);
-	    n = malloc(strlen(p->name) + 2 + 1);
-	    if (!n) {
+	    if (asprintf(&n, "No%s", p->name) == -1) {
 		p->found = FALSE;
 		return FALSE;
 	    }
-	    strcpy(n, "No");
-	    strcat(n, p->name);
 	    newn = n;
 	}
 	if ((s = xf86findOptionValue(options, newn)) != NULL) {
diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c
index ce86090..c0fa80a 100644
--- a/hw/xfree86/common/xf86ShowOpts.c
+++ b/hw/xfree86/common/xf86ShowOpts.c
@@ -97,11 +97,8 @@ void DoShowOptions (void) {
 				);
 				continue;                                                       
 			}
-			pSymbol = malloc(
-				strlen(xf86DriverList[i]->driverName) + strlen("ModuleData") + 1
-			);
-			strcpy (pSymbol, xf86DriverList[i]->driverName);
-			strcat (pSymbol, "ModuleData");
+			XNFasprintf(&pSymbol, "%sModuleData",
+				    xf86DriverList[i]->driverName);
 			initData = LoaderSymbol (pSymbol);
 			if (initData) {
 				XF86ModuleVersionInfo *vers = initData->vers;
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index f4e922c..168795d 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -146,11 +146,8 @@ extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
     for (i = 0; extensionModules[i].name != NULL; i++) {
 	if (opts) {
 	    char *s;
-	    s = (char *)malloc(strlen(extensionModules[i].name) + 5);
-	    if (s) {
+	    if (Xasprinf(&s, "omit%s", extensionModules[i].name) != -1) {
 		pointer o;
-		strcpy(s, "omit");
-		strcat(s, extensionModules[i].name);
 		o = xf86FindOption(opts, s);
 		free(s);
 		if (o) {
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 1f6933a..3b3511c 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -933,16 +933,14 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
      * now check if the special data object <modulename>ModuleData is
      * present.
      */
-    p = malloc(strlen(name) + strlen("ModuleData") + 1);
-    if (!p) {
+    if (asprintf(&p, "%sModuleData", name) == -1) {
+	p = NULL;
 	if (errmaj)
 	    *errmaj = LDR_NOMEM;
 	if (errmin)
 	    *errmin = 0;
 	goto LoadModule_fail;
     }
-    strcpy(p, name);
-    strcat(p, "ModuleData");
     initdata = LoaderSymbol(p);
     if (initdata) {
 	ModuleSetupProc setup;
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 08d384f..c4470c3 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -510,7 +510,6 @@ static void
 xf86OutputSetMonitor (xf86OutputPtr output)
 {
     char    *option_name;
-    static const char monitor_prefix[] = "monitor-";
     char    *monitor;
 
     if (!output->name)
@@ -520,11 +519,8 @@ xf86OutputSetMonitor (xf86OutputPtr output)
 
     output->options = xnfalloc (sizeof (xf86OutputOptions));
     memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions));
-    
-    option_name = xnfalloc (strlen (monitor_prefix) +
-			    strlen (output->name) + 1);
-    strcpy (option_name, monitor_prefix);
-    strcat (option_name, output->name);
+
+    XNFasprintf(&option_name, "monitor-%s", output->name);
     monitor = xf86findOptionValue (output->scrn->options, option_name);
     if (!monitor)
 	monitor = output->name;
commit 3a9bb93dd178084f4ff1abcea331ca5a62f88ce6
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 22:38:27 2010 -0800

    Convert alloc+sprintf pairs into asprintf() & XNFasprintf() calls
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/config/hal.c b/config/hal.c
index 5e35911..0b848a0 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -63,10 +63,8 @@ device_removed(LibHalContext *ctx, const char *udi)
 {
     char *value;
 
-    value = malloc(strlen(udi) + 5); /* "hal:" + NULL */
-    if (!value)
+    if (asprintf (&value, "hal:%s", udi) == -1)
         return;
-    sprintf(value, "hal:%s", udi);
 
     remove_devices("hal", value);
 
@@ -228,12 +226,11 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     add_option(&options, "driver", driver);
     add_option(&options, "name", name);
 
-    config_info = malloc(strlen(udi) + 5); /* "hal:" and NULL */
-    if (!config_info) {
+    if (asprintf (&config_info, "hal:%s", udi) == -1) {
+        config_info = NULL;
         LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
         goto unwind;
     }
-    sprintf(config_info, "hal:%s", udi);
 
     /* Check for duplicate devices */
     if (device_is_duplicate(config_info))
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index 7235c61..b89f701 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -205,12 +205,9 @@ configureScreenSection (int screennum)
     int depths[] = { 1, 4, 8, 15, 16, 24/*, 32*/ };
     parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec)
 
-    ptr->scrn_identifier = malloc(18);
-    sprintf(ptr->scrn_identifier, "Screen%d", screennum);
-    ptr->scrn_monitor_str = malloc(19);
-    sprintf(ptr->scrn_monitor_str, "Monitor%d", screennum);
-    ptr->scrn_device_str = malloc(16);
-    sprintf(ptr->scrn_device_str, "Card%d", screennum);
+    XNFasprintf(&ptr->scrn_identifier, "Screen%d", screennum);
+    XNFasprintf(&ptr->scrn_monitor_str, "Monitor%d", screennum);
+    XNFasprintf(&ptr->scrn_device_str, "Card%d", screennum);
 
     for (i=0; i<sizeof(depths)/sizeof(depths[0]); i++)
     {
@@ -256,14 +253,13 @@ optionTypeToString(OptionValueType type)
 static XF86ConfDevicePtr
 configureDeviceSection (int screennum)
 {
-    char identifier[16];
     OptionInfoPtr p;
     int i = 0;
     parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec)
 
     /* Move device info to parser structure */
-    sprintf(identifier, "Card%d", screennum);
-    ptr->dev_identifier = strdup(identifier);
+    if (asprintf(&ptr->dev_identifier, "Card%d", screennum) == -1)
+        ptr->dev_identifier = NULL;
     ptr->dev_chipset = DevToConfig[screennum].GDev.chipset;
     ptr->dev_busid = DevToConfig[screennum].GDev.busID;
     ptr->dev_driver = DevToConfig[screennum].GDev.driver;
@@ -306,10 +302,8 @@ configureDeviceSection (int screennum)
 		int len = strlen(ptr->dev_comment) + strlen(prefix) +
 			  strlen(middle) + strlen(suffix) + 1;
 		
-		optname = malloc(strlen(p->name) + 2 + 1);
-		if (!optname)
+		if (asprintf(&optname, "\"%s\"", p->name) == -1)
 		    break;
-		sprintf(optname, "\"%s\"", p->name);
 
 		len += max(20, strlen(optname));
 		len += strlen(opttype);
@@ -370,16 +364,14 @@ configureLayoutSection (void)
 	aptr->adj_x = 0;
 	aptr->adj_y = 0;
 	aptr->adj_scrnum = scrnum;
-	aptr->adj_screen_str = xnfalloc(18);
-	sprintf(aptr->adj_screen_str, "Screen%d", scrnum);
+	XNFasprintf(&aptr->adj_screen_str, "Screen%d", scrnum);
 	if (scrnum == 0) {
 	    aptr->adj_where = CONF_ADJ_ABSOLUTE;
 	    aptr->adj_refscreen = NULL;
 	}
 	else {
 	    aptr->adj_where = CONF_ADJ_RIGHTOF;
-	    aptr->adj_refscreen = xnfalloc(18);
-	    sprintf(aptr->adj_refscreen, "Screen%d", scrnum - 1);
+	    XNFasprintf(&aptr->adj_refscreen, "Screen%d", scrnum - 1);
 	}
     	ptr->lay_adjacency_lst =
 	    (XF86ConfAdjacencyPtr)xf86addListItem((glp)ptr->lay_adjacency_lst,
@@ -443,8 +435,7 @@ configureMonitorSection (int screennum)
 {
     parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
 
-    ptr->mon_identifier = malloc(19);
-    sprintf(ptr->mon_identifier, "Monitor%d", screennum);
+    XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum);
     ptr->mon_vendor = strdup("Monitor Vendor");
     ptr->mon_modelname = strdup("Monitor Model");
 
@@ -491,11 +482,9 @@ configureDDCMonitorSection (int screennum)
 
     parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
 
-    ptr->mon_identifier = malloc(19);
-    sprintf(ptr->mon_identifier, "Monitor%d", screennum);
+    XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum);
     ptr->mon_vendor = strdup(ConfiguredMonitor->vendor.name);
-    ptr->mon_modelname = malloc(12);
-    sprintf(ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id);
+    XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id);
 
     /* features in centimetres, we want millimetres */
     mon_width  = 10 * ConfiguredMonitor->features.hsize ;
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index ce14454..9e2ffaa 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1284,11 +1284,8 @@ xf86LogInit(void)
     /* Get the log file name */
     if (xf86LogFileFrom == X_DEFAULT) {
 	/* Append the display number and ".log" */
-	lf = malloc(strlen(xf86LogFile) + strlen("%s") +
-		    strlen(LOGSUFFIX) + 1);
-	if (!lf)
+	if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1)
 	    FatalError("Cannot allocate space for the log file name\n");
-	sprintf(lf, "%s%%s" LOGSUFFIX, xf86LogFile);
 	xf86LogFile = lf;
     }
 
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index ef90fa5..78f51e1 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -536,8 +536,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 
     for (i = 0; i < xf86NumScreens; i++) {
       if (xf86Screens[i]->name == NULL) {
-	xf86Screens[i]->name = xnfalloc(strlen("screen") + 10 + 1);
-	sprintf(xf86Screens[i]->name, "screen%d", i);
+	XNFasprintf(&xf86Screens[i]->name, "screen%d", i);
 	xf86MsgVerb(X_WARNING, 0,
 		    "Screen driver %d has no name set, using `%s'.\n",
 		    i, xf86Screens[i]->name);
diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c
index eac25d7..ce86090 100644
--- a/hw/xfree86/common/xf86ShowOpts.c
+++ b/hw/xfree86/common/xf86ShowOpts.c
@@ -111,6 +111,9 @@ void DoShowOptions (void) {
 				);
 				for (p = pOption; p->name != NULL; p++) {
 					const char *opttype = optionTypeToSting(p->type);
+					/* XXX: Why overallocate by 2 bytes?
+					 * Otherwise, this would be strdup()
+					 */
 					char *optname = malloc(strlen(p->name) + 2 + 1);
 					if (!optname) {
 						continue;                      
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index d689832..447b192 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -1347,9 +1347,9 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
 
     pVideo = (struct pci_device *) busData;
 
-    GDev->busID = xnfalloc(16);
     xf86FormatPciBusNumber(pVideo->bus, busnum);
-    sprintf(GDev->busID, "PCI:%s:%d:%d", busnum, pVideo->dev, pVideo->func);
+    XNFasprintf(&GDev->busID, "PCI:%s:%d:%d",
+		busnum, pVideo->dev, pVideo->func);
 
     GDev->chipID = pVideo->device_id;
     GDev->chipRev = pVideo->revision;
diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c
index d7c928b..8cfac84 100644
--- a/hw/xfree86/common/xf86sbusBus.c
+++ b/hw/xfree86/common/xf86sbusBus.c
@@ -706,11 +706,9 @@ xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec *GDev)
         sparcPromClose();
     }
     if (promPath) {
-        GDev->busID = xnfalloc(strlen(promPath) + 6);
-        sprintf(GDev->busID, "SBUS:%s", promPath);
+        XNFasprintf(&GDev->busID, "SBUS:%s", promPath);
         free(promPath);
     } else {
-        GDev->busID = xnfalloc(12);
-        sprintf(GDev->busID, "SBUS:fb%d", sBus->fbNum);
+        XNFsprintf(&GDev->busID, "SBUS:fb%d", sBus->fbNum);
     }
 }
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index fe99a2d..1d83630 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -2426,13 +2426,10 @@ DRICreatePCIBusID(const struct pci_device * dev)
 {
     char *busID;
 
-    busID = malloc(20);
-    if (busID == NULL)
+    if (asprintf(&busID, "pci:%04x:%02x:%02x.%d",
+		 dev->domain, dev->bus, dev->dev, dev->func) == -1)
 	return NULL;
 
-    snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", dev->domain, dev->bus,
-	dev->dev, dev->func);
-
     return busID;
 }
 
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 06d082b..1f6933a 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -406,22 +406,22 @@ FindModuleInSubdir(const char *dirpath, const char *module)
  
         snprintf(tmpBuf, PATH_MAX, "lib%s.so", module);
         if (strcmp(direntry->d_name, tmpBuf) == 0) {
-            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1);
-            sprintf(ret, "%s%s", dirpath, tmpBuf);
+            if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1)
+		ret = NULL;
             break;
         }
 
         snprintf(tmpBuf, PATH_MAX, "%s_drv.so", module);
         if (strcmp(direntry->d_name, tmpBuf) == 0) {
-            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1);
-            sprintf(ret, "%s%s", dirpath, tmpBuf);
+            if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1)
+		ret = NULL;
             break;
         }
 
         snprintf(tmpBuf, PATH_MAX, "%s.so", module);
         if (strcmp(direntry->d_name, tmpBuf) == 0) {
-            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1);
-            sprintf(ret, "%s%s", dirpath, tmpBuf);
+            if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1)
+		ret = NULL;
             break;
         }
     }
diff --git a/hw/xfree86/vbe/vbeModes.c b/hw/xfree86/vbe/vbeModes.c
index 3f2cae5..ea24b61 100644
--- a/hw/xfree86/vbe/vbeModes.c
+++ b/hw/xfree86/vbe/vbeModes.c
@@ -356,8 +356,8 @@ VBESetModeNames(DisplayModePtr pMode)
 		pMode->VDisplay > 10000 || pMode->VDisplay < 0) {
 		pMode->name = strdup("BADMODE");
 	    } else {
-		pMode->name = xnfalloc(4 + 1 + 4 + 1);
-		sprintf(pMode->name, "%dx%d", pMode->HDisplay, pMode->VDisplay);
+		XNFasprintf(&pMode->name, "%dx%d",
+			    pMode->HDisplay, pMode->VDisplay);
 	    }
 	}
 	pMode = pMode->next;
diff --git a/os/log.c b/os/log.c
index 1ad87df..65195ba 100644
--- a/os/log.c
+++ b/os/log.c
@@ -177,10 +177,8 @@ LogInit(const char *fname, const char *backup)
     char *logFileName = NULL;
 
     if (fname && *fname) {
-	logFileName = malloc(strlen(fname) + strlen(display) + 1);
-	if (!logFileName)
+	if (asprintf(&logFileName, fname, display) == -1)
 	    FatalError("Cannot allocate space for the log file name\n");
-	sprintf(logFileName, fname, display);
 
 	if (backup && *backup) {
 	    struct stat buf;
@@ -189,13 +187,9 @@ LogInit(const char *fname, const char *backup)
 		char *suffix;
 		char *oldLog;
 
-		oldLog = malloc(strlen(logFileName) + strlen(backup) +
-				strlen(display) + 1);
-		suffix = malloc(strlen(backup) + strlen(display) + 1);
-		if (!oldLog || !suffix)
+		if ((asprintf(&suffix, backup, display) == -1) ||
+		    (asprintf(&oldLog, "%s%s", logFileName, suffix) == -1))
 		    FatalError("Cannot allocate space for the log file name\n");
-		sprintf(suffix, backup, display);
-		sprintf(oldLog, "%s%s", logFileName, suffix);
 		free(suffix);
 		if (rename(logFileName, oldLog) == -1) {
 		    FatalError("Cannot move old log file \"%s\" to \"%s\"\n",
commit 2416255f7e3fd9190a9e01bda57c992932de4bd9
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 22:36:44 2010 -0800

    Convert hw/xfree86/parser code to use asprintf() calls
    
    Requires linking xprintf.c into libxf86config for those who build it.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c
index a9149c2..7a0794b 100644
--- a/hw/xfree86/parser/Flags.c
+++ b/hw/xfree86/parser/Flags.c
@@ -61,8 +61,8 @@
 #include "xf86Parser.h"
 #include "xf86tokens.h"
 #include "Configint.h"
-#include <math.h>
 #include <X11/Xfuncproto.h>
+#include "Xprintf.h"
 
 extern LexRec val;
 
@@ -143,9 +143,8 @@ xf86parseFlagsSection (void)
 							} else {
 								if (tokentype != NUMBER)
 									Error (NUMBER_MSG, tmp);
-								valstr = malloc(16);
-								if (valstr)
-									sprintf(valstr, "%d", val.num);
+								if (asprintf(&valstr, "%d", val.num) == -1)
+									valstr = NULL;
 							}
 						}
 						ptr->flg_option_lst = xf86addNewOption
@@ -426,13 +425,9 @@ char *
 xf86uLongToString(unsigned long i)
 {
 	char *s;
-	int l;
 
-	l = ceil(log10((double)i) + 2.5);
-	s = malloc(l);
-	if (!s)
+	if (asprintf(&s, "%lu", i) == -1)
 		return NULL;
-	sprintf(s, "%lu", i);
 	return s;
 }
 
diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am
index caf7079..a5adc01 100644
--- a/hw/xfree86/parser/Makefile.am
+++ b/hw/xfree86/parser/Makefile.am
@@ -31,6 +31,7 @@ libxf86config_internal_la_SOURCES = \
 	$(INTERNAL_SOURCES)
 
 libxf86config_a_SOURCES = \
+	$(TOP_SRCDIR)/os/xprintf.c \
 	$(INTERNAL_SOURCES)
 libxf86config_a_CFLAGS = $(AM_CFLAGS)
 
diff --git a/hw/xfree86/parser/Pointer.c b/hw/xfree86/parser/Pointer.c
index 56a26ba..65397cd 100644
--- a/hw/xfree86/parser/Pointer.c
+++ b/hw/xfree86/parser/Pointer.c
@@ -62,6 +62,7 @@
 #include "xf86Parser.h"
 #include "xf86tokens.h"
 #include "Configint.h"
+#include "Xprintf.h"
 
 extern LexRec val;
 
@@ -99,8 +100,8 @@ static xf86ConfigSymTabRec ZMapTab[] =
 XF86ConfInputPtr
 xf86parsePointerSection (void)
 {
-	char *s, *s1, *s2;
-	int l;
+	char *s;
+	unsigned long val1;
 	int token;
 	parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
 
@@ -184,17 +185,12 @@ xf86parsePointerSection (void)
 			case NUMBER:
 				if (val.num < 0)
 					Error (ZAXISMAPPING_MSG, NULL);
-				s1 = xf86uLongToString(val.num);
+				val1 = val.num;
 				if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) {
-					free(s1);
 					Error (ZAXISMAPPING_MSG, NULL);
 				}
-				s2 = xf86uLongToString(val.num);
-				l = strlen(s1) + 1 + strlen(s2) + 1;
-				s = malloc(l);
-				sprintf(s, "%s %s", s1, s2);
-				free(s1);
-				free(s2);
+				if (asprintf(&s, "%ul %ul", val1, val.num) == -1)
+				    s = NULL;
 				break;
 			case XAXIS:
 				s = strdup("x");
commit 03e8bfa1d122f7dea905d48c93cfd54afd991dfd
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 20:09:04 2010 -0800

    Convert existing Xprintf style calls to asprintf style
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/config/hal.c b/config/hal.c
index 6e2850c..5e35911 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -200,7 +200,9 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                        "config/hal: getting usb.product_id on %s "
                        "returned %04x\n", parent, usb_product);
         if (usb_vendor && usb_product)
-            attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_product);
+            if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_product)
+		== -1)
+		attrs.usb_id = NULL;
 
         free(parent);
     }
diff --git a/config/udev.c b/config/udev.c
index 31f4f80..496bfbf 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -108,8 +108,10 @@ device_added(struct udev_device *udev_device)
 
         /* construct USB ID in lowercase hex - "0000:ffff" */
         if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
-            attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_model);
-            if (attrs.usb_id)
+            if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_model)
+                == -1)
+                attrs.usb_id = NULL;
+            else
                 LOG_PROPERTY(path, "PRODUCT", product);
         }
     }
@@ -127,9 +129,10 @@ device_added(struct udev_device *udev_device)
     LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop);
     attrs.tags = xstrtokenize(tags_prop, ",");
 
-    config_info = Xprintf("udev:%s", syspath);
-    if (!config_info)
+    if (asprintf(&config_info, "udev:%s", syspath) == -1) {
+        config_info = NULL;
         goto unwind;
+    }
 
     if (device_is_duplicate(config_info)) {
         LogMessage(X_WARNING, "config/udev: device %s already added. "
@@ -217,8 +220,7 @@ device_removed(struct udev_device *device)
     char *value;
     const char *syspath = udev_device_get_syspath(device);
 
-    value = Xprintf("udev:%s", syspath);
-    if (!value)
+    if (asprintf(&value, "udev:%s", syspath) == -1)
         return;
 
     remove_devices("udev", value);
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index ccb4627..bd1ad30 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1817,7 +1817,9 @@ SetDefaultFontPath(char *path)
 	start = end;
     }
     if (!start) {
-	temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : "");
+	if (asprintf(&temp_path, "%s%sbuilt-ins", path, *path ? "," : "")
+	    == -1)
+	    temp_path = NULL;
     } else {
 	temp_path = strdup(path);
     }
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 3cd5ef6..eb61f87 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -297,8 +297,8 @@ copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver)
     }
     memcpy(cptr, odev, sizeof(GDevRec));
 
-    cptr->identifier = Xprintf("Autoconfigured Video Device %s", driver);
-    if (!cptr->identifier) {
+    if (asprintf(&cptr->identifier, "Autoconfigured Video Device %s", driver)
+        == -1) {
         free(cptr);
         free(nscreen);
         return FALSE;
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index ae9592e..5f3b8e8 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -585,12 +585,11 @@ configFiles(XF86ConfFilesPtr fileconf)
     else if (fileconf && fileconf->file_fontpath) {
 	pathFrom = X_CONFIG;
 	if (xf86Info.useDefaultFontPath) {
-	    defaultFontPath = Xprintf("%s%s%s",
-				      fileconf->file_fontpath,
-				      *temp_path ? "," : "", temp_path);
-	    if (defaultFontPath != NULL) {
+	    if (asprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath,
+			 *temp_path ? "," : "", temp_path) == -1)
+		defaultFontPath = NULL;
+	    else
 		must_copy = FALSE;
-	    }
 	}
 	else
 	    defaultFontPath = fileconf->file_fontpath;
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 01f9864..ce14454 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1193,9 +1193,13 @@ xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *forma
 {
     char *msg;
 
-    msg = Xprintf("%s: %s: %s", dev->drv->driverName, dev->name, format);
-    LogVMessageVerb(type, verb, msg, args);
-    free(msg);
+    if (asprintf(&msg, "%s: %s: %s", dev->drv->driverName, dev->name, format)
+	== -1) {
+	LogVMessageVerb(type, verb, "%s", args);
+    } else {
+	LogVMessageVerb(type, verb, msg, args);
+	free(msg);
+    }
 }
 
 /* Print input driver message, with verbose level specified directly */
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 51eb4c9..75584cf 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -132,8 +132,8 @@ xf86SetModeDefaultName(DisplayModePtr mode)
 
     free(mode->name);
 
-    mode->name = XNFprintf("%dx%d%s", mode->HDisplay, mode->VDisplay,
-			   interlaced ? "i" : "");
+    XNFasprintf(&mode->name, "%dx%d%s", mode->HDisplay, mode->VDisplay,
+		interlaced ? "i" : "");
 }
 
 /*
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index f22a2d5..4430781 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -221,9 +221,10 @@ if (fDebugProcMsg) \
 { \
   char *pszTemp; \
   int iLength; \
-  pszTemp = Xprintf (str, ##__VA_ARGS__); \
-  MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \
-  free(pszTemp); \
+  if (asprintf (&pszTemp, str, ##__VA_ARGS__) != -1) { \
+    MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \
+    free (pszTemp); \
+  } \
 }
 #else
 #define DEBUG_MSG(str,...)
diff --git a/hw/xwin/windialogs.c b/hw/xwin/windialogs.c
index 22d8cd7..679b3fa 100644
--- a/hw/xwin/windialogs.c
+++ b/hw/xwin/windialogs.c
@@ -341,11 +341,10 @@ winExitDlgProc (HWND hDialog, UINT message,
 	winInitDialog (hDialog);
 
 	/* Format the connected clients string */
-	pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT,
+	if (asprintf (&pszConnectedClients, CONNECTED_CLIENTS_FORMAT,
            (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
             s_pScreenPriv->iConnectedClients,
-           (s_pScreenPriv->iConnectedClients == 1) ? "" : "s");
-	if (!pszConnectedClients)
+           (s_pScreenPriv->iConnectedClients == 1) ? "" : "s") == -1)
 	    return TRUE;
      
         
diff --git a/hw/xwin/winerror.c b/hw/xwin/winerror.c
index aadfd28..5e32d09 100644
--- a/hw/xwin/winerror.c
+++ b/hw/xwin/winerror.c
@@ -101,12 +101,15 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
   char *	pszErrorF = NULL;
   char *	pszMsgBox = NULL;
   va_list	args;
+  int		size;
 
   va_start(args, uType);
-  pszErrorF = Xvprintf(pszError, args);
+  size = vasprintf (&pszErrorF, pszError, args);
   va_end(args);
-  if (!pszErrorF)
+  if (size == -1) {
+    pszErrorF = NULL;
     goto winMessageBoxF_Cleanup;
+  }
 
 #define MESSAGEBOXF \
 	"%s\n" \
@@ -117,15 +120,18 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
 	"XWin was started with the following command-line:\n\n" \
 	"%s\n"
 
-  pszMsgBox = Xprintf (MESSAGEBOXF,
-                       pszErrorF, XVENDORNAME,
-		       XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT,
-		       BUILDERADDR,
-		       BUILDERSTRING,
-		       g_pszCommandLine);
+  size = asprintf (&pszMsgBox, MESSAGEBOXF,
+		   pszErrorF, XVENDORNAME,
+		   XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH,
+		    XORG_VERSION_SNAP, XORG_VERSION_CURRENT,
+		   BUILDERADDR,
+		   BUILDERSTRING,
+		   g_pszCommandLine);
 
-  if (!pszMsgBox)
+  if (size == -1) {
+    pszMsgBox = NULL;
     goto winMessageBoxF_Cleanup;
+  }
 
   /* Display the message box string */
   MessageBox (NULL,
diff --git a/xkb/ddxList.c b/xkb/ddxList.c
index c1ada5c..9623cb6 100644
--- a/xkb/ddxList.c
+++ b/xkb/ddxList.c
@@ -156,34 +156,45 @@ char	tmpname[PATH_MAX];
 #endif
     if (XkbBaseDirectory!=NULL) {
 	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
-	    buf = Xprintf("%s/%s.dir",XkbBaseDirectory,componentDirs[what]);
-	    in= fopen(buf,"r");
+	    if (asprintf(&buf, "%s/%s.dir", XkbBaseDirectory,
+			 componentDirs[what]) == -1)
+		buf = NULL;
+	    else
+		in = fopen(buf,"r");
 	}
 	if (!in) {
 	    haveDir= FALSE;
 	    free(buf);
-	    buf = Xprintf(
-		"'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
-                XkbBinDirectory,XkbBaseDirectory,componentDirs[what],(long)
-		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
-		file W32_tmpfile
-                );
+	    if (asprintf
+		(&buf,
+		 "'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
+		 XkbBinDirectory, XkbBaseDirectory, componentDirs[what],
+		 (long) ((xkbDebugFlags < 2) ? 1 :
+			 ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)),
+		 file W32_tmpfile
+		    ) == -1)
+		buf = NULL;
 	}
     }
     else {
 	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
-	    buf = Xprintf("%s.dir",componentDirs[what]);
-	    in= fopen(buf,"r");
+	    if (asprintf(&buf, "%s.dir", componentDirs[what]) == -1)
+		buf = NULL;
+	    else
+		in = fopen(buf,"r");
 	}
 	if (!in) {
 	    haveDir= FALSE;
 	    free(buf);
-	    buf = Xprintf(
-		"xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
-                componentDirs[what],(long)
-		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
-		file W32_tmpfile
-                );
+	    if (asprintf
+		(&buf,
+		 "xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
+		 componentDirs[what],
+		 (long)	((xkbDebugFlags < 2) ? 1 :
+			 ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)),
+		 file W32_tmpfile
+		    ) == -1)
+		buf = NULL;
 	}
     }
     status= Success;
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index cfc6198..e6904a5 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -210,7 +210,8 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
 #endif
 
     if (XkbBaseDirectory != NULL) {
-	xkbbasedirflag = Xprintf("\"-R%s\"", XkbBaseDirectory);
+	if (asprintf(&xkbbasedirflag, "\"-R%s\"", XkbBaseDirectory) == -1)
+	    xkbbasedirflag = NULL;
     }
 
     if (XkbBinDirectory != NULL) {
@@ -225,14 +226,16 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
 	}
     }
 
-    buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
+    if (asprintf(&buf,
+		 "\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
 		  "-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
-		  xkbbindir, xkbbindirsep,
-		  ( (xkbDebugFlags < 2) ? 1 :
-		    ((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ),
-		  xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
-		  PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
-		  xkm_output_dir, keymap);
+		 xkbbindir, xkbbindirsep,
+		 ((xkbDebugFlags < 2) ? 1 :
+		  ((xkbDebugFlags > 10) ? 10 : (int) xkbDebugFlags)),
+		 xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
+		 PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
+		 xkm_output_dir, keymap) == -1)
+	buf = NULL;
 
     free(xkbbasedirflag);
 
commit c95c1d338fdb62dbe3dba934b97324fa778b7fce
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 18:43:12 2010 -0800

    Add asprintf() implementation for platforms without it
    
    Provides a portable implementation of this common allocating sprintf()
    API found in many, but not yet all, of the platforms we support.
    If the platform provides vasprintf() we simply wrap it, otherwise we
    implement it - either way callers can use it regardless of platform.
    
    Since not all platforms guarantee to NULL out the return pointer on
    failure, we don't either, and require callers to check the return
    value for -1.
    
    The old Xprintf() API is deprecated, but left for compatibility for now.
    
    The new API is added in a new header so that it can be used in parts of
    the server such as hw/xfree86/parser that don't include all the server
    headers.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/COPYING b/COPYING
index bbf09ca..cd9e80a 100644
--- a/COPYING
+++ b/COPYING
@@ -15,7 +15,7 @@ Copyright © 2006 Nokia Corporation
 Copyright © 2006-2008 Peter Hutterer
 Copyright © 2006 Adam Jackson
 Copyright © 2009-2010 NVIDIA Corporation
-Copyright © 1987, 2003-2006, 2008-2009 Oracle and/or its affiliates.
+Copyright © 1987, 2003-2006, 2008-2010 Oracle and/or its affiliates.
 Copyright © 1999 Keith Packard
 Copyright © 2007-2009 Red Hat, Inc.
 Copyright © 2005-2008 Daniel Stone
diff --git a/configure.ac b/configure.ac
index b56d3e8..d2318da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -203,7 +203,7 @@ dnl Checks for library functions.
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr \
 		strtol getopt getopt_long vsnprintf walkcontext backtrace \
-		getisax getzoneid shmctl64 strcasestr ffs])
+		getisax getzoneid shmctl64 strcasestr ffs vasprintf])
 AC_FUNC_ALLOCA
 dnl Old HAS_* names used in os/*.c.
 AC_CHECK_FUNC([getdtablesize],
diff --git a/hw/xfree86/loader/sdksyms.sh b/hw/xfree86/loader/sdksyms.sh
index 4ac3c81..356d490 100755
--- a/hw/xfree86/loader/sdksyms.sh
+++ b/hw/xfree86/loader/sdksyms.sh
@@ -253,6 +253,7 @@ cat > sdksyms.c << EOF
 
 /* include/Makefile.am */
 #include "XIstubs.h"
+#include "Xprintf.h"
 #include "closestr.h"
 #include "closure.h"
 #include "colormap.h"
diff --git a/include/Makefile.am b/include/Makefile.am
index 966d215..42f0082 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,6 +1,7 @@
 if XORG
 sdk_HEADERS =		\
 	XIstubs.h	\
+	Xprintf.h	\
 	callback.h	\
 	closestr.h	\
 	closure.h	\
diff --git a/include/Xprintf.h b/include/Xprintf.h
new file mode 100644
index 0000000..5177122
--- /dev/null
+++ b/include/Xprintf.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef XPRINTF_H
+#define XPRINTF_H
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <X11/Xfuncproto.h>
+
+#ifndef _X_RESTRICT_KYWD
+# if defined(restrict) /* assume autoconf set it correctly */ || \
+   (defined(__STDC__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */
+#  define _X_RESTRICT_KYWD  restrict
+# elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
+#  define _X_RESTRICT_KYWD __restrict__
+# else
+#  define _X_RESTRICT_KYWD
+# endif
+#endif
+
+/*
+ * These functions provide a portable implementation of the common (but not
+ * yet universal) asprintf & vasprintf routines to allocate a buffer big
+ * enough to sprintf the arguments to.  The XNF variants terminate the server
+ * if the allocation fails.
+ * The buffer allocated is returned in the pointer provided in the first
+ * argument.   The return value is the size of the allocated buffer, or -1
+ * on failure.
+ */
+extern _X_EXPORT int Xasprintf (char **ret,
+				const char * _X_RESTRICT_KYWD fmt,
+				...) _X_ATTRIBUTE_PRINTF(2,3);
+extern _X_EXPORT int Xvasprintf (char **ret,
+				 const char * _X_RESTRICT_KYWD fmt,
+				 va_list va) _X_ATTRIBUTE_PRINTF(2,0);
+extern _X_EXPORT int XNFasprintf (char **ret,
+				  const char * _X_RESTRICT_KYWD fmt,
+				  ...) _X_ATTRIBUTE_PRINTF(2,3);
+extern _X_EXPORT int XNFvasprintf (char **ret,
+				   const char * _X_RESTRICT_KYWD fmt,
+				   va_list va) _X_ATTRIBUTE_PRINTF(2,0);
+
+#if !defined(HAVE_ASPRINTF) && !defined(HAVE_VASPRINTF)
+# define asprintf  Xasprintf
+# define vasprintf Xvasprintf
+#endif
+
+#endif /* XPRINTF_H */
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 6a33264..5622766 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -243,6 +243,9 @@
 /* Define to 1 if you have the `vprintf' function. */
 #undef HAVE_VPRINTF
 
+/* Define to 1 if you have the `vasprintf' function. */
+#undef HAVE_VASPRINTF
+
 /* Support IPv6 for TCP connections */
 #undef IPv6
 
diff --git a/include/os.h b/include/os.h
index 566514d..88f23ae 100644
--- a/include/os.h
+++ b/include/os.h
@@ -263,10 +263,14 @@ extern _X_EXPORT char *Xstrdup(const char *s);
  */
 extern _X_EXPORT char *XNFstrdup(const char *s);
 
-extern _X_EXPORT char *Xprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2);
-extern _X_EXPORT char *Xvprintf(const char *fmt, va_list va);
-extern _X_EXPORT char *XNFprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2);
-extern _X_EXPORT char *XNFvprintf(const char *fmt, va_list va);
+/* Include new X*asprintf API */
+#include "Xprintf.h"
+
+/* Older api deprecated in favor of the asprintf versions */
+extern _X_EXPORT char *Xprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_DEPRECATED;
+extern _X_EXPORT char *Xvprintf(const char *fmt, va_list va)_X_ATTRIBUTE_PRINTF(1,0) _X_DEPRECATED;
+extern _X_EXPORT char *XNFprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_DEPRECATED;
+extern _X_EXPORT char *XNFvprintf(const char *fmt, va_list va)_X_ATTRIBUTE_PRINTF(1,0) _X_DEPRECATED;
 
 typedef void (*OsSigHandlerPtr)(int /* sig */);
 typedef int (*OsSigWrapperPtr)(int /* sig */);
diff --git a/os/xprintf.c b/os/xprintf.c
index 71a4424..0a8bd06 100644
--- a/os/xprintf.c
+++ b/os/xprintf.c
@@ -1,6 +1,13 @@
-/* 
- * printf routines which xalloc their buffer
- */ 
+/**
+ * @file
+ *
+ * @section DESCRIPTION
+ *
+ * These functions provide a portable implementation of the common (but not
+ * yet universal) asprintf & vasprintf routines to allocate a buffer big
+ * enough to sprintf the arguments to.  The XNF variants terminate the server
+ * if the allocation fails.
+ */
 /*
  * Copyright (c) 2004 Alexander Gottwald
  *
@@ -26,6 +33,29 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
 #endif
@@ -35,6 +65,13 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+#ifdef asprintf
+# undef asprintf
+#endif
+#ifdef vasprintf
+# undef vasprintf
+#endif
+
 #ifndef va_copy
 # ifdef __va_copy
 #  define va_copy __va_copy
@@ -42,11 +79,23 @@
 #  error "no working va_copy was found"
 # endif
 #endif
-    
-char *
-Xvprintf(const char *format, va_list va)
+
+/**
+ * Varargs sprintf that allocates a string buffer the right size for
+ * the pattern & data provided and prints the requested data to it.
+ *
+ * @param ret     Pointer to which the newly allocated buffer is written
+ *                (contents undefined on error)
+ * @param format  printf style format string
+ * @param va      variable argument list
+ * @return        size of allocated buffer, or -1 on error.
+ */
+int
+Xvasprintf(char **ret, const char * _X_RESTRICT_KYWD format, va_list va)
 {
-    char *ret;
+#ifdef HAVE_VASPRINTF
+    return vasprintf(ret, format, va);
+#else
     int size;
     va_list va2;
 
@@ -54,12 +103,94 @@ Xvprintf(const char *format, va_list va)
     size = vsnprintf(NULL, 0, format, va2);
     va_end(va2);
 
-    ret = (char *)malloc(size + 1);
-    if (ret == NULL)
-        return NULL;
+    *ret = malloc(size + 1);
+    if (*ret == NULL)
+        return -1;
 
-    vsnprintf(ret, size + 1, format, va);
+    vsnprintf(*ret, size + 1, format, va);
     ret[size] = 0;
+    return size;
+#endif
+}
+
+#ifndef HAVE_VASPRINTF
+# define vasprintf Xvasprintf
+#endif
+
+/**
+ * sprintf that allocates a string buffer the right size for
+ * the pattern & data provided and prints the requested data to it.
+ *
+ * @param ret     Pointer to which the newly allocated buffer is written
+ *                (contents undefined on error)
+ * @param format  printf style format string
+ * @param ...     arguments for specified format
+ * @return        size of allocated buffer, or -1 on error.
+ */
+int
+Xasprintf(char ** ret, const char * _X_RESTRICT_KYWD format, ...)
+{
+    int size;
+    va_list va;
+    va_start(va, format);
+    size = vasprintf(ret, format, va);
+    va_end(va);
+    return size;
+}
+
+/**
+ * Varargs sprintf that allocates a string buffer the right size for
+ * the pattern & data provided and prints the requested data to it.
+ * On failure, issues a FatalError message and aborts the server.
+ *
+ * @param ret     Pointer to which the newly allocated buffer is written
+ *                (contents undefined on error)
+ * @param format  printf style format string
+ * @param va      variable argument list
+ * @return        size of allocated buffer
+ */
+int
+XNFvasprintf(char **ret, const char * _X_RESTRICT_KYWD format, va_list va)
+{
+    int size = vasprintf(ret, format, va);
+    if ((size == -1) || (*ret == NULL)) {
+	Error("XNFvasprintf");
+	FatalError("XNFvasprintf failed");
+    }
+    return size;
+}
+
+/**
+ * sprintf that allocates a string buffer the right size for
+ * the pattern & data provided and prints the requested data to it.
+ * On failure, issues a FatalError message and aborts the server.
+ *
+ * @param ret     Pointer to which the newly allocated buffer is written
+ *                (contents undefined on error)
+ * @param format  printf style format string
+ * @param ...     arguments for specified format
+ * @return        size of allocated buffer
+ */
+int
+XNFasprintf(char ** ret, const char * _X_RESTRICT_KYWD format, ...)
+{
+    int size;
+    va_list va;
+    va_start(va, format);
+    size = XNFvasprintf(ret, format, va);
+    va_end(va);
+    return size;
+}
+
+/* Old api, now deprecated, may be removed in the future */
+char *
+Xvprintf(const char *format, va_list va)
+{
+    char *ret;
+
+    if (vasprintf(&ret, format, va) == -1)
+	ret = NULL;
+
     return ret;
 }
 
@@ -68,7 +199,8 @@ char *Xprintf(const char *format, ...)
     char *ret;
     va_list va;
     va_start(va, format);
-    ret = Xvprintf(format, va);
+    if (vasprintf(&ret, format, va) == -1)
+	ret = NULL;
     va_end(va);
     return ret;
 }
@@ -77,19 +209,9 @@ char *
 XNFvprintf(const char *format, va_list va)
 {
     char *ret;
-    int size;
-    va_list va2;
-
-    va_copy(va2, va);
-    size = vsnprintf(NULL, 0, format, va2);
-    va_end(va2);
 
-    ret = (char *)xnfalloc(size + 1);
-    if (ret == NULL)
-        return NULL;
+    XNFvasprintf(&ret, format, va);
 
-    vsnprintf(ret, size + 1, format, va);
-    ret[size] = 0;
     return ret;
 }
 
@@ -98,7 +220,7 @@ char *XNFprintf(const char *format, ...)
     char *ret;
     va_list va;
     va_start(va, format);
-    ret = XNFvprintf(format, va);
+    XNFvasprintf(&ret, format, va);
     va_end(va);
     return ret;
 }
commit 2db6951763115a4a5dfac53d1a8f78ac33f91235
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri Dec 3 16:32:01 2010 -0800

    Sun's copyrights now belong to Oracle
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/COPYING b/COPYING
index 3aad5fa..bbf09ca 100644
--- a/COPYING
+++ b/COPYING
@@ -15,11 +15,11 @@ Copyright © 2006 Nokia Corporation
 Copyright © 2006-2008 Peter Hutterer
 Copyright © 2006 Adam Jackson
 Copyright © 2009-2010 NVIDIA Corporation
+Copyright © 1987, 2003-2006, 2008-2009 Oracle and/or its affiliates.
 Copyright © 1999 Keith Packard
 Copyright © 2007-2009 Red Hat, Inc.
 Copyright © 2005-2008 Daniel Stone
 Copyright © 2006-2009 Simon Thum
-Copyright © 1987, 2003-2006, 2008-2009 Sun Microsystems, Inc.
 Copyright © 2006 Luc Verhaegen
 
 Permission is hereby granted, free of charge, to any person obtaining a
diff --git a/composite/compalloc.c b/composite/compalloc.c
index c86eb9b..93571ee 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/composite/compext.c b/composite/compext.c
index 7fddbba..fbd36b5 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/composite/compinit.c b/composite/compinit.c
index 5db9f02..159f7c2 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/composite/compint.h b/composite/compint.h
index ae41c44..9ba5dd0 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/composite/compoverlay.c b/composite/compoverlay.c
index 3bace79..047f069 100644
--- a/composite/compoverlay.c
+++ b/composite/compoverlay.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/composite/compwindow.c b/composite/compwindow.c
index 62283ee..bbd5756 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/dix/Xserver-dtrace.h.in b/dix/Xserver-dtrace.h.in
index fce2836..daf3faf 100644
--- a/dix/Xserver-dtrace.h.in
+++ b/dix/Xserver-dtrace.h.in
@@ -1,4 +1,4 @@
-/* Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/dix/Xserver.d b/dix/Xserver.d
index 4bc0b9a..2ad3373 100644
--- a/dix/Xserver.d
+++ b/dix/Xserver.d
@@ -1,4 +1,4 @@
-/* Copyright 2005-2006 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/dix/dispatch.c b/dix/dispatch.c
index b66861f..7b2132d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -75,7 +75,7 @@ Equipment Corporation.
 ******************************************************************/
 
 /* XSERVER_DTRACE additions:
- * Copyright 2005-2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/dix/events.c b/dix/events.c
index e8cf8d4..ac07923 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -75,7 +75,7 @@ Equipment Corporation.
 ******************************************************************/
 
 /*
- * Copyright © 2003-2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2003-2005, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/dix/resource.c b/dix/resource.c
index a0fe719..6bd2403 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -73,7 +73,7 @@ Equipment Corporation.
 
 ******************************************************************/
 /* XSERVER_DTRACE additions:
- * Copyright 2005-2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/fb/fbcmap_mi.c b/fb/fbcmap_mi.c
index d75a38f..227da31 100644
--- a/fb/fbcmap_mi.c
+++ b/fb/fbcmap_mi.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 1987 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 1987, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/solaris-amd64.S b/hw/xfree86/os-support/solaris/solaris-amd64.S
index 94ffa40..4cc0642 100644
--- a/hw/xfree86/os-support/solaris/solaris-amd64.S
+++ b/hw/xfree86/os-support/solaris/solaris-amd64.S
@@ -1,4 +1,4 @@
-/ Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+/ Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
 / 
 / Permission is hereby granted, free of charge, to any person obtaining a
 / copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/solaris-ia32.S b/hw/xfree86/os-support/solaris/solaris-ia32.S
index 4dadf7f..74d787d 100644
--- a/hw/xfree86/os-support/solaris/solaris-ia32.S
+++ b/hw/xfree86/os-support/solaris/solaris-ia32.S
@@ -1,4 +1,4 @@
-/ Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+/ Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
 / 
 / Permission is hereby granted, free of charge, to any person obtaining a
 / copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S b/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S
index 0f6d694..0ecafb3 100644
--- a/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S
+++ b/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S
@@ -1,4 +1,4 @@
-/* Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/sun_VTsw.c b/hw/xfree86/os-support/solaris/sun_VTsw.c
index cff279e..e6f3187 100644
--- a/hw/xfree86/os-support/solaris/sun_VTsw.c
+++ b/hw/xfree86/os-support/solaris/sun_VTsw.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/sun_agp.c b/hw/xfree86/os-support/solaris/sun_agp.c
index dd4b1e2..a4517d6 100644
--- a/hw/xfree86/os-support/solaris/sun_agp.c
+++ b/hw/xfree86/os-support/solaris/sun_agp.c
@@ -6,7 +6,7 @@
  * Copyright © 2000 VA Linux Systems, Inc.
  * Copyright © 2001 The XFree86 Project, Inc.
  */
-/* Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/sun_apm.c b/hw/xfree86/os-support/solaris/sun_apm.c
index 23e14f1..55081b6 100644
--- a/hw/xfree86/os-support/solaris/sun_apm.c
+++ b/hw/xfree86/os-support/solaris/sun_apm.c
@@ -27,7 +27,7 @@
  * XFree86 Project.
  */
 
-/* Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/sun_bell.c b/hw/xfree86/os-support/solaris/sun_bell.c
index bab3913..b59835e 100644
--- a/hw/xfree86/os-support/solaris/sun_bell.c
+++ b/hw/xfree86/os-support/solaris/sun_bell.c
@@ -1,4 +1,4 @@
-/* Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2004-2005, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c
index 9497973..f99bac5 100644
--- a/hw/xfree86/os-support/solaris/sun_vid.c
+++ b/hw/xfree86/os-support/solaris/sun_vid.c
@@ -22,7 +22,7 @@
  * OF THIS SOFTWARE.
  *
  */
-/* Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am
index 6b99cbd..0658682 100644
--- a/hw/xfree86/utils/cvt/Makefile.am
+++ b/hw/xfree86/utils/cvt/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
diff --git a/hw/xfree86/utils/gtf/Makefile.am b/hw/xfree86/utils/gtf/Makefile.am
index d1a6d61..ea1c5fb 100644
--- a/hw/xfree86/utils/gtf/Makefile.am
+++ b/hw/xfree86/utils/gtf/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
diff --git a/mi/micmap.c b/mi/micmap.c
index 8d76f4d..41e0300 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 1987 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 1987, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/os/access.c b/os/access.c
index d9de264..a532db6 100644
--- a/os/access.c
+++ b/os/access.c
@@ -54,7 +54,7 @@ SOFTWARE.
 ******************************************************************/
 
 /*
- * Copyright © 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 41ba0fb..54e5d75 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 5dbfbec..e8c7bf1 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/xfixes/xfixesint.h b/xfixes/xfixesint.h
index 9e50993..d005369 100644
--- a/xfixes/xfixesint.h
+++ b/xfixes/xfixesint.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
commit f06e8a61d6ed8f3054878167bffee619f852aad9
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Nov 30 16:34:38 2010 -0800

    Move inclusion of panoramiX headers to top of render.c
    
    Fixes compiler error from Sun compilers due to _X_EXPORT declaration
    being included after the unlabeled version:
    
    "../Xext/panoramiXsrv.h", line 29: redeclaration must have the same or more restrictive linker scoping: XRT_PICTURE
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/render/render.c b/render/render.c
index 85a4392..0bbbae8 100644
--- a/render/render.c
+++ b/render/render.c
@@ -47,6 +47,11 @@
 #include "xace.h"
 #include "protocol-versions.h"
 
+#ifdef PANORAMIX
+#include "panoramiX.h"
+#include "panoramiXsrv.h"
+#endif
+
 #if HAVE_STDINT_H
 #include <stdint.h>
 #elif !defined(UINT32_MAX)
@@ -2651,9 +2656,6 @@ SProcRenderDispatch (ClientPtr client)
 }
 
 #ifdef PANORAMIX
-#include "panoramiX.h"
-#include "panoramiXsrv.h"
-
 #define VERIFY_XIN_PICTURE(pPicture, pid, client, mode) {\
     int rc = dixLookupResourceByType((pointer *)&(pPicture), pid,\
                                      XRT_PICTURE, client, mode);\
commit 9f9c732311ef0cc198e5ec44d02412eb7e8c3f3a
Author: Cyril Brulebois <kibi at debian.org>
Date:   Fri Nov 12 21:35:25 2010 +0100

    dix: Fix logic for displaying deprecation warning only once.
    
    As pointed out by Jamey Sharp (again), the logic is faulty: --warn is
    always going to be false. Replace it with warn-- accordingly, so that
    there's (at least, but also only) one warning showing up.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/dix/deprecated.c b/dix/deprecated.c
index 4cf596a..f05588e 100644
--- a/dix/deprecated.c
+++ b/dix/deprecated.c
@@ -67,7 +67,7 @@ SecurityLookupWindow(XID id, ClientPtr client, Mask access_mode)
     WindowPtr pWin;
     static int warn = 1;
     dixLookupWindow(&pWin, id, client, access_mode);
-    if (warn > 0 && --warn)
+    if (warn > 0 && warn--)
 	ErrorF("Warning: LookupWindow()/SecurityLookupWindow() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupWindow().\n");
@@ -88,7 +88,7 @@ SecurityLookupDrawable(XID id, ClientPtr client, Mask access_mode)
     DrawablePtr pDraw;
     static int warn = 1;
     dixLookupDrawable(&pDraw, id, client, M_DRAWABLE, access_mode);
-    if (warn > 0 && --warn)
+    if (warn > 0 && warn--)
 	ErrorF("Warning: LookupDrawable()/SecurityLookupDrawable() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupDrawable().\n");
@@ -109,7 +109,7 @@ LookupClient(XID id, ClientPtr client)
     ClientPtr pClient;
     static int warn = 1;
     dixLookupClient(&pClient, id, client, DixUnknownAccess);
-    if (warn > 0 && --warn)
+    if (warn > 0 && warn--)
 	ErrorF("Warning: LookupClient() is deprecated.  Please convert your "
 	       "driver/module to use dixLookupClient().\n");
     return pClient;
@@ -123,7 +123,7 @@ SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype,
     pointer retval;
     static int warn = 1;
     dixLookupResourceByType(&retval, id, rtype, client, access_mode);
-    if (warn > 0 && --warn)
+    if (warn > 0 && warn--)
 	ErrorF("Warning: LookupIDByType()/SecurityLookupIDByType() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupResourceByType().\n");
@@ -137,7 +137,7 @@ SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes,
     pointer retval;
     static int warn = 1;
     dixLookupResourceByClass(&retval, id, classes, client, access_mode);
-    if (warn > 0 && --warn)
+    if (warn > 0 && warn--)
 	ErrorF("Warning: LookupIDByClass()/SecurityLookupIDByClass() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupResourceByClass().\n");
commit a937803c1f671ef29332e5fe8c190d8b48239912
Author: Cyril Brulebois <kibi at debian.org>
Date:   Fri Nov 12 21:29:26 2010 +0100

    dix: Simplify deprecated *Lookup* wrappers around dixLookup*.
    
    As pointed out by Jamey Sharp: “the result pointer is already guaranteed
    to be NULL if the return value is not Success”, so get rid of the
    variable used to catch the return value, and used in a ternary operation
    to decide whether to return the pointer or NULL. Always return the
    result pointer instead.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/dix/deprecated.c b/dix/deprecated.c
index 21d0f57..4cf596a 100644
--- a/dix/deprecated.c
+++ b/dix/deprecated.c
@@ -65,13 +65,13 @@ WindowPtr
 SecurityLookupWindow(XID id, ClientPtr client, Mask access_mode)
 {
     WindowPtr pWin;
-    int i = dixLookupWindow(&pWin, id, client, access_mode);
     static int warn = 1;
+    dixLookupWindow(&pWin, id, client, access_mode);
     if (warn > 0 && --warn)
 	ErrorF("Warning: LookupWindow()/SecurityLookupWindow() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupWindow().\n");
-    return (i == Success) ? pWin : NULL;
+    return pWin;
 }
 
 /* replaced by dixLookupWindow */
@@ -86,13 +86,13 @@ pointer
 SecurityLookupDrawable(XID id, ClientPtr client, Mask access_mode)
 {
     DrawablePtr pDraw;
-    int i = dixLookupDrawable(&pDraw, id, client, M_DRAWABLE, access_mode);
     static int warn = 1;
+    dixLookupDrawable(&pDraw, id, client, M_DRAWABLE, access_mode);
     if (warn > 0 && --warn)
 	ErrorF("Warning: LookupDrawable()/SecurityLookupDrawable() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupDrawable().\n");
-    return (i == Success) ? pDraw : NULL;
+    return pDraw;
 }
 
 /* replaced by dixLookupDrawable */
@@ -107,12 +107,12 @@ ClientPtr
 LookupClient(XID id, ClientPtr client)
 {
     ClientPtr pClient;
-    int i = dixLookupClient(&pClient, id, client, DixUnknownAccess);
     static int warn = 1;
+    dixLookupClient(&pClient, id, client, DixUnknownAccess);
     if (warn > 0 && --warn)
 	ErrorF("Warning: LookupClient() is deprecated.  Please convert your "
 	       "driver/module to use dixLookupClient().\n");
-    return (i == Success) ? pClient : NULL;
+    return pClient;
 }
 
 /* replaced by dixLookupResourceByType */
@@ -121,13 +121,13 @@ SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype,
 		       Mask access_mode)
 {
     pointer retval;
-    int i = dixLookupResourceByType(&retval, id, rtype, client, access_mode);
     static int warn = 1;
+    dixLookupResourceByType(&retval, id, rtype, client, access_mode);
     if (warn > 0 && --warn)
 	ErrorF("Warning: LookupIDByType()/SecurityLookupIDByType() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupResourceByType().\n");
-    return (i == Success) ? retval : NULL;
+    return retval;
 }
 
 pointer
@@ -135,13 +135,13 @@ SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes,
 			Mask access_mode)
 {
     pointer retval;
-    int i = dixLookupResourceByClass(&retval, id, classes, client, access_mode);
     static int warn = 1;
+    dixLookupResourceByClass(&retval, id, classes, client, access_mode);
     if (warn > 0 && --warn)
 	ErrorF("Warning: LookupIDByClass()/SecurityLookupIDByClass() "
 	       "are deprecated.  Please convert your driver/module "
 	       "to use dixLookupResourceByClass().\n");
-    return (i == Success) ? retval : NULL;
+    return retval;
 }
 
 /* replaced by dixLookupResourceByType */
commit 73fbc4a4a7997b3ee1c779d8f394114270bcb20d
Author: Cyril Brulebois <kibi at debian.org>
Date:   Fri Nov 12 12:04:11 2010 +0100

    Replace SecurityLookupIDByClass() with dixLookupResourceByClass().
    
    This patch has been prepared with the following Coccinelle semantic patch:
    
    @@
    expression a, b, c, d;
    identifier r;
    type t;
    @@
    -r = (t) SecurityLookupIDByClass(a, b, c, d);
    +dixLookupResourceByClass((pointer*) &r, b, c, a, d);
    
    The only occurrence not matching directly was processed after separating
    declaration of pXinDraw and call to SecurityLookupIDByClass().
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 0f8e8d8..a58eb35 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -1104,14 +1104,16 @@ static int MakeCurrent(__GLXclientState *cl,
        to_screen = screenInfo.numScreens - 1;
 
        if (pDraw && new_reply.writeType != GLX_PBUFFER_TYPE) {
-	  pXinDraw = (PanoramiXRes *)
-	     SecurityLookupIDByClass(client, pDraw->id, XRC_DRAWABLE, DixReadAccess);
+	  dixLookupResourceByClass((pointer*) &pXinDraw,
+				   pDraw->id, XRC_DRAWABLE,
+				   client, DixReadAccess);
        }
 
        if (pReadDraw && pReadDraw != pDraw && 
 	     new_reply.readType != GLX_PBUFFER_TYPE) {
-	  pXinReadDraw = (PanoramiXRes *)
-	     SecurityLookupIDByClass(client, pReadDraw->id, XRC_DRAWABLE, DixReadAccess);
+	  dixLookupResourceByClass((pointer*) &pXinReadDraw,
+				   pReadDraw->id, XRC_DRAWABLE,
+				   client, DixReadAccess);
        }
        else {
 	  pXinReadDraw = pXinDraw;
@@ -1765,8 +1767,9 @@ static int CreateGLXPixmap(__GLXclientState *cl,
        from_screen = 0;
        to_screen = screenInfo.numScreens - 1;
 
-       pXinDraw = (PanoramiXRes *)
-	  SecurityLookupIDByClass(client, pDraw->id, XRC_DRAWABLE, DixReadAccess);
+       dixLookupResourceByClass((pointer*) &pXinDraw,
+				pDraw->id, XRC_DRAWABLE,
+				client, DixReadAccess);
     }
 #endif
 
@@ -2013,8 +2016,9 @@ int __glXDoSwapBuffers(__GLXclientState *cl, XID drawId, GLXContextTag tag)
     if (!noPanoramiXExtension) {
        from_screen = 0;
        to_screen = screenInfo.numScreens - 1;
-       pXinDraw = (PanoramiXRes *)
-        SecurityLookupIDByClass(client, pDraw->id, XRC_DRAWABLE, DixReadAccess);
+       dixLookupResourceByClass((pointer*) &pXinDraw,
+				pDraw->id, XRC_DRAWABLE,
+				client, DixReadAccess);
     }
 #endif
 
@@ -3369,9 +3373,9 @@ int __glXGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
 
 #ifdef PANORAMIX
        if (!noPanoramiXExtension) {
-	  pXinDraw = (PanoramiXRes *)
-	     SecurityLookupIDByClass(client, pDraw->id, XRC_DRAWABLE, DixReadAccess);
-	  if (!pXinDraw) {
+	  if (Success != dixLookupResourceByClass((pointer*) &pXinDraw,
+						  pDraw->id, XRC_DRAWABLE,
+						  client, DixReadAccess)) {
 	     client->errorValue = drawId;
 	     return __glXBadDrawable;
 	  }
@@ -3533,9 +3537,10 @@ int __glXChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
 
 #ifdef PANORAMIX
        if (!noPanoramiXExtension) {
-	  PanoramiXRes *pXinDraw = (PanoramiXRes *)
-	     SecurityLookupIDByClass(client, pDraw->id, XRC_DRAWABLE, DixReadAccess);
-	  if (!pXinDraw) {
+	  PanoramiXRes *pXinDraw;
+	  if (Success != dixLookupResourceByClass((pointer*) &pXinDraw,
+						  pDraw->id, XRC_DRAWABLE,
+						  client, DixReadAccess)) {
 	     client->errorValue = drawId;
 	     return __glXBadDrawable;
 	  }
commit 6e8b34b7048bc9e49ef52b81e2de1b518a05890e
Author: Cyril Brulebois <kibi at debian.org>
Date:   Fri Nov 12 11:36:36 2010 +0100

    Replace SecurityLookupIDByType() with dixLookupResourceByType(), take 2.
    
    These occurrences are a bit harder to catch through a semantic patch,
    so process them “manually”.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 1dee077..f3e41ac 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -231,8 +231,9 @@ static int ProcDMXForceWindowCreation(ClientPtr client)
         PanoramiXRes *win;
         int          i;
 
-        if (!(win = SecurityLookupIDByType(client, stuff->window, XRT_WINDOW,
-                                           DixReadAccess)))
+        if (Success != dixLookupResourceByType((pointer*) &win,
+					       stuff->window, XRT_WINDOW,
+					       client, DixReadAccess))
             return -1;           /* BadWindow */
 
         FOR_NSCREENS(i) {
@@ -506,8 +507,9 @@ static int dmxPopulatePanoramiX(ClientPtr client, Window window,
     int                    count = 0;
     DMXWindowAttributesRec attr;
     
-    if (!(win = SecurityLookupIDByType(client, window, XRT_WINDOW,
-                                       DixReadAccess)))
+    if (Success != dixLookupResourceByType((pointer*) &win,
+					   window, XRT_WINDOW,
+					   client, DixReadAccess))
         return -1;               /* BadWindow */
     
     FOR_NSCREENS(i) {
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 4e2e62f..0f8e8d8 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -3074,7 +3074,10 @@ int __glXQueryContextInfoEXT(__GLXclientState *cl, GLbyte *pc)
     int nReplyBytes;
 
     req = (xGLXQueryContextInfoEXTReq *)pc;
-    ctx = (__GLXcontext *) SecurityLookupIDByType(client, req->context, __glXContextRes, DixReadAccess);
+    dixLookupResourceByType((pointer*) &ctx,
+			    req->context, __glXContextRes,
+			    client,  DixReadAccess);
+
     if (!ctx) {
         client->errorValue = req->context;
         return __glXBadContext;
commit ac04c1377a42ab6803adf551756653fd8e1a694b
Author: Cyril Brulebois <kibi at debian.org>
Date:   Fri Nov 12 11:36:31 2010 +0100

    Replace SecurityLookupIDByType() with dixLookupResourceByType(), take 1.
    
    This patch has been prepared with the following Coccinelle semantic patch:
    
    @@
    expression a, b, c, d;
    identifier r;
    @@
    -r = SecurityLookupIDByType(a, b, c, d);
    +dixLookupResourceByType((pointer*) &r, b, c, a, d);
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
index ab26593..bbde8fd 100644
--- a/hw/dmx/dmxpict.c
+++ b/hw/dmx/dmxpict.c
@@ -271,9 +271,11 @@ static int dmxProcRenderCreateGlyphSet(ClientPtr client)
 	/* Look up glyphSet that was just created ???? */
 	/* Store glyphsets from backends in glyphSet->devPrivate ????? */
 	/* Make sure we handle all errors here!! */
-	
-	glyphSet = SecurityLookupIDByType(client, stuff->gsid, GlyphSetType,
-					  DixDestroyAccess);
+
+	dixLookupResourceByType((pointer*) &glyphSet,
+				stuff->gsid, GlyphSetType,
+				client, DixDestroyAccess);
+
 	glyphPriv = malloc(sizeof(dmxGlyphPrivRec));
 	if (!glyphPriv) return BadAlloc;
         glyphPriv->glyphSets = NULL;
@@ -314,8 +316,9 @@ static int dmxProcRenderFreeGlyphSet(ClientPtr client)
     REQUEST(xRenderFreeGlyphSetReq);
 
     REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq);
-    glyphSet = SecurityLookupIDByType(client, stuff->glyphset, GlyphSetType,
-				      DixDestroyAccess);
+    dixLookupResourceByType((pointer*) &glyphSet,
+			    stuff->glyphset, GlyphSetType,
+			    client, DixDestroyAccess);
 
     if (glyphSet && glyphSet->refcnt == 1) {
 	dmxGlyphPrivPtr  glyphPriv = DMX_GET_GLYPH_PRIV(glyphSet);
@@ -357,8 +360,9 @@ static int dmxProcRenderAddGlyphs(ClientPtr client)
 	CARD8           *bits;
 	int              nbytes;
 
-	glyphSet = SecurityLookupIDByType(client, stuff->glyphset,
-					  GlyphSetType, DixReadAccess);
+	dixLookupResourceByType((pointer*) &glyphSet,
+				stuff->glyphset, GlyphSetType,
+				client, DixReadAccess);
 	glyphPriv = DMX_GET_GLYPH_PRIV(glyphSet);
 
 	nglyphs = stuff->nglyphs;
@@ -400,8 +404,9 @@ static int dmxProcRenderFreeGlyphs(ClientPtr client)
     REQUEST(xRenderFreeGlyphsReq);
 
     REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq);
-    glyphSet = SecurityLookupIDByType(client, stuff->glyphset, GlyphSetType,
-				      DixWriteAccess);
+    dixLookupResourceByType((pointer*) &glyphSet,
+			    stuff->glyphset, GlyphSetType,
+			    client, DixWriteAccess);
 
     if (glyphSet) {
 	dmxGlyphPrivPtr  glyphPriv = DMX_GET_GLYPH_PRIV(glyphSet);
@@ -472,14 +477,18 @@ static int dmxProcRenderCompositeGlyphs(ClientPtr client)
 	GlyphSetPtr        glyphSet;
 	dmxGlyphPrivPtr    glyphPriv;
 
-	pSrc = SecurityLookupIDByType(client, stuff->src, PictureType,
-				      DixReadAccess);
+	dixLookupResourceByType((pointer*) &pSrc,
+				stuff->src, PictureType,
+				client, DixReadAccess);
+
 	pSrcPriv = DMX_GET_PICT_PRIV(pSrc);
 	if (!pSrcPriv->pict)
 	    return ret;
 
-	pDst = SecurityLookupIDByType(client, stuff->dst, PictureType,
-				      DixWriteAccess);
+	dixLookupResourceByType((pointer*) &pDst,
+				stuff->dst, PictureType,
+				client, DixWriteAccess);
+
 	pDstPriv = DMX_GET_PICT_PRIV(pDst);
 	if (!pDstPriv->pict)
 	    return ret;
@@ -495,8 +504,9 @@ static int dmxProcRenderCompositeGlyphs(ClientPtr client)
 	    return ret;
 
 	if (stuff->maskFormat)
-	    pFmt = SecurityLookupIDByType(client, stuff->maskFormat,
-					  PictFormatType, DixReadAccess);
+	    dixLookupResourceByType((pointer*) &pFmt,
+				    stuff->maskFormat, PictFormatType,
+				    client, DixReadAccess);
 	else
 	    pFmt = NULL;
 
@@ -546,8 +556,9 @@ static int dmxProcRenderCompositeGlyphs(ClientPtr client)
 	curGlyph = glyphs;
 	curElt = elts;
 
-	glyphSet = SecurityLookupIDByType(client, stuff->glyphset,
-					  GlyphSetType, DixReadAccess);
+	dixLookupResourceByType((pointer*) &glyphSet,
+				stuff->glyphset, GlyphSetType,
+				client, DixReadAccess);
 	glyphPriv = DMX_GET_GLYPH_PRIV(glyphSet);
 
 	while (buffer + sizeof(xGlyphElt) < end) {
@@ -555,10 +566,11 @@ static int dmxProcRenderCompositeGlyphs(ClientPtr client)
 	    buffer += sizeof(xGlyphElt);
 
 	    if (elt->len == 0xff) {
-		glyphSet = SecurityLookupIDByType(client,
-						  *((CARD32 *)buffer),
-						  GlyphSetType,
-						  DixReadAccess);
+		dixLookupResourceByType((pointer*) &glyphSet,
+					*((CARD32 *)buffer),
+					GlyphSetType,
+					client,
+					DixReadAccess);
 		glyphPriv = DMX_GET_GLYPH_PRIV(glyphSet);
 		buffer += 4;
 	    } else {
commit 28b4c02d7463ffe5c29f803f5656c5ecfc040185
Author: Cyril Brulebois <kibi at debian.org>
Date:   Thu Nov 11 18:36:45 2010 +0100

    Enable silent rules for cat and echo.
    
    One gets this:
    |   GEN    lf3-xaaBitmap.c
    |   GEN    lf3-xaaBitmap.c
    |   GEN    lf3-xaaBitmap.c
    |   GEN    lf3-xaaBitmap.c
    |   CC     lf3-xaaBitmap.lo
    
    instead of this:
    | echo "#define LSBFIRST" > l3-xaaBitmap.c
    | echo "#define TRIPLE_BITS" >> l3-xaaBitmap.c
    | echo '#include "../../../../hw/xfree86/xaa/xaaBitmap.c"' >> l3-xaaBitmap.c
    |   CC     l3-xaaBitmap.lo
    
    Occurrences found using:
    | git grep -E '(cat|echo)' -- '*Makefile.am'
    
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 989208f..4abf217 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -24,8 +24,8 @@ BUSSOURCES = xf86pciBus.c xf86fbBus.c xf86noBus.c $(SBUS_SOURCES)
 MODEDEFSOURCES = $(srcdir)/vesamodes $(srcdir)/extramodes
 
 xf86DefModeSet.c: $(srcdir)/modeline2c.awk $(MODEDEFSOURCES)
-	cat $(MODEDEFSOURCES) | LC_ALL=C $(AWK) -f $(srcdir)/modeline2c.awk > $@
-	echo >> $@
+	$(AM_V_GEN)cat $(MODEDEFSOURCES) | LC_ALL=C $(AWK) -f $(srcdir)/modeline2c.awk > $@
+	$(AM_V_GEN)echo >> $@
 
 BUILT_SOURCES = xf86DefModeSet.c
 
diff --git a/hw/xfree86/ramdac/Makefile.am b/hw/xfree86/ramdac/Makefile.am
index 98e367c..3c37805 100644
--- a/hw/xfree86/ramdac/Makefile.am
+++ b/hw/xfree86/ramdac/Makefile.am
@@ -15,5 +15,5 @@ AM_CFLAGS = -DXAAReverseBitOrder=xf86ReverseBitOrder -DRAMDAC_MODULE \
 INCLUDES = $(XORG_INCS)
 
 xf86BitOrder.c:
-	echo "#define XAAReverseBitOrder xf86ReverseBitOrder" > $@
-	echo "#include \"$(srcdir)/../xaa/xaaBitOrder.c\"" >> $@
+	$(AM_V_GEN)echo "#define XAAReverseBitOrder xf86ReverseBitOrder" > $@
+	$(AM_V_GEN)echo "#include \"$(srcdir)/../xaa/xaaBitOrder.c\"" >> $@
diff --git a/hw/xfree86/xaa/Makefile.am b/hw/xfree86/xaa/Makefile.am
index 4ba1f78..5bfb4e9 100644
--- a/hw/xfree86/xaa/Makefile.am
+++ b/hw/xfree86/xaa/Makefile.am
@@ -25,40 +25,40 @@ libxaa_la_SOURCES = xaaInit.c xaaGC.c xaaInitAccel.c xaaFallback.c \
                    $(LSB_FIRST) $(MSB_FIRST) $(LSB_FIXED) $(MSB_FIXED) \
                    $(LSB_3_FIRST) $(MSB_3_FIRST) $(LSB_3_FIXED) $(MSB_3_FIXED)
 ${POLYSEG}:
-	echo "#define POLYSEGMENT" > $@
-	echo '#include "$(srcdir)/${@:s-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define POLYSEGMENT" > $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:s-%=%}"' >> $@
 ${LSB_FIRST}:
-	echo "#define LSBFIRST" > $@
-	echo '#include "$(srcdir)/${@:l-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define LSBFIRST" > $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:l-%=%}"' >> $@
 ${LSB_3_FIRST}:
-	echo "#define LSBFIRST" > $@
-	echo "#define TRIPLE_BITS" >> $@
-	echo '#include "$(srcdir)/${@:l3-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define LSBFIRST" > $@
+	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:l3-%=%}"' >> $@
 ${LSB_FIXED}:
-	echo "#define LSBFIRST" > $@
-	echo "#define FIXEDBASE" >> $@
-	echo '#include "$(srcdir)/${@:lf-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define LSBFIRST" > $@
+	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:lf-%=%}"' >> $@
 ${LSB_3_FIXED}:
-	echo "#define LSBFIRST" > $@
-	echo "#define TRIPLE_BITS" >> $@
-	echo "#define FIXEDBASE" >> $@
-	echo '#include "$(srcdir)/${@:lf3-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define LSBFIRST" > $@
+	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
+	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:lf3-%=%}"' >> $@
 ${MSB_FIRST}:
-	echo "#define MSBFIRST" > $@
-	echo '#include "$(srcdir)/${@:m-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define MSBFIRST" > $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:m-%=%}"' >> $@
 ${MSB_3_FIRST}:
-	echo "#define MSBFIRST" > $@
-	echo "#define TRIPLE_BITS" >> $@
-	echo '#include "$(srcdir)/${@:m3-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define MSBFIRST" > $@
+	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:m3-%=%}"' >> $@
 ${MSB_FIXED}:
-	echo "#define MSBFIRST" > $@
-	echo "#define FIXEDBASE" >> $@
-	echo '#include "$(srcdir)/${@:mf-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define MSBFIRST" > $@
+	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:mf-%=%}"' >> $@
 ${MSB_3_FIXED}:
-	echo "#define MSBFIRST" > $@
-	echo "#define TRIPLE_BITS" >> $@
-	echo "#define FIXEDBASE" >> $@
-	echo '#include "$(srcdir)/${@:mf3-%=%}"' >> $@
+	$(AM_V_GEN)echo "#define MSBFIRST" > $@
+	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
+	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
+	$(AM_V_GEN)echo '#include "$(srcdir)/${@:mf3-%=%}"' >> $@
 
 DISTCLEANFILES = $(POLYSEG) \
 	$(LSB_FIRST) $(LSB_FIXED) $(MSB_FIRST) $(MSB_FIXED) \
commit 838b9582280030a159878af566126cb0a523ec29
Author: Cyril Brulebois <kibi at debian.org>
Date:   Thu Nov 11 15:40:13 2010 +0100

    Replace LookupIDByType() with dixLookupResourceByType(), take 2.
    
    These occurrences are a bit harder to catch through a semantic patch,
    so process them “manually”.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/hw/dmx/dmxgcops.c b/hw/dmx/dmxgcops.c
index 425aa7c..bc8cd9e 100644
--- a/hw/dmx/dmxgcops.c
+++ b/hw/dmx/dmxgcops.c
@@ -523,8 +523,10 @@ static DMXScreenInfo *dmxFindAlternatePixmap(DrawablePtr pDrawable, XID *draw)
             
     if (noPanoramiXExtension)               return NULL;
     if (pDrawable->type != DRAWABLE_PIXMAP) return NULL;
-    
-    if (!(pXinPix = (PanoramiXRes *)LookupIDByType(pDrawable->id, XRT_PIXMAP)))
+
+    if (Success != dixLookupResourceByType((pointer*) &pXinPix,
+					   pDrawable->id, XRT_PIXMAP,
+					   NullClient, DixUnknownAccess))
         return NULL;
 
     for (i = 1; i < PanoramiXNumScreens; i++) {
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 050d1e3..4e2e62f 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -2897,6 +2897,7 @@ int __glXCreateWindow(__GLXclientState *cl, GLbyte *pc)
     VisualPtr pVisual;
     VisualID visId;
     int i, rc;
+    pointer val;
 
     /*
     ** Check if windowId is valid 
@@ -2962,7 +2963,9 @@ int __glXCreateWindow(__GLXclientState *cl, GLbyte *pc)
     /*
     ** Check if there is already a fbconfig associated with this window
     */
-    if ( LookupIDByType(glxwindowId, __glXWindowRes) ) {
+    if (Success == dixLookupResourceByType(&val,
+					   glxwindowId, __glXWindowRes,
+					   NullClient, DixUnknownAccess)) {
 	client->errorValue = glxwindowId;
 	return BadAlloc;
     }
@@ -2994,11 +2997,14 @@ int __glXDestroyWindow(__GLXclientState *cl, GLbyte *pc)
     ClientPtr client = cl->client;
     xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
     XID glxwindow = req->glxwindow;
+    pointer val;
 
     /*
     ** Check if it's a valid GLX window.
     */
-    if (!LookupIDByType(glxwindow, __glXWindowRes)) {
+    if (Success != dixLookupResourceByType(&val,
+					   glxwindow, __glXWindowRes,
+					   NullClient, DixUnknownAccess)) {
 	client->errorValue = glxwindow;
 	return __glXBadDrawable;
     }
diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
index 886b317..7f63b6b 100644
--- a/hw/dmx/glxProxy/glxext.c
+++ b/hw/dmx/glxProxy/glxext.c
@@ -186,8 +186,12 @@ void __glXFreeGLXWindow(__glXWindow *pGlxWindow)
 {
     if (!pGlxWindow->idExists && !pGlxWindow->refcnt) {
 	WindowPtr pWindow = (WindowPtr) pGlxWindow->pDraw;
+	WindowPtr ret;
 
-        if (LookupIDByType(pWindow->drawable.id, RT_WINDOW) == pWindow) {
+	dixLookupResourceByType((pointer) &ret,
+				pWindow->drawable.id, RT_WINDOW,
+				NullClient, DixUnknownAccess);
+        if (ret == pWindow) {
             (*pGlxWindow->pScreen->DestroyWindow)(pWindow);
         }
 
commit ffb93533fd8067c7383aef5e0018a197af59b46c
Author: Cyril Brulebois <kibi at debian.org>
Date:   Thu Nov 11 15:30:15 2010 +0100

    Replace LookupIDByType() with dixLookupResourceByType(), take 1.
    
    This patch has been prepared with the following Coccinelle semantic patch:
    
    @@
    expression x, y;
    type t;
    identifier r;
    @@
    -r = (t) LookupIDByType(x, y);
    +dixLookupResourceByType((pointer*)&r, x, y, NullClient, DixUnknownAccess);
    
    @@
    expression x, y;
    type t;
    identifier r;
    @@
    -t r = (t) LookupIDByType(x, y);
    +t r;
    +dixLookupResourceByType((pointer*)&r, x, y, NullClient, DixUnknownAccess);
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/hw/dmx/dmxextension.c b/hw/dmx/dmxextension.c
index 0092835..45cb3db 100644
--- a/hw/dmx/dmxextension.c
+++ b/hw/dmx/dmxextension.c
@@ -699,7 +699,8 @@ static void dmxBERestorePixmapImage(pointer value, XID id, RESTYPE type,
 	PixmapPtr      pPix;
 	int            i;
 
-	pPix = (PixmapPtr)LookupIDByType(pXinPix->info[idx].id, RT_PIXMAP);
+	dixLookupResourceByType((pointer*) &pPix, pXinPix->info[idx].id,
+				RT_PIXMAP, NullClient, DixUnknownAccess);
 	if (pPix != pDst) return; /* Not a match.... Next! */
 
 	for (i = 0; i < PanoramiXNumScreens; i++) {
@@ -708,8 +709,8 @@ static void dmxBERestorePixmapImage(pointer value, XID id, RESTYPE type,
 
 	    if (i == idx) continue; /* Self replication is bad */
 
-	    pSrc =
-		(PixmapPtr)LookupIDByType(pXinPix->info[i].id, RT_PIXMAP);
+	    dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
+				    RT_PIXMAP, NullClient, DixUnknownAccess);
 	    pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
 	    if (pSrcPriv->pixmap) {
 		DMXScreenInfo *dmxSrcScreen = &dmxScreens[i];
@@ -1365,7 +1366,8 @@ static void dmxBEFindPixmapImage(pointer value, XID id, RESTYPE type,
 	PixmapPtr      pPix;
 	int            i;
 
-	pPix = (PixmapPtr)LookupIDByType(pXinPix->info[idx].id, RT_PIXMAP);
+	dixLookupResourceByType((pointer*) &pPix, pXinPix->info[idx].id,
+				RT_PIXMAP, NullClient, DixUnknownAccess);
 	if (pPix != pDst) return; /* Not a match.... Next! */
 
 	for (i = 0; i < PanoramiXNumScreens; i++) {
@@ -1374,8 +1376,8 @@ static void dmxBEFindPixmapImage(pointer value, XID id, RESTYPE type,
 
 	    if (i == idx) continue; /* Self replication is bad */
 
-	    pSrc =
-		(PixmapPtr)LookupIDByType(pXinPix->info[i].id, RT_PIXMAP);
+	    dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
+				    RT_PIXMAP, NullClient, DixUnknownAccess);
 	    pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
 	    if (pSrcPriv->pixmap) {
 		FoundPixImage = True;
diff --git a/hw/dmx/dmxgcops.c b/hw/dmx/dmxgcops.c
index 589c637..425aa7c 100644
--- a/hw/dmx/dmxgcops.c
+++ b/hw/dmx/dmxgcops.c
@@ -533,8 +533,8 @@ static DMXScreenInfo *dmxFindAlternatePixmap(DrawablePtr pDrawable, XID *draw)
             PixmapPtr     pSrc;
             dmxPixPrivPtr pSrcPriv;
             
-            pSrc = (PixmapPtr)LookupIDByType(pXinPix->info[i].id,
-                                             RT_PIXMAP);
+            dixLookupResourceByType((pointer*) &pSrc, pXinPix->info[i].id,
+				    RT_PIXMAP, NullClient, DixUnknownAccess);
             pSrcPriv = DMX_GET_PIXMAP_PRIV(pSrc);
             if (pSrcPriv->pixmap) {
                 *draw = pSrcPriv->pixmap;
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index 4484828..c3b4700 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -84,7 +84,8 @@ Window dmxCreateRootWindow(WindowPtr pWindow)
     parent = dmxScreen->scrnWin; /* This is our "Screen" window */
     visual = dmxScreen->beVisuals[dmxScreen->beDefVisualIndex].visual;
 
-    pCmap = (ColormapPtr)LookupIDByType(wColormap(pWindow), RT_COLORMAP);
+    dixLookupResourceByType((pointer*) &pCmap, wColormap(pWindow),
+			    RT_COLORMAP, NullClient, DixUnknownAccess);
     pCmapPriv = DMX_GET_COLORMAP_PRIV(pCmap);
 
     mask = CWEventMask | CWBackingStore | CWColormap | CWBorderPixel;
@@ -191,8 +192,8 @@ void dmxGetDefaultWindowAttributes(WindowPtr pWindow,
 	    ColormapPtr         pCmap;
 	    dmxColormapPrivPtr  pCmapPriv;
 
-	    pCmap = (ColormapPtr)LookupIDByType(wColormap(pWindow),
-						RT_COLORMAP);
+	    dixLookupResourceByType((pointer*) &pCmap, wColormap(pWindow),
+				    RT_COLORMAP, NullClient, DixUnknownAccess);
 	    pCmapPriv = DMX_GET_COLORMAP_PRIV(pCmap);
 	    *cmap = pCmapPriv->cmap;
 	} else {
@@ -545,7 +546,8 @@ static void dmxDoChangeWindowAttributes(WindowPtr pWindow,
 	ColormapPtr         pCmap;
 	dmxColormapPrivPtr  pCmapPriv;
 
-	pCmap = (ColormapPtr)LookupIDByType(wColormap(pWindow), RT_COLORMAP);
+	dixLookupResourceByType((pointer*) &pCmap, wColormap(pWindow),
+				RT_COLORMAP, NullClient, DixUnknownAccess);
 	pCmapPriv = DMX_GET_COLORMAP_PRIV(pCmap);
 	attribs->colormap = pCmapPriv->cmap;
     }
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 6a0aae7..050d1e3 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -129,7 +129,8 @@ static int CreateContext(__GLXclientState *cl,
     if (shareList == None) {
        shareglxc = NULL;
     } else {
-       shareglxc = (__GLXcontext *) LookupIDByType(shareList, __glXContextRes);
+       dixLookupResourceByType((pointer*) &shareglxc, shareList,
+                               __glXContextRes, NullClient, DixUnknownAccess);
        if (!shareglxc) {
 	  client->errorValue = shareList;
 	  return __glXBadContext;
@@ -420,14 +421,14 @@ int __glXBindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc)
 
     rc = dixLookupDrawable(&pDraw, req->drawable, client, 0, DixGetAttrAccess);
     if (rc != Success) {
-	pGlxPixmap = (__GLXpixmap *) LookupIDByType(req->drawable,
-						    __glXPixmapRes);
+	dixLookupResourceByType((pointer*) &pGlxPixmap, req->drawable,
+				__glXPixmapRes, NullClient, DixUnknownAccess);
 	if (pGlxPixmap) pDraw = pGlxPixmap->pDraw;
     }
 
     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-       pGlxWindow = (__glXWindow *) LookupIDByType(req->drawable,
-						   __glXWindowRes);
+       dixLookupResourceByType((pointer*) &pGlxWindow, req->drawable,
+                               __glXWindowRes, NullClient, DixUnknownAccess);
        if (pGlxWindow) pDraw = pGlxWindow->pDraw;
     }
 
@@ -450,14 +451,14 @@ int __glXJoinSwapGroupSGIX(__GLXclientState *cl, GLbyte *pc)
 
     rc = dixLookupDrawable(&pDraw, req->drawable, client, 0, DixManageAccess);
     if (rc != Success) {
-	pGlxPixmap = (__GLXpixmap *) LookupIDByType(req->drawable,
-						    __glXPixmapRes);
+	dixLookupResourceByType((pointer*) &pGlxPixmap, req->drawable,
+				__glXPixmapRes, NullClient, DixUnknownAccess);
 	if (pGlxPixmap) pDraw = pGlxPixmap->pDraw;
     }
 
     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-       pGlxWindow = (__glXWindow *) LookupIDByType(req->drawable,
-						   __glXWindowRes);
+       dixLookupResourceByType((pointer*) &pGlxWindow, req->drawable,
+                               __glXWindowRes, NullClient, DixUnknownAccess);
        if (pGlxWindow) pDraw = pGlxWindow->pDraw;
     }
 
@@ -470,14 +471,16 @@ int __glXJoinSwapGroupSGIX(__GLXclientState *cl, GLbyte *pc)
 	rc = dixLookupDrawable(&pMember, req->member, client, 0,
 			       DixGetAttrAccess);
 	if (rc != Success) {
-	    pGlxPixmap = (__GLXpixmap *) LookupIDByType(req->member,
-							__glXPixmapRes);
+	    dixLookupResourceByType((pointer*) &pGlxPixmap, req->member,
+                                    __glXPixmapRes, NullClient,
+                                    DixUnknownAccess);
 	    if (pGlxPixmap) pMember = pGlxPixmap->pDraw;
 	}
 
 	if (!pMember && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-	    pGlxWindow = (__glXWindow *) LookupIDByType(req->member,
-							__glXWindowRes);
+	    dixLookupResourceByType((pointer*) &pGlxWindow, req->member,
+                                    __glXWindowRes, NullClient,
+                                    DixUnknownAccess);
 	    if (pGlxWindow) pMember = pGlxWindow->pDraw;
 	}
 
@@ -505,7 +508,8 @@ int __glXDestroyContext(__GLXclientState *cl, GLbyte *pc)
     int to_screen = 0;
     int s;
     
-    glxc = (__GLXcontext *) LookupIDByType(gcId, __glXContextRes);
+    dixLookupResourceByType((pointer*) &glxc, gcId, __glXContextRes,
+			    NullClient, DixUnknownAccess);
     if (glxc) {
 	/*
 	** Just free the resource; don't actually destroy the context,
@@ -752,7 +756,8 @@ static int MakeCurrent(__GLXclientState *cl,
     ** Lookup new context.  It must not be current for someone else.
     */
     if (contextId != None) {
-	glxc = (__GLXcontext *) LookupIDByType(contextId, __glXContextRes);
+	dixLookupResourceByType((pointer*) &glxc, contextId, __glXContextRes,
+				NullClient, DixUnknownAccess);
 	if (!glxc) {
 	    client->errorValue = contextId;
 	    return __glXBadContext;
@@ -802,8 +807,9 @@ static int MakeCurrent(__GLXclientState *cl,
 	}
 
         if (!pDraw) {
-	    pGlxPixmap = (__GLXpixmap *) LookupIDByType(drawId,
-							__glXPixmapRes);
+	    dixLookupResourceByType((pointer*) &pGlxPixmap, drawId,
+				    __glXPixmapRes, NullClient,
+				    DixUnknownAccess);
 	    if (pGlxPixmap) {
 		/*
 		** Check if pixmap and context are similar.
@@ -826,7 +832,9 @@ static int MakeCurrent(__GLXclientState *cl,
 	}
 
 	if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-	   pGlxWindow = (__glXWindow *) LookupIDByType(drawId, __glXWindowRes);
+	   dixLookupResourceByType((pointer*) &pGlxWindow, drawId,
+                                   __glXWindowRes, NullClient,
+                                   DixUnknownAccess);
             if (pGlxWindow) {
                 /*
                 ** Drawable is a GLXWindow.
@@ -847,7 +855,9 @@ static int MakeCurrent(__GLXclientState *cl,
 	}
 
 	if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-	   pGlxPbuffer = (__glXPbuffer *)LookupIDByType(drawId, __glXPbufferRes);
+	   dixLookupResourceByType((pointer*) &pGlxPbuffer, drawId,
+                                   __glXPbufferRes, NullClient,
+                                   DixUnknownAccess);
 	   if (pGlxPbuffer) {
                 if (pGlxPbuffer->pScreen != glxc->pScreen ||
                     pGlxPbuffer->pFBConfig != glxc->pFBConfig) {
@@ -908,8 +918,9 @@ static int MakeCurrent(__GLXclientState *cl,
 	}
 
 	if (!pReadDraw) {
-	    pReadGlxPixmap = (__GLXpixmap *) LookupIDByType(readId,
-							__glXPixmapRes);
+	    dixLookupResourceByType((pointer*) &pReadGlxPixmap, readId,
+				    __glXPixmapRes, NullClient,
+				    DixUnknownAccess);
 	    if (pReadGlxPixmap) {
 		/*
 		** Check if pixmap and context are similar.
@@ -929,8 +940,9 @@ static int MakeCurrent(__GLXclientState *cl,
 	}
 
 	if (!pReadDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-	   pGlxReadWindow = (__glXWindow *)
-                                LookupIDByType(readId, __glXWindowRes);
+	   dixLookupResourceByType((pointer*) &pGlxReadWindow, readId,
+                                   __glXWindowRes, NullClient,
+                                   DixUnknownAccess);
             if (pGlxReadWindow) {
                 /*
                 ** Drawable is a GLXWindow.
@@ -950,7 +962,9 @@ static int MakeCurrent(__GLXclientState *cl,
 	}
 
 	if (!pReadDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-	   pGlxReadPbuffer = (__glXPbuffer *)LookupIDByType(readId, __glXPbufferRes);
+	   dixLookupResourceByType((pointer*) &pGlxReadPbuffer, readId,
+                                   __glXPbufferRes, NullClient,
+                                   DixUnknownAccess);
 	   if (pGlxReadPbuffer) {
                 if (pGlxReadPbuffer->pScreen != glxc->pScreen ||
                     pGlxReadPbuffer->pFBConfig != glxc->pFBConfig) {
@@ -1303,7 +1317,8 @@ int __glXIsDirect(__GLXclientState *cl, GLbyte *pc)
     /*
     ** Find the GL context.
     */
-    glxc = (__GLXcontext *) LookupIDByType(req->context, __glXContextRes);
+    dixLookupResourceByType((pointer*) &glxc, req->context, __glXContextRes,
+                            NullClient, DixUnknownAccess);
     if (!glxc) {
 	client->errorValue = req->context;
 	return __glXBadContext;
@@ -1449,12 +1464,14 @@ int __glXCopyContext(__GLXclientState *cl, GLbyte *pc)
     /*
     ** Check that each context exists.
     */
-    src = (__GLXcontext *) LookupIDByType(source, __glXContextRes);
+    dixLookupResourceByType((pointer*) &src, source, __glXContextRes,
+                            NullClient, DixUnknownAccess);
     if (!src) {
 	client->errorValue = source;
 	return __glXBadContext;
     }
-    dst = (__GLXcontext *) LookupIDByType(dest, __glXContextRes);
+    dixLookupResourceByType((pointer*) &dst, dest, __glXContextRes,
+                            NullClient, DixUnknownAccess);
     if (!dst) {
 	client->errorValue = dest;
 	return __glXBadContext;
@@ -1870,7 +1887,8 @@ int __glXDestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc)
     /*
     ** Check if it's a valid GLX pixmap.
     */
-    pGlxPixmap = (__GLXpixmap *)LookupIDByType(glxpixmap, __glXPixmapRes);
+    dixLookupResourceByType((pointer*) &pGlxPixmap, glxpixmap,
+                            __glXPixmapRes, NullClient, DixUnknownAccess);
     if (!pGlxPixmap) {
 	client->errorValue = glxpixmap;
 	return __glXBadPixmap;
@@ -1953,8 +1971,8 @@ int __glXDoSwapBuffers(__GLXclientState *cl, XID drawId, GLXContextTag tag)
     } 
 
     if (!pDraw) {
-	pGlxPixmap = (__GLXpixmap *) LookupIDByType(drawId,
-						    __glXPixmapRes);
+	dixLookupResourceByType((pointer*) &pGlxPixmap, drawId,
+				__glXPixmapRes, NullClient, DixUnknownAccess);
 	if (pGlxPixmap) {
 	    /*
 	    ** Drawable is a GLX pixmap.
@@ -1965,7 +1983,8 @@ int __glXDoSwapBuffers(__GLXclientState *cl, XID drawId, GLXContextTag tag)
     }
 
     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-       pGlxWindow = (__glXWindow *) LookupIDByType(drawId, __glXWindowRes);
+       dixLookupResourceByType((pointer*) &pGlxWindow, drawId,
+                               __glXWindowRes, NullClient, DixUnknownAccess);
        if (pGlxWindow) {
 	  /*
 	   ** Drawable is a GLXWindow.
@@ -2100,8 +2119,8 @@ int __glXSwapBuffers(__GLXclientState *cl, GLbyte *pc)
     } 
 
     if (!pDraw) {
-	pGlxPixmap = (__GLXpixmap *) LookupIDByType(drawId,
-						    __glXPixmapRes);
+	dixLookupResourceByType((pointer*) &pGlxPixmap, drawId,
+				__glXPixmapRes, NullClient, DixUnknownAccess);
 	if (pGlxPixmap) {
 	    /*
 	    ** Drawable is a GLX pixmap.
@@ -2111,7 +2130,8 @@ int __glXSwapBuffers(__GLXclientState *cl, GLbyte *pc)
     }
 
     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1,3) ) {
-       pGlxWindow = (__glXWindow *) LookupIDByType(drawId, __glXWindowRes);
+       dixLookupResourceByType((pointer*) &pGlxWindow, drawId,
+                               __glXWindowRes, NullClient, DixUnknownAccess);
        if (pGlxWindow) {
 	  /*
 	   ** Drawable is a GLXWindow.
@@ -2620,9 +2640,13 @@ int __glXUseXFont(__GLXclientState *cl, GLbyte *pc)
     ** Font can actually be either the ID of a font or the ID of a GC
     ** containing a font.
     */
-    pFont = (FontPtr)LookupIDByType(req->font, RT_FONT);
+    dixLookupResourceByType((pointer*) &pFont, req->font, RT_FONT,
+                            NullClient, DixUnknownAccess);
     if (!pFont) {
-        GC *pGC = (GC *)LookupIDByType(req->font, RT_GC);
+        GC *pGC;
+        dixLookupResourceByType((pointer*) &pGC, req->font,
+				RT_GC, NullClient,
+				DixUnknownAccess);
         if (!pGC) {
 	    client->errorValue = req->font;
             return BadFont;
@@ -2998,7 +3022,8 @@ int __glXQueryContext(__GLXclientState *cl, GLbyte *pc)
     int nReplyBytes;
 
     req = (xGLXQueryContextReq *)pc;
-    ctx = (__GLXcontext *) LookupIDByType(req->context, __glXContextRes);
+    dixLookupResourceByType((pointer*) &ctx, req->context, __glXContextRes,
+                            NullClient, DixUnknownAccess);
     if (!ctx) {
         client->errorValue = req->context;
         return __glXBadContext;
@@ -3208,7 +3233,8 @@ int __glXDestroyPbuffer(__GLXclientState *cl, GLbyte *pc)
     /*
     ** Check if it's a valid Pbuffer
     */
-    pGlxPbuffer = (__glXPbuffer *)LookupIDByType(pbuffer, __glXPbufferRes);
+    dixLookupResourceByType((pointer*) &pGlxPbuffer, pbuffer,
+                            __glXPbufferRes, NullClient, DixUnknownAccess);
     if (!pGlxPbuffer) {
 	client->errorValue = pbuffer;
 	return __glXBadPbuffer;
@@ -3280,8 +3306,10 @@ int __glXGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
       }
 
       if (!pDraw) {
-	 __GLXpixmap *pGlxPixmap = (__GLXpixmap *) LookupIDByType(drawId,
-							__glXPixmapRes);
+	 __GLXpixmap *pGlxPixmap;
+	 dixLookupResourceByType((pointer*) &pGlxPixmap,
+				 drawId, __glXPixmapRes,
+				 NullClient, DixUnknownAccess);
 	 if (pGlxPixmap) {
 		pDraw = pGlxPixmap->pDraw;
 		screen = pGlxPixmap->pScreen->myNum;
@@ -3290,7 +3318,10 @@ int __glXGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
       }
 
       if (!pDraw) {
-	 __glXWindow *pGlxWindow = (__glXWindow *) LookupIDByType(drawId, __glXWindowRes);
+	 __glXWindow *pGlxWindow;
+	 dixLookupResourceByType((pointer*) &pGlxWindow,
+				 drawId, __glXWindowRes,
+				 NullClient, DixUnknownAccess);
 	 if (pGlxWindow) {
 	    pDraw = pGlxWindow->pDraw;
 	    screen = pGlxWindow->pScreen->myNum;
@@ -3299,7 +3330,10 @@ int __glXGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
       }
 
       if (!pDraw) {
-	 __glXPbuffer *pGlxPbuffer = (__glXPbuffer *)LookupIDByType(drawId, __glXPbufferRes);
+	 __glXPbuffer *pGlxPbuffer;
+	 dixLookupResourceByType((pointer*) &pGlxPbuffer,
+				 drawId, __glXPbufferRes,
+				 NullClient, DixUnknownAccess);
 	 if (pGlxPbuffer) {
     	    pDraw = (DrawablePtr)pGlxPbuffer;
 	    screen = pGlxPbuffer->pScreen->myNum;
@@ -3436,8 +3470,10 @@ int __glXChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
       }
 
       if (!pDraw) {
-	 __GLXpixmap *pGlxPixmap = (__GLXpixmap *) LookupIDByType(drawId,
-							__glXPixmapRes);
+	 __GLXpixmap *pGlxPixmap;
+	 dixLookupResourceByType((pointer*) &pGlxPixmap,
+				 drawId, __glXPixmapRes,
+				 NullClient, DixUnknownAccess);
 	 if (pGlxPixmap) {
 		pDraw = pGlxPixmap->pDraw;
 		screen = pGlxPixmap->pScreen->myNum;
@@ -3446,7 +3482,10 @@ int __glXChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
       }
 
       if (!pDraw) {
-	 __glXWindow *pGlxWindow = (__glXWindow *) LookupIDByType(drawId, __glXWindowRes);
+	 __glXWindow *pGlxWindow;
+	 dixLookupResourceByType((pointer*) &pGlxWindow,
+				 drawId, __glXWindowRes,
+				 NullClient, DixUnknownAccess);
 	 if (pGlxWindow) {
 	    pDraw = pGlxWindow->pDraw;
 	    screen = pGlxWindow->pScreen->myNum;
@@ -3455,7 +3494,10 @@ int __glXChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
       }
 
       if (!pDraw) {
-	 __glXPbuffer *pGlxPbuffer = (__glXPbuffer *)LookupIDByType(drawId, __glXPbufferRes);
+	 __glXPbuffer *pGlxPbuffer;
+	 dixLookupResourceByType((pointer*) &pGlxPbuffer,
+				 drawId, __glXPbufferRes,
+				 NullClient, DixUnknownAccess);
 	 if (pGlxPbuffer) {
     	    pDraw = (DrawablePtr)pGlxPbuffer;
 	    screen = pGlxPbuffer->pScreen->myNum;
commit d1b45b0fd54efb952f9ff435a516c1bfd85ca186
Author: Cyril Brulebois <kibi at debian.org>
Date:   Thu Nov 11 11:35:47 2010 +0100

    Fix missing <string.h> include.
    
    The following happens otherwise (with -Wall -Werror):
    | In file included from /usr/include/X11/Xfuncs.h:47,
    |                  from ../../include/misc.h:112,
    |                  from ../../include/screenint.h:52,
    |                  from ../../include/scrnintstr.h:52,
    |                  from ../../dix/cursor.c:58:
    | /usr/include/string.h:534: error: conflicting types for ‘xstrcasecmp’
    | ../../include/os.h:488: note: previous declaration of ‘xstrcasecmp’ was here
    | /usr/include/string.h:538: error: conflicting types for ‘xstrncasecmp’
    | ../../include/os.h:493: note: previous declaration of ‘xstrncasecmp’ was here
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/include/os.h b/include/os.h
index 566514d..d587f34 100644
--- a/include/os.h
+++ b/include/os.h
@@ -51,6 +51,7 @@ SOFTWARE.
 
 #include "misc.h"
 #include <stdarg.h>
+#include <string.h>
 
 #define SCREEN_SAVER_ON   0
 #define SCREEN_SAVER_OFF  1
commit 780754050bc9cb1489f92a2a890ab5665e3e6358
Author: Cyril Brulebois <kibi at debian.org>
Date:   Fri Nov 12 12:18:59 2010 +0100

    Fix GLX_LIBS vs. DMX_LIBS order.
    
    If glxproxy needs symbols which aren't pulled in by dmx itself, glxproxy
    fails to link because of undefined references.
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/dmx/Makefile.am b/hw/dmx/Makefile.am
index 0d06346..5c16dc3 100644
--- a/hw/dmx/Makefile.am
+++ b/hw/dmx/Makefile.am
@@ -81,8 +81,8 @@ Xdmx_SOURCES = dmx.c \
 #endif
 
 XDMX_LIBS = \
-	@XDMX_LIBS@ \
 	$(GLX_LIBS) \
+	@XDMX_LIBS@ \
         input/libdmxinput.a \
         config/libdmxconfig.a
 
commit 14983286c489ea1ec6ba4fadbeaec5c2d2ee34e1
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 20:45:35 2010 -0800

    Version bumped to 1.9.99.901 (1.10 RC1)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index d1fc379..b56d3e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,8 +26,8 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.57)
-AC_INIT([xorg-server], 1.9.99.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2010-10-01"
+AC_INIT([xorg-server], 1.9.99.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2010-12-06"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit d96d5f5443358e33e47d1a61f9bd2afd8064a8dd
Author: James Jones <jajones at nvidia.com>
Date:   Sun Dec 5 19:42:41 2010 -0800

    Bump extension ABI to 5
    
    Commit 606e079cc4d9a9db3197652ca51683c36f74efb8 moved the visual
    field in WindowOptRec, breaking the extension module ABI.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 72f6cf0..af7b778 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -84,7 +84,7 @@ typedef enum {
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
 #define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(9, 0)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(12, 0)
-#define ABI_EXTENSION_VERSION	SET_ABI_VERSION(4, 0)
+#define ABI_EXTENSION_VERSION	SET_ABI_VERSION(5, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
 
 #define MODINFOSTRING1	0xef23fdc5
commit 435361bd73b9fc733f093d81af6b839953e35176
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 20:38:14 2010 -0800

    sync: syncObject may be None in SyncInitTrigger
    
    And often is, especially when called from ProcSyncCreateAlarm.
    Crashing in this case seems unwise.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index ce00755..ab8f20d 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -296,7 +296,7 @@ SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject,
 
     /* if system counter, ask it what the current value is */
 
-    if (SYNC_COUNTER == pSync->type)
+    if (pSync && SYNC_COUNTER == pSync->type)
     {
 	pCounter = (SyncCounter *)pSync;
 
@@ -320,7 +320,7 @@ SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject,
     if (changes & XSyncCATestType)
     {
 
-	if (SYNC_FENCE == pSync->type)
+	if (pSync && SYNC_FENCE == pSync->type)
 	{
 	    pTrigger->CheckTrigger = SyncCheckTriggerFence;
 	}
commit 0d01b66df9081ef48843b3bad81c56bb2cd1ae69
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Dec 5 23:35:28 2010 -0800

    randr: handle RRSetCrtcConfigs request with zero configs
    
    Need to actually return a reply in this case.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 0fc8188..5fe6900 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1750,9 +1750,6 @@ ProcRRSetCrtcConfigs (ClientPtr client)
     screen_config.mm_width = stuff->widthInMillimeters;
     screen_config.mm_height = stuff->heightInMillimeters;
 
-    if (num_configs == 0)
-	return Success;
-
     output_ids = (RROutput *) (x_configs + num_configs);
 
     /*
@@ -1760,7 +1757,7 @@ ProcRRSetCrtcConfigs (ClientPtr client)
      * server crtc configurations
      */
     configs = calloc(num_configs, sizeof (RRCrtcConfigRec));
-    if (!configs)
+    if (num_configs > 0 && configs == NULL)
 	return BadAlloc;
     for (i = 0; i < num_configs; i++) {
 	rc = RRConvertCrtcConfig(client, screen, &screen_config,
@@ -1773,7 +1770,8 @@ ProcRRSetCrtcConfigs (ClientPtr client)
 	output_ids += x_configs[i].nOutput;
     }
 
-    if (!RRSetCrtcConfigs (screen, &screen_config, configs, num_configs))
+    if (num_configs &&
+	!RRSetCrtcConfigs (screen, &screen_config, configs, num_configs))
     {
 	rep.status = RRSetConfigFailed;
 	goto sendReply;
commit b0f4bd61f0caf80f3be9a176f1f7a707bc6628d8
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Dec 5 21:53:25 2010 -0800

    ProcRRSetCrtcConfigs uses 'configs' without being initialized
    
    If the client sends invalid data for this request, the server
    will jump to 'sendReply' and call RRFreeCrtcConfigs, passing it the
    uninitialized 'configs' and 'num_configs' values.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 97aa3d7..0fc8188 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1682,9 +1682,9 @@ ProcRRSetCrtcConfigs (ClientPtr client)
     rrScrPrivPtr	    scr_priv;
     xRRCrtcConfig	    *x_configs;
     RRScreenConfigRec	    screen_config;
-    RRCrtcConfigPtr	    configs;
+    RRCrtcConfigPtr	    configs = NULL;
     RROutput		    *output_ids;
-    int			    num_configs;
+    int			    num_configs = 0;
     int			    rc, i;
     int			    extra_len;
     int			    num_output_ids;
commit 752c368421c1c824752cf467fba9318d75d2ca2c
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Dec 5 20:57:47 2010 -0800

    Separate out screen size and screen pixmap sizes in RRScreenSizeSet
    
    This provides for separate sizes for the screen scanout and rendering
    buffer and the application-visible screen size.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index ea0acbf..01f9864 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1038,7 +1038,12 @@ xf86SetRootClip (ScreenPtr pScreen, Bool enable)
 	RegionInit(&pWin->winSize, &box, 1);
 	RegionInit(&pWin->borderSize, &box, 1);
 	if (WasViewable)
+	{
+	    PixmapPtr	pPixmap = (*pScreen->GetScreenPixmap) (pScreen);
+	    box.x2 = pPixmap->drawable.width;
+	    box.y2 = pPixmap->drawable.height;
 	    RegionReset(&pWin->borderClip, &box);
+	}
 	pWin->drawable.width = pScreen->width;
 	pWin->drawable.height = pScreen->height;
         RegionBreak(&pWin->clipList);
@@ -1116,7 +1121,6 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
 	 */
 	if (!xf86Resetting)
 	    xf86SetRootClip (pScreen, TRUE);
-
     }
     else
     {
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index dfe2cc3..407bf35 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -659,10 +659,12 @@ xf86RandR12SetConfig (ScreenPtr		pScreen,
 
 static Bool
 xf86RandR12ScreenSetSize (ScreenPtr	pScreen,
-			CARD16		width,
-			CARD16		height,
-			CARD32		mmWidth,
-			CARD32		mmHeight)
+			  CARD16	width,
+			  CARD16	height,
+			  CARD16	pixWidth,
+			  CARD16	pixHeight,
+			  CARD32	mmWidth,
+			  CARD32	mmHeight)
 {
     XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
     ScrnInfoPtr		pScrn = XF86SCRNINFO(pScreen);
@@ -670,6 +672,8 @@ xf86RandR12ScreenSetSize (ScreenPtr	pScreen,
     WindowPtr		pRoot = pScreen->root;
     PixmapPtr		pScrnPix;
     Bool		ret = FALSE;
+    Bool		pixSizeChanged = FALSE;
+    Bool		winSizeChanged = FALSE;
     int                 c;
 
     if (xf86RandR12Key) {
@@ -677,46 +681,85 @@ xf86RandR12ScreenSetSize (ScreenPtr	pScreen,
         {
 	    randrp->virtualX = pScrn->virtualX;
 	    randrp->virtualY = pScrn->virtualY;
+	    pixSizeChanged = TRUE;
         }
     }
-    if (pRoot && pScrn->vtSema)
-	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE);
 
-    /* Let the driver update virtualX and virtualY */
-    if (!(*config->funcs->resize)(pScrn, width, height))
-	goto finish;
+    pScrnPix = (*pScreen->GetScreenPixmap)(pScreen);
+    if (pixWidth != pScrnPix->drawable.width ||
+	pixHeight != pScrnPix->drawable.height)
+	pixSizeChanged = TRUE;
+
+    if (width != pScreen->width || height != pScreen->height)
+	winSizeChanged = TRUE;
+
+    if (pixSizeChanged)
+    {
+	if (pRoot && pScrn->vtSema)
+	    (*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+
+	/* Let the driver update virtualX and virtualY */
+	if (!(*config->funcs->resize)(pScrn, pixWidth, pixHeight))
+	    goto finish;
+    }
 
     ret = TRUE;
-    /* Update panning information */
-    for (c = 0; c < config->num_crtc; c++) {
-	xf86CrtcPtr crtc = config->crtc[c];
-	if (crtc->panningTotalArea.x2 > crtc->panningTotalArea.x1 ||
-	    crtc->panningTotalArea.y2 > crtc->panningTotalArea.y1) {
-	    if (crtc->panningTotalArea.x2 > crtc->panningTrackingArea.x1)
-		crtc->panningTotalArea.x2 += width  - pScreen->width;
-	    if (crtc->panningTotalArea.y2 > crtc->panningTrackingArea.y1)
-		crtc->panningTotalArea.y2 += height - pScreen->height;
-	    if (crtc->panningTrackingArea.x2 > crtc->panningTrackingArea.x1)
-		crtc->panningTrackingArea.x2 += width  - pScreen->width;
-	    if (crtc->panningTrackingArea.y2 > crtc->panningTrackingArea.y1)
-		crtc->panningTrackingArea.y2 += height - pScreen->height;
-	    xf86RandR13VerifyPanningArea (crtc, width, height);
-	    xf86RandR13Pan (crtc, randrp->pointerX, randrp->pointerY);
+
+    if (winSizeChanged)
+    {
+	/* Update panning information */
+	for (c = 0; c < config->num_crtc; c++) {
+	    xf86CrtcPtr crtc = config->crtc[c];
+	    if (crtc->panningTotalArea.x2 > crtc->panningTotalArea.x1 ||
+		crtc->panningTotalArea.y2 > crtc->panningTotalArea.y1) {
+		if (crtc->panningTotalArea.x2 > crtc->panningTrackingArea.x1)
+		    crtc->panningTotalArea.x2 += width  - pScreen->width;
+		if (crtc->panningTotalArea.y2 > crtc->panningTrackingArea.y1)
+		    crtc->panningTotalArea.y2 += height - pScreen->height;
+		if (crtc->panningTrackingArea.x2 > crtc->panningTrackingArea.x1)
+		    crtc->panningTrackingArea.x2 += width  - pScreen->width;
+		if (crtc->panningTrackingArea.y2 > crtc->panningTrackingArea.y1)
+		    crtc->panningTrackingArea.y2 += height - pScreen->height;
+		xf86RandR13VerifyPanningArea (crtc, width, height);
+		xf86RandR13Pan (crtc, randrp->pointerX, randrp->pointerY);
+	    }
 	}
     }
 
     pScrnPix = (*pScreen->GetScreenPixmap)(pScreen);
-    pScreen->width = pScrnPix->drawable.width = width;
-    pScreen->height = pScrnPix->drawable.height = height;
+    pScreen->width = width;
+    pScreen->height = height;
+    if (pRoot)
+    {
+	BoxRec	box;
+
+	pRoot->drawable.width = width;
+	pRoot->drawable.height = height;
+	box.x1 = 0;
+	box.y1 = 0;
+	box.x2 = width;
+	box.y2 = height;
+	RegionInit(&pRoot->winSize, &box, 1);
+	RegionInit(&pRoot->borderSize, &box, 1);
+    }
+    pScrnPix->drawable.width = pixWidth;
+    pScrnPix->drawable.height = pixHeight;
     randrp->mmWidth = pScreen->mmWidth = mmWidth;
     randrp->mmHeight = pScreen->mmHeight = mmHeight;
 
-    xf86SetViewport (pScreen, pScreen->width-1, pScreen->height-1);
-    xf86SetViewport (pScreen, 0, 0);
+    if (winSizeChanged)
+    {
+	xf86SetViewport (pScreen, pScreen->width-1, pScreen->height-1);
+	xf86SetViewport (pScreen, 0, 0);
+    }
 
 finish:
-    if (pRoot && pScrn->vtSema)
-	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+    if (pixSizeChanged)
+    {
+	if (pRoot && pScrn->vtSema)
+	    (*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+    }
+
 #if RANDR_12_INTERFACE
     if (xf86RandR12Key && pScreen->root && ret)
 	RRScreenSizeNotify (pScreen);
@@ -818,6 +861,8 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen)
 	xf86RandR12ScreenSetSize (pScreen,
 				  width,
 				  height,
+				  width,
+				  height,
 				  mmWidth,
 				  mmHeight);
     }
diff --git a/randr/mirrcrtc.c b/randr/mirrcrtc.c
index d493a0e..a9ee6b4 100644
--- a/randr/mirrcrtc.c
+++ b/randr/mirrcrtc.c
@@ -28,11 +28,6 @@ miRRSetScreenConfig(ScreenPtr screen,
 {
     RRScreenConfigRec	old_screen_config;
 
-    /* XXX deal with separate pixmap/screen sizes */
-    if (screen_config->screen_pixmap_width != screen_config->screen_width ||
-	screen_config->screen_pixmap_height != screen_config->screen_height)
-	return FALSE;
-
     RRScreenCurrentConfig(screen, &old_screen_config);
 
     /* Check and see if nothing has changed */
@@ -47,6 +42,8 @@ miRRSetScreenConfig(ScreenPtr screen,
     return RRScreenSizeSet(screen,
 			   screen_config->screen_width,
 			   screen_config->screen_height,
+			   screen_config->screen_pixmap_width,
+			   screen_config->screen_pixmap_height,
 			   screen_config->mm_width,
 			   screen_config->mm_height);
 }
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 8240824..7c553f2 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -191,6 +191,8 @@ struct _rrOutput {
 typedef Bool (*RRScreenSetSizeProcPtr) (ScreenPtr	pScreen,
 					CARD16		width,
 					CARD16		height,
+					CARD16		pixWidth,
+					CARD16		pixHeight,
 					CARD32		mmWidth,
 					CARD32		mmHeight);
 					
@@ -478,6 +480,8 @@ extern _X_EXPORT Bool
 RRScreenSizeSet (ScreenPtr  pScreen,
 		 CARD16	    width,
 		 CARD16	    height,
+		 CARD16	    pixWidth,
+		 CARD16	    pixHeight,
 		 CARD32	    mmWidth,
 		 CARD32	    mmHeight);
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 0b2bc28..97aa3d7 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -435,10 +435,9 @@ RRCrtcCurrentConfig(RRCrtcPtr crtc,
     crtc_config->sprite_position_f_transform = crtc->client_sprite_f_position_transform;
     crtc_config->sprite_image_f_transform = crtc->client_sprite_f_image_transform;
 
-    /* XXX add pixmap stuff */
-    crtc_config->pixmap = NULL;
-    crtc_config->pixmap_x = 0;
-    crtc_config->pixmap_y = 0;
+    crtc_config->pixmap = crtc->scanoutPixmap;
+    crtc_config->pixmap_x = crtc->x;
+    crtc_config->pixmap_y = crtc->y;
     return TRUE;
 }
 
@@ -1510,6 +1509,8 @@ RRConvertCrtcConfig(ClientPtr client, ScreenPtr screen,
 
     if (x->pixmap == None)
 	pixmap = NULL;
+    else if (x->pixmap == RR_CurrentScanoutPixmap)
+	pixmap = crtc->scanoutPixmap;
     else
     {
 	rc = dixLookupResourceByType((pointer *) &pixmap, x->pixmap,
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 0c52347..292163f 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -168,6 +168,8 @@ Bool
 RRScreenSizeSet (ScreenPtr  pScreen,
 		 CARD16	    width,
 		 CARD16	    height,
+		 CARD16	    pixWidth,
+		 CARD16	    pixHeight,
 		 CARD32	    mmWidth,
 		 CARD32	    mmHeight)
 {
@@ -178,6 +180,7 @@ RRScreenSizeSet (ScreenPtr  pScreen,
     {
 	return (*pScrPriv->rrScreenSetSize) (pScreen,
 					     width, height,
+					     pixWidth, pixHeight,
 					     mmWidth, mmHeight);
     }
 #endif
@@ -318,6 +321,7 @@ ProcRRSetScreenSize (ClientPtr client)
     }
     if (!RRScreenSizeSet (pScreen, 
 			  stuff->width, stuff->height,
+			  stuff->width, stuff->height,
 			  stuff->widthInMillimeters,
 			  stuff->heightInMillimeters))
     {
@@ -949,7 +953,7 @@ ProcRRSetScreenConfig (ClientPtr client)
 		goto sendReply;
 	    }
 	}
-	if (!RRScreenSizeSet (pScreen, width, height,
+	if (!RRScreenSizeSet (pScreen, width, height, width, height,
 			      pScreen->mmWidth, pScreen->mmHeight))
 	{
 	    rep.status = RRSetConfigFailed;
commit a88d70fb20a2bc3152b84adff4380857e6cfadf5
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Dec 5 20:55:46 2010 -0800

    Set sprite transforms from RRSetCrtcConfigs
    
    These were getting ignored.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index b0eabdd..dfe2cc3 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1819,8 +1819,8 @@ xf86RRConvertCrtcConfig(xf86CrtcSetConfigPtr	xf86_config,
 	return FALSE;
     for (o = 0; o < rr_config->numOutputs; o++)
 	xf86_config->outputs[o] = rr_config->outputs[o]->devPrivate;
-    xf86_config->sprite_position_transform = rr_config->sprite_position_transform;
-    xf86_config->sprite_image_transform = rr_config->sprite_image_transform;
+    xf86_config->sprite_position_transform = rr_config->sprite_position_f_transform;
+    xf86_config->sprite_image_transform = rr_config->sprite_image_f_transform;
     xf86_config->pixmap = rr_config->pixmap;
     xf86_config->pixmap_x = rr_config->pixmap_x;
     xf86_config->pixmap_y = rr_config->pixmap_y;
diff --git a/randr/mirrcrtc.c b/randr/mirrcrtc.c
index cc76797..d493a0e 100644
--- a/randr/mirrcrtc.c
+++ b/randr/mirrcrtc.c
@@ -60,14 +60,21 @@ miRRSetCrtcConfig(RRCrtcConfigPtr crtc_config)
 	x = crtc_config->pixmap_x;
 	y = crtc_config->pixmap_y;
     }
-    return RRCrtcSet(crtc_config->crtc,
-		     crtc_config->mode,
-		     x,
-		     y,
-		     crtc_config->rotation,
-		     crtc_config->numOutputs,
-		     crtc_config->outputs,
-		     crtc_config->pixmap);
+    if (!RRCrtcSet(crtc_config->crtc,
+		   crtc_config->mode,
+		   x,
+		   y,
+		   crtc_config->rotation,
+		   crtc_config->numOutputs,
+		   crtc_config->outputs,
+		   crtc_config->pixmap))
+	return FALSE;
+    RRCrtcSpriteTransformSet(crtc_config->crtc,
+			     &crtc_config->sprite_position_transform,
+			     &crtc_config->sprite_image_transform,
+			     &crtc_config->sprite_position_f_transform,
+			     &crtc_config->sprite_image_f_transform);
+    return TRUE;
 }
 
 Bool
diff --git a/randr/randrstr.h b/randr/randrstr.h
index c231972..8240824 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -154,8 +154,10 @@ struct _rrCrtcConfig {
     Rotation			rotation;
     int				numOutputs;
     RROutputPtr			*outputs;
-    struct pict_f_transform	sprite_position_transform;
-    struct pict_f_transform	sprite_image_transform;
+    PictTransform		sprite_position_transform;
+    PictTransform		sprite_image_transform;
+    struct pict_f_transform	sprite_position_f_transform;
+    struct pict_f_transform	sprite_image_f_transform;
     PixmapPtr			pixmap;
     int				pixmap_x, pixmap_y;
 };
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 12982a8..0b2bc28 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -430,8 +430,10 @@ RRCrtcCurrentConfig(RRCrtcPtr crtc,
     if (!crtc_config->outputs)
 	return FALSE;
     memcpy(crtc_config->outputs, crtc->outputs, crtc->numOutputs * sizeof (RROutputPtr));
-    crtc_config->sprite_position_transform = crtc->client_sprite_f_position_transform;
-    crtc_config->sprite_image_transform = crtc->client_sprite_f_image_transform;
+    crtc_config->sprite_position_transform = crtc->client_sprite_position_transform;
+    crtc_config->sprite_image_transform = crtc->client_sprite_image_transform;
+    crtc_config->sprite_position_f_transform = crtc->client_sprite_f_position_transform;
+    crtc_config->sprite_image_f_transform = crtc->client_sprite_f_image_transform;
 
     /* XXX add pixmap stuff */
     crtc_config->pixmap = NULL;
@@ -718,8 +720,8 @@ RRScreenCoversCrtc(RRScreenConfigPtr screen_config,
 			crtc_config->mode->mode.width, crtc_config->mode->mode.height,
 			crtc_config->rotation,
 			client_transform,
-			&crtc_config->sprite_position_transform,
-			&crtc_config->sprite_image_transform,
+			&crtc_config->sprite_position_f_transform,
+			&crtc_config->sprite_image_f_transform,
 			NULL, &f_transform, NULL, NULL, NULL, NULL);
 
     RRModeGetScanoutSize (crtc_config->mode, &f_transform,
@@ -1469,15 +1471,6 @@ ProcRRGetCrtcTransform (ClientPtr client)
     return Success;
 }
 
-static void
-pixman_f_transform_from_xRenderTransform(struct pixman_f_transform *f_transform,
-					 xRenderTransform *x_transform)
-{
-    struct pixman_transform	transform;
-    PictTransform_from_xRenderTransform(&transform, x_transform);
-    pixman_f_transform_from_pixman_transform(f_transform, &transform);
-}
-
 static int
 RRConvertCrtcConfig(ClientPtr client, ScreenPtr screen,
 		    RRScreenConfigPtr screen_config,
@@ -1594,10 +1587,14 @@ RRConvertCrtcConfig(ClientPtr client, ScreenPtr screen,
     config->rotation = x->rotation;
     config->numOutputs = x->nOutput;
     config->outputs = outputs;
-    pixman_f_transform_from_xRenderTransform(&config->sprite_position_transform,
+    PictTransform_from_xRenderTransform(&config->sprite_position_transform,
 					     &x->spritePositionTransform);
-    pixman_f_transform_from_xRenderTransform(&config->sprite_image_transform,
+    PictTransform_from_xRenderTransform(&config->sprite_image_transform,
 					     &x->spriteImageTransform);
+    pixman_f_transform_from_pixman_transform(&config->sprite_position_f_transform,
+					     &config->sprite_position_transform);
+    pixman_f_transform_from_pixman_transform(&config->sprite_image_f_transform,
+					     &config->sprite_image_transform);
     config->pixmap = pixmap;
     config->pixmap_x = x->xPixmap;
     config->pixmap_y = x->yPixmap;
commit 96b4d4787bf82edd9d06eb9a6e94bc45412c7df2
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Dec 5 20:49:19 2010 -0800

    DIX is responsible for ref counting scanout pixmaps.
    
    Remove some extra ref counting inside hw/xfree86/modes
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 5bf12f0..08d384f 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -414,10 +414,6 @@ done:
 	crtc->active = TRUE;
 	if (scrn->pScreen)
 	    xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
-	if (crtc->scanoutPixmap)
-	    ++crtc->scanoutPixmap->refcnt;
-	if (saved_scanout_pixmap)
-	    (*scrn->pScreen->DestroyPixmap)(saved_scanout_pixmap);
 	if (scrn->ModeSet)
 	    scrn->ModeSet(scrn);
     } else {
commit afb6ebf1d5829346c40fe1053c9f50afe926e6c6
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Dec 3 13:04:37 2010 -0800

    randr: Hook up the new RandR 1.4 functionality
    
    This bumps the supported RandR protocol version and adds the dispatch
    hooks needed to call the new functions
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 1d33bdd..c8c7f5f 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -65,7 +65,7 @@
 
 /* RandR */
 #define SERVER_RANDR_MAJOR_VERSION		1
-#define SERVER_RANDR_MINOR_VERSION		3
+#define SERVER_RANDR_MINOR_VERSION		4
 
 /* Record */
 #define SERVER_RECORD_MAJOR_VERSION		1
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index ebfda57..aed746b 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -224,5 +224,11 @@ int (*ProcRandrVector[RRNumberRequests])(ClientPtr) = {
     ProcRRSetPanning,		/* 29 */
     ProcRRSetOutputPrimary,	/* 30 */
     ProcRRGetOutputPrimary,	/* 31 */
+/* V1.4 additions */
+    ProcRRQueryScanoutPixmaps,	/* 32 */
+    ProcRRCreateScanoutPixmap,	/* 33 */
+    ProcRRSetCrtcSpriteTransform,/* 34 */
+    ProcRRGetCrtcSpriteTransform,/* 35 */
+    ProcRRSetCrtcConfigs,	 /* 36 */
 };
 
diff --git a/randr/rrsdispatch.c b/randr/rrsdispatch.c
index e16090a..c848f91 100644
--- a/randr/rrsdispatch.c
+++ b/randr/rrsdispatch.c
@@ -461,6 +461,132 @@ SProcRRGetOutputPrimary (ClientPtr client)
     return ProcRandrVector[stuff->randrReqType](client);
 }
 
+static int
+SProcRRQueryScanoutPixmaps (ClientPtr client)
+{
+    int n;
+    REQUEST(xRRQueryScanoutPixmapsReq);
+
+    REQUEST_SIZE_MATCH(xRRQueryScanoutPixmapsReq);
+    swaps(&stuff->length, n);
+    swapl(&stuff->drawable, n);
+    return ProcRandrVector[stuff->randrReqType](client);
+}
+
+static int
+SProcRRCreateScanoutPixmap (ClientPtr client)
+{
+    int n;
+    REQUEST(xRRCreateScanoutPixmapReq);
+
+    REQUEST_SIZE_MATCH(xRRCreateScanoutPixmapReq);
+    swaps(&stuff->length, n);
+    swapl(&stuff->pid, n);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swapl(&stuff->format, n);
+    swaps(&stuff->rotations, n);
+    return ProcRandrVector[stuff->randrReqType](client);
+}
+
+static void
+swap_transform(xRenderTransform *t)
+{
+    int n;
+    swapl(&t->matrix11, n);
+    swapl(&t->matrix12, n);
+    swapl(&t->matrix13, n);
+    swapl(&t->matrix21, n);
+    swapl(&t->matrix22, n);
+    swapl(&t->matrix23, n);
+    swapl(&t->matrix31, n);
+    swapl(&t->matrix32, n);
+    swapl(&t->matrix33, n);
+}
+
+static int
+SProcRRSetCrtcSpriteTransform (ClientPtr client)
+{
+    int n;
+    REQUEST(xRRSetCrtcSpriteTransformReq);
+
+    REQUEST_SIZE_MATCH(xRRSetCrtcSpriteTransformReq);
+    swaps(&stuff->length, n);
+    swapl(&stuff->crtc, n);
+    swap_transform(&stuff->positionTransform);
+    swap_transform(&stuff->imageTransform);
+    return ProcRandrVector[stuff->randrReqType](client);
+}
+
+static int
+SProcRRGetCrtcSpriteTransform (ClientPtr client)
+{
+    int n;
+    REQUEST(xRRGetCrtcSpriteTransformReq);
+
+    REQUEST_SIZE_MATCH(xRRGetCrtcSpriteTransformReq);
+    swaps(&stuff->length, n);
+    swapl(&stuff->crtc, n);
+    return ProcRandrVector[stuff->randrReqType](client);
+}
+
+static int
+SProcRRSetCrtcConfigs (ClientPtr client)
+{
+    int n;
+    REQUEST(xRRSetCrtcConfigsReq);
+    int c;
+    int extra_len;
+    int num_configs;
+    int num_output_ids;
+    xRRCrtcConfig *x_configs;
+
+    REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigsReq);
+    swaps(&stuff->length, n);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->screenPixmapWidth, n);
+    swaps(&stuff->screenPixmapHeight, n);
+    swaps(&stuff->screenWidth, n);
+    swaps(&stuff->screenHeight, n);
+    swapl(&stuff->widthInMillimeters, n);
+    swapl(&stuff->heightInMillimeters, n);
+    swaps(&stuff->nConfigs, n);
+
+    extra_len = client->req_len - bytes_to_int32(sizeof(xRRSetCrtcConfigsReq));
+
+    num_configs = stuff->nConfigs;
+
+    /* Check request length against number of configs specified */
+    if (num_configs * (sizeof (xRRCrtcConfig) >> 2) > extra_len)
+	return BadLength;
+
+    x_configs = (xRRCrtcConfig *) (stuff + 1);
+    for (c = 0; c < num_configs; c++) {
+	swapl(&x_configs->crtc, n);
+	swaps(&x_configs->x, n);
+	swaps(&x_configs->y, n);
+	swapl(&x_configs->mode, n);
+	swaps(&x_configs->rotation, n);
+	swaps(&x_configs->nOutput, n);
+	swap_transform(&x_configs->spritePositionTransform);
+	swap_transform(&x_configs->spriteImageTransform);
+	swapl(&x_configs->pixmap, n);
+	swaps(&x_configs->xPixmap, n);
+	swaps(&x_configs->yPixmap, n);
+	x_configs++;
+    }
+
+    /* Let the other dispatch function deal with verifying that
+     * the right number of output ids are present, just
+     * swap whatever is here
+     */
+    num_output_ids = extra_len - (num_configs * (sizeof (xRRCrtcConfig)) >> 2);
+    SwapLongs((CARD32 *) x_configs, num_output_ids);
+
+    return ProcRandrVector[stuff->randrReqType](client);
+}
+
 int (*SProcRandrVector[RRNumberRequests])(ClientPtr) = {
     SProcRRQueryVersion,	/* 0 */
 /* we skip 1 to make old clients fail pretty immediately */
@@ -499,5 +625,11 @@ int (*SProcRandrVector[RRNumberRequests])(ClientPtr) = {
     SProcRRSetPanning,		/* 29 */
     SProcRRSetOutputPrimary,	/* 30 */
     SProcRRGetOutputPrimary,	/* 31 */
+/* V1.4 additions */
+    SProcRRQueryScanoutPixmaps,	/* 32 */
+    SProcRRCreateScanoutPixmap,	/* 33 */
+    SProcRRSetCrtcSpriteTransform,/* 34 */
+    SProcRRGetCrtcSpriteTransform,/* 35 */
+    SProcRRSetCrtcConfigs,	/* 36 */
 };
 
commit 82612045e11f2b882ae132e184a9629f43f1c424
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Dec 3 13:00:46 2010 -0800

    randr: Add per-crtc pixmaps
    
    This adds new driver hooks to allocate scanout pixmaps and
    changes the mode setting APIs to pass the new scanout pixmaps
    along from DIX. DIX is responsible for reference counting the pixmaps
    by tracking them through RRCrtcNotify.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 3fccaea..5bf12f0 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -82,6 +82,17 @@ xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
     config->maxHeight = maxHeight;
 }
 
+void
+xf86CrtcSetScanoutFormats(ScrnInfoPtr		scrn,
+			  int			num_formats,
+			  xf86CrtcScanoutFormat	*formats)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    config->num_scanout_formats = num_formats;
+    config->scanout_formats = formats;
+}
+
 /*
  * Crtc functions
  */
@@ -265,6 +276,7 @@ xf86CrtcSet(xf86CrtcPtr crtc, xf86CrtcSetRec *set)
     Rotation		saved_rotation;
     RRTransformRec	saved_transform;
     Bool		saved_transform_present;
+    PixmapPtr		saved_scanout_pixmap;
 
     crtc->enabled = xf86CrtcInUse (crtc);
 
@@ -284,6 +296,7 @@ xf86CrtcSet(xf86CrtcPtr crtc, xf86CrtcSetRec *set)
     saved_x = crtc->x;
     saved_y = crtc->y;
     saved_rotation = crtc->rotation;
+    saved_scanout_pixmap = crtc->scanoutPixmap;
     if (crtc->transformPresent) {
 	RRTransformInit (&saved_transform);
 	RRTransformCopy (&saved_transform, &crtc->transform);
@@ -301,6 +314,8 @@ xf86CrtcSet(xf86CrtcPtr crtc, xf86CrtcSetRec *set)
     }
     if (set->flags & XF86CrtcSetRotation)
 	crtc->rotation = set->rotation;
+    if (set->flags & XF86CrtcSetScanoutPixmap)
+	crtc->scanoutPixmap = set->scanout_pixmap;
 
     if (set->flags & XF86CrtcSetTransform) {
 	if (set->transform) {
@@ -399,6 +414,10 @@ done:
 	crtc->active = TRUE;
 	if (scrn->pScreen)
 	    xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
+	if (crtc->scanoutPixmap)
+	    ++crtc->scanoutPixmap->refcnt;
+	if (saved_scanout_pixmap)
+	    (*scrn->pScreen->DestroyPixmap)(saved_scanout_pixmap);
 	if (scrn->ModeSet)
 	    scrn->ModeSet(scrn);
     } else {
@@ -409,6 +428,7 @@ done:
 	if (saved_transform_present)
 	    RRTransformCopy (&crtc->transform, &saved_transform);
 	crtc->transformPresent = saved_transform_present;
+	crtc->scanoutPixmap = saved_scanout_pixmap;
     }
 
     if (adjusted_mode) {
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index c2e8131..9a520fc 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -79,6 +79,7 @@ typedef enum _xf86CrtcSetFlags {
     XF86CrtcSetTransform = 8,		/* transform */
     XF86CrtcSetRotation = 16,		/* rotation */
     XF86CrtcSetProperty = 32,		/* output property */
+    XF86CrtcSetScanoutPixmap = 64,	/* scanout pixmap */
 } xf86CrtcSetFlags;
 
 typedef struct _xf86CrtcSet {
@@ -87,6 +88,7 @@ typedef struct _xf86CrtcSet {
     Rotation		rotation;
     RRTransformPtr	transform;
     int			x, y;
+    PixmapPtr		scanout_pixmap;
 } xf86CrtcSetRec;
 
 typedef struct _xf86CrtcFuncs {
@@ -277,6 +279,7 @@ struct _xf86Crtc {
     Rotation	    rotation;
     PixmapPtr	    rotatedPixmap;
     void	    *rotatedData;
+    PixmapPtr	    scanoutPixmap;
     
     /**
      * Position on screen
@@ -670,6 +673,14 @@ typedef struct _xf86CrtcSetConfig {
     int				pixmap_x, pixmap_y;
 } xf86CrtcSetConfigRec, *xf86CrtcSetConfigPtr;
 
+typedef struct _xf86CrtcScanoutFormat {
+    int		    depth;
+    int		    bitsPerPixel;
+    int		    maxWidth, maxHeight;
+    Rotation	    rotations;
+    PictFormatShort format;
+} xf86CrtcScanoutFormat;
+
 typedef struct _xf86CrtcConfigFuncs {
     /**
      * Requests that the driver resize the screen.
@@ -693,6 +704,17 @@ typedef struct _xf86CrtcConfigFuncs {
 		   RRScreenConfigPtr	screen_config,
 		   xf86CrtcSetConfigPtr	crtc_configs,
 		   int			num_configs);
+
+    /**
+     * Create a scanout pixmap
+     */
+    PixmapPtr
+    (*create_scanout_pixmap)(ScrnInfoPtr		scrn,
+			     int			width,
+			     int			height,
+			     Rotation			rotations,
+			     xf86CrtcScanoutFormat	*format);
+
 } xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
 
 typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen);
@@ -752,6 +774,11 @@ typedef struct _xf86CrtcConfig {
     /* callback when crtc configuration changes */
     xf86_crtc_notify_proc_ptr  xf86_crtc_notify;
 
+    /*
+     * Supported scanout pixmap formats
+     */
+    int			num_scanout_formats;
+    xf86CrtcScanoutFormat	*scanout_formats;
 } xf86CrtcConfigRec, *xf86CrtcConfigPtr;
 
 extern _X_EXPORT int xf86CrtcConfigPrivateIndex;
@@ -797,6 +824,11 @@ xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
 		      int minWidth, int minHeight,
 		      int maxWidth, int maxHeight);
 
+extern _X_EXPORT void
+xf86CrtcSetScanoutFormats (ScrnInfoPtr			scrn,
+			   int				num_formats,
+			   xf86CrtcScanoutFormat	*formats);
+
 /*
  * Crtc functions
  */
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index e3330f4..b0eabdd 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1083,7 +1083,7 @@ xf86RandR12CrtcNotify (RRCrtcPtr	randr_crtc)
     ret = RRCrtcNotify (randr_crtc, randr_mode, x, y,
 			rotation,
 			crtc->transformPresent ? &crtc->transform : NULL,
-			numOutputs, randr_outputs);
+			numOutputs, randr_outputs, crtc->scanoutPixmap);
     free(randr_outputs);
     return ret;
 }
@@ -1126,7 +1126,8 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 		    int		    y,
 		    Rotation	    rotation,
 		    int		    num_randr_outputs,
-		    RROutputPtr	    *randr_outputs)
+		    RROutputPtr	    *randr_outputs,
+		    PixmapPtr	    scanout_pixmap)
 {
     XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
@@ -1157,6 +1158,9 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 				  sizeof (transform->transform)) != 0)
 	flags |= XF86CrtcSetTransform;
 
+    if (scanout_pixmap != crtc->scanoutPixmap)
+	flags |= XF86CrtcSetScanoutPixmap;
+
     if (x != crtc->x || y != crtc->y)
 	flags |= XF86CrtcSetOrigin;
     for (o = 0; o < config->num_output; o++)
@@ -1203,6 +1207,7 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 	    set.transform = transform;
 	    set.x = x;
 	    set.y = y;
+	    set.scanout_pixmap = scanout_pixmap;
 	    set.flags = flags;
 	    if (!xf86CrtcSet(crtc, &set))
 	    {
@@ -1732,6 +1737,54 @@ xf86RandR12ChangeGamma(int scrnIndex, Gamma gamma)
     return Success;
 }
 
+static RRScanoutPixmapInfo *
+xf86RRQueryScanoutPixmaps(ScreenPtr screen, int *n_info)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    RRScanoutPixmapInfo	*info;
+    int			f;
+
+    info = calloc(config->num_scanout_formats, sizeof (RRScanoutPixmapInfo));
+    if (config->num_scanout_formats && !info) {
+	*n_info = 0;
+	return NULL;
+    }
+    for (f = 0; f < config->num_scanout_formats; f++) {
+	info[f].maxWidth = config->scanout_formats[f].maxWidth;
+	info[f].maxHeight = config->scanout_formats[f].maxHeight;
+	info[f].depth = config->scanout_formats[f].depth;
+	info[f].rotations = config->scanout_formats[f].rotations;
+	info[f].format = PictureMatchFormat (screen, info[f].depth,
+					     config->scanout_formats[f].format);
+    }
+    *n_info = config->num_scanout_formats;
+    return info;
+}
+
+static PixmapPtr
+xf86RRCreateScanoutPixmap(ScreenPtr screen,
+			  int width, int height, int depth,
+			  Rotation rotations,
+			  PictFormatPtr format)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			f;
+
+    if (!config->funcs->create_scanout_pixmap)
+	return NullPixmap;
+
+    for (f = 0; f < config->num_scanout_formats; f++)
+	if (config->scanout_formats[f].depth == depth &&
+	    (config->scanout_formats[f].format & 0xffffff) == format->format) {
+	    return (*config->funcs->create_scanout_pixmap) (scrn, width, height,
+							    rotations,
+							    &config->scanout_formats[f]);
+	}
+    return NullPixmap;
+}
+
 static void
 xf86RandR14SetCrtcSpriteTransform(ScreenPtr		pScreen,
 				  RRCrtcPtr		randr_crtc,
@@ -1893,17 +1946,17 @@ xf86RandR12Init12 (ScreenPtr pScreen)
     rp->rrCrtcGetGamma = xf86RandR12CrtcGetGamma;
     rp->rrOutputSetProperty = xf86RandR12OutputSetProperty;
     rp->rrOutputValidateMode = xf86RandR12OutputValidateMode;
-#if RANDR_13_INTERFACE
     rp->rrOutputGetProperty = xf86RandR13OutputGetProperty;
     rp->rrGetPanning = xf86RandR13GetPanning;
     rp->rrSetPanning = xf86RandR13SetPanning;
-#endif
     rp->rrModeDestroy = xf86RandR12ModeDestroy;
     rp->rrSetConfig = NULL;
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
     rp->rrSetCrtcSpriteTransform = xf86RandR14SetCrtcSpriteTransform;
     rp->rrSetCrtcConfigs = xf86RRSetCrtcConfigs;
+    rp->rrQueryScanoutPixmaps = xf86RRQueryScanoutPixmaps;
+    rp->rrCreateScanoutPixmap = xf86RRCreateScanoutPixmap;
 
     randrp->orig_EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = xf86RandR12EnterVT;
diff --git a/randr/Makefile.am b/randr/Makefile.am
index a1c88dc..b7664c6 100644
--- a/randr/Makefile.am
+++ b/randr/Makefile.am
@@ -16,6 +16,7 @@ librandr_la_SOURCES =	\
 	rrinfo.c	\
 	rrmode.c	\
 	rroutput.c	\
+	rrpixmap.c	\
 	rrpointer.c	\
 	rrproperty.c	\
 	rrscreen.c	\
diff --git a/randr/mirrcrtc.c b/randr/mirrcrtc.c
index b1e2c9f..cc76797 100644
--- a/randr/mirrcrtc.c
+++ b/randr/mirrcrtc.c
@@ -66,7 +66,8 @@ miRRSetCrtcConfig(RRCrtcConfigPtr crtc_config)
 		     y,
 		     crtc_config->rotation,
 		     crtc_config->numOutputs,
-		     crtc_config->outputs);
+		     crtc_config->outputs,
+		     crtc_config->pixmap);
 }
 
 Bool
diff --git a/randr/randr.c b/randr/randr.c
index 6077705..c22657e 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -98,6 +98,7 @@ RRCloseScreen (int i, ScreenPtr pScreen)
     
     free(pScrPriv->crtcs);
     free(pScrPriv->outputs);
+    free(pScrPriv->scanout_info);
     free(pScrPriv);
     RRNScreens -= 1;	/* ok, one fewer screen with RandR running */
     return (*pScreen->CloseScreen) (i, pScreen);    
@@ -248,6 +249,8 @@ Bool RRScreenInit(ScreenPtr pScreen)
     pScrPriv->rrCrtcSet = NULL;
     pScrPriv->rrCrtcSetGamma = NULL;
 #endif
+    pScrPriv->scanout_info = NULL;
+    pScrPriv->n_scanout_info = 0;
 #if RANDR_10_INTERFACE    
     pScrPriv->rrSetConfig = 0;
     pScrPriv->rotations = RR_Rotate_0;
@@ -482,6 +485,18 @@ RRVerticalRefresh (xRRModeInfo *mode)
     return (CARD16) refresh;
 }
 
+RRScanoutPixmapInfo *
+RRQueryScanoutPixmapInfo(ScreenPtr screen, int *n_info)
+{
+    rrScrPriv(screen);
+
+    if (!pScrPriv->scanout_info && pScrPriv->rrQueryScanoutPixmaps)
+	pScrPriv->scanout_info = pScrPriv->rrQueryScanoutPixmaps(screen,
+								 &pScrPriv->n_scanout_info);
+    *n_info = pScrPriv->n_scanout_info;
+    return pScrPriv->scanout_info;
+}
+
 static int
 ProcRRDispatch (ClientPtr client)
 {
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 2fe9602..c231972 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -123,6 +123,7 @@ struct _rrCrtc {
     CARD16	    *gammaGreen;
     void	    *devPrivate;
     Bool	    transforms;
+    PixmapPtr	    scanoutPixmap;
     RRTransformRec  client_pending_transform;
     RRTransformRec  client_current_transform;
     PictTransform   client_sprite_position_transform;
@@ -198,7 +199,8 @@ typedef Bool (*RRCrtcSetProcPtr) (ScreenPtr		pScreen,
 				  int			y,
 				  Rotation		rotation,
 				  int			numOutputs,
-				  RROutputPtr		*outputs);
+				  RROutputPtr		*outputs,
+				  PixmapPtr		scanout_pixmap);
 
 typedef Bool (*RRCrtcSetGammaProcPtr) (ScreenPtr	pScreen,
 				       RRCrtcPtr	crtc);
@@ -264,6 +266,20 @@ typedef Bool (*RRSetConfigProcPtr) (ScreenPtr		pScreen,
 
 #endif
 	
+typedef struct {
+    PictFormatPtr	format;
+    int			maxWidth, maxHeight;
+    int			depth;
+    Rotation		rotations;
+} RRScanoutPixmapInfo;
+
+typedef RRScanoutPixmapInfo *(*RRQueryScanoutPixmapsPtr) (ScreenPtr pScreen,
+							  int *num_info);
+
+typedef PixmapPtr (*RRCreateScanoutPixmapPtr) (ScreenPtr pScreen,
+					       int width, int height, int depth,
+					       Rotation rotations,
+					       PictFormatPtr format);
 
 typedef void (*RRSetCrtcSpriteTransformPtr) (ScreenPtr pScreen,
 					     RRCrtcPtr randr_crtc,
@@ -303,6 +319,8 @@ typedef struct _rrScrPriv {
     RRGetPanningProcPtr	rrGetPanning;
     RRSetPanningProcPtr	rrSetPanning;
 #endif
+    RRQueryScanoutPixmapsPtr	rrQueryScanoutPixmaps;
+    RRCreateScanoutPixmapPtr	rrCreateScanoutPixmap;
     RRSetCrtcSpriteTransformPtr	rrSetCrtcSpriteTransform;
     RRGetCrtcSpriteTransformPtr	rrGetCrtcSpriteTransform;
     RRSetCrtcConfigsPtr rrSetCrtcConfigs;
@@ -333,6 +351,8 @@ typedef struct _rrScrPriv {
     /* Last known pointer position */
     RRCrtcPtr		    pointerCrtc;
 
+    RRScanoutPixmapInfo	    *scanout_info;
+    int			    n_scanout_info;
 #ifdef RANDR_10_INTERFACE
     /*
      * Configuration information
@@ -347,6 +367,7 @@ typedef struct _rrScrPriv {
     int			    rate;
     int			    size;
 #endif
+
 } rrScrPrivRec, *rrScrPrivPtr;
 
 extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
@@ -521,6 +542,9 @@ RRGetRotation (ScreenPtr pScreen);
 extern _X_EXPORT CARD16
 RRVerticalRefresh (xRRModeInfo *mode);
 
+extern _X_EXPORT RRScanoutPixmapInfo *
+RRQueryScanoutPixmapInfo(ScreenPtr screen, int *n_info);
+
 #ifdef RANDR_10_INTERFACE					
 /*
  * This is the old interface, deprecated but left
@@ -599,7 +623,8 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
 	      Rotation	    rotation,
 	      RRTransformPtr transform,
 	      int	    numOutputs,
-	      RROutputPtr   *outputs);
+	      RROutputPtr   *outputs,
+	      PixmapPtr	    scanoutPixmap);
 
 extern _X_EXPORT void
 RRDeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc);
@@ -614,7 +639,8 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	   int		y,
 	   Rotation	rotation,
 	   int		numOutput,
-	   RROutputPtr  *outputs);
+	   RROutputPtr  *outputs,
+	   PixmapPtr	scanout_pixmap);
 
 /*
  * Request that the Crtc gamma be changed
@@ -643,6 +669,10 @@ RRCrtcGammaGet(RRCrtcPtr crtc);
 extern _X_EXPORT Bool
 RRCrtcGammaNotify (RRCrtcPtr	crtc);
 
+void
+RRModeGetScanoutSize (RRModePtr mode, struct pixman_f_transform *transform,
+		      int *width, int *height);
+
 /*
  * Set the size of the gamma table at server startup time
  */
@@ -778,11 +808,23 @@ RRCrtcSpriteTransformSet(RRCrtcPtr crtc,
 			 struct pict_f_transform *f_image_transform);
 
 int
+ProcRRQueryScanoutPixmaps (ClientPtr client);
+
+int
+ProcRRCreateScanoutPixmap (ClientPtr client);
+
+int
+ProcRRSetCrtcPixmapConfig (ClientPtr client);
+
+int
 ProcRRSetCrtcSpriteTransform (ClientPtr client);
 
 int
 ProcRRGetCrtcSpriteTransform (ClientPtr client);
 
+int
+ProcRRSetCrtcConfigs (ClientPtr client);
+
 /* rrdispatch.c */
 extern _X_EXPORT Bool
 RRClientKnowsRates (ClientPtr	pClient);
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 1f8f2e6..12982a8 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -138,7 +138,8 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
 	      Rotation	    rotation,
 	      RRTransformPtr transform,
 	      int	    numOutputs,
-	      RROutputPtr   *outputs)
+	      RROutputPtr   *outputs,
+	      PixmapPtr	    scanoutPixmap)
 {
     int	    i, j;
 
@@ -236,6 +237,15 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
 	RRCrtcChanged (crtc, TRUE);
     }
 
+    if (scanoutPixmap != crtc->scanoutPixmap)
+    {
+	if (scanoutPixmap)
+	    ++scanoutPixmap->refcnt;
+	if (crtc->scanoutPixmap)
+	    (*crtc->scanoutPixmap->drawable.pScreen->DestroyPixmap) (crtc->scanoutPixmap);
+	crtc->scanoutPixmap = scanoutPixmap;
+    }
+
     if (crtc->changed && mode)
     {
 	RRTransformCompute (x, y,
@@ -312,7 +322,8 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	   int		y,
 	   Rotation	rotation,
 	   int		numOutputs,
-	   RROutputPtr  *outputs)
+	   RROutputPtr  *outputs,
+	   PixmapPtr	scanout_pixmap)
 {
     ScreenPtr	pScreen = crtc->pScreen;
     Bool	ret = FALSE;
@@ -326,7 +337,8 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	crtc->numOutputs == numOutputs &&
 	!memcmp (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)) &&
 	!RRCrtcPendingProperties (crtc) &&
-	!RRCrtcPendingTransform (crtc))
+	!RRCrtcPendingTransform (crtc) &&
+	crtc->scanoutPixmap == scanout_pixmap)
     {
 	ret = TRUE;
     }
@@ -336,7 +348,7 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	if (pScrPriv->rrCrtcSet)
 	{
 	    ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y,
-					  rotation, numOutputs, outputs);
+					  rotation, numOutputs, outputs, scanout_pixmap);
 	}
 	else
 #endif
@@ -349,7 +361,7 @@ RRCrtcSet (RRCrtcPtr    crtc,
 
 		if (!mode)
 		{
-		    RRCrtcNotify (crtc, NULL, x, y, rotation, NULL, 0, NULL);
+		    RRCrtcNotify (crtc, NULL, x, y, rotation, NULL, 0, NULL, scanout_pixmap);
 		    ret = TRUE;
 		}
 		else
@@ -375,7 +387,7 @@ RRCrtcSet (RRCrtcPtr    crtc,
 		     */
 		    if (ret)
 		    {
-			RRCrtcNotify (crtc, mode, x, y, rotation, NULL, 1, outputs);
+			RRCrtcNotify (crtc, mode, x, y, rotation, NULL, 1, outputs, scanout_pixmap);
 			RRScreenSizeNotify (pScreen);
 		    }
 		}
@@ -573,7 +585,10 @@ RRCrtcGammaNotify (RRCrtcPtr	crtc)
     return TRUE;    /* not much going on here */
 }
 
-static void
+/*
+ * Compute overall scanout buffer requirements for the specified mode
+ */
+void
 RRModeGetScanoutSize (RRModePtr mode, struct pixman_f_transform *transform,
 		      int *width, int *height)
 {
@@ -1049,7 +1064,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
     }
 
     if (!RRCrtcSet (crtc, mode, stuff->x, stuff->y,
-		   rotation, numOutputs, outputs))
+		    rotation, numOutputs, outputs, NULL))
     {
 	rep.status = RRSetConfigFailed;
 	goto sendReply;
diff --git a/randr/rrinfo.c b/randr/rrinfo.c
index fdf3726..549ebcc 100644
--- a/randr/rrinfo.c
+++ b/randr/rrinfo.c
@@ -168,7 +168,7 @@ RRScanOldConfig (ScreenPtr pScreen, Rotation rotations)
     /* notice current mode */
     if (newMode)
 	RRCrtcNotify (crtc, newMode, 0, 0, pScrPriv->rotation,
-		      NULL, 1, &output);
+		      NULL, 1, &output, NULL);
 }
 #endif
 
diff --git a/randr/rrpixmap.c b/randr/rrpixmap.c
new file mode 100644
index 0000000..7d4543c
--- /dev/null
+++ b/randr/rrpixmap.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright © 2010 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+#include "xace.h"
+
+int
+ProcRRQueryScanoutPixmaps (ClientPtr client)
+{
+    REQUEST(xRRQueryScanoutPixmapsReq);
+    xRRQueryScanoutPixmapsReply	rep;
+    RRScanoutPixmapInfo		*info;
+    xRRScanoutPixmapInfo	*x_info;
+    int				n_info;
+    int				rc;
+    DrawablePtr			drawable;
+    ScreenPtr			screen;
+    rrScrPrivPtr		screen_priv;
+    int 			n, s;
+
+    REQUEST_SIZE_MATCH(xRRQueryScanoutPixmapsReq);
+    rc = dixLookupDrawable(&drawable, stuff->drawable, client, 0, DixGetAttrAccess);
+    if (rc != Success) {
+	client->errorValue = stuff->drawable;
+	return rc;
+    }
+
+    screen = drawable->pScreen;
+    screen_priv = rrGetScrPriv(screen);
+
+    rep.type = X_Reply;
+    /* rep.status has already been filled in */
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    info = RRQueryScanoutPixmapInfo(screen, &n_info);
+    x_info = calloc(n_info, sizeof (xRRScanoutPixmapInfo));
+    if (n_info && !x_info)
+	return BadAlloc;
+    rep.length += (n_info * sizeof (xRRScanoutPixmapInfo)) >> 2;
+    if (client->swapped) {
+	swaps(&rep.sequenceNumber, n);
+	swapl(&rep.length, n);
+    }
+
+    for (s = 0; s < n_info; s++) {
+	x_info[s].format = info[s].format->id;
+	x_info[s].maxWidth = info[s].maxWidth;
+	x_info[s].maxHeight = info[s].maxHeight;
+	x_info[s].rotations = info[s].rotations;
+	if (client->swapped) {
+	    swapl(&x_info[s].format, n);
+	    swaps(&x_info[s].maxWidth, n);
+	    swaps(&x_info[s].maxHeight, n);
+	    swaps(&x_info[s].rotations, n);
+	}
+    }
+
+    WriteToClient(client, sizeof(rep), (char *)&rep);
+    if (n_info)
+	WriteToClient(client, n_info * sizeof (xRRScanoutPixmapInfo),
+		      (char *) x_info);
+    return Success;
+}
+
+int
+ProcRRCreateScanoutPixmap (ClientPtr client)
+{
+    REQUEST(xRRCreateScanoutPixmapReq);
+    int 		rc;
+    DrawablePtr		drawable;
+    ScreenPtr		screen;
+    rrScrPrivPtr	screen_priv;
+    PixmapPtr		pixmap;
+    int			n_info;
+    RRScanoutPixmapInfo	*info;
+    int			s;
+
+    REQUEST_SIZE_MATCH(xRRCreateScanoutPixmapReq);
+    client->errorValue = stuff->pid;
+    LEGAL_NEW_RESOURCE(stuff->pid, client);
+
+    rc = dixLookupDrawable(&drawable, stuff->drawable, client, 0, DixGetAttrAccess);
+    if (rc != Success) {
+	client->errorValue = stuff->drawable;
+	return rc;
+    }
+    screen = drawable->pScreen;
+    screen_priv = rrGetScrPriv(screen);
+    if (!screen_priv)
+	return BadValue;
+
+    info = RRQueryScanoutPixmapInfo(screen, &n_info);
+    for (s = 0; s < n_info; s++) {
+	if (info[s].format->id == stuff->format)
+	    break;
+    }
+    if (s == n_info || !screen_priv->rrCreateScanoutPixmap) {
+	client->errorValue = stuff->format;
+	return BadValue;
+    }
+    info = &info[s];
+    if (!stuff->width || stuff->width > info->maxWidth) {
+	client->errorValue = stuff->width;
+	return BadValue;
+    }
+    if (!stuff->height || stuff->height > info->maxHeight) {
+	client->errorValue = stuff->height;
+	return BadValue;
+    }
+    if ((stuff->rotations & info->rotations) != stuff->rotations) {
+	client->errorValue = stuff->rotations;
+	return BadValue;
+    }
+
+    pixmap = screen_priv->rrCreateScanoutPixmap (screen,
+						 stuff->width, stuff->height,
+						 info->depth,
+						 stuff->rotations,
+						 info->format);
+    if (!pixmap)
+	return BadAlloc;
+
+    pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    pixmap->drawable.id = stuff->pid;
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP,
+		  pixmap, RT_NONE, NULL, DixCreateAccess);
+    if (rc != Success) {
+	screen->DestroyPixmap(pixmap);
+	return rc;
+    }
+    if (!AddResource(stuff->pid, RT_PIXMAP, pixmap))
+	return BadAlloc;
+    return Success;
+}
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 62ea2b6..0c52347 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -794,8 +794,10 @@ ProcRRSetScreenConfig (ClientPtr client)
     }
     
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess);
-    if (rc != Success)
+    if (rc != Success) {
+	client->errorValue = stuff->drawable;
 	return rc;
+    }
 
     pScreen = pDraw->pScreen;
 
@@ -940,7 +942,7 @@ ProcRRSetScreenConfig (ClientPtr client)
 	for (c = 0; c < pScrPriv->numCrtcs; c++)
 	{
 	    if (!RRCrtcSet (pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0,
-			    0, NULL))
+			    0, NULL, NULL))
 	    {
 		rep.status = RRSetConfigFailed;
 		/* XXX recover from failure */
@@ -956,7 +958,7 @@ ProcRRSetScreenConfig (ClientPtr client)
 	}
     }
 
-    if (!RRCrtcSet (crtc, mode, 0, 0, stuff->rotation, 1, &output))
+    if (!RRCrtcSet (crtc, mode, 0, 0, stuff->rotation, 1, &output, NULL))
 	rep.status = RRSetConfigFailed;
     else {
 	pScrPriv->lastSetTime = time;
commit 86c489c319c705f710bee3897fe27600ce15008e
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Dec 4 20:12:26 2010 -0800

    hw/xfree86/modes: Add optional driver API for RRSetCrtcConfigs
    
    This provides a driver hook which can either completely replace, or
    just validate the parameters for, the RRSetCrtcConfigs request.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 8b42efc..c2e8131 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -647,6 +647,29 @@ struct _xf86Output {
     INT16           initialBorder[4];
 };
 
+typedef enum _xf86SetConfigResponse {
+    xf86SetConfigFailed,		/* set_config failed */
+    xf86SetConfigChecked,		/* set_config validated the configuration */
+    xf86SetConfigDone,			/* set_config finished the work */
+} xf86SetConfigResponse;
+
+typedef struct _xf86CrtcSetConfig {
+    xf86CrtcPtr			crtc;
+    int				x, y;
+    DisplayModeRec		mode;
+    Rotation			rotation;
+    int				numOutputs;
+    xf86OutputPtr		*outputs;
+    struct pict_f_transform	sprite_position_transform;
+    struct pict_f_transform	sprite_image_transform;
+
+    /* Probably want some internal structure for the pixmap so that
+     * this can be set before the server is running
+     */
+    PixmapPtr			pixmap;
+    int				pixmap_x, pixmap_y;
+} xf86CrtcSetConfigRec, *xf86CrtcSetConfigPtr;
+
 typedef struct _xf86CrtcConfigFuncs {
     /**
      * Requests that the driver resize the screen.
@@ -664,6 +687,12 @@ typedef struct _xf86CrtcConfigFuncs {
     (*resize)(ScrnInfoPtr	scrn,
 	      int		width,
 	      int		height);
+
+    xf86SetConfigResponse
+    (*set_config) (ScrnInfoPtr		scrn,
+		   RRScreenConfigPtr	screen_config,
+		   xf86CrtcSetConfigPtr	crtc_configs,
+		   int			num_configs);
 } xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
 
 typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen);
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index ac58135..e3330f4 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -758,7 +758,7 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen)
 	xf86CrtcPtr crtc = config->crtc[c];
 	int	    crtc_width = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation);
 	int	    crtc_height = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation);
-	
+
 	if (crtc->enabled) {
 	    if (crtc_width > width)
 		width = crtc_width;
@@ -770,13 +770,13 @@ xf86RandR12CreateScreenResources (ScreenPtr pScreen)
 		height = crtc->panningTotalArea.y2;
 	}
     }
-    
+
     if (width && height)
     {
 	/*
 	 * Compute physical size of screen
 	 */
-	if (monitorResolution) 
+	if (monitorResolution)
 	{
 	    mmWidth = width * 25.4 / monitorResolution;
 	    mmHeight = height * 25.4 / monitorResolution;
@@ -1007,7 +1007,7 @@ xf86RandRModeMatches (RRModePtr		randr_mode,
 	if (memcmp (randr_mode->name, mode->name, len) != 0)	return FALSE;
     }
 #endif
-    
+
     /* check for same timings */
     if (randr_mode->mode.dotClock / 1000 != mode->Clock)    return FALSE;
     if (randr_mode->mode.width        != mode->HDisplay)    return FALSE;
@@ -1019,11 +1019,11 @@ xf86RandRModeMatches (RRModePtr		randr_mode,
     if (randr_mode->mode.vSyncStart   != mode->VSyncStart)  return FALSE;
     if (randr_mode->mode.vSyncEnd     != mode->VSyncEnd)    return FALSE;
     if (randr_mode->mode.vTotal       != mode->VTotal)	    return FALSE;
-    
+
     /* check for same flags (using only the XF86 valid flag bits) */
     if ((randr_mode->mode.modeFlags & FLAG_BITS) != (mode->Flags & FLAG_BITS))
 	return FALSE;
-    
+
     /* everything matches */
     return TRUE;
 }
@@ -1063,7 +1063,7 @@ xf86RandR12CrtcNotify (RRCrtcPtr	randr_crtc)
 	    randr_output = output->randr_output;
 	    randr_outputs[numOutputs++] = randr_output;
 	    /*
-	     * We make copies of modes, so pointer equality 
+	     * We make copies of modes, so pointer equality
 	     * isn't sufficient
 	     */
 	    for (j = 0; j < randr_output->numModes + randr_output->numUserModes; j++)
@@ -1071,7 +1071,7 @@ xf86RandR12CrtcNotify (RRCrtcPtr	randr_crtc)
 		RRModePtr   m = (j < randr_output->numModes ?
 				 randr_output->modes[j] :
 				 randr_output->userModes[j-randr_output->numModes]);
-					 
+
 		if (xf86RandRModeMatches (m, mode))
 		{
 		    randr_mode = m;
@@ -1081,7 +1081,7 @@ xf86RandR12CrtcNotify (RRCrtcPtr	randr_crtc)
 	}
     }
     ret = RRCrtcNotify (randr_crtc, randr_mode, x, y,
-			rotation, 
+			rotation,
 			crtc->transformPresent ? &crtc->transform : NULL,
 			numOutputs, randr_outputs);
     free(randr_outputs);
@@ -1100,13 +1100,13 @@ xf86RandRModeConvert (ScrnInfoPtr	scrn,
     mode->status = MODE_OK;
 
     mode->Clock = randr_mode->mode.dotClock / 1000;
-    
+
     mode->HDisplay = randr_mode->mode.width;
     mode->HSyncStart = randr_mode->mode.hSyncStart;
     mode->HSyncEnd = randr_mode->mode.hSyncEnd;
     mode->HTotal = randr_mode->mode.hTotal;
     mode->HSkew = randr_mode->mode.hSkew;
-    
+
     mode->VDisplay = randr_mode->mode.height;
     mode->VSyncStart = randr_mode->mode.vSyncStart;
     mode->VSyncEnd = randr_mode->mode.vSyncEnd;
@@ -1146,7 +1146,7 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 	flags |= XF86CrtcSetMode;
     else if (randr_mode && !xf86RandRModeMatches (randr_mode, &crtc->mode))
 	flags |= XF86CrtcSetMode;
-    
+
     if (rotation != crtc->rotation)
 	flags |= XF86CrtcSetRotation;
 
@@ -1159,18 +1159,18 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 
     if (x != crtc->x || y != crtc->y)
 	flags |= XF86CrtcSetOrigin;
-    for (o = 0; o < config->num_output; o++) 
+    for (o = 0; o < config->num_output; o++)
     {
 	xf86OutputPtr  output = config->output[o];
 	xf86CrtcPtr    new_crtc;
 
 	save_crtcs[o] = output->crtc;
-	
+
 	if (output->crtc == crtc)
 	    new_crtc = NULL;
 	else
 	    new_crtc = output->crtc;
-	for (ro = 0; ro < num_randr_outputs; ro++) 
+	for (ro = 0; ro < num_randr_outputs; ro++)
 	    if (output->randr_output == randr_outputs[ro])
 	    {
 		new_crtc = crtc;
@@ -1182,7 +1182,7 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 	    output->crtc = new_crtc;
 	}
     }
-    for (ro = 0; ro < num_randr_outputs; ro++) 
+    for (ro = 0; ro < num_randr_outputs; ro++)
         if (randr_outputs[ro]->pendingProperties)
 	    flags |= XF86CrtcSetProperty;
 
@@ -1385,7 +1385,7 @@ xf86RROutputSetModes (RROutputPtr randr_output, DisplayModePtr modes)
 
     if (nmode) {
 	rrmodes = malloc(nmode * sizeof (RRModePtr));
-	
+
 	if (!rrmodes)
 	    return FALSE;
 	nmode = 0;
@@ -1395,7 +1395,7 @@ xf86RROutputSetModes (RROutputPtr randr_output, DisplayModePtr modes)
 		if ((pref != 0) == ((mode->type & M_T_PREFERRED) != 0)) {
 		    xRRModeInfo		modeInfo;
 		    RRModePtr		rrmode;
-		    
+
 		    modeInfo.nameLength = strlen (mode->name);
 		    modeInfo.width = mode->HDisplay;
 		    modeInfo.dotClock = mode->Clock * 1000;
@@ -1419,7 +1419,7 @@ xf86RROutputSetModes (RROutputPtr randr_output, DisplayModePtr modes)
 	    }
 	}
     }
-    
+
     ret = RROutputSetModes (randr_output, rrmodes, nmode, npreferred);
     free(rrmodes);
     return ret;
@@ -1439,13 +1439,13 @@ xf86RandR12SetInfo12 (ScreenPtr pScreen)
     int			o, c, l;
     RRCrtcPtr		randr_crtc;
     int			nclone;
-    
+
     clones = malloc(config->num_output * sizeof (RROutputPtr));
     crtcs = malloc(config->num_crtc * sizeof (RRCrtcPtr));
     for (o = 0; o < config->num_output; o++)
     {
 	xf86OutputPtr	output = config->output[o];
-	
+
 	ncrtc = 0;
 	for (c = 0; c < config->num_crtc; c++)
 	    if (output->possible_crtcs & (1 << c))
@@ -1463,7 +1463,7 @@ xf86RandR12SetInfo12 (ScreenPtr pScreen)
 	    return FALSE;
 	}
 
-	RROutputSetPhysicalSize(output->randr_output, 
+	RROutputSetPhysicalSize(output->randr_output,
 				output->mm_width,
 				output->mm_height);
 	xf86RROutputSetModes (output->randr_output, output->probed_modes);
@@ -1489,7 +1489,7 @@ xf86RandR12SetInfo12 (ScreenPtr pScreen)
 	for (l = 0; l < config->num_output; l++)
 	{
 	    xf86OutputPtr	    clone = config->output[l];
-	    
+
 	    if (l != o && (output->possible_clones & (1 << l)))
 		clones[nclone++] = clone->randr_output;
 	}
@@ -1530,7 +1530,7 @@ xf86RandR12CreateObjects12 (ScreenPtr pScreen)
     xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
     int			c;
     int			o;
-    
+
     if (!RRInit ())
 	return FALSE;
 
@@ -1540,7 +1540,7 @@ xf86RandR12CreateObjects12 (ScreenPtr pScreen)
     for (c = 0; c < config->num_crtc; c++)
     {
 	xf86CrtcPtr    crtc = config->crtc[c];
-	
+
 	crtc->randr_crtc = RRCrtcCreate (pScreen, crtc);
 	RRCrtcGammaSetSize (crtc->randr_crtc, 256);
     }
@@ -1551,7 +1551,7 @@ xf86RandR12CreateObjects12 (ScreenPtr pScreen)
     {
 	xf86OutputPtr	output = config->output[o];
 
-	output->randr_output = RROutputCreate (pScreen, output->name, 
+	output->randr_output = RROutputCreate (pScreen, output->name,
 					       strlen (output->name),
 					       output);
 
@@ -1574,7 +1574,7 @@ xf86RandR12CreateScreenResources12 (ScreenPtr pScreen)
 
     for (c = 0; c < config->num_crtc; c++)
         xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc);
-    
+
     RRScreenSetSizeRange (pScreen, config->minWidth, config->minHeight,
 			  config->maxWidth, config->maxHeight);
     return TRUE;
@@ -1747,6 +1747,112 @@ xf86RandR14SetCrtcSpriteTransform(ScreenPtr		pScreen,
 }
 
 static Bool
+xf86RRConvertCrtcConfig(xf86CrtcSetConfigPtr	xf86_config,
+			RRCrtcConfigPtr		rr_config)
+{
+    RRCrtcPtr		rr_crtc = rr_config->crtc;
+    xf86CrtcPtr		crtc = rr_crtc->devPrivate;
+    ScrnInfoPtr		scrn = xf86Screens[rr_crtc->pScreen->myNum];
+    int			o;
+
+    xf86_config->crtc = crtc;
+    xf86_config->x = rr_config->x;
+    xf86_config->y = rr_config->y;
+    xf86RandRModeConvert(scrn, rr_config->mode, &xf86_config->mode);
+    xf86_config->rotation = rr_config->rotation;
+    xf86_config->numOutputs = rr_config->numOutputs;
+    xf86_config->outputs = calloc(rr_config->numOutputs, sizeof (xf86OutputPtr));
+    if (!xf86_config->outputs)
+	return FALSE;
+    for (o = 0; o < rr_config->numOutputs; o++)
+	xf86_config->outputs[o] = rr_config->outputs[o]->devPrivate;
+    xf86_config->sprite_position_transform = rr_config->sprite_position_transform;
+    xf86_config->sprite_image_transform = rr_config->sprite_image_transform;
+    xf86_config->pixmap = rr_config->pixmap;
+    xf86_config->pixmap_x = rr_config->pixmap_x;
+    xf86_config->pixmap_y = rr_config->pixmap_y;
+    return TRUE;
+}
+
+static void
+xf86FreeCrtcSetConfigs(xf86CrtcSetConfigPtr xf86_crtc_configs, int num_configs)
+{
+    int	i;
+
+    for (i = 0; i < num_configs; i++)
+	free(xf86_crtc_configs[i].outputs);
+    free(xf86_crtc_configs);
+}
+
+static Bool
+xf86RRSetCrtcConfigs(ScreenPtr screen,
+		     RRScreenConfigPtr screen_config,
+		     RRCrtcConfigPtr crtc_configs,
+		     int num_configs)
+{
+    ScrnInfoPtr	     		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr		config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    if (config->funcs->set_config) {
+	xf86CrtcSetConfigPtr	xf86_crtc_configs;
+	int			i;
+	xf86SetConfigResponse	response;
+
+	/*
+	 * Convert RRCrtcConfigRecs to xf86CrtcSetConfigs
+	 */
+	xf86_crtc_configs = calloc(num_configs, sizeof (xf86CrtcSetConfigRec));
+	if (!xf86_crtc_configs)
+	    return FALSE;
+	for (i = 0; i < num_configs; i++)
+	    if (!xf86RRConvertCrtcConfig(&xf86_crtc_configs[i], &crtc_configs[i])) {
+		xf86FreeCrtcSetConfigs(xf86_crtc_configs, num_configs);
+		return FALSE;
+	    }
+
+	/*
+	 * Ask the driver to set the configuration
+	 */
+	response = (*config->funcs->set_config)(scrn,
+						screen_config,
+						xf86_crtc_configs,
+						num_configs);
+	xf86FreeCrtcSetConfigs(xf86_crtc_configs, num_configs);
+
+	/*
+	 * The driver is allowed to answer with one of three
+	 * responses:
+	 */
+	switch (response) {
+	case xf86SetConfigFailed:
+
+	    /* The configuration isn't usable, or some error
+	     * occurred while setting it. Everything has been
+	     * cleaned up and we're ready to return an error
+	     * back to the client
+	     */
+	    return FALSE;
+	case xf86SetConfigDone:
+
+	    /* The configuration was acceptable, and the whole
+	     * mode setting experience is over. Nothing more to do
+	     * here.
+	     */
+	    return TRUE;
+	case xf86SetConfigChecked:
+
+	    /* The configuration was acceptable, but the driver
+	     * didn't actually do anything. Go ask the DIX code
+	     * to do the mode setting operation using the simpler
+	     * interfaces
+	     */
+	    break;
+	}
+    }
+    return miRRSetCrtcConfigs(screen, screen_config, crtc_configs, num_configs);
+}
+
+static Bool
 xf86RandR12EnterVT (int screen_index, int flags)
 {
     ScreenPtr        pScreen = screenInfo.screens[screen_index];
@@ -1797,7 +1903,7 @@ xf86RandR12Init12 (ScreenPtr pScreen)
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
     rp->rrSetCrtcSpriteTransform = xf86RandR14SetCrtcSpriteTransform;
-    rp->rrSetCrtcConfigs = miRRSetCrtcConfigs;
+    rp->rrSetCrtcConfigs = xf86RRSetCrtcConfigs;
 
     randrp->orig_EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = xf86RandR12EnterVT;
commit d94a035ea9eb3167fc4f35b2d9f0d53f8807014c
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Dec 4 19:22:11 2010 -0800

    randr: Implement RRSetCrtcConfigs
    
    This provides a driver-independent implementation of the
    RRSetCrtcConfigs API by simply using the existing interfaces.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index bbf28cd..ac58135 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1797,6 +1797,7 @@ xf86RandR12Init12 (ScreenPtr pScreen)
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
     rp->rrSetCrtcSpriteTransform = xf86RandR14SetCrtcSpriteTransform;
+    rp->rrSetCrtcConfigs = miRRSetCrtcConfigs;
 
     randrp->orig_EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = xf86RandR12EnterVT;
diff --git a/randr/Makefile.am b/randr/Makefile.am
index 4b38e52..a1c88dc 100644
--- a/randr/Makefile.am
+++ b/randr/Makefile.am
@@ -22,7 +22,9 @@ librandr_la_SOURCES =	\
 	rrsdispatch.c	\
 	rrsprite.c	\
 	rrtransform.h	\
-	rrtransform.c
+	rrtransform.c	\
+	mirrcrtc.c
+
 
 if XINERAMA
 librandr_la_SOURCES += ${XINERAMA_SRCS}
diff --git a/randr/mirrcrtc.c b/randr/mirrcrtc.c
new file mode 100644
index 0000000..b1e2c9f
--- /dev/null
+++ b/randr/mirrcrtc.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright © 2010 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+
+Bool
+miRRSetScreenConfig(ScreenPtr screen,
+		    RRScreenConfigPtr screen_config)
+{
+    RRScreenConfigRec	old_screen_config;
+
+    /* XXX deal with separate pixmap/screen sizes */
+    if (screen_config->screen_pixmap_width != screen_config->screen_width ||
+	screen_config->screen_pixmap_height != screen_config->screen_height)
+	return FALSE;
+
+    RRScreenCurrentConfig(screen, &old_screen_config);
+
+    /* Check and see if nothing has changed */
+    if (old_screen_config.screen_width == screen_config->screen_width &&
+	old_screen_config.screen_height == screen_config->screen_height &&
+	old_screen_config.screen_pixmap_width == screen_config->screen_pixmap_width &&
+	old_screen_config.screen_pixmap_height == screen_config->screen_pixmap_height &&
+	old_screen_config.mm_width == screen_config->mm_width &&
+	old_screen_config.mm_height == screen_config->mm_height)
+	return TRUE;
+
+    return RRScreenSizeSet(screen,
+			   screen_config->screen_width,
+			   screen_config->screen_height,
+			   screen_config->mm_width,
+			   screen_config->mm_height);
+}
+
+Bool
+miRRSetCrtcConfig(RRCrtcConfigPtr crtc_config)
+{
+    int	x = crtc_config->x, y = crtc_config->y;
+
+    if (crtc_config->pixmap) {
+	x = crtc_config->pixmap_x;
+	y = crtc_config->pixmap_y;
+    }
+    return RRCrtcSet(crtc_config->crtc,
+		     crtc_config->mode,
+		     x,
+		     y,
+		     crtc_config->rotation,
+		     crtc_config->numOutputs,
+		     crtc_config->outputs);
+}
+
+Bool
+miRRDisableCrtc(RRCrtcPtr crtc)
+{
+    RRCrtcConfigRec	off_config;
+
+    memset(&off_config, '\0', sizeof (RRCrtcConfigRec));
+    off_config.crtc = crtc;
+    return miRRSetCrtcConfig(&off_config);
+}
+
+/*
+ * If the current crtc configuration doesn't fit
+ * with the new screen config, disable it
+ */
+Bool
+miRRCheckDisableCrtc(RRScreenConfigPtr new_screen_config,
+		     RRCrtcConfigPtr old_crtc_config)
+{
+    RRCrtcPtr crtc = old_crtc_config->crtc;
+
+    /* If it's already disabled, we're done */
+    if (!old_crtc_config->mode)
+	return TRUE;
+
+    /* If the crtc isn't scanning from the screen pixmap,
+     * we're done
+     */
+    if (old_crtc_config->pixmap)
+	return TRUE;
+
+    /* If the new screen configuration covers the existing CRTC space,
+     * we're done
+     */
+    if (RRScreenCoversCrtc(new_screen_config, old_crtc_config,
+			   &crtc->client_current_transform, NULL))
+	return TRUE;
+
+    /* Disable the crtc and let it get re-enabled */
+    return miRRDisableCrtc(crtc);
+}
+
+Bool
+miRRSetCrtcConfigs(ScreenPtr screen,
+		   RRScreenConfigPtr screen_config,
+		   RRCrtcConfigPtr crtc_configs,
+		   int num_configs)
+{
+    RRScreenConfigRec	old_screen_config;
+    RRCrtcConfigPtr	old_crtc_configs;
+    int			i;
+
+    /*
+     * Save existing state
+     */
+
+    RRScreenCurrentConfig(screen, &old_screen_config);
+    old_crtc_configs = calloc(num_configs, sizeof (RRCrtcConfigRec));
+    if (!old_crtc_configs)
+	return FALSE;
+
+    for (i = 0; i < num_configs; i++)
+	if (!RRCrtcCurrentConfig(crtc_configs[i].crtc, &old_crtc_configs[i]))
+	    goto fail_save;
+    /*
+     * Set the new configuration. If anything goes wrong,
+     * bail and restore the old configuration
+     */
+    for (i = 0; i < num_configs; i++)
+	if (!miRRCheckDisableCrtc(screen_config, &old_crtc_configs[i]))
+	    goto fail_disable;
+
+    if (!miRRSetScreenConfig(screen, screen_config))
+	goto fail_set_screen;
+
+    for (i = 0; i < num_configs; i++)
+	if (!miRRSetCrtcConfig(&crtc_configs[i]))
+	    goto fail_set_crtc;
+
+    RRFreeCrtcConfigs(old_crtc_configs, num_configs);
+    return TRUE;
+
+fail_set_crtc:
+    /*
+     * Restore the previous configuration. Ignore any errors
+     * as we just need to hope that the driver can manage to
+     * get back to the previous state without trouble.
+     */
+    for (i = 0; i < num_configs; i++)
+	(void) miRRDisableCrtc(old_crtc_configs[i].crtc);
+    (void) miRRSetScreenConfig(screen, &old_screen_config);
+fail_set_screen:
+fail_disable:
+    for (i = 0; i < num_configs; i++)
+	(void) miRRSetCrtcConfig(&old_crtc_configs[i]);
+fail_save:
+    RRFreeCrtcConfigs(old_crtc_configs, num_configs);
+    return FALSE;
+}
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 5e2a351..2fe9602 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -78,6 +78,8 @@ typedef struct _rrMode		RRModeRec, *RRModePtr;
 typedef struct _rrPropertyValue	RRPropertyValueRec, *RRPropertyValuePtr;
 typedef struct _rrProperty	RRPropertyRec, *RRPropertyPtr;
 typedef struct _rrCrtc		RRCrtcRec, *RRCrtcPtr;
+typedef struct _rrScreenConfig	RRScreenConfigRec, *RRScreenConfigPtr;
+typedef struct _rrCrtcConfig	RRCrtcConfigRec, *RRCrtcConfigPtr;
 typedef struct _rrOutput	RROutputRec, *RROutputPtr;
 
 struct _rrMode {
@@ -135,6 +137,28 @@ struct _rrCrtc {
     struct pict_f_transform f_sprite_image_inverse;	/* image from crtc */
 };
 
+struct _rrScreenConfig {
+    CARD16			screen_pixmap_width;
+    CARD16			screen_pixmap_height;
+    CARD16			screen_width;
+    CARD16			screen_height;
+    CARD32			mm_width;
+    CARD32			mm_height;
+};
+
+struct _rrCrtcConfig {
+    RRCrtcPtr			crtc;
+    int				x, y;
+    RRModePtr			mode;
+    Rotation			rotation;
+    int				numOutputs;
+    RROutputPtr			*outputs;
+    struct pict_f_transform	sprite_position_transform;
+    struct pict_f_transform	sprite_image_transform;
+    PixmapPtr			pixmap;
+    int				pixmap_x, pixmap_y;
+};
+
 struct _rrOutput {
     RROutput	    id;
     ScreenPtr	    pScreen;
@@ -251,6 +275,11 @@ typedef void (*RRGetCrtcSpriteTransformPtr) (ScreenPtr pScreen,
 					     struct pict_f_transform *position_transform,
 					     struct pict_f_transform *image_transform);
 
+typedef Bool (*RRSetCrtcConfigsPtr) (ScreenPtr screen,
+				     RRScreenConfigPtr screen_config,
+				     RRCrtcConfigPtr crtc_configs,
+				     int num_configs);
+
 typedef struct _rrScrPriv {
     /*
      * 'public' part of the structure; DDXen fill this in
@@ -276,6 +305,7 @@ typedef struct _rrScrPriv {
 #endif
     RRSetCrtcSpriteTransformPtr	rrSetCrtcSpriteTransform;
     RRGetCrtcSpriteTransformPtr	rrGetCrtcSpriteTransform;
+    RRSetCrtcConfigsPtr rrSetCrtcConfigs;
 
     /*
      * Private part of the structure; not considered part of the ABI
@@ -428,6 +458,10 @@ RRScreenSizeSet (ScreenPtr  pScreen,
 		 CARD32	    mmWidth,
 		 CARD32	    mmHeight);
 
+extern _X_EXPORT void
+RRScreenCurrentConfig(ScreenPtr screen,
+		      RRScreenConfigPtr screen_config);
+
 /*
  * Send ConfigureNotify event to root window when 'something' happens
  */
@@ -671,6 +705,38 @@ extern _X_EXPORT void
 RRCrtcInitErrorValue (void);
 
 /*
+ * Free a set of crtc configs and their attached output arrays
+ */
+void
+RRFreeCrtcConfigs(RRCrtcConfigPtr configs, int num_configs);
+
+/*
+ * Convert the current crtc configuration into an RRCrtcConfig
+ */
+extern _X_EXPORT Bool
+RRCrtcCurrentConfig(RRCrtcPtr crtc,
+		    RRCrtcConfigPtr crtc_config);
+
+/*
+ * Figure out whether the specific crtc_config can fit
+ * within the screen_config
+ */
+Bool
+RRScreenCoversCrtc(RRScreenConfigPtr screen_config,
+		   RRCrtcConfigPtr crtc_config,
+		   RRTransformPtr client_transform,
+		   XID *errorValue);
+
+/*
+ * Set a screen and set of crtc configurations in one operation
+ */
+Bool
+RRSetCrtcConfigs(ScreenPtr screen,
+		 RRScreenConfigPtr screen_config,
+		 RRCrtcConfigPtr crtc_configs,
+		 int num_configs);
+
+/*
  * Crtc dispatch
  */
 
@@ -695,6 +761,9 @@ ProcRRSetCrtcTransform (ClientPtr client);
 extern _X_EXPORT int
 ProcRRGetCrtcTransform (ClientPtr client);
 
+extern _X_EXPORT int
+ProcRRSetCrtcConfigs (ClientPtr client);
+
 int
 ProcRRGetPanning (ClientPtr client);
 
@@ -916,6 +985,27 @@ extern _X_EXPORT void
 RRXineramaExtensionInit(void);
 #endif
 
+/* mirrcrtc.c */
+Bool
+miRRSetScreenConfig(ScreenPtr screen,
+		    RRScreenConfigPtr screen_config);
+
+Bool
+miRRSetCrtcConfig(RRCrtcConfigPtr crtc_config);
+
+Bool
+miRRDisableCrtc(RRCrtcPtr crtc);
+
+Bool
+miRRCheckDisableCrtc(RRScreenConfigPtr new_screen_config,
+		     RRCrtcConfigPtr old_crtc_config);
+
+Bool
+miRRSetCrtcConfigs(ScreenPtr screen,
+		   RRScreenConfigPtr screen_config,
+		   RRCrtcConfigPtr crtc_configs,
+		   int num_configs);
+
 #endif /* _RANDRSTR_H_ */
 
 /*
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index c2f6963..1f8f2e6 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -37,7 +37,7 @@ RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged)
     if (pScreen)
     {
 	rrScrPriv(pScreen);
-    
+
 	pScrPriv->changed = TRUE;
 	/*
 	 * Send ConfigureNotify on any layout change
@@ -59,19 +59,19 @@ RRCrtcCreate (ScreenPtr pScreen, void *devPrivate)
 
     if (!RRInit())
 	return NULL;
-    
+
     pScrPriv = rrGetScrPriv(pScreen);
 
     /* make space for the crtc pointer */
     if (pScrPriv->numCrtcs)
-	crtcs = realloc(pScrPriv->crtcs, 
+	crtcs = realloc(pScrPriv->crtcs,
 			  (pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr));
     else
 	crtcs = malloc(sizeof (RRCrtcPtr));
     if (!crtcs)
 	return FALSE;
     pScrPriv->crtcs = crtcs;
-    
+
     crtc = calloc(1, sizeof (RRCrtcRec));
     if (!crtc)
 	return NULL;
@@ -90,6 +90,8 @@ RRCrtcCreate (ScreenPtr pScreen, void *devPrivate)
     crtc->devPrivate = devPrivate;
     RRTransformInit (&crtc->client_pending_transform);
     RRTransformInit (&crtc->client_current_transform);
+    pixman_transform_init_identity (&crtc->client_sprite_position_transform);
+    pixman_transform_init_identity (&crtc->client_sprite_image_transform);
     pixman_transform_init_identity (&crtc->transform);
     pixman_f_transform_init_identity (&crtc->f_transform);
     pixman_f_transform_init_identity (&crtc->f_inverse);
@@ -102,7 +104,7 @@ RRCrtcCreate (ScreenPtr pScreen, void *devPrivate)
     /* attach the screen and crtc together */
     crtc->pScreen = pScreen;
     pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc;
-    
+
     return crtc;
 }
 
@@ -139,7 +141,7 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
 	      RROutputPtr   *outputs)
 {
     int	    i, j;
-    
+
     /*
      * Check to see if any of the new outputs were
      * not in the old list and mark them as changed
@@ -179,7 +181,7 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
     if (numOutputs != crtc->numOutputs)
     {
 	RROutputPtr *newoutputs;
-	
+
 	if (numOutputs)
 	{
 	    if (crtc->numOutputs)
@@ -258,7 +260,7 @@ RRDeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc)
     rrScrPriv (pScreen);
     xRRCrtcChangeNotifyEvent	ce;
     RRModePtr	mode = crtc->mode;
-    
+
     ce.type = RRNotify + RREventBase;
     ce.subCode = RRNotify_CrtcChange;
     ce.timestamp = pScrPriv->lastSetTime.milliseconds;
@@ -333,7 +335,7 @@ RRCrtcSet (RRCrtcPtr    crtc,
 #if RANDR_12_INTERFACE
 	if (pScrPriv->rrCrtcSet)
 	{
-	    ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y, 
+	    ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y,
 					  rotation, numOutputs, outputs);
 	}
 	else
@@ -392,6 +394,59 @@ RRCrtcSet (RRCrtcPtr    crtc,
     return ret;
 }
 
+void
+RRFreeCrtcConfigs(RRCrtcConfigPtr configs, int num_configs)
+{
+    int	i;
+
+    for (i = 0; i < num_configs; i++)
+	free(configs[i].outputs);
+    free(configs);
+}
+
+Bool
+RRCrtcCurrentConfig(RRCrtcPtr crtc,
+		    RRCrtcConfigPtr crtc_config)
+{
+    crtc_config->crtc = crtc;
+    crtc_config->x = crtc->x;
+    crtc_config->y = crtc->y;
+    crtc_config->mode = crtc->mode;
+    crtc_config->rotation = crtc->rotation;
+    crtc_config->numOutputs = crtc->numOutputs;
+    crtc_config->outputs = calloc(crtc->numOutputs, sizeof (RROutputPtr));
+    if (!crtc_config->outputs)
+	return FALSE;
+    memcpy(crtc_config->outputs, crtc->outputs, crtc->numOutputs * sizeof (RROutputPtr));
+    crtc_config->sprite_position_transform = crtc->client_sprite_f_position_transform;
+    crtc_config->sprite_image_transform = crtc->client_sprite_f_image_transform;
+
+    /* XXX add pixmap stuff */
+    crtc_config->pixmap = NULL;
+    crtc_config->pixmap_x = 0;
+    crtc_config->pixmap_y = 0;
+    return TRUE;
+}
+
+
+/*
+ * Request that a set of crtcs be configured at the same
+ * time on a single screen
+ */
+
+Bool
+RRSetCrtcConfigs(ScreenPtr screen,
+		 RRScreenConfigPtr screen_config,
+		 RRCrtcConfigPtr crtc_configs,
+		 int num_configs)
+{
+    rrScrPrivPtr	scr_priv = rrGetScrPriv(screen);
+
+    if (!scr_priv)
+	return FALSE;
+    return (*scr_priv->rrSetCrtcConfigs)(screen, screen_config, crtc_configs, num_configs);
+}
+
 /*
  * Return crtc transform
  */
@@ -435,7 +490,7 @@ RRCrtcDestroyResource (pointer value, XID pid)
     {
 	rrScrPriv(pScreen);
 	int		i;
-    
+
 	for (i = 0; i < pScrPriv->numCrtcs; i++)
 	{
 	    if (pScrPriv->crtcs[i] == crtc)
@@ -468,7 +523,7 @@ RRCrtcGammaSet (RRCrtcPtr   crtc,
 #if RANDR_12_INTERFACE
     ScreenPtr	pScreen = crtc->pScreen;
 #endif
-    
+
     memcpy (crtc->gammaRed, red, crtc->gammaSize * sizeof (CARD16));
     memcpy (crtc->gammaGreen, green, crtc->gammaSize * sizeof (CARD16));
     memcpy (crtc->gammaBlue, blue, crtc->gammaSize * sizeof (CARD16));
@@ -631,6 +686,44 @@ RRCrtcTransformSet (RRCrtcPtr		crtc,
 }
 
 /*
+ * Figure out whether the specific crtc_config can fit
+ * within the screen_config
+ */
+Bool
+RRScreenCoversCrtc(RRScreenConfigPtr screen_config,
+		   RRCrtcConfigPtr crtc_config,
+		   RRTransformPtr client_transform,
+		   XID *errorValue)
+{
+    int source_width;
+    int	source_height;
+    struct pixman_f_transform f_transform;
+
+    RRTransformCompute (crtc_config->x, crtc_config->y,
+			crtc_config->mode->mode.width, crtc_config->mode->mode.height,
+			crtc_config->rotation,
+			client_transform,
+			&crtc_config->sprite_position_transform,
+			&crtc_config->sprite_image_transform,
+			NULL, &f_transform, NULL, NULL, NULL, NULL);
+
+    RRModeGetScanoutSize (crtc_config->mode, &f_transform,
+			  &source_width, &source_height);
+    if (crtc_config->x + source_width > screen_config->screen_pixmap_width) {
+	if (errorValue)
+	    *errorValue = crtc_config->x;
+	return FALSE;
+    }
+
+    if (crtc_config->y + source_height > screen_config->screen_pixmap_height) {
+	if (errorValue)
+	    *errorValue = crtc_config->y;
+	return FALSE;
+    }
+    return TRUE;
+}
+
+/*
  * Initialize crtc type
  */
 Bool
@@ -639,7 +732,7 @@ RRCrtcInit (void)
     RRCrtcType = CreateNewResourceType (RRCrtcDestroyResource, "CRTC");
     if (!RRCrtcType)
 	return FALSE;
-    
+
     return TRUE;
 }
 
@@ -668,7 +761,7 @@ ProcRRGetCrtcInfo (ClientPtr client)
     int				i, j, k, n;
     int				width, height;
     BoxRec			panned_area;
-    
+
     REQUEST_SIZE_MATCH(xRRGetCrtcInfoReq);
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
 
@@ -679,7 +772,7 @@ ProcRRGetCrtcInfo (ClientPtr client)
     pScrPriv = rrGetScrPriv(pScreen);
 
     mode = crtc->mode;
-    
+
     rep.type = X_Reply;
     rep.status = RRSetConfigSuccess;
     rep.sequenceNumber = client->sequence;
@@ -712,7 +805,7 @@ ProcRRGetCrtcInfo (ClientPtr client)
 	    if (pScrPriv->outputs[i]->crtcs[j] == crtc)
 		k++;
     rep.nPossibleOutput = k;
-    
+
     rep.length = rep.nOutput + rep.nPossibleOutput;
 
     extraLen = rep.length << 2;
@@ -727,7 +820,7 @@ ProcRRGetCrtcInfo (ClientPtr client)
 
     outputs = (RROutput *) extra;
     possible = (RROutput *) (outputs + rep.nOutput);
-    
+
     for (i = 0; i < crtc->numOutputs; i++)
     {
 	outputs[i] = crtc->outputs[i]->id;
@@ -744,7 +837,7 @@ ProcRRGetCrtcInfo (ClientPtr client)
 		    swapl (&possible[k], n);
 		k++;
 	    }
-    
+
     if (client->swapped) {
 	swaps(&rep.sequenceNumber, n);
 	swapl(&rep.length, n);
@@ -765,7 +858,7 @@ ProcRRGetCrtcInfo (ClientPtr client)
 	WriteToClient (client, extraLen, (char *) extra);
 	free(extra);
     }
-    
+
     return Success;
 }
 
@@ -785,10 +878,10 @@ ProcRRSetCrtcConfig (ClientPtr client)
     TimeStamp		    time;
     Rotation		    rotation;
     int			    rc, i, j;
-    
+
     REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq);
     numOutputs = (stuff->length - bytes_to_int32(SIZEOF (xRRSetCrtcConfigReq)));
-    
+
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixSetAttrAccess);
 
     if (stuff->mode == None)
@@ -811,7 +904,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
     }
     else
 	outputs = NULL;
-    
+
     outputIds = (RROutput *) (stuff + 1);
     for (i = 0; i < numOutputs; i++)
     {
@@ -834,7 +927,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	/* validate mode for this output */
 	for (j = 0; j < outputs[i]->numModes + outputs[i]->numUserModes; j++)
 	{
-	    RRModePtr	m = (j < outputs[i]->numModes ? 
+	    RRModePtr	m = (j < outputs[i]->numModes ?
 			     outputs[i]->modes[j] :
 			     outputs[i]->userModes[j - outputs[i]->numModes]);
 	    if (m == mode)
@@ -869,17 +962,17 @@ ProcRRSetCrtcConfig (ClientPtr client)
 
     pScreen = crtc->pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
-    
+
     time = ClientTimeToServerTime(stuff->timestamp);
     configTime = ClientTimeToServerTime(stuff->configTimestamp);
-    
+
     if (!pScrPriv)
     {
 	time = currentTime;
 	rep.status = RRSetConfigFailed;
 	goto sendReply;
     }
-    
+
     /*
      * Validate requested rotation
      */
@@ -912,7 +1005,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	    free(outputs);
 	    return BadMatch;
 	}
-    
+
 #ifdef RANDR_12_INTERFACE
 	/*
 	 * Check screen size bounds if the DDX provides a 1.2 interface
@@ -944,7 +1037,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 		free(outputs);
 		return BadValue;
 	    }
-	    
+
 	    if (stuff->y + source_height > pScreen->height)
 	    {
 		client->errorValue = stuff->y;
@@ -954,7 +1047,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	}
 #endif
     }
-    
+
     if (!RRCrtcSet (crtc, mode, stuff->x, stuff->y,
 		   rotation, numOutputs, outputs))
     {
@@ -963,17 +1056,17 @@ ProcRRSetCrtcConfig (ClientPtr client)
     }
     rep.status = RRSetConfigSuccess;
     pScrPriv->lastSetTime = time;
-    
+
 sendReply:
     free(outputs);
-    
+
     rep.type = X_Reply;
     /* rep.status has already been filled in */
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
     rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
 
-    if (client->swapped) 
+    if (client->swapped)
     {
 	int n;
     	swaps(&rep.sequenceNumber, n);
@@ -981,7 +1074,7 @@ sendReply:
 	swapl(&rep.newTimestamp, n);
     }
     WriteToClient(client, sizeof(xRRSetCrtcConfigReply), (char *)&rep);
-    
+
     return Success;
 }
 
@@ -997,7 +1090,7 @@ ProcRRGetPanning (ClientPtr client)
     BoxRec		tracking;
     INT16		border[4];
     int			n;
-    
+
     REQUEST_SIZE_MATCH(xRRGetPanningReq);
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
 
@@ -1067,7 +1160,7 @@ ProcRRSetPanning (ClientPtr client)
     BoxRec		tracking;
     INT16		border[4];
     int			n;
-    
+
     REQUEST_SIZE_MATCH(xRRSetPanningReq);
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
 
@@ -1082,9 +1175,9 @@ ProcRRSetPanning (ClientPtr client)
 	rep.status = RRSetConfigFailed;
 	goto sendReply;
     }
-    
+
     time = ClientTimeToServerTime(stuff->timestamp);
-    
+
     if (!pScrPriv->rrGetPanning)
 	return RRErrorBase + BadRRCrtc;
 
@@ -1160,7 +1253,7 @@ ProcRRGetCrtcGamma (ClientPtr client)
     int				n;
     unsigned long		len;
     char			*extra = NULL;
-    
+
     REQUEST_SIZE_MATCH(xRRGetCrtcGammaReq);
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
 
@@ -1169,7 +1262,7 @@ ProcRRGetCrtcGamma (ClientPtr client)
         return RRErrorBase + BadRRCrtc;
 
     len = crtc->gammaSize * 3 * 2;
-    
+
     if (crtc->gammaSize) {
 	extra = malloc(len);
 	if (!extra)
@@ -1203,21 +1296,21 @@ ProcRRSetCrtcGamma (ClientPtr client)
     RRCrtcPtr			crtc;
     unsigned long		len;
     CARD16			*red, *green, *blue;
-    
+
     REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq);
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
-    
+
     len = client->req_len - bytes_to_int32(sizeof (xRRSetCrtcGammaReq));
     if (len < (stuff->size * 3 + 1) >> 1)
 	return BadLength;
 
     if (stuff->size != crtc->gammaSize)
 	return BadMatch;
-    
+
     red = (CARD16 *) (stuff + 1);
     green = red + crtc->gammaSize;
     blue = green + crtc->gammaSize;
-    
+
     RRCrtcGammaSet (crtc, red, green, blue);
 
     return Success;
@@ -1258,7 +1351,7 @@ ProcRRSetCrtcTransform (ClientPtr client)
 
 
 #define CrtcTransformExtra	(SIZEOF(xRRGetCrtcTransformReply) - 32)
-				
+
 static int
 transform_filter_length (RRTransformPtr transform)
 {
@@ -1360,3 +1453,336 @@ ProcRRGetCrtcTransform (ClientPtr client)
     free(reply);
     return Success;
 }
+
+static void
+pixman_f_transform_from_xRenderTransform(struct pixman_f_transform *f_transform,
+					 xRenderTransform *x_transform)
+{
+    struct pixman_transform	transform;
+    PictTransform_from_xRenderTransform(&transform, x_transform);
+    pixman_f_transform_from_pixman_transform(f_transform, &transform);
+}
+
+static int
+RRConvertCrtcConfig(ClientPtr client, ScreenPtr screen,
+		    RRScreenConfigPtr screen_config,
+		    RRCrtcConfigPtr config, xRRCrtcConfig *x,
+		    RROutput *outputIds)
+{
+    RRCrtcPtr		crtc;
+    RROutputPtr		*outputs;
+    rrScrPrivPtr	scr_priv;
+    RRModePtr		mode;
+    PixmapPtr		pixmap;
+    int			rc, i, j;
+    Rotation		rotation;
+
+    VERIFY_RR_CRTC(x->crtc, crtc, DixSetAttrAccess);
+
+    if (x->mode == None)
+    {
+	mode = NULL;
+	if (x->nOutput > 0)
+	    return BadMatch;
+    }
+    else
+    {
+	VERIFY_RR_MODE(x->mode, mode, DixSetAttrAccess);
+	if (x->nOutput == 0)
+	    return BadMatch;
+    }
+    if (x->nOutput)
+    {
+	outputs = malloc(x->nOutput * sizeof (RROutputPtr));
+	if (!outputs)
+	    return BadAlloc;
+    }
+    else
+	outputs = NULL;
+
+    if (x->pixmap == None)
+	pixmap = NULL;
+    else
+    {
+	rc = dixLookupResourceByType((pointer *) &pixmap, x->pixmap,
+				     RT_PIXMAP, client, DixWriteAccess);
+	if (rc != Success) {
+	    free(outputs);
+	    return rc;
+	}
+	/* XXX check to make sure this is a scanout pixmap */
+    }
+
+    for (i = 0; i < x->nOutput; i++)
+    {
+	rc = dixLookupResourceByType((pointer *)(outputs + i), outputIds[i],
+				     RROutputType, client, DixSetAttrAccess);
+	if (rc != Success)
+	{
+	    free(outputs);
+	    return rc;
+	}
+	/* validate crtc for this output */
+	for (j = 0; j < outputs[i]->numCrtcs; j++)
+	    if (outputs[i]->crtcs[j] == crtc)
+		break;
+	if (j == outputs[i]->numCrtcs)
+	{
+	    free(outputs);
+	    return BadMatch;
+	}
+	/* validate mode for this output */
+	for (j = 0; j < outputs[i]->numModes + outputs[i]->numUserModes; j++)
+	{
+	    RRModePtr	m = (j < outputs[i]->numModes ?
+			     outputs[i]->modes[j] :
+			     outputs[i]->userModes[j - outputs[i]->numModes]);
+	    if (m == mode)
+		break;
+	}
+	if (j == outputs[i]->numModes + outputs[i]->numUserModes)
+	{
+	    free(outputs);
+	    return BadMatch;
+	}
+    }
+    /* validate clones */
+    for (i = 0; i < x->nOutput; i++)
+    {
+	for (j = 0; j < x->nOutput; j++)
+	{
+	    int k;
+	    if (i == j)
+		continue;
+	    for (k = 0; k < outputs[i]->numClones; k++)
+	    {
+		if (outputs[i]->clones[k] == outputs[j])
+		    break;
+	    }
+	    if (k == outputs[i]->numClones)
+	    {
+		free(outputs);
+		return BadMatch;
+	    }
+	}
+    }
+
+    if (crtc->pScreen != screen)
+	return BadMatch;
+
+    scr_priv = rrGetScrPriv(screen);
+
+    config->crtc = crtc;
+    config->x = x->x;
+    config->y = x->y;
+    config->mode = mode;
+    config->rotation = x->rotation;
+    config->numOutputs = x->nOutput;
+    config->outputs = outputs;
+    pixman_f_transform_from_xRenderTransform(&config->sprite_position_transform,
+					     &x->spritePositionTransform);
+    pixman_f_transform_from_xRenderTransform(&config->sprite_image_transform,
+					     &x->spriteImageTransform);
+    config->pixmap = pixmap;
+    config->pixmap_x = x->xPixmap;
+    config->pixmap_y = x->yPixmap;
+
+    /*
+     * Validate requested rotation
+     */
+    rotation = (Rotation) x->rotation;
+
+    /* test the rotation bits only! */
+    switch (rotation & 0xf) {
+    case RR_Rotate_0:
+    case RR_Rotate_90:
+    case RR_Rotate_180:
+    case RR_Rotate_270:
+	break;
+    default:
+	/*
+	 * Invalid rotation
+	 */
+	client->errorValue = x->rotation;
+	free(outputs);
+	return BadValue;
+    }
+
+    if (mode)
+    {
+	if ((~crtc->rotations) & rotation)
+	{
+	    /*
+	     * requested rotation or reflection not supported by screen
+	     */
+	    client->errorValue = x->rotation;
+	    free(outputs);
+	    return BadMatch;
+	}
+
+	/*
+	 * If scanning out from another pixmap, make sure the mode
+	 * fits
+	 */
+	if (pixmap)
+	{
+	    if (x->xPixmap + mode->mode.width > pixmap->drawable.width) {
+		client->errorValue = x->xPixmap;
+		free(outputs);
+		return BadValue;
+	    }
+	    if (x->yPixmap + mode->mode.height > pixmap->drawable.height) {
+		client->errorValue = x->yPixmap;
+		free(outputs);
+		return BadValue;
+	    }
+	}
+	/*
+	 * Check screen size bounds if the DDX provides a 1.2 interface
+	 * for setting screen size. Else, assume the CrtcSet sets
+	 * the size along with the mode. If the driver supports transforms,
+	 * then it must allow crtcs to display a subset of the screen, so
+	 * only do this check for drivers without transform support.
+	 */
+	else if (scr_priv->rrScreenSetSize && !crtc->transforms)
+	{
+	    if (!RRScreenCoversCrtc(screen_config, config,
+				    &crtc->client_pending_transform,
+				    &client->errorValue))
+	    {
+		free(outputs);
+		return BadValue;
+	    }
+	}
+    }
+
+    return Success;
+}
+
+int
+ProcRRSetCrtcConfigs (ClientPtr client)
+{
+    REQUEST(xRRSetCrtcConfigsReq);
+    xRRSetCrtcConfigsReply  rep;
+    DrawablePtr		    drawable;
+    ScreenPtr		    screen;
+    rrScrPrivPtr	    scr_priv;
+    xRRCrtcConfig	    *x_configs;
+    RRScreenConfigRec	    screen_config;
+    RRCrtcConfigPtr	    configs;
+    RROutput		    *output_ids;
+    int			    num_configs;
+    int			    rc, i;
+    int			    extra_len;
+    int			    num_output_ids;
+
+    REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigsReq);
+
+    extra_len = client->req_len - bytes_to_int32(sizeof(xRRSetCrtcConfigsReq));
+
+    num_configs = stuff->nConfigs;
+
+    /* Check request length against number of configs specified */
+    if (num_configs * (sizeof (xRRCrtcConfig) >> 2) > extra_len)
+	return BadLength;
+
+    extra_len -= num_configs * (sizeof (xRRCrtcConfig) >> 2);
+    x_configs = (xRRCrtcConfig *) (stuff + 1);
+
+    /* Check remaining request length against number of outputs */
+    num_output_ids = 0;
+    for (i = 0; i < num_configs; i++)
+	num_output_ids += x_configs[i].nOutput;
+
+    if (extra_len != num_output_ids)
+	return BadLength;
+
+    rc = dixLookupDrawable(&drawable, stuff->drawable, client, 0, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    screen = drawable->pScreen;
+
+    scr_priv = rrGetScrPriv(screen);
+
+    if (!scr_priv)
+    {
+	rep.status = RRSetConfigFailed;
+	goto sendReply;
+    }
+
+    if (stuff->widthInMillimeters == 0 || stuff->heightInMillimeters == 0)
+    {
+	client->errorValue = 0;
+	return BadValue;
+    }
+
+    if (stuff->screenPixmapWidth < scr_priv->minWidth ||
+	scr_priv->maxWidth < stuff->screenPixmapWidth)
+    {
+	client->errorValue = stuff->screenPixmapWidth;
+	return BadValue;
+    }
+    if (stuff->screenPixmapHeight < scr_priv->minHeight ||
+	scr_priv->maxHeight < stuff->screenPixmapHeight)
+    {
+	client->errorValue = stuff->screenPixmapHeight;
+	return BadValue;
+    }
+
+    screen_config.screen_pixmap_width = stuff->screenPixmapWidth;
+    screen_config.screen_pixmap_height = stuff->screenPixmapHeight;
+    screen_config.screen_width = stuff->screenWidth;
+    screen_config.screen_height = stuff->screenHeight;
+    screen_config.mm_width = stuff->widthInMillimeters;
+    screen_config.mm_height = stuff->heightInMillimeters;
+
+    if (num_configs == 0)
+	return Success;
+
+    output_ids = (RROutput *) (x_configs + num_configs);
+
+    /*
+     * Convert protocol crtc configurations into
+     * server crtc configurations
+     */
+    configs = calloc(num_configs, sizeof (RRCrtcConfigRec));
+    if (!configs)
+	return BadAlloc;
+    for (i = 0; i < num_configs; i++) {
+	rc = RRConvertCrtcConfig(client, screen, &screen_config,
+				 &configs[i],
+				 &x_configs[i], output_ids);
+	if (rc != Success) {
+	    rep.status = RRSetConfigFailed;
+	    goto sendReply;
+	}
+	output_ids += x_configs[i].nOutput;
+    }
+
+    if (!RRSetCrtcConfigs (screen, &screen_config, configs, num_configs))
+    {
+	rep.status = RRSetConfigFailed;
+	goto sendReply;
+    }
+    rep.status = RRSetConfigSuccess;
+    scr_priv->lastSetTime = currentTime;
+
+sendReply:
+    RRFreeCrtcConfigs(configs, num_configs);
+
+    rep.type = X_Reply;
+    /* rep.status has already been filled in */
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (client->swapped)
+    {
+	int n;
+	swaps(&rep.sequenceNumber, n);
+	swapl(&rep.length, n);
+    }
+    WriteToClient(client, sizeof(xRRSetCrtcConfigsReply), (char *)&rep);
+
+    return Success;
+}
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index f58e657..62ea2b6 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -191,6 +191,24 @@ RRScreenSizeSet (ScreenPtr  pScreen,
 }
 
 /*
+ * Compute an RRScreenConfig from the current screen information
+ */
+void
+RRScreenCurrentConfig(ScreenPtr screen,
+		      RRScreenConfigPtr screen_config)
+{
+    PixmapPtr		screen_pixmap = screen->GetScreenPixmap(screen);
+    WindowPtr		root = screen->root;
+
+    screen_config->screen_pixmap_width = screen_pixmap->drawable.width;
+    screen_config->screen_pixmap_height = screen_pixmap->drawable.height;
+    screen_config->screen_width = root->drawable.width;
+    screen_config->screen_height = root->drawable.height;
+    screen_config->mm_width = screen->mmWidth;
+    screen_config->mm_height = screen->mmHeight;
+}
+
+/*
  * Retrieve valid screen size range
  */
 int
commit 66294afcab7b7a82f7dd897767e46c48a94b8ee8
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Dec 3 22:08:06 2010 -0800

    randr: Add sprite position transforms
    
    This implements sprite position transformations. Sprite image
    transforms are passed all the way to the DDX layer, but the images are
    not yet manipulated before being passed to the drivers.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 4573f62..3fccaea 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -106,12 +106,17 @@ xf86CrtcCreate (ScrnInfoPtr		scrn,
     pixman_transform_init_identity (&crtc->crtc_to_framebuffer);
     pixman_f_transform_init_identity (&crtc->f_crtc_to_framebuffer);
     pixman_f_transform_init_identity (&crtc->f_framebuffer_to_crtc);
+    pixman_f_transform_init_identity (&crtc->f_screen_to_crtc);
+    pixman_f_transform_init_identity (&crtc->user_sprite_position_transform);
+    pixman_f_transform_init_identity (&crtc->f_crtc_to_cursor);
+    pixman_f_transform_init_identity (&crtc->user_sprite_image_transform);
     crtc->filter = NULL;
     crtc->params = NULL;
     crtc->nparams = 0;
     crtc->filter_width = 0;
     crtc->filter_height = 0;
     crtc->transform_in_use = FALSE;
+    crtc->sprite_transform_in_use = FALSE;
     crtc->transformPresent = FALSE;
     crtc->desiredTransformPresent = FALSE;
     memset (&crtc->bounds, '\0', sizeof (crtc->bounds));
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index f43e0a7..8b42efc 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -345,6 +345,7 @@ struct _xf86Crtc {
     int		    filter_width; /* ABI 2 */
     int		    filter_height; /* ABI 2 */
     Bool	    transform_in_use;
+    Bool	    sprite_transform_in_use;
     RRTransformRec  transform; /* ABI 2 */
     Bool	    transformPresent; /* ABI 2 */
     RRTransformRec  desiredTransform; /* ABI 2 */
@@ -384,6 +385,22 @@ struct _xf86Crtc {
      * Clear the shadow
      */
     Bool	    shadowClear;
+
+    /**
+     * Sprite position transforms
+     */
+
+    /* Transform a screen coordinate to a crtc coordinate */
+    struct pixman_f_transform f_screen_to_crtc;
+
+    /* The user-specified portion of the screen to crtc conversion */
+    struct pixman_f_transform user_sprite_position_transform;
+
+    /* Transform a hardware cursor coordinate to a cursor coordinate */
+    struct pixman_f_transform f_crtc_to_cursor;
+
+    /* The user-specified portion of the cursor to hardware transform */
+    struct pixman_f_transform user_sprite_image_transform;
 };
 
 typedef struct _xf86OutputFuncs {
@@ -777,6 +794,14 @@ xf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y);
 extern _X_EXPORT Bool
 xf86CrtcRotate (xf86CrtcPtr crtc);
 
+
+/*
+ * Update cursor transform matrices after user changes
+ * This is just the cursor subset of xf86CrtcRotate
+ */
+extern _X_EXPORT void
+xf86CrtcRotateCursor (xf86CrtcPtr crtc);
+
 /*
  * Clean up any rotation data, used when a crtc is turned off
  * as well as when rotation is disabled.
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 0667447..7b43bcb 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -338,7 +338,7 @@ xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
     /*
      * Transform position of cursor on screen
      */
-    if (crtc->transform_in_use)
+    if (crtc->sprite_transform_in_use)
     {
 	ScreenPtr	screen = scrn->pScreen;
 	xf86CursorScreenPtr ScreenPriv =
@@ -349,7 +349,7 @@ xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 	v.v[0] = (x + ScreenPriv->HotX) + 0.5;
 	v.v[1] = (y + ScreenPriv->HotY) + 0.5;
 	v.v[2] = 1;
-	pixman_f_transform_point (&crtc->f_framebuffer_to_crtc, &v);
+	pixman_f_transform_point (&crtc->f_screen_to_crtc, &v);
 	/* cursor will have 0.5 added to it already so floor is sufficent */
 	x = floor (v.v[0]);
 	y = floor (v.v[1]);
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index d60ee3c..bbf28cd 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -180,14 +180,14 @@ xf86RandR13VerifyPanningArea (xf86CrtcPtr crtc, int screenWidth, int screenHeigh
  */
 
 static void
-xf86ComputeCrtcPan (Bool transform_in_use,
+xf86ComputeCrtcPan (Bool sprite_transform_in_use,
 		    struct pixman_f_transform *m,
 		    double screen_x, double screen_y,
 		    double crtc_x, double crtc_y,
 		    int old_pan_x, int old_pan_y,
 		    int *new_pan_x, int *new_pan_y)
 {
-    if (transform_in_use) {
+    if (sprite_transform_in_use) {
 	/*
 	 * Given the current transform, M, the current position
 	 * on the Screen, S, and the desired position on the CRTC,
@@ -374,8 +374,8 @@ xf86RandR13Pan (xf86CrtcPtr crtc, int x, int y)
 	c.v[0] = x;
 	c.v[1] = y;
 	c.v[2] = 1.0;
-	if (crtc->transform_in_use) {
-	    pixman_f_transform_point(&crtc->f_framebuffer_to_crtc, &c);
+	if (crtc->sprite_transform_in_use) {
+	    pixman_f_transform_point(&crtc->f_screen_to_crtc, &c);
 	} else {
 	    c.v[0] -= crtc->x;
 	    c.v[1] -= crtc->y;
@@ -402,8 +402,8 @@ xf86RandR13Pan (xf86CrtcPtr crtc, int x, int y)
 	    }
 	}
 	if (panned)
-	    xf86ComputeCrtcPan (crtc->transform_in_use,
-				&crtc->f_framebuffer_to_crtc,
+	    xf86ComputeCrtcPan (crtc->sprite_transform_in_use,
+				&crtc->f_screen_to_crtc,
 				x, y, c.v[0], c.v[1],
 				newX, newY, &newX, &newY);
     }
@@ -414,7 +414,7 @@ xf86RandR13Pan (xf86CrtcPtr crtc, int x, int y)
      * XXX This computation only works when we do not have a transform
      * in use.
      */
-    if (!crtc->transform_in_use)
+    if (!crtc->sprite_transform_in_use)
     {
 	/* Validate against [xy]1 after [xy]2, to be sure that results are > 0 for [xy]1 > 0 */
 	if (crtc->panningTotalArea.x2 > crtc->panningTotalArea.x1) {
@@ -1732,6 +1732,20 @@ xf86RandR12ChangeGamma(int scrnIndex, Gamma gamma)
     return Success;
 }
 
+static void
+xf86RandR14SetCrtcSpriteTransform(ScreenPtr		pScreen,
+				  RRCrtcPtr		randr_crtc,
+				  struct pixman_f_transform *f_position_transform,
+				  struct pixman_f_transform *f_image_transform)
+{
+    xf86CrtcPtr		crtc = randr_crtc->devPrivate;
+
+    crtc->user_sprite_position_transform = *f_position_transform;
+    crtc->user_sprite_image_transform = *f_image_transform;
+    xf86CrtcRotateCursor(crtc);
+    xf86_reload_cursors(pScreen);
+}
+
 static Bool
 xf86RandR12EnterVT (int screen_index, int flags)
 {
@@ -1740,6 +1754,7 @@ xf86RandR12EnterVT (int screen_index, int flags)
     XF86RandRInfoPtr randrp  = XF86RANDRINFO(pScreen);
     rrScrPrivPtr     rp = rrGetScrPriv(pScreen);
     Bool	     ret;
+    int i;
 
     if (randrp->orig_EnterVT) {
 	pScrn->EnterVT = randrp->orig_EnterVT;
@@ -1751,7 +1766,6 @@ xf86RandR12EnterVT (int screen_index, int flags)
     }
 
     /* reload gamma */
-    int i;
     for (i = 0; i < rp->numCrtcs; i++)
 	xf86RandR12CrtcSetGamma(pScreen, rp->crtcs[i]);
 
@@ -1782,6 +1796,7 @@ xf86RandR12Init12 (ScreenPtr pScreen)
     rp->rrSetConfig = NULL;
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
+    rp->rrSetCrtcSpriteTransform = xf86RandR14SetCrtcSpriteTransform;
 
     randrp->orig_EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = xf86RandR12EnterVT;
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 57c3499..ddc6d4c 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -369,6 +369,39 @@ xf86CrtcFitsScreen (xf86CrtcPtr crtc, struct pict_f_transform *crtc_to_fb)
 	    0 <= b.y1 && b.y2 <= pScrn->virtualY);
 }
 
+/*
+ * A subset of xf86CrtcRotate that just deals with
+ * cursor image/position transforms. Used when changing
+ * the cursor transform
+ */
+void
+xf86CrtcRotateCursor (xf86CrtcPtr crtc)
+{
+    /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */
+    RRTransformPtr	transform = NULL;
+    PictTransform	crtc_to_fb;
+    struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc, f_screen_to_crtc, f_crtc_to_cursor;
+
+    if (crtc->transformPresent)
+	transform = &crtc->transform;
+
+    (void) RRTransformCompute (crtc->x, crtc->y,
+			       crtc->mode.HDisplay, crtc->mode.VDisplay,
+			       crtc->rotation,
+			       transform,
+			       &crtc->user_sprite_position_transform,
+			       &crtc->user_sprite_image_transform,
+
+			       &crtc_to_fb,
+			       &f_crtc_to_fb,
+			       &f_fb_to_crtc,
+			       &f_screen_to_crtc,
+			       &f_crtc_to_cursor,
+			       &crtc->sprite_transform_in_use);
+    crtc->f_screen_to_crtc = f_screen_to_crtc;
+    crtc->f_crtc_to_cursor = f_crtc_to_cursor;
+}
+
 Bool
 xf86CrtcRotate (xf86CrtcPtr crtc)
 {
@@ -377,7 +410,7 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
     /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */
     ScreenPtr		pScreen = screenInfo.screens[pScrn->scrnIndex];
     PictTransform	crtc_to_fb;
-    struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc;
+    struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc, f_screen_to_crtc, f_crtc_to_cursor;
     xFixed		*new_params = NULL;
     int			new_nparams = 0;
     PictFilterPtr	new_filter = NULL;
@@ -393,10 +426,15 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
 			     crtc->mode.HDisplay, crtc->mode.VDisplay,
 			     crtc->rotation,
 			     transform,
+			     &crtc->user_sprite_position_transform,
+			     &crtc->user_sprite_image_transform,
 
 			     &crtc_to_fb,
 			     &f_crtc_to_fb,
-			     &f_fb_to_crtc) &&
+			     &f_fb_to_crtc,
+			     &f_screen_to_crtc,
+			     &f_crtc_to_cursor,
+			     &crtc->sprite_transform_in_use) &&
 	xf86CrtcFitsScreen (crtc, &f_crtc_to_fb))
     {
 	/*
@@ -505,6 +543,8 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
     crtc->crtc_to_framebuffer = crtc_to_fb;
     crtc->f_crtc_to_framebuffer = f_crtc_to_fb;
     crtc->f_framebuffer_to_crtc = f_fb_to_crtc;
+    crtc->f_screen_to_crtc = f_screen_to_crtc;
+    crtc->f_crtc_to_cursor = f_crtc_to_cursor;
     free(crtc->params);
     crtc->params = new_params;
     crtc->nparams = new_nparams;
diff --git a/randr/Makefile.am b/randr/Makefile.am
index de338b9..4b38e52 100644
--- a/randr/Makefile.am
+++ b/randr/Makefile.am
@@ -20,6 +20,7 @@ librandr_la_SOURCES =	\
 	rrproperty.c	\
 	rrscreen.c	\
 	rrsdispatch.c	\
+	rrsprite.c	\
 	rrtransform.h	\
 	rrtransform.c
 
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 7ea6080..5e2a351 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -55,9 +55,10 @@
 #define RANDR_10_INTERFACE 1
 #define RANDR_12_INTERFACE 1
 #define RANDR_13_INTERFACE 1 /* requires RANDR_12_INTERFACE */
+#define RANDR_14_INTERFACE 1 /* requires RANDR_13_INTERFACE */
 #define RANDR_GET_CRTC_INTERFACE 1
 
-#define RANDR_INTERFACE_VERSION 0x0103
+#define RANDR_INTERFACE_VERSION 0x0104
 
 typedef XID	RRMode;
 typedef XID	RROutput;
@@ -122,9 +123,16 @@ struct _rrCrtc {
     Bool	    transforms;
     RRTransformRec  client_pending_transform;
     RRTransformRec  client_current_transform;
+    PictTransform   client_sprite_position_transform;
+    PictTransform   client_sprite_image_transform;
+    struct pict_f_transform	client_sprite_f_position_transform;
+    struct pict_f_transform	client_sprite_f_image_transform;
+
     PictTransform   transform;
     struct pict_f_transform f_transform;
     struct pict_f_transform f_inverse;
+    struct pict_f_transform f_sprite_position;		/* crtc from screen */
+    struct pict_f_transform f_sprite_image_inverse;	/* image from crtc */
 };
 
 struct _rrOutput {
@@ -233,6 +241,16 @@ typedef Bool (*RRSetConfigProcPtr) (ScreenPtr		pScreen,
 #endif
 	
 
+typedef void (*RRSetCrtcSpriteTransformPtr) (ScreenPtr pScreen,
+					     RRCrtcPtr randr_crtc,
+					     struct pict_f_transform *position_transform,
+					     struct pict_f_transform *image_transform);
+
+typedef void (*RRGetCrtcSpriteTransformPtr) (ScreenPtr pScreen,
+					     RRCrtcPtr randr_crtc,
+					     struct pict_f_transform *position_transform,
+					     struct pict_f_transform *image_transform);
+
 typedef struct _rrScrPriv {
     /*
      * 'public' part of the structure; DDXen fill this in
@@ -256,7 +274,9 @@ typedef struct _rrScrPriv {
     RRGetPanningProcPtr	rrGetPanning;
     RRSetPanningProcPtr	rrSetPanning;
 #endif
-    
+    RRSetCrtcSpriteTransformPtr	rrSetCrtcSpriteTransform;
+    RRGetCrtcSpriteTransformPtr	rrGetCrtcSpriteTransform;
+
     /*
      * Private part of the structure; not considered part of the ABI
      */
@@ -606,25 +626,6 @@ extern _X_EXPORT void
 RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height);
 
 /*
- * Compute the complete transformation matrix including
- * client-specified transform, rotation/reflection values and the crtc 
- * offset.
- *
- * Return TRUE if the resulting transform is not a simple translation.
- */
-extern _X_EXPORT Bool
-RRTransformCompute (int			    x,
-		    int			    y,
-		    int			    width,
-		    int			    height,
-		    Rotation		    rotation,
-		    RRTransformPtr	    rr_transform,
-
-		    PictTransformPtr	    transform,
-		    struct pict_f_transform *f_transform,
-		    struct pict_f_transform *f_inverse);
-
-/*
  * Return crtc transform
  */
 extern _X_EXPORT RRTransformPtr
@@ -700,6 +701,19 @@ ProcRRGetPanning (ClientPtr client);
 int
 ProcRRSetPanning (ClientPtr client);
 
+void
+RRCrtcSpriteTransformSet(RRCrtcPtr crtc,
+			 PictTransform *position_transform,
+			 PictTransform *image_transform,
+			 struct pict_f_transform *f_position_transform,
+			 struct pict_f_transform *f_image_transform);
+
+int
+ProcRRSetCrtcSpriteTransform (ClientPtr client);
+
+int
+ProcRRGetCrtcSpriteTransform (ClientPtr client);
+
 /* rrdispatch.c */
 extern _X_EXPORT Bool
 RRClientKnowsRates (ClientPtr	pClient);
@@ -889,6 +903,13 @@ ProcRRConfigureOutputProperty (ClientPtr client);
 extern _X_EXPORT int
 ProcRRDeleteOutputProperty (ClientPtr client);
 
+/* rrsprite.c */
+extern _X_EXPORT int
+ProcRRSetCrtcSpriteTransform (ClientPtr client);
+
+extern _X_EXPORT int
+ProcRRGetCrtcSpriteTransform (ClientPtr client);
+
 /* rrxinerama.c */
 #ifdef XINERAMA
 extern _X_EXPORT void
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 98206a2..c2f6963 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -93,6 +93,8 @@ RRCrtcCreate (ScreenPtr pScreen, void *devPrivate)
     pixman_transform_init_identity (&crtc->transform);
     pixman_f_transform_init_identity (&crtc->f_transform);
     pixman_f_transform_init_identity (&crtc->f_inverse);
+    pixman_f_transform_init_identity (&crtc->f_sprite_position);
+    pixman_f_transform_init_identity (&crtc->f_sprite_image_inverse);
 
     if (!AddResource (crtc->id, RRCrtcType, (pointer) crtc))
 	return NULL;
@@ -231,15 +233,21 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
 	RRTransformCopy (&crtc->client_current_transform, transform);
 	RRCrtcChanged (crtc, TRUE);
     }
+
     if (crtc->changed && mode)
     {
 	RRTransformCompute (x, y,
 			    mode->mode.width, mode->mode.height,
 			    rotation,
 			    &crtc->client_current_transform,
+			    &crtc->client_sprite_f_position_transform,
+			    &crtc->client_sprite_f_image_transform,
 			    &crtc->transform, &crtc->f_transform,
-			    &crtc->f_inverse);
+			    &crtc->f_inverse, &crtc->f_sprite_position,
+			    &crtc->f_sprite_image_inverse,
+			    NULL);
     }
+
     return TRUE;
 }
 
@@ -511,7 +519,7 @@ RRCrtcGammaNotify (RRCrtcPtr	crtc)
 }
 
 static void
-RRModeGetScanoutSize (RRModePtr mode, PictTransformPtr transform,
+RRModeGetScanoutSize (RRModePtr mode, struct pixman_f_transform *transform,
 		      int *width, int *height)
 {
     BoxRec  box;
@@ -527,7 +535,7 @@ RRModeGetScanoutSize (RRModePtr mode, PictTransformPtr transform,
     box.x2 = mode->mode.width;
     box.y2 = mode->mode.height;
 
-    pixman_transform_bounds (transform, &box);
+    pixman_f_transform_bounds (transform, &box);
     *width = box.x2 - box.x1;
     *height = box.y2 - box.y1;
 }
@@ -538,7 +546,7 @@ RRModeGetScanoutSize (RRModePtr mode, PictTransformPtr transform,
 void
 RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height)
 {
-    return RRModeGetScanoutSize (crtc->mode, &crtc->transform, width, height);
+    RRModeGetScanoutSize (crtc->mode, &crtc->f_transform, width, height);
 }
 
 /*
@@ -924,9 +932,12 @@ ProcRRSetCrtcConfig (ClientPtr client)
 				mode->mode.width, mode->mode.height,
 				rotation,
 				&crtc->client_pending_transform,
-				&transform, &f_transform, &f_inverse);
+				&crtc->client_sprite_f_position_transform,
+				&crtc->client_sprite_f_image_transform,
+				&transform, &f_transform, &f_inverse, NULL, NULL, NULL);
 
-	    RRModeGetScanoutSize (mode, &transform, &source_width, &source_height);
+	    RRModeGetScanoutSize (mode, &f_transform,
+				  &source_width, &source_height);
 	    if (stuff->x + source_width > pScreen->width)
 	    {
 		client->errorValue = stuff->x;
diff --git a/randr/rrsprite.c b/randr/rrsprite.c
new file mode 100644
index 0000000..5bf312c
--- /dev/null
+++ b/randr/rrsprite.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2010 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+#include "swaprep.h"
+
+void
+RRCrtcSpriteTransformSet(RRCrtcPtr crtc,
+			 PictTransform *position_transform,
+			 PictTransform *image_transform,
+			 struct pict_f_transform *f_position_transform,
+			 struct pict_f_transform *f_image_transform)
+{
+    ScreenPtr			pScreen;
+    rrScrPrivPtr		pScrPriv;
+
+    pScreen = crtc->pScreen;
+    pScrPriv = rrGetScrPriv(pScreen);
+    crtc->client_sprite_position_transform = *position_transform;
+    crtc->client_sprite_image_transform = *image_transform;
+    crtc->client_sprite_f_position_transform = *f_position_transform;
+    crtc->client_sprite_f_image_transform = *f_image_transform;
+    if (pScrPriv->rrSetCrtcSpriteTransform)
+	(*pScrPriv->rrSetCrtcSpriteTransform) (pScreen, crtc,
+					       &crtc->client_sprite_f_position_transform,
+					       &crtc->client_sprite_f_image_transform);
+}
+
+int
+ProcRRSetCrtcSpriteTransform (ClientPtr client)
+{
+    REQUEST(xRRSetCrtcSpriteTransformReq);
+    RRCrtcPtr		    crtc;
+    PictTransform	    position_transform, image_transform;
+    struct pixman_f_transform f_position_transform, f_image_transform;
+
+    REQUEST_AT_LEAST_SIZE(xRRSetCrtcSpriteTransformReq);
+    VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
+
+    PictTransform_from_xRenderTransform (&position_transform, &stuff->positionTransform);
+    PictTransform_from_xRenderTransform (&image_transform, &stuff->imageTransform);
+    pixman_f_transform_from_pixman_transform (&f_position_transform, &position_transform);
+    pixman_f_transform_from_pixman_transform (&f_image_transform, &image_transform);
+
+    RRCrtcSpriteTransformSet (crtc, &position_transform, &image_transform,
+			      &f_position_transform, &f_image_transform);
+    return Success;
+}
+
+#define CrtcSpriteTransformExtra	(SIZEOF(xRRGetCrtcSpriteTransformReply) - 32)
+
+int
+ProcRRGetCrtcSpriteTransform (ClientPtr client)
+{
+    REQUEST(xRRGetCrtcSpriteTransformReq);
+    xRRGetCrtcSpriteTransformReply	*reply;
+    RRCrtcPtr			crtc;
+    int				n;
+    char			*extra;
+
+    REQUEST_SIZE_MATCH (xRRGetCrtcSpriteTransformReq);
+    VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
+
+    reply = malloc(sizeof (xRRGetCrtcSpriteTransformReply));
+    if (!reply)
+	return BadAlloc;
+
+    extra = (char *) (reply + 1);
+    reply->type = X_Reply;
+    reply->sequenceNumber = client->sequence;
+    reply->length = bytes_to_int32(CrtcSpriteTransformExtra);
+
+    xRenderTransform_from_PictTransform(&reply->positionTransform, &crtc->client_sprite_position_transform);
+    xRenderTransform_from_PictTransform(&reply->imageTransform, &crtc->client_sprite_image_transform);
+
+    if (client->swapped) {
+	swaps (&reply->sequenceNumber, n);
+	swapl (&reply->length, n);
+	SwapLongs((CARD32 *) &reply->positionTransform, bytes_to_int32(sizeof(xRenderTransform)));
+	SwapLongs((CARD32 *) &reply->imageTransform, bytes_to_int32(sizeof(xRenderTransform)));
+    }
+    WriteToClient (client, sizeof (xRRGetCrtcSpriteTransformReply), (char *) reply);
+    free(reply);
+    return Success;
+}
diff --git a/randr/rrtransform.c b/randr/rrtransform.c
index e162049..3eda5f3 100644
--- a/randr/rrtransform.c
+++ b/randr/rrtransform.c
@@ -134,6 +134,24 @@ RRTransformRescale(struct pixman_f_transform *f_transform, double limit)
 	    f_transform->m[j][i] *= scale;
 }
 
+#define EPSILON (1e-20)
+#define IS_F_SAME(a,b)	(fabs((a)-(b)) < EPSILON)
+#define IS_F_ZERO(a)	(fabs(a) < EPSILON)
+
+static Bool
+pict_f_transform_is_identity (const struct pixman_f_transform *t)
+{
+    return (IS_F_SAME (t->m[0][0], t->m[1][1]) &&
+	    IS_F_SAME (t->m[0][0], t->m[2][2]) &&
+	    !IS_F_ZERO (t->m[0][0]) &&
+	    IS_F_ZERO (t->m[0][1]) &&
+	    IS_F_ZERO (t->m[0][2]) &&
+	    IS_F_ZERO (t->m[1][0]) &&
+	    IS_F_ZERO (t->m[1][2]) &&
+	    IS_F_ZERO (t->m[2][0]) &&
+	    IS_F_ZERO (t->m[2][1]));
+}
+
 /*
  * Compute the complete transformation matrix including
  * client-specified transform, rotation/reflection values and the crtc 
@@ -148,23 +166,39 @@ RRTransformCompute (int			    x,
 		    int			    height,
 		    Rotation		    rotation,
 		    RRTransformPtr	    rr_transform,
+		    struct pixman_f_transform *sprite_position_transform,
+		    struct pixman_f_transform *sprite_image_transform,
 
 		    PictTransformPtr	    transform,
 		    struct pixman_f_transform *f_transform,
-		    struct pixman_f_transform *f_inverse)
+		    struct pixman_f_transform *f_inverse,
+		    struct pixman_f_transform *f_fb_to_sprite,
+		    struct pixman_f_transform *f_sprite_to_image,
+		    Bool		      *sprite_transform_in_use)
 {
     PictTransform	    t_transform, inverse;
     struct pixman_f_transform tf_transform, tf_inverse;
+    struct pixman_f_transform sf_position_transform, sf_image_transform;
+    struct pixman_f_transform f_image_to_sprite;
     Bool		    overflow = FALSE;
+    Bool		    ret = TRUE;
 
     if (!transform) transform = &t_transform;
     if (!f_transform) f_transform = &tf_transform;
     if (!f_inverse) f_inverse = &tf_inverse;
+    if (!f_fb_to_sprite) f_fb_to_sprite = &sf_position_transform;
+    if (!f_sprite_to_image) f_sprite_to_image = &sf_image_transform;
+
+    /* invert the sprite image transform to have it go from dest to source */
+    if (!pixman_f_transform_invert (&f_image_to_sprite, f_sprite_to_image))
+	pixman_f_transform_init_identity(&f_image_to_sprite);
 
     pixman_transform_init_identity (transform);
     pixman_transform_init_identity (&inverse);
     pixman_f_transform_init_identity (f_transform);
     pixman_f_transform_init_identity (f_inverse);
+    pixman_f_transform_init_identity (f_fb_to_sprite);
+    pixman_f_transform_init_identity (f_sprite_to_image);
     if (rotation != RR_Rotate_0)
     {
 	double	f_rot_cos, f_rot_sin, f_rot_dx, f_rot_dy;
@@ -246,7 +280,14 @@ RRTransformCompute (int			    x,
 	pixman_f_transform_translate (f_transform, f_inverse, f_scale_dx, f_scale_dy);
     }
     
-#ifdef RANDR_12_INTERFACE
+    /*
+     * Sprite position is affected by the transform matrix,
+     * but the image is not
+     */
+    pixman_f_transform_multiply(f_sprite_to_image,
+				f_transform,
+				&f_image_to_sprite);
+
     if (rr_transform)
     {
         if (!pixman_transform_multiply (transform, &rr_transform->transform, transform))
@@ -254,7 +295,7 @@ RRTransformCompute (int			    x,
 	pixman_f_transform_multiply (f_transform, &rr_transform->f_transform, f_transform);
 	pixman_f_transform_multiply (f_inverse, f_inverse, &rr_transform->f_inverse);
     }
-#endif
+
     /*
      * Compute the class of the resulting transform
      */
@@ -264,7 +305,7 @@ RRTransformCompute (int			    x,
 
 	pixman_f_transform_init_translate (f_transform,  x,  y);
 	pixman_f_transform_init_translate (f_inverse,   -x, -y);
-	return FALSE;
+	ret = FALSE;
     }
     else
     {
@@ -278,6 +319,19 @@ RRTransformCompute (int			    x,
 	    RRTransformRescale(&f_scaled, 16384.0);
 	    pixman_transform_from_pixman_f_transform(transform, &f_scaled);
 	}
-	return TRUE;
+	ret = TRUE;
     }
+
+    /*
+     * Sprite position is affected by the transform matrix,
+     * but the image is not
+     */
+    pixman_f_transform_multiply(f_fb_to_sprite,
+				f_inverse,
+				sprite_position_transform);
+    if (sprite_transform_in_use)
+	*sprite_transform_in_use = ret || !pict_f_transform_is_identity(f_fb_to_sprite);
+    return ret;
 }
+
+
diff --git a/randr/rrtransform.h b/randr/rrtransform.h
index 561762d..5cfcf8d 100644
--- a/randr/rrtransform.h
+++ b/randr/rrtransform.h
@@ -59,6 +59,13 @@ RRTransformSetFilter (RRTransformPtr	dst,
 extern _X_EXPORT Bool
 RRTransformCopy (RRTransformPtr dst, RRTransformPtr src);
 
+/*
+ * Compute the complete transformation matrix including
+ * client-specified transform, rotation/reflection values and the crtc
+ * offset.
+ *
+ * Return TRUE if the resulting transform is not a simple translation.
+ */
 extern _X_EXPORT Bool
 RRTransformCompute (int			    x,
 		    int			    y,
@@ -66,10 +73,14 @@ RRTransformCompute (int			    x,
 		    int			    height,
 		    Rotation		    rotation,
 		    RRTransformPtr	    rr_transform,
+		    struct pict_f_transform *sprite_position_transform,
+		    struct pict_f_transform *sprite_image_transform,
 
 		    PictTransformPtr	    transform,
 		    struct pict_f_transform *f_transform,
-		    struct pict_f_transform *f_inverse);
-
+		    struct pict_f_transform *f_inverse,
+		    struct pict_f_transform *f_fb_to_sprite,
+		    struct pict_f_transform *f_sprite_to_image,
+		    Bool		    *sprite_transform_in_use);
 
 #endif /* _RRTRANSFORM_H_ */
commit c8bc25fd7629df10f2825b7cc713b031ae78f223
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 19:40:30 2010 -0800

    Require RandR protocol version 1.4 or newer
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 3021bdd..d1fc379 100644
--- a/configure.ac
+++ b/configure.ac
@@ -788,7 +788,7 @@ WINDOWSWMPROTO="windowswmproto"
 APPLEWMPROTO="applewmproto >= 1.4"
 
 dnl Core modules for most extensions, et al.
-SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto"
+SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.4] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto"
 # Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
 AC_SUBST(SDK_REQUIRED_MODULES)
 
commit 8b35118c03590a7ad3786d3284bafb3f40fcb8cc
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Jun 6 15:23:37 2010 -0700

    Replace huge argument list in xf86CrtcSetModeTransform with struct
    
    xf86CrtcSetModeTransform was starting to get ridiculous with 6
    arguments, this change has it take a single structure that contains
    all of those values along with a set of flags that says which have
    changed.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index b94bc09..4573f62 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -247,15 +247,14 @@ xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen)
  * Sets the given video mode on the given crtc
  */
 Bool
-xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
-			  RRTransformPtr transform, int x, int y)
+xf86CrtcSet(xf86CrtcPtr crtc, xf86CrtcSetRec *set)
 {
     ScrnInfoPtr		scrn = crtc->scrn;
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
     int			i;
     Bool		ret = FALSE;
     Bool		didLock = FALSE;
-    DisplayModePtr	adjusted_mode;
+    DisplayModePtr	adjusted_mode = NULL;
     DisplayModeRec	saved_mode;
     int			saved_x, saved_y;
     Rotation		saved_rotation;
@@ -272,8 +271,9 @@ xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotati
 	return TRUE;
     }
 
-    adjusted_mode = xf86DuplicateMode(mode);
-
+    /* See if nothing has changed */
+    if (!set->flags)
+	return TRUE;
 
     saved_mode = crtc->mode;
     saved_x = crtc->x;
@@ -288,21 +288,44 @@ xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotati
     /* Update crtc values up front so the driver can rely on them for mode
      * setting.
      */
-    crtc->mode = *mode;
-    crtc->x = x;
-    crtc->y = y;
-    crtc->rotation = rotation;
-    if (transform) {
-	RRTransformCopy (&crtc->transform, transform);
-	crtc->transformPresent = TRUE;
-    } else
-	crtc->transformPresent = FALSE;
+    if (set->flags & XF86CrtcSetMode)
+	crtc->mode = *set->mode;
+    if (set->flags & XF86CrtcSetOrigin) {
+	crtc->x = set->x;
+	crtc->y = set->y;
+    }
+    if (set->flags & XF86CrtcSetRotation)
+	crtc->rotation = set->rotation;
+
+    if (set->flags & XF86CrtcSetTransform) {
+	if (set->transform) {
+	    RRTransformCopy (&crtc->transform, set->transform);
+	    crtc->transformPresent = TRUE;
+	} else
+	    crtc->transformPresent = FALSE;
+    }
+
+    if (crtc->funcs->set) {
+	ret = crtc->funcs->set(crtc, set->flags);
+	goto done;
+    }
+
+    if (set->flags == XF86CrtcSetOrigin && crtc->funcs->set_origin) {
+	ret = xf86CrtcRotate(crtc);
+	if (ret)
+	    crtc->funcs->set_origin(crtc, crtc->x, crtc->y);
+	goto done;
+    }
 
     if (crtc->funcs->set_mode_major) {
-	ret = crtc->funcs->set_mode_major(crtc, mode, rotation, x, y);
+	ret = crtc->funcs->set_mode_major(crtc, &crtc->mode,
+					  crtc->rotation,
+					  crtc->x, crtc->y);
 	goto done;
     }
 
+    adjusted_mode = xf86DuplicateMode(&crtc->mode);
+
     didLock = crtc->funcs->lock (crtc);
     /* Pass our mode to the outputs and the CRTC to give them a chance to
      * adjust it according to limitations or output properties, and also
@@ -314,12 +337,12 @@ xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotati
 	if (output->crtc != crtc)
 	    continue;
 
-	if (!output->funcs->mode_fixup(output, mode, adjusted_mode)) {
+	if (!output->funcs->mode_fixup(output, &crtc->mode, adjusted_mode)) {
 	    goto done;
 	}
     }
 
-    if (!crtc->funcs->mode_fixup(crtc, mode, adjusted_mode)) {
+    if (!crtc->funcs->mode_fixup(crtc, &crtc->mode, adjusted_mode)) {
 	goto done;
     }
 
@@ -342,12 +365,12 @@ xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotati
     /* Set up the DPLL and any output state that needs to adjust or depend
      * on the DPLL.
      */
-    crtc->funcs->mode_set(crtc, mode, adjusted_mode, crtc->x, crtc->y);
+    crtc->funcs->mode_set(crtc, &crtc->mode, adjusted_mode, crtc->x, crtc->y);
     for (i = 0; i < xf86_config->num_output; i++) 
     {
 	xf86OutputPtr output = xf86_config->output[i];
 	if (output->crtc == crtc)
-	    output->funcs->mode_set(output, mode, adjusted_mode);
+	    output->funcs->mode_set(output, &crtc->mode, adjusted_mode);
     }
 
     /* Only upload when needed, to avoid unneeded delays. */
@@ -383,8 +406,10 @@ done:
 	crtc->transformPresent = saved_transform_present;
     }
 
-    free(adjusted_mode->name);
-    free(adjusted_mode);
+    if (adjusted_mode) {
+	free(adjusted_mode->name);
+	free(adjusted_mode);
+    }
 
     if (didLock)
 	crtc->funcs->unlock (crtc);
@@ -393,35 +418,19 @@ done:
 }
 
 /**
- * Sets the given video mode on the given crtc, but without providing
- * a transform
- */
-Bool
-xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
-		 int x, int y)
-{
-    return xf86CrtcSetModeTransform (crtc, mode, rotation, NULL, x, y);
-}
-
-/**
  * Pans the screen, does not change the mode
  */
 void
 xf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y)
 {
-    ScrnInfoPtr scrn = crtc->scrn;
+    xf86CrtcSetRec	set;
 
-    crtc->x = x;
-    crtc->y = y;
-    if (crtc->funcs->set_origin) {
-	if (!xf86CrtcRotate (crtc))
-	    return;
-	crtc->funcs->set_origin (crtc, x, y);
-	if (scrn->ModeSet)
-	    scrn->ModeSet(scrn);
+    if (x != crtc->x || y != crtc->y) {
+	set.x = x;
+	set.y = y;
+	set.flags = XF86CrtcSetOrigin;
+	(void) xf86CrtcSet(crtc, &set);
     }
-    else
-	xf86CrtcSetMode (crtc, &crtc->mode, crtc->rotation, x, y);
 }
 
 /*
@@ -2617,6 +2626,7 @@ xf86SetDesiredModes (ScrnInfoPtr scrn)
     for (c = 0; c < config->num_crtc; c++)
     {
 	xf86OutputPtr	output = NULL;
+	xf86CrtcSetRec	set;
 	int		o;
 	RRTransformPtr	transform;
 
@@ -2660,8 +2670,15 @@ xf86SetDesiredModes (ScrnInfoPtr scrn)
 	    transform = &crtc->desiredTransform;
 	else
 	    transform = NULL;
-	if (!xf86CrtcSetModeTransform (crtc, &crtc->desiredMode, crtc->desiredRotation,
-				       transform, crtc->desiredX, crtc->desiredY))
+	set.mode = &crtc->desiredMode;
+	set.rotation = crtc->desiredRotation;
+	set.transform = transform;
+	set.x = crtc->desiredX;
+	set.y = crtc->desiredY;
+	set.flags = (XF86CrtcSetMode | XF86CrtcSetOutput |
+		     XF86CrtcSetOrigin | XF86CrtcSetTransform |
+		     XF86CrtcSetRotation);
+	if (!xf86CrtcSet(crtc, &set))
 	    return FALSE;
     }
 
@@ -2765,6 +2782,7 @@ xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation)
 	xf86CrtcPtr	crtc = config->crtc[c];
 	DisplayModePtr	crtc_mode = NULL;
 	int		o;
+	xf86CrtcSetRec	set;
 
 	if (!crtc->enabled)
 	    continue;
@@ -2792,7 +2810,15 @@ xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation)
 	    crtc->enabled = FALSE;
 	    continue;
 	}
-	if (!xf86CrtcSetModeTransform (crtc, crtc_mode, rotation, NULL, 0, 0))
+	set.mode = crtc_mode;
+	set.rotation = rotation;
+	set.transform = NULL;
+	set.x = 0;
+	set.y = 0;
+	set.flags = (XF86CrtcSetMode | XF86CrtcSetOutput |
+		     XF86CrtcSetOrigin | XF86CrtcSetTransform |
+		     XF86CrtcSetRotation);
+	if (!xf86CrtcSet (crtc, &set))
 	    ok = FALSE;
 	else
 	{
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 68a968c..f43e0a7 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -72,6 +72,23 @@ typedef enum _xf86OutputStatus {
    XF86OutputStatusUnknown
 } xf86OutputStatus;
 
+typedef enum _xf86CrtcSetFlags {
+    XF86CrtcSetMode = 1,		/* mode */
+    XF86CrtcSetOutput = 2,		/* outputs */
+    XF86CrtcSetOrigin = 4,		/* x/y */
+    XF86CrtcSetTransform = 8,		/* transform */
+    XF86CrtcSetRotation = 16,		/* rotation */
+    XF86CrtcSetProperty = 32,		/* output property */
+} xf86CrtcSetFlags;
+
+typedef struct _xf86CrtcSet {
+    xf86CrtcSetFlags	flags;
+    DisplayModePtr	mode;
+    Rotation		rotation;
+    RRTransformPtr	transform;
+    int			x, y;
+} xf86CrtcSetRec;
+
 typedef struct _xf86CrtcFuncs {
    /**
     * Turns the crtc on/off, or sets intermediate power levels if available.
@@ -221,6 +238,12 @@ typedef struct _xf86CrtcFuncs {
     void
     (*set_origin)(xf86CrtcPtr crtc, int x, int y);
 
+    /**
+     * General mode setting entry point that does everything
+     */
+    Bool
+    (*set)(xf86CrtcPtr crtc, xf86CrtcSetFlags flags);
+
 } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
 
 #define XF86_CRTC_VERSION 3
@@ -738,18 +761,12 @@ xf86CrtcCreate (ScrnInfoPtr		scrn,
 extern _X_EXPORT void
 xf86CrtcDestroy (xf86CrtcPtr		crtc);
 
-
 /**
- * Sets the given video mode on the given crtc
+ * Change a crtc configuration (modes, outputs, etc)
  */
 
 extern _X_EXPORT Bool
-xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
-			  RRTransformPtr transform, int x, int y);
-
-extern _X_EXPORT Bool
-xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
-		 int x, int y);
+xf86CrtcSet (xf86CrtcPtr crtc, xf86CrtcSetRec *set);
 
 extern _X_EXPORT void
 xf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y);
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 2fe0c47..d60ee3c 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1133,7 +1133,7 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
     xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
     xf86CrtcPtr		crtc = randr_crtc->devPrivate;
     RRTransformPtr	transform;
-    Bool		changed = FALSE;
+    xf86CrtcSetFlags	flags = 0;
     int			o, ro;
     xf86CrtcPtr		*save_crtcs;
     Bool		save_enabled = crtc->enabled;
@@ -1143,22 +1143,22 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 
     save_crtcs = malloc(config->num_output * sizeof (xf86CrtcPtr));
     if ((randr_mode != NULL) != crtc->enabled)
-	changed = TRUE;
+	flags |= XF86CrtcSetMode;
     else if (randr_mode && !xf86RandRModeMatches (randr_mode, &crtc->mode))
-	changed = TRUE;
+	flags |= XF86CrtcSetMode;
     
     if (rotation != crtc->rotation)
-	changed = TRUE;
+	flags |= XF86CrtcSetRotation;
 
     transform = RRCrtcGetTransform (randr_crtc);
     if ((transform != NULL) != crtc->transformPresent)
-	changed = TRUE;
+	flags |= XF86CrtcSetTransform;
     else if (transform && memcmp (&transform->transform, &crtc->transform.transform,
 				  sizeof (transform->transform)) != 0)
-	changed = TRUE;
+	flags |= XF86CrtcSetTransform;
 
     if (x != crtc->x || y != crtc->y)
-	changed = TRUE;
+	flags |= XF86CrtcSetOrigin;
     for (o = 0; o < config->num_output; o++) 
     {
 	xf86OutputPtr  output = config->output[o];
@@ -1178,16 +1178,16 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 	    }
 	if (new_crtc != output->crtc)
 	{
-	    changed = TRUE;
+	    flags |= XF86CrtcSetOutput;
 	    output->crtc = new_crtc;
 	}
     }
     for (ro = 0; ro < num_randr_outputs; ro++) 
         if (randr_outputs[ro]->pendingProperties)
-	    changed = TRUE;
+	    flags |= XF86CrtcSetProperty;
 
     /* XXX need device-independent mode setting code through an API */
-    if (changed)
+    if (flags)
     {
 	crtc->enabled = randr_mode != NULL;
 
@@ -1195,9 +1195,16 @@ xf86RandR12CrtcSet (ScreenPtr	    pScreen,
 	{
 	    DisplayModeRec  mode;
 	    RRTransformPtr  transform = RRCrtcGetTransform (randr_crtc);
+	    xf86CrtcSetRec  set;
 
 	    xf86RandRModeConvert (pScrn, randr_mode, &mode);
-	    if (!xf86CrtcSetModeTransform (crtc, &mode, rotation, transform, x, y))
+	    set.mode = &mode;
+	    set.rotation = rotation;
+	    set.transform = transform;
+	    set.x = x;
+	    set.y = y;
+	    set.flags = flags;
+	    if (!xf86CrtcSet(crtc, &set))
 	    {
 		crtc->enabled = save_enabled;
 		for (o = 0; o < config->num_output; o++)
commit f5b8bd620f91214c0b87e9b04d57015655792352
Merge: 01e9fa7... 8127c83...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 19:51:06 2010 -0800

    Merge remote branch 'jajones/for-keith'

commit 01e9fa7da389fc7ab834b4234b8484514144b7f4
Merge: 79870db... 68a1b0d...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 19:45:11 2010 -0800

    Merge remote branch 'whot/for-keith'

commit 79870dbf72d463cf9efea1b3e61d1d5759df27b5
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Dec 4 16:13:29 2010 -0500

    config: build Xserver man pages using XORG_MANPAGE_SECTIONS
    
    Nothing requires the use of a C preprocessor
    Using standard file exentions (.man) means no need for .gitignore
    Use standard directory and makefile
    Fix man page whitespace issues
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matt Dew <matt at osource.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 34d1806..c5abed6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2180,6 +2180,7 @@ damageext/Makefile
 dbe/Makefile
 dix/Makefile
 doc/Makefile
+doc/man/Makefile
 doc/xml/Makefile
 doc/xml/dtrace/Makefile
 doc/xml/xserver.ent
diff --git a/doc/.gitignore b/doc/.gitignore
deleted file mode 100644
index 952f528..0000000
--- a/doc/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-#		Add & Override for this directory and it's subdirectories
-Xserver.man
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 43606a3..4c08b6f 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,26 +1,3 @@
+SUBDIRS = man xml
 
-# Xserver.man covers options generic to all X servers built in this tree
-# (i.e. those handled in the os/utils.c options processing instead of in
-#  the DDX-level options processing)
-appmandir = $(APP_MAN_DIR)
-appman_PRE = Xserver.man.pre
-
-appman_PROCESSED = $(appman_PRE:man.pre=man)
-appman_DATA = $(appman_PRE:man.pre=@APP_MAN_SUFFIX@)
-
-BUILT_SOURCES = $(appman_PROCESSED)
-CLEANFILES = $(appman_PROCESSED) $(appman_DATA)
-
-include $(top_srcdir)/cpprules.in
-
-.man.$(APP_MAN_SUFFIX):
-	$(AM_V_at)cp $< $@
-
-EXTRAMANDEFS = -D__default_font_path__="`echo $(COMPILEDDEFAULTFONTPATH) | $(SED) -e 's/,/, /g'`"
-
-# Docs about X server internals that we ship with source but don't install
-DEVEL_DOCS = smartsched
-
-EXTRA_DIST = $(DEVEL_DOCS) $(appman_PRE) $(fileman_PRE)
-
-SUBDIRS = xml
+dist_noinst_DATA = smartsched
diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
deleted file mode 100644
index 240f05c..0000000
--- a/doc/Xserver.man.pre
+++ /dev/null
@@ -1,584 +0,0 @@
-.\" $Xorg: Xserver.man,v 1.4 2001/02/09 02:04:07 xorgcvs Exp $
-.\" $XdotOrg: xserver/xorg/doc/Xserver.man.pre,v 1.4 2005/12/23 20:11:12 alanc Exp $
-.\" Copyright 1984 - 1991, 1993, 1994, 1998  The Open Group
-.\"
-.\" Permission to use, copy, modify, distribute, and sell this software and its
-.\" documentation for any purpose is hereby granted without fee, provided that
-.\" the above copyright notice appear in all copies and that both that
-.\" copyright notice and this permission notice appear in supporting
-.\" documentation.
-.\"
-.\" The above copyright notice and this permission notice shall be included
-.\" in all copies or substantial portions of the Software.
-.\"
-.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-.\" OTHER DEALINGS IN THE SOFTWARE.
-.\"
-.\" Except as contained in this notice, the name of The Open Group shall
-.\" not be used in advertising or otherwise to promote the sale, use or
-.\" other dealings in this Software without prior written authorization
-.\" from The Open Group.
-.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.31 2004/01/10 22:27:46 dawes Exp $
-.\" shorthand for double quote that works everywhere.
-.ds q \N'34'
-.TH XSERVER 1 __xorgversion__
-.SH NAME
-Xserver \- X Window System display server
-.SH SYNOPSIS
-.B X
-[option ...]
-.SH DESCRIPTION
-.I X
-is the generic name for the X Window System display server.  It is
-frequently a link or a copy of the appropriate server binary for
-driving the most frequently used server on a given machine.
-.SH "STARTING THE SERVER"
-The X server is usually started from the X Display Manager program 
-\fIxdm\fP(1) or a similar display manager program.
-This utility is run from the system boot files and takes care of keeping
-the server running, prompting for usernames and passwords, and starting up
-the user sessions.
-.PP
-Installations that run more than one window system may need to use the
-\fIxinit\fP(1) utility instead of a display manager.  However, \fIxinit\fP is
-to be considered a tool for building startup scripts and is not
-intended for use by end users.  Site administrators are \fBstrongly\fP
-urged to use a display manager, or build other interfaces for novice users.
-.PP
-The X server may also be started directly by the user, though this
-method is usually reserved for testing and is not recommended for
-normal operation.  On some platforms, the user must have special
-permission to start the X server, often because access to certain
-devices (e.g. \fI/dev/mouse\fP) is restricted.
-.PP
-When the X server starts up, it typically takes over the display.  If
-you are running on a workstation whose console is the display, you may
-not be able to log into the console while the server is running.
-.SH OPTIONS
-Many X servers have device-specific command line options.  See the manual
-pages for the individual servers for more details; a list of
-server-specific manual pages is provided in the SEE ALSO section below.
-.PP
-All of the X servers accept the command line options described below.
-Some X servers may have alternative ways of providing the parameters
-described here, but the values provided via the command line options
-should override values specified via other mechanisms.
-.TP 8
-.B :\fIdisplaynumber\fP
-The X server runs as the given \fIdisplaynumber\fP, which by default is 0.
-If multiple X servers are to run simultaneously on a host, each must have
-a unique display number.  See the DISPLAY
-NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
-specify which display number clients should try to use.
-.TP 8
-.B \-a \fInumber\fP
-sets pointer acceleration (i.e. the ratio of how much is reported to how much
-the user actually moved the pointer).
-.TP 8
-.B \-ac
-disables host-based access control mechanisms.  Enables access by any host,
-and permits any host to modify the access control list.
-Use with extreme caution.
-This option exists primarily for running test suites remotely.
-.TP 8
-.B \-audit \fIlevel\fP
-sets the audit trail level.  The default level is 1, meaning only connection
-rejections are reported.  Level 2 additionally reports all successful
-connections and disconnects.  Level 4 enables messages from the
-SECURITY extension, if present, including generation and revocation of
-authorizations and violations of the security policy.
-Level 0 turns off the audit trail.
-Audit lines are sent as standard error output.
-.TP 8
-.B \-auth \fIauthorization-file\fP
-specifies a file which contains a collection of authorization records used
-to authenticate access.  See also the \fIxdm\fP(1) and 
-\fIXsecurity\fP(__miscmansuffix__) manual pages.
-.TP 8
-.B \-br
-sets the default root window to solid black instead of the standard root weave
-pattern.   This is the default unless -retro or -wr is specified.
-.TP 8
-.B \-bs
-disables backing store support on all screens.
-.TP 8
-.B \-c
-turns off key-click.
-.TP 8
-.B c \fIvolume\fP
-sets key-click volume (allowable range: 0-100).
-.TP 8
-.B \-cc \fIclass\fP
-sets the visual class for the root window of color screens.
-The class numbers are as specified in the X protocol.
-Not obeyed by all servers.
-.TP 8
-.B \-core
-causes the server to generate a core dump on fatal errors.
-.TP 8
-.B \-deferglyphs \fIwhichfonts\fP
-specifies the types of fonts for which the server should attempt to use
-deferred glyph loading.  \fIwhichfonts\fP can be all (all fonts),
-none (no fonts), or 16 (16 bit fonts only).
-.TP 8
-.B \-dpi \fIresolution\fP
-sets the resolution for all screens, in dots per inch.
-To be used when the server cannot determine the screen size(s) from the
-hardware.
-.TP 8
-.B dpms
-enables DPMS (display power management services), where supported.  The
-default state is platform and configuration specific.
-.TP 8
-.B \-dpms
-disables DPMS (display power management services).  The default state
-is platform and configuration specific.
-.TP 8
-.BI \-extension extensionName
-disables named extension.   If an unknown extension name is specified,
-a list of accepted extension names is printed.
-.TP 8
-.BI \+extension extensionName
-enables named extension.   If an unknown extension name is specified,
-a list of accepted extension names is printed.
-.TP 8
-.B \-f \fIvolume\fP
-sets feep (bell) volume (allowable range: 0-100).
-.TP 8
-.B \-fc \fIcursorFont\fP
-sets default cursor font.
-.TP 8
-.B \-fn \fIfont\fP
-sets the default font.
-.TP 8
-.B \-fp \fIfontPath\fP
-sets the search path for fonts.  This path is a comma separated list
-of directories which the X server searches for font databases.
-See the FONTS section of this manual page for more information and the default
-list.
-.TP 8
-.B \-help
-prints a usage message.
-.TP 8
-.B \-I
-causes all remaining command line arguments to be ignored.
-.TP 8
-.B \-maxbigreqsize \fIsize\fP
-sets the maximum big request to
-.I size
-MB.
-.TP 8
-.B \-nocursor
-disable the display of the pointer cursor.
-.TP 8
-.B \-nolisten \fItrans-type\fP
-disables a transport type.  For example, TCP/IP connections can be disabled
-with
-.BR "\-nolisten tcp" .
-This option may be issued multiple times to disable listening to different
-transport types.
-.TP 8
-.B \-noreset
-prevents a server reset when the last client connection is closed.  This
-overrides a previous
-.B \-terminate
-command line option.
-.TP 8
-.B \-p \fIminutes\fP
-sets screen-saver pattern cycle time in minutes.
-.TP 8
-.B \-pn
-permits the server to continue running if it fails to establish all of
-its well-known sockets (connection points for clients), but
-establishes at least one.  This option is set by default.
-.TP 8
-.B \-nopn
-causes the server to exit if it fails to establish all of its well-known
-sockets (connection points for clients).
-.TP 8
-.B \-r
-turns off auto-repeat.
-.TP 8
-.B r
-turns on auto-repeat.
-.TP 8
-.B -retro
-starts the stipple with the classic stipple and cursor visible.  The default
-is to start with a black root window, and to suppress display of the cursor
-until the first time an application calls XDefineCursor().  For the Xorg
-server, this also sets the default for the DontZap option to FALSE.  For
-kdrive servers, this implies -zap.
-.TP 8
-.B \-s \fIminutes\fP
-sets screen-saver timeout time in minutes.
-.TP 8
-.B \-su
-disables save under support on all screens.
-.TP 8
-.B \-t \fInumber\fP
-sets pointer acceleration threshold in pixels (i.e. after how many pixels
-pointer acceleration should take effect).
-.TP 8
-.B \-terminate
-causes the server to terminate at server reset, instead of continuing to run.
-This overrides a previous
-.B \-noreset
-command line option.
-.TP 8
-.B \-to \fIseconds\fP
-sets default connection timeout in seconds.
-.TP 8
-.B \-tst
-disables all testing extensions (e.g., XTEST, XTrap, XTestExtension1, RECORD).
-.TP 8
-.B tty\fIxx\fP
-ignored, for servers started the ancient way (from init).
-.TP 8
-.B v
-sets video-off screen-saver preference.
-.TP 8
-.B \-v
-sets video-on screen-saver preference.
-.TP 8
-.B \-wm
-forces the default backing-store of all windows to be WhenMapped.  This
-is a backdoor way of getting backing-store to apply to all windows.
-Although all mapped windows will have backing store, the backing store
-attribute value reported by the server for a window will be the last
-value established by a client.  If it has never been set by a client,
-the server will report the default value, NotUseful.  This behavior is
-required by the X protocol, which allows the server to exceed the
-client's backing store expectations but does not provide a way to tell
-the client that it is doing so.
-.TP 8
-.B \-wr
-sets the default root window to solid white instead of the standard root weave
-pattern.
-.TP 8
-.B \-x \fIextension\fP
-loads the specified extension at init.
-This is a no-op for most implementations.
-.TP 8
-.B [+-]xinerama
-enables(+) or disables(-) the XINERAMA extension.  The default state is
-platform and configuration specific.
-.SH SERVER DEPENDENT OPTIONS
-Some X servers accept the following options:
-.TP 8
-.B \-ld \fIkilobytes\fP
-sets the data space limit of the server to the specified number of kilobytes.
-A value of zero makes the data size as large as possible.  The default value
-of \-1 leaves the data space limit unchanged.
-.TP 8
-.B \-lf \fIfiles\fP
-sets the number-of-open-files limit of the server to the specified number.
-A value of zero makes the limit as large as possible.  The default value
-of \-1 leaves the limit unchanged.
-.TP 8
-.B \-ls \fIkilobytes\fP
-sets the stack space limit of the server to the specified number of kilobytes.
-A value of zero makes the stack size as large as possible.  The default value
-of \-1 leaves the stack space limit unchanged.
-.TP 8
-.B \-render 
-.BR default | mono | gray | color
-sets the color allocation policy that will be used by the render extension.
-.RS 8
-.TP 8
-.I default
-selects the default policy defined for the display depth of the X
-server. 
-.TP 8
-.I mono
-don't use any color cell. 
-.TP 8
-.I gray 
-use a gray map of 13 color cells for the X render extension.
-.TP 8
-.I color
-use a color cube of at most 4*4*4 colors (that is 64 color cells).
-.RE
-.TP 8
-.B \-dumbSched
-disables smart scheduling on platforms that support the smart scheduler.
-.TP
-.B \-schedInterval \fIinterval\fP
-sets the smart scheduler's scheduling interval to
-.I interval
-milliseconds.
-.SH XDMCP OPTIONS
-X servers that support XDMCP have the following options.
-See the \fIX Display Manager Control Protocol\fP specification for more
-information.
-.TP 8
-.B \-query \fIhostname\fP
-enables XDMCP and sends Query packets to the specified
-.IR hostname .
-.TP 8
-.B \-broadcast
-enable XDMCP and broadcasts BroadcastQuery packets to the network.  The
-first responding display manager will be chosen for the session.
-.TP 8
-.B \-multicast [\fIaddress\fP [\fIhop count\fP]]
-Enable XDMCP and multicast BroadcastQuery packets to the  network.   
-The first responding display manager is chosen for the session.  If an 
-address is specified, the multicast is sent to that address.  If no 
-address is specified, the multicast is sent to the default XDMCP IPv6 
-multicast group.  If a hop count is specified, it is used as the maximum 
-hop count for the multicast.  If no hop count is specified, the multicast 
-is set to a maximum of 1 hop, to prevent the multicast from being routed 
-beyond the local network.
-.TP 8
-.B \-indirect \fIhostname\fP
-enables XDMCP and send IndirectQuery packets to the specified
-.IR hostname .
-.TP 8
-.B \-port \fIport-number\fP
-uses the specified \fIport-number\fP for XDMCP packets, instead of the
-default.  This option must be specified before any \-query, \-broadcast,
-\-multicast, or \-indirect options.
-.TP 8
-.B \-from \fIlocal-address\fP
-specifies the local address to connect from (useful if the connecting host
-has multiple network interfaces).  The \fIlocal-address\fP may be expressed
-in any form acceptable to the host platform's \fIgethostbyname\fP(3)
-implementation.
-.TP 8
-.B \-once
-causes the server to terminate (rather than reset) when the XDMCP session
-ends.
-.TP 8
-.B \-class \fIdisplay-class\fP
-XDMCP has an additional display qualifier used in resource lookup for
-display-specific options.  This option sets that value, by default it
-is "MIT-Unspecified" (not a very useful value).
-.TP 8
-.B \-cookie \fIxdm-auth-bits\fP
-When testing XDM-AUTHENTICATION-1, a private key is shared between the
-server and the manager.  This option sets the value of that private
-data (not that it is very private, being on the command line!).
-.TP 8
-.B \-displayID \fIdisplay-id\fP
-Yet another XDMCP specific value, this one allows the display manager to
-identify each display so that it can locate the shared key.
-.SH XKEYBOARD OPTIONS
-X servers that support the XKEYBOARD (a.k.a. \*qXKB\*q) extension accept the
-following options.  All layout files specified on the command line must be 
-located in the XKB base directory or a subdirectory, and specified as the
-relative path from the XKB base directory.  The default XKB base directory is
-.IR __projectroot__/lib/X11/xkb .
-.TP 8
-.BR [+-]accessx " [ \fItimeout\fP [ \fItimeout_mask\fP [ \fIfeedback\fP [ \fIoptions_mask\fP ] ] ] ]"
-enables(+) or disables(-) AccessX key sequences.
-.TP 8
-.B \-xkbdir \fIdirectory\fP
-base directory for keyboard layout files.  This option is not available
-for setuid X servers (i.e., when the X server's real and effective uids
-are different).
-.TP 8
-.B \-ardelay \fImilliseconds\fP
-sets the autorepeat delay (length of time in milliseconds that a key must
-be depressed before autorepeat starts).
-.TP 8
-.B \-arinterval \fImilliseconds\fP
-sets the autorepeat interval (length of time in milliseconds that should
-elapse between autorepeat-generated keystrokes).
-.TP 8
-.B \-xkbmap \fIfilename\fP
-loads keyboard description in \fIfilename\fP on server startup.
-.SH "NETWORK CONNECTIONS"
-The X server supports client connections via a platform-dependent subset of
-the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
-and several varieties of SVR4 local connections.  See the DISPLAY
-NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
-specify which transport type clients should try to use.
-.SH GRANTING ACCESS
-The X server implements a platform-dependent subset of the following
-authorization protocols: MIT-MAGIC-COOKIE-1, XDM-AUTHORIZATION-1,
-XDM-AUTHORIZATION-2, SUN-DES-1, and MIT-KERBEROS-5.  See the 
-\fIXsecurity\fP(__miscmansuffix__) manual page for information on the 
-operation of these protocols.
-.PP
-Authorization data required by the above protocols is passed to the
-server in a private file named with the \fB\-auth\fP command line
-option.  Each time the server is about to accept the first connection
-after a reset (or when the server is starting), it reads this file.
-If this file contains any authorization records, the local host is not
-automatically allowed access to the server, and only clients which
-send one of the authorization records contained in the file in the
-connection setup information will be allowed access.  See the
-\fIXau\fP manual page for a description of the binary format of this
-file.  See \fIxauth\fP(1) for maintenance of this file, and distribution
-of its contents to remote hosts.
-.PP
-The X server also uses a host-based access control list for deciding
-whether or not to accept connections from clients on a particular machine.
-If no other authorization mechanism is being used,
-this list initially consists of the host on which the server is running as
-well as any machines listed in the file \fI/etc/X\fBn\fI.hosts\fR, where
-\fBn\fP is the display number of the server.  Each line of the file should
-contain either an Internet hostname (e.g. expo.lcs.mit.edu) or a DECnet
-hostname in double colon format (e.g. hydra::) or a complete name in the format
-\fIfamily\fP:\fIname\fP as described in the \fIxhost\fP(1) manual page.
-There should be no leading or trailing spaces on any lines.  For example:
-.sp
-.in +8
-.nf
-joesworkstation
-corporate.company.com
-star::
-inet:bigcpu
-local:
-.fi
-.in -8
-.PP
-Users can add or remove hosts from this list and enable or disable access
-control using the \fIxhost\fP command from the same machine as the server.
-.PP
-If the X FireWall Proxy (\fIxfwp\fP) is being used without a sitepolicy,
-host-based authorization must be turned on for clients to be able to
-connect to the X server via the \fIxfwp\fP.  If \fIxfwp\fP is run without
-a configuration file and thus no sitepolicy is defined, if \fIxfwp\fP
-is using an X server where xhost + has been run to turn off host-based
-authorization checks, when a client tries to connect to this X server
-via \fIxfwp\fP, the X server will deny the connection.  See \fIxfwp\fP(1)
-for more information about this proxy.
-.PP
-The X protocol intrinsically does not have any notion of window operation
-permissions or place any restrictions on what a client can do; if a program can
-connect to a display, it has full run of the screen.
-X servers that support the SECURITY extension fare better because clients
-can be designated untrusted via the authorization they use to connect; see
-the \fIxauth\fP(1) manual page for details.  Restrictions are imposed
-on untrusted clients that curtail the mischief they can do.  See the SECURITY
-extension specification for a complete list of these restrictions.
-.PP
-Sites that have better
-authentication and authorization systems might wish to make
-use of the hooks in the libraries and the server to provide additional
-security models.
-.SH SIGNALS
-The X server attaches special meaning to the following signals:
-.TP 8
-.I SIGHUP
-This signal causes the server to close all existing connections, free all
-resources, and restore all defaults.  It is sent by the display manager
-whenever the main user's main application (usually an \fIxterm\fP or window
-manager) exits to force the server to clean up and prepare for the next
-user.
-.TP 8
-.I SIGTERM
-This signal causes the server to exit cleanly.
-.TP 8
-.I SIGUSR1
-This signal is used quite differently from either of the above.  When the
-server starts, it checks to see if it has inherited SIGUSR1 as SIG_IGN
-instead of the usual SIG_DFL.  In this case, the server sends a SIGUSR1 to
-its parent process after it has set up the various connection schemes.
-\fIXdm\fP uses this feature to recognize when connecting to the server
-is possible.
-.SH FONTS
-The X server can obtain fonts from directories and/or from font servers.
-The list of directories and font servers
-the X server uses when trying to open a font is controlled
-by the \fIfont path\fP.  
-.LP
-The default font path is
-__default_font_path__ .
-.LP
-A special kind of directory can be specified using the \fBcatalogue\fP:
-prefix. Directories specified this way can contain symlinks pointing to the
-real font directories. See the FONTPATH.D section for details.
-.LP
-The font path can be set with the \fB\-fp\fP option or by \fIxset\fP(1)
-after the server has started.
-.SH "FONTPATH.D"
-You can specify a special kind of font path in the form \fBcatalogue:<dir>\fR.
-The directory specified after the catalogue: prefix will be scanned for symlinks
-and each symlink destination will be added as a local fontfile FPE.
-.PP
-The symlink can be suffixed by attributes such as '\fBunscaled\fR', which
-will be passed through to the underlying fontfile FPE. The only exception is
-the newly introduced '\fBpri\fR' attribute, which will be used for ordering
-the font paths specified by the symlinks.
-
-An example configuration:
-
-.nf
-    75dpi:unscaled:pri=20 \-> /usr/share/X11/fonts/75dpi
-    ghostscript:pri=60 \-> /usr/share/fonts/default/ghostscript
-    misc:unscaled:pri=10 \-> /usr/share/X11/fonts/misc
-    type1:pri=40 \-> /usr/share/X11/fonts/Type1
-    type1:pri=50 \-> /usr/share/fonts/default/Type1
-.fi
-
-This will add /usr/share/X11/fonts/misc as the first FPE with the attribute
-'unscaled', second FPE will be /usr/share/X11/fonts/75dpi, also with
-the attribute unscaled etc. This is functionally equivalent to setting
-the following font path:
-
-.nf
-    /usr/share/X11/fonts/misc:unscaled,
-    /usr/share/X11/fonts/75dpi:unscaled,
-    /usr/share/X11/fonts/Type1,
-    /usr/share/fonts/default/Type1,
-    /usr/share/fonts/default/ghostscript
-.fi
-
-.SH FILES
-.TP 30
-.I /etc/X\fBn\fP.hosts
-Initial access control list for display number \fBn\fP
-.TP 30
-.IR __datadir__/fonts/X11/misc , __datadir__/fonts/X11/75dpi , __datadir__/fonts/X11/100dpi
-Bitmap font directories
-.TP 30
-.IR __datadir__/fonts/X11/TTF , __datadir__/fonts/X11/Type1
-Outline font directories
-.TP 30
-.I /tmp/.X11-unix/X\fBn\fP
-Unix domain socket for display number \fBn\fP
-.TP 30
-.I /usr/adm/X\fBn\fPmsgs
-Error log file for display number \fBn\fP if run from \fIinit\fP(__adminmansuffix__)
-.TP 30
-.I __projectroot__/lib/X11/xdm/xdm-errors
-Default error log file if the server is run from \fIxdm\fP(1)
-.SH "SEE ALSO"
-General information: \fIX\fP(__miscmansuffix__)
-.PP
-Protocols:
-.I "X Window System Protocol,"
-.I "The X Font Service Protocol,"
-.I "X Display Manager Control Protocol"
-.PP
-Fonts: \fIbdftopcf\fP(1), \fImkfontdir\fP(1), \fImkfontscale\fP(1),
-\fIxfs\fP(1), \fIxlsfonts\fP(1), \fIxfontsel\fP(1), \fIxfd\fP(1),
-.I "X Logical Font Description Conventions"
-.PP
-Security: \fIXsecurity\fP(__miscmansuffix__), \fIxauth\fP(1), \fIXau\fP(1), 
-\fIxdm\fP(1), \fIxhost\fP(1), \fIxfwp\fP(1),
-.I "Security Extension Specification"
-.PP
-Starting the server: \fIstartx\fP(1), \fIxdm\fP(1), \fIxinit\fP(1)
-.PP
-Controlling the server once started: \fIxset\fP(1), \fIxsetroot\fP(1),
-\fIxhost\fP(1), \fIxinput\fP(1), \fIxrandr\fP(1)
-.PP
-Server-specific man pages:
-\fIXorg\fP(1), \fIXdmx\fP(1), \fIXephyr\fP(1), \fIXnest\fP(1),
-\fIXvfb\fP(1), \fIXquartz\fP(1), \fIXWin\fP(1).
-.PP
-Server internal documentation:
-.I "Definition of the Porting Layer for the X v11 Sample Server"
-.SH AUTHORS
-The sample server was originally written by Susan Angebranndt, Raymond
-Drewry, Philip Karlton, and Todd Newman, from Digital Equipment
-Corporation, with support from a large cast.  It has since been
-extensively rewritten by Keith Packard and Bob Scheifler, from MIT.
-Dave Wiggins took over post-R5 and made substantial improvements.
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
new file mode 100644
index 0000000..dd08512
--- /dev/null
+++ b/doc/man/Makefile.am
@@ -0,0 +1,20 @@
+# Xserver.man covers options generic to all X servers built in this tree
+# (i.e. those handled in the os/utils.c options processing instead of in
+#  the DDX-level options processing)
+
+appmandir = $(APP_MAN_DIR)
+appman_PRE = Xserver.man
+appman_DATA = $(appman_PRE:man=$(APP_MAN_SUFFIX))
+
+EXTRA_DIST = $(appman_PRE)
+CLEANFILES = $(appman_DATA)
+SUFFIXES = .$(APP_MAN_SUFFIX) .man
+
+# String replacements in MAN_SUBSTS now come from xorg-macros.m4 via configure
+# 's|/,|/, |g' will add a space to help font path formatting
+MAN_SUBSTS += 	-e 's|__datadir__|$(datadir)|g' \
+		-e 's|__default_font_path__|$(COMPILEDDEFAULTFONTPATH)|g' \
+		-e '\|$(COMPILEDDEFAULTFONTPATH)| s|/,|/, |g'
+
+.man.$(APP_MAN_SUFFIX):
+	$(AM_V_GEN)$(SED) $(MAN_SUBSTS) < $< > $@
diff --git a/doc/man/Xserver.man b/doc/man/Xserver.man
new file mode 100644
index 0000000..b725949
--- /dev/null
+++ b/doc/man/Xserver.man
@@ -0,0 +1,584 @@
+.\" $Xorg: Xserver.man,v 1.4 2001/02/09 02:04:07 xorgcvs Exp $
+.\" $XdotOrg: xserver/xorg/doc/Xserver.man.pre,v 1.4 2005/12/23 20:11:12 alanc Exp $
+.\" Copyright 1984 - 1991, 1993, 1994, 1998  The Open Group
+.\"
+.\" Permission to use, copy, modify, distribute, and sell this software and its
+.\" documentation for any purpose is hereby granted without fee, provided that
+.\" the above copyright notice appear in all copies and that both that
+.\" copyright notice and this permission notice appear in supporting
+.\" documentation.
+.\"
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name of The Open Group shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from The Open Group.
+.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.31 2004/01/10 22:27:46 dawes Exp $
+.\" shorthand for double quote that works everywhere.
+.ds q \N'34'
+.TH XSERVER 1 __xorgversion__
+.SH NAME
+Xserver \- X Window System display server
+.SH SYNOPSIS
+.B X
+[option ...]
+.SH DESCRIPTION
+.I X
+is the generic name for the X Window System display server.  It is
+frequently a link or a copy of the appropriate server binary for
+driving the most frequently used server on a given machine.
+.SH "STARTING THE SERVER"
+The X server is usually started from the X Display Manager program
+\fIxdm\fP(1) or a similar display manager program.
+This utility is run from the system boot files and takes care of keeping
+the server running, prompting for usernames and passwords, and starting up
+the user sessions.
+.PP
+Installations that run more than one window system may need to use the
+\fIxinit\fP(1) utility instead of a display manager.  However, \fIxinit\fP is
+to be considered a tool for building startup scripts and is not
+intended for use by end users.  Site administrators are \fBstrongly\fP
+urged to use a display manager, or build other interfaces for novice users.
+.PP
+The X server may also be started directly by the user, though this
+method is usually reserved for testing and is not recommended for
+normal operation.  On some platforms, the user must have special
+permission to start the X server, often because access to certain
+devices (e.g. \fI/dev/mouse\fP) is restricted.
+.PP
+When the X server starts up, it typically takes over the display.  If
+you are running on a workstation whose console is the display, you may
+not be able to log into the console while the server is running.
+.SH OPTIONS
+Many X servers have device-specific command line options.  See the manual
+pages for the individual servers for more details; a list of
+server-specific manual pages is provided in the SEE ALSO section below.
+.PP
+All of the X servers accept the command line options described below.
+Some X servers may have alternative ways of providing the parameters
+described here, but the values provided via the command line options
+should override values specified via other mechanisms.
+.TP 8
+.B :\fIdisplaynumber\fP
+The X server runs as the given \fIdisplaynumber\fP, which by default is 0.
+If multiple X servers are to run simultaneously on a host, each must have
+a unique display number.  See the DISPLAY
+NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
+specify which display number clients should try to use.
+.TP 8
+.B \-a \fInumber\fP
+sets pointer acceleration (i.e. the ratio of how much is reported to how much
+the user actually moved the pointer).
+.TP 8
+.B \-ac
+disables host-based access control mechanisms.  Enables access by any host,
+and permits any host to modify the access control list.
+Use with extreme caution.
+This option exists primarily for running test suites remotely.
+.TP 8
+.B \-audit \fIlevel\fP
+sets the audit trail level.  The default level is 1, meaning only connection
+rejections are reported.  Level 2 additionally reports all successful
+connections and disconnects.  Level 4 enables messages from the
+SECURITY extension, if present, including generation and revocation of
+authorizations and violations of the security policy.
+Level 0 turns off the audit trail.
+Audit lines are sent as standard error output.
+.TP 8
+.B \-auth \fIauthorization-file\fP
+specifies a file which contains a collection of authorization records used
+to authenticate access.  See also the \fIxdm\fP(1) and
+\fIXsecurity\fP(__miscmansuffix__) manual pages.
+.TP 8
+.B \-br
+sets the default root window to solid black instead of the standard root weave
+pattern.   This is the default unless -retro or -wr is specified.
+.TP 8
+.B \-bs
+disables backing store support on all screens.
+.TP 8
+.B \-c
+turns off key-click.
+.TP 8
+.B c \fIvolume\fP
+sets key-click volume (allowable range: 0-100).
+.TP 8
+.B \-cc \fIclass\fP
+sets the visual class for the root window of color screens.
+The class numbers are as specified in the X protocol.
+Not obeyed by all servers.
+.TP 8
+.B \-core
+causes the server to generate a core dump on fatal errors.
+.TP 8
+.B \-deferglyphs \fIwhichfonts\fP
+specifies the types of fonts for which the server should attempt to use
+deferred glyph loading.  \fIwhichfonts\fP can be all (all fonts),
+none (no fonts), or 16 (16 bit fonts only).
+.TP 8
+.B \-dpi \fIresolution\fP
+sets the resolution for all screens, in dots per inch.
+To be used when the server cannot determine the screen size(s) from the
+hardware.
+.TP 8
+.B dpms
+enables DPMS (display power management services), where supported.  The
+default state is platform and configuration specific.
+.TP 8
+.B \-dpms
+disables DPMS (display power management services).  The default state
+is platform and configuration specific.
+.TP 8
+.BI \-extension extensionName
+disables named extension.   If an unknown extension name is specified,
+a list of accepted extension names is printed.
+.TP 8
+.BI \+extension extensionName
+enables named extension.   If an unknown extension name is specified,
+a list of accepted extension names is printed.
+.TP 8
+.B \-f \fIvolume\fP
+sets feep (bell) volume (allowable range: 0-100).
+.TP 8
+.B \-fc \fIcursorFont\fP
+sets default cursor font.
+.TP 8
+.B \-fn \fIfont\fP
+sets the default font.
+.TP 8
+.B \-fp \fIfontPath\fP
+sets the search path for fonts.  This path is a comma separated list
+of directories which the X server searches for font databases.
+See the FONTS section of this manual page for more information and the default
+list.
+.TP 8
+.B \-help
+prints a usage message.
+.TP 8
+.B \-I
+causes all remaining command line arguments to be ignored.
+.TP 8
+.B \-maxbigreqsize \fIsize\fP
+sets the maximum big request to
+.I size
+MB.
+.TP 8
+.B \-nocursor
+disable the display of the pointer cursor.
+.TP 8
+.B \-nolisten \fItrans-type\fP
+disables a transport type.  For example, TCP/IP connections can be disabled
+with
+.BR "\-nolisten tcp" .
+This option may be issued multiple times to disable listening to different
+transport types.
+.TP 8
+.B \-noreset
+prevents a server reset when the last client connection is closed.  This
+overrides a previous
+.B \-terminate
+command line option.
+.TP 8
+.B \-p \fIminutes\fP
+sets screen-saver pattern cycle time in minutes.
+.TP 8
+.B \-pn
+permits the server to continue running if it fails to establish all of
+its well-known sockets (connection points for clients), but
+establishes at least one.  This option is set by default.
+.TP 8
+.B \-nopn
+causes the server to exit if it fails to establish all of its well-known
+sockets (connection points for clients).
+.TP 8
+.B \-r
+turns off auto-repeat.
+.TP 8
+.B r
+turns on auto-repeat.
+.TP 8
+.B -retro
+starts the stipple with the classic stipple and cursor visible.  The default
+is to start with a black root window, and to suppress display of the cursor
+until the first time an application calls XDefineCursor().  For the Xorg
+server, this also sets the default for the DontZap option to FALSE.  For
+kdrive servers, this implies -zap.
+.TP 8
+.B \-s \fIminutes\fP
+sets screen-saver timeout time in minutes.
+.TP 8
+.B \-su
+disables save under support on all screens.
+.TP 8
+.B \-t \fInumber\fP
+sets pointer acceleration threshold in pixels (i.e. after how many pixels
+pointer acceleration should take effect).
+.TP 8
+.B \-terminate
+causes the server to terminate at server reset, instead of continuing to run.
+This overrides a previous
+.B \-noreset
+command line option.
+.TP 8
+.B \-to \fIseconds\fP
+sets default connection timeout in seconds.
+.TP 8
+.B \-tst
+disables all testing extensions (e.g., XTEST, XTrap, XTestExtension1, RECORD).
+.TP 8
+.B tty\fIxx\fP
+ignored, for servers started the ancient way (from init).
+.TP 8
+.B v
+sets video-off screen-saver preference.
+.TP 8
+.B \-v
+sets video-on screen-saver preference.
+.TP 8
+.B \-wm
+forces the default backing-store of all windows to be WhenMapped.  This
+is a backdoor way of getting backing-store to apply to all windows.
+Although all mapped windows will have backing store, the backing store
+attribute value reported by the server for a window will be the last
+value established by a client.  If it has never been set by a client,
+the server will report the default value, NotUseful.  This behavior is
+required by the X protocol, which allows the server to exceed the
+client's backing store expectations but does not provide a way to tell
+the client that it is doing so.
+.TP 8
+.B \-wr
+sets the default root window to solid white instead of the standard root weave
+pattern.
+.TP 8
+.B \-x \fIextension\fP
+loads the specified extension at init.
+This is a no-op for most implementations.
+.TP 8
+.B [+-]xinerama
+enables(+) or disables(-) the XINERAMA extension.  The default state is
+platform and configuration specific.
+.SH SERVER DEPENDENT OPTIONS
+Some X servers accept the following options:
+.TP 8
+.B \-ld \fIkilobytes\fP
+sets the data space limit of the server to the specified number of kilobytes.
+A value of zero makes the data size as large as possible.  The default value
+of \-1 leaves the data space limit unchanged.
+.TP 8
+.B \-lf \fIfiles\fP
+sets the number-of-open-files limit of the server to the specified number.
+A value of zero makes the limit as large as possible.  The default value
+of \-1 leaves the limit unchanged.
+.TP 8
+.B \-ls \fIkilobytes\fP
+sets the stack space limit of the server to the specified number of kilobytes.
+A value of zero makes the stack size as large as possible.  The default value
+of \-1 leaves the stack space limit unchanged.
+.TP 8
+.B \-render
+.BR default | mono | gray | color
+sets the color allocation policy that will be used by the render extension.
+.RS 8
+.TP 8
+.I default
+selects the default policy defined for the display depth of the X
+server.
+.TP 8
+.I mono
+don't use any color cell.
+.TP 8
+.I gray
+use a gray map of 13 color cells for the X render extension.
+.TP 8
+.I color
+use a color cube of at most 4*4*4 colors (that is 64 color cells).
+.RE
+.TP 8
+.B \-dumbSched
+disables smart scheduling on platforms that support the smart scheduler.
+.TP
+.B \-schedInterval \fIinterval\fP
+sets the smart scheduler's scheduling interval to
+.I interval
+milliseconds.
+.SH XDMCP OPTIONS
+X servers that support XDMCP have the following options.
+See the \fIX Display Manager Control Protocol\fP specification for more
+information.
+.TP 8
+.B \-query \fIhostname\fP
+enables XDMCP and sends Query packets to the specified
+.IR hostname .
+.TP 8
+.B \-broadcast
+enable XDMCP and broadcasts BroadcastQuery packets to the network.  The
+first responding display manager will be chosen for the session.
+.TP 8
+.B \-multicast [\fIaddress\fP [\fIhop count\fP]]
+Enable XDMCP and multicast BroadcastQuery packets to the  network.
+The first responding display manager is chosen for the session.  If an
+address is specified, the multicast is sent to that address.  If no
+address is specified, the multicast is sent to the default XDMCP IPv6
+multicast group.  If a hop count is specified, it is used as the maximum
+hop count for the multicast.  If no hop count is specified, the multicast
+is set to a maximum of 1 hop, to prevent the multicast from being routed
+beyond the local network.
+.TP 8
+.B \-indirect \fIhostname\fP
+enables XDMCP and send IndirectQuery packets to the specified
+.IR hostname .
+.TP 8
+.B \-port \fIport-number\fP
+uses the specified \fIport-number\fP for XDMCP packets, instead of the
+default.  This option must be specified before any \-query, \-broadcast,
+\-multicast, or \-indirect options.
+.TP 8
+.B \-from \fIlocal-address\fP
+specifies the local address to connect from (useful if the connecting host
+has multiple network interfaces).  The \fIlocal-address\fP may be expressed
+in any form acceptable to the host platform's \fIgethostbyname\fP(3)
+implementation.
+.TP 8
+.B \-once
+causes the server to terminate (rather than reset) when the XDMCP session
+ends.
+.TP 8
+.B \-class \fIdisplay-class\fP
+XDMCP has an additional display qualifier used in resource lookup for
+display-specific options.  This option sets that value, by default it
+is "MIT-Unspecified" (not a very useful value).
+.TP 8
+.B \-cookie \fIxdm-auth-bits\fP
+When testing XDM-AUTHENTICATION-1, a private key is shared between the
+server and the manager.  This option sets the value of that private
+data (not that it is very private, being on the command line!).
+.TP 8
+.B \-displayID \fIdisplay-id\fP
+Yet another XDMCP specific value, this one allows the display manager to
+identify each display so that it can locate the shared key.
+.SH XKEYBOARD OPTIONS
+X servers that support the XKEYBOARD (a.k.a. \*qXKB\*q) extension accept the
+following options.  All layout files specified on the command line must be
+located in the XKB base directory or a subdirectory, and specified as the
+relative path from the XKB base directory.  The default XKB base directory is
+.IR __projectroot__/lib/X11/xkb .
+.TP 8
+.BR [+-]accessx " [ \fItimeout\fP [ \fItimeout_mask\fP [ \fIfeedback\fP [ \fIoptions_mask\fP ] ] ] ]"
+enables(+) or disables(-) AccessX key sequences.
+.TP 8
+.B \-xkbdir \fIdirectory\fP
+base directory for keyboard layout files.  This option is not available
+for setuid X servers (i.e., when the X server's real and effective uids
+are different).
+.TP 8
+.B \-ardelay \fImilliseconds\fP
+sets the autorepeat delay (length of time in milliseconds that a key must
+be depressed before autorepeat starts).
+.TP 8
+.B \-arinterval \fImilliseconds\fP
+sets the autorepeat interval (length of time in milliseconds that should
+elapse between autorepeat-generated keystrokes).
+.TP 8
+.B \-xkbmap \fIfilename\fP
+loads keyboard description in \fIfilename\fP on server startup.
+.SH "NETWORK CONNECTIONS"
+The X server supports client connections via a platform-dependent subset of
+the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
+and several varieties of SVR4 local connections.  See the DISPLAY
+NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
+specify which transport type clients should try to use.
+.SH GRANTING ACCESS
+The X server implements a platform-dependent subset of the following
+authorization protocols: MIT-MAGIC-COOKIE-1, XDM-AUTHORIZATION-1,
+XDM-AUTHORIZATION-2, SUN-DES-1, and MIT-KERBEROS-5.  See the
+\fIXsecurity\fP(__miscmansuffix__) manual page for information on the
+operation of these protocols.
+.PP
+Authorization data required by the above protocols is passed to the
+server in a private file named with the \fB\-auth\fP command line
+option.  Each time the server is about to accept the first connection
+after a reset (or when the server is starting), it reads this file.
+If this file contains any authorization records, the local host is not
+automatically allowed access to the server, and only clients which
+send one of the authorization records contained in the file in the
+connection setup information will be allowed access.  See the
+\fIXau\fP manual page for a description of the binary format of this
+file.  See \fIxauth\fP(1) for maintenance of this file, and distribution
+of its contents to remote hosts.
+.PP
+The X server also uses a host-based access control list for deciding
+whether or not to accept connections from clients on a particular machine.
+If no other authorization mechanism is being used,
+this list initially consists of the host on which the server is running as
+well as any machines listed in the file \fI/etc/X\fBn\fI.hosts\fR, where
+\fBn\fP is the display number of the server.  Each line of the file should
+contain either an Internet hostname (e.g. expo.lcs.mit.edu) or a DECnet
+hostname in double colon format (e.g. hydra::) or a complete name in the format
+\fIfamily\fP:\fIname\fP as described in the \fIxhost\fP(1) manual page.
+There should be no leading or trailing spaces on any lines.  For example:
+.sp
+.in +8
+.nf
+joesworkstation
+corporate.company.com
+star::
+inet:bigcpu
+local:
+.fi
+.in -8
+.PP
+Users can add or remove hosts from this list and enable or disable access
+control using the \fIxhost\fP command from the same machine as the server.
+.PP
+If the X FireWall Proxy (\fIxfwp\fP) is being used without a sitepolicy,
+host-based authorization must be turned on for clients to be able to
+connect to the X server via the \fIxfwp\fP.  If \fIxfwp\fP is run without
+a configuration file and thus no sitepolicy is defined, if \fIxfwp\fP
+is using an X server where xhost + has been run to turn off host-based
+authorization checks, when a client tries to connect to this X server
+via \fIxfwp\fP, the X server will deny the connection.  See \fIxfwp\fP(1)
+for more information about this proxy.
+.PP
+The X protocol intrinsically does not have any notion of window operation
+permissions or place any restrictions on what a client can do; if a program can
+connect to a display, it has full run of the screen.
+X servers that support the SECURITY extension fare better because clients
+can be designated untrusted via the authorization they use to connect; see
+the \fIxauth\fP(1) manual page for details.  Restrictions are imposed
+on untrusted clients that curtail the mischief they can do.  See the SECURITY
+extension specification for a complete list of these restrictions.
+.PP
+Sites that have better
+authentication and authorization systems might wish to make
+use of the hooks in the libraries and the server to provide additional
+security models.
+.SH SIGNALS
+The X server attaches special meaning to the following signals:
+.TP 8
+.I SIGHUP
+This signal causes the server to close all existing connections, free all
+resources, and restore all defaults.  It is sent by the display manager
+whenever the main user's main application (usually an \fIxterm\fP or window
+manager) exits to force the server to clean up and prepare for the next
+user.
+.TP 8
+.I SIGTERM
+This signal causes the server to exit cleanly.
+.TP 8
+.I SIGUSR1
+This signal is used quite differently from either of the above.  When the
+server starts, it checks to see if it has inherited SIGUSR1 as SIG_IGN
+instead of the usual SIG_DFL.  In this case, the server sends a SIGUSR1 to
+its parent process after it has set up the various connection schemes.
+\fIXdm\fP uses this feature to recognize when connecting to the server
+is possible.
+.SH FONTS
+The X server can obtain fonts from directories and/or from font servers.
+The list of directories and font servers
+the X server uses when trying to open a font is controlled
+by the \fIfont path\fP.
+.LP
+The default font path is
+__default_font_path__ .
+.LP
+A special kind of directory can be specified using the \fBcatalogue\fP:
+prefix. Directories specified this way can contain symlinks pointing to the
+real font directories. See the FONTPATH.D section for details.
+.LP
+The font path can be set with the \fB\-fp\fP option or by \fIxset\fP(1)
+after the server has started.
+.SH "FONTPATH.D"
+You can specify a special kind of font path in the form \fBcatalogue:<dir>\fR.
+The directory specified after the catalogue: prefix will be scanned for symlinks
+and each symlink destination will be added as a local fontfile FPE.
+.PP
+The symlink can be suffixed by attributes such as '\fBunscaled\fR', which
+will be passed through to the underlying fontfile FPE. The only exception is
+the newly introduced '\fBpri\fR' attribute, which will be used for ordering
+the font paths specified by the symlinks.
+
+An example configuration:
+
+.nf
+    75dpi:unscaled:pri=20 \-> /usr/share/X11/fonts/75dpi
+    ghostscript:pri=60 \-> /usr/share/fonts/default/ghostscript
+    misc:unscaled:pri=10 \-> /usr/share/X11/fonts/misc
+    type1:pri=40 \-> /usr/share/X11/fonts/Type1
+    type1:pri=50 \-> /usr/share/fonts/default/Type1
+.fi
+
+This will add /usr/share/X11/fonts/misc as the first FPE with the attribute
+'unscaled', second FPE will be /usr/share/X11/fonts/75dpi, also with
+the attribute unscaled etc. This is functionally equivalent to setting
+the following font path:
+
+.nf
+    /usr/share/X11/fonts/misc:unscaled,
+    /usr/share/X11/fonts/75dpi:unscaled,
+    /usr/share/X11/fonts/Type1,
+    /usr/share/fonts/default/Type1,
+    /usr/share/fonts/default/ghostscript
+.fi
+
+.SH FILES
+.TP 30
+.I /etc/X\fBn\fP.hosts
+Initial access control list for display number \fBn\fP
+.TP 30
+.IR __datadir__/fonts/X11/misc , __datadir__/fonts/X11/75dpi , __datadir__/fonts/X11/100dpi
+Bitmap font directories
+.TP 30
+.IR __datadir__/fonts/X11/TTF , __datadir__/fonts/X11/Type1
+Outline font directories
+.TP 30
+.I /tmp/.X11-unix/X\fBn\fP
+Unix domain socket for display number \fBn\fP
+.TP 30
+.I /usr/adm/X\fBn\fPmsgs
+Error log file for display number \fBn\fP if run from \fIinit\fP(__adminmansuffix__)
+.TP 30
+.I __projectroot__/lib/X11/xdm/xdm-errors
+Default error log file if the server is run from \fIxdm\fP(1)
+.SH "SEE ALSO"
+General information: \fIX\fP(__miscmansuffix__)
+.PP
+Protocols:
+.I "X Window System Protocol,"
+.I "The X Font Service Protocol,"
+.I "X Display Manager Control Protocol"
+.PP
+Fonts: \fIbdftopcf\fP(1), \fImkfontdir\fP(1), \fImkfontscale\fP(1),
+\fIxfs\fP(1), \fIxlsfonts\fP(1), \fIxfontsel\fP(1), \fIxfd\fP(1),
+.I "X Logical Font Description Conventions"
+.PP
+Security: \fIXsecurity\fP(__miscmansuffix__), \fIxauth\fP(1), \fIXau\fP(1),
+\fIxdm\fP(1), \fIxhost\fP(1), \fIxfwp\fP(1),
+.I "Security Extension Specification"
+.PP
+Starting the server: \fIstartx\fP(1), \fIxdm\fP(1), \fIxinit\fP(1)
+.PP
+Controlling the server once started: \fIxset\fP(1), \fIxsetroot\fP(1),
+\fIxhost\fP(1), \fIxinput\fP(1), \fIxrandr\fP(1)
+.PP
+Server-specific man pages:
+\fIXorg\fP(1), \fIXdmx\fP(1), \fIXephyr\fP(1), \fIXnest\fP(1),
+\fIXvfb\fP(1), \fIXquartz\fP(1), \fIXWin\fP(1).
+.PP
+Server internal documentation:
+.I "Definition of the Porting Layer for the X v11 Sample Server"
+.SH AUTHORS
+The sample server was originally written by Susan Angebranndt, Raymond
+Drewry, Philip Karlton, and Todd Newman, from Digital Equipment
+Corporation, with support from a large cast.  It has since been
+extensively rewritten by Keith Packard and Bob Scheifler, from MIT.
+Dave Wiggins took over post-R5 and made substantial improvements.
commit c4a7a5917ab828d4a0bd825a98e4d641bcb378f1
Merge: 5de312a... 714b68d...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 19:28:07 2010 -0800

    Merge remote branch 'jeremyhu/master'

commit 5de312a60d8227ed670849ecf888ea878aa81430
Merge: 311cad3... 8f42b2b...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 6 19:22:52 2010 -0800

    Merge remote branch 'alanc/master'

commit 8127c83c81bf64369a8ba2999088226d14e0b128
Author: James Jones <jajones at nvidia.com>
Date:   Mon Dec 6 12:14:01 2010 -0800

    Expose Sync Fence Object protocol
    
    Add the new protocol handlers for XSync 3.1 to the
    dispatch tables and report support for Sync protocol
    version 3.1.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index 8361620..ce00755 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -2165,6 +2165,18 @@ ProcSyncDispatch(ClientPtr client)
 	return ProcSyncSetPriority(client);
       case X_SyncGetPriority:
 	return ProcSyncGetPriority(client);
+      case X_SyncCreateFence:
+	return ProcSyncCreateFence(client);
+      case X_SyncTriggerFence:
+	return ProcSyncTriggerFence(client);
+      case X_SyncResetFence:
+	return ProcSyncResetFence(client);
+      case X_SyncDestroyFence:
+	return ProcSyncDestroyFence(client);
+      case X_SyncQueryFence:
+	return ProcSyncQueryFence(client);
+      case X_SyncAwaitFence:
+	return ProcSyncAwaitFence(client);
       default:
 	return BadRequest;
     }
@@ -2477,6 +2489,18 @@ SProcSyncDispatch(ClientPtr client)
 	return SProcSyncSetPriority(client);
       case X_SyncGetPriority:
 	return SProcSyncGetPriority(client);
+      case X_SyncCreateFence:
+	return SProcSyncCreateFence(client);
+      case X_SyncTriggerFence:
+	return SProcSyncTriggerFence(client);
+      case X_SyncResetFence:
+	return SProcSyncResetFence(client);
+      case X_SyncDestroyFence:
+	return SProcSyncDestroyFence(client);
+      case X_SyncQueryFence:
+	return SProcSyncQueryFence(client);
+      case X_SyncAwaitFence:
+	return SProcSyncAwaitFence(client);
       default:
 	return BadRequest;
     }
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index ce28797..1d33bdd 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -97,7 +97,7 @@
 
 /* Sync */
 #define SERVER_SYNC_MAJOR_VERSION		3
-#define SERVER_SYNC_MINOR_VERSION		0
+#define SERVER_SYNC_MINOR_VERSION		1
 
 /* Windows WM */
 #define SERVER_WINDOWSWM_MAJOR_VERSION		1
commit 9c0c7cc9a7adf230b5eee0b4166f9e17e07a088b
Author: James Jones <jajones at nvidia.com>
Date:   Mon Dec 6 13:10:42 2010 -0800

    Add XSyncAwaitFence() handler
    
    -Add the actual ProcSyncAwaitFence() dispatch func
    
    -Add support for fence sync triggers.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index 1e8dadf..8361620 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -147,6 +147,9 @@ SyncDeleteTriggerFromSyncObject(SyncTrigger *pTrigger)
 
 	if (IsSystemCounter(pCounter))
 	    SyncComputeBracketValues(pCounter);
+    } else if (SYNC_FENCE == pTrigger->pSync->type) {
+	SyncFence* pFence = (SyncFence*) pTrigger->pSync;
+	pFence->funcs.DeleteTrigger(pTrigger);
     }
 }
 
@@ -180,23 +183,27 @@ SyncAddTriggerToSyncObject(SyncTrigger *pTrigger)
 
 	if (IsSystemCounter(pCounter))
 	    SyncComputeBracketValues(pCounter);
+    } else if (SYNC_FENCE == pTrigger->pSync->type) {
+	SyncFence* pFence = (SyncFence*) pTrigger->pSync;
+	pFence->funcs.AddTrigger(pTrigger);
     }
 
     return Success;
 }
 
 
-/*  Below are four possible functions that can be plugged into
- *  pTrigger->CheckTrigger, corresponding to the four possible
- *  test-types.  These functions are called after the counter's
- *  value changes but are also passed the old counter value
- *  so they can inspect both the old and new values.
- *  (PositiveTransition and NegativeTransition need to see both
- *  pieces of information.)  These functions return the truth value
- *  of the trigger.
+/*  Below are five possible functions that can be plugged into
+ *  pTrigger->CheckTrigger for counter sync objects, corresponding to
+ *  the four possible test-types, and the one possible function that
+ *  can be plugged into pTrigger->CheckTrigger for fence sync objects.
+ *  These functions are called after the sync object's state changes
+ *  but are also passed the old state so they can inspect both the old
+ *  and new values.  (PositiveTransition and NegativeTransition need to
+ *  see both pieces of information.)  These functions return the truth
+ *  value of the trigger.
  *
- *  All of them include the condition pTrigger->pCounter == NULL.
- *  This is because the spec says that a trigger with a counter value
+ *  All of them include the condition pTrigger->pSync == NULL.
+ *  This is because the spec says that a trigger with a sync value
  *  of None is always TRUE.
  */
 
@@ -250,6 +257,16 @@ SyncCheckTriggerNegativeTransition(SyncTrigger *pTrigger, CARD64 oldval)
 	     XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value)));
 }
 
+static Bool
+SyncCheckTriggerFence(SyncTrigger *pTrigger, CARD64 unused)
+{
+    SyncFence* pFence = (SyncFence*) pTrigger->pSync;
+    (void)unused;
+
+    return (pFence == NULL ||
+	    pFence->funcs.CheckTriggered(pFence));
+}
+
 static int
 SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject,
 		RESTYPE resType, Mask changes)
@@ -302,30 +319,38 @@ SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject,
 
     if (changes & XSyncCATestType)
     {
-	if (pTrigger->test_type != XSyncPositiveTransition &&
-	    pTrigger->test_type != XSyncNegativeTransition &&
-	    pTrigger->test_type != XSyncPositiveComparison &&
-	    pTrigger->test_type != XSyncNegativeComparison)
+
+	if (SYNC_FENCE == pSync->type)
 	{
-	    client->errorValue = pTrigger->test_type;
-	    return BadValue;
+	    pTrigger->CheckTrigger = SyncCheckTriggerFence;
 	}
-	/* select appropriate CheckTrigger function */
-
-	switch (pTrigger->test_type)
+	else
 	{
-	case XSyncPositiveTransition:
-	    pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition;
-	    break;
-	case XSyncNegativeTransition:
-	    pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition;
-	    break;
-	case XSyncPositiveComparison:
-	    pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison;
-	    break;
-	case XSyncNegativeComparison:
-	    pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison;
-	    break;
+	    if (pTrigger->test_type != XSyncPositiveTransition &&
+		pTrigger->test_type != XSyncNegativeTransition &&
+		pTrigger->test_type != XSyncPositiveComparison &&
+		pTrigger->test_type != XSyncNegativeComparison)
+	    {
+		client->errorValue = pTrigger->test_type;
+		return BadValue;
+	    }
+	    /* select appropriate CheckTrigger function */
+
+	    switch (pTrigger->test_type)
+	    {
+	    case XSyncPositiveTransition:
+		pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition;
+		break;
+	    case XSyncNegativeTransition:
+		pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition;
+		break;
+	    case XSyncPositiveComparison:
+		pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison;
+		break;
+	    case XSyncNegativeComparison:
+		pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison;
+		break;
+	    }
 	}
     }
 
@@ -2019,6 +2044,89 @@ ProcSyncQueryFence(ClientPtr client)
     return client->noClientException;
 }
 
+static int
+ProcSyncAwaitFence(ClientPtr client)
+{
+    REQUEST(xSyncAwaitFenceReq);
+    SyncAwaitUnion *pAwaitUnion;
+    SyncAwait *pAwait;
+    /* Use CARD32 rather than XSyncFence because XIDs are hard-coded to
+     * CARD32 in protocol definitions */
+    CARD32 *pProtocolFences;
+    int status;
+    int len;
+    int items;
+    int i;
+
+    REQUEST_AT_LEAST_SIZE(xSyncAwaitFenceReq);
+
+    len = client->req_len << 2;
+    len -= sz_xSyncAwaitFenceReq;
+    items = len / sizeof(CARD32);
+
+    if (items * sizeof(CARD32) != len)
+    {
+	return BadLength;
+    }
+    if (items == 0)
+    {
+	client->errorValue = items; /* XXX protocol change */
+	return BadValue;
+    }
+
+    if (!(pAwaitUnion = SyncAwaitPrologue(client, items)))
+	return BadAlloc;
+
+    /* don't need to do any more memory allocation for this request! */
+
+    pProtocolFences = (CARD32 *) & stuff[1];
+
+    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
+    for (i = 0; i < items; i++, pProtocolFences++, pAwait++)
+    {
+	if (*pProtocolFences == None) /* XXX protocol change */
+	{
+	    /*  this should take care of removing any triggers created by
+	     *  this request that have already been registered on sync objects
+	     */
+	    FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
+	    client->errorValue = *pProtocolFences;
+	    return SyncErrorBase + XSyncBadCounter;
+	}
+
+	pAwait->trigger.pSync = NULL;
+	/* Provide acceptable values for these unused fields to
+	 * satisfy SyncInitTrigger's validation logic
+	 */
+	pAwait->trigger.value_type = XSyncAbsolute;
+	XSyncIntToValue(&pAwait->trigger.wait_value, 0);
+	pAwait->trigger.test_type = 0;
+
+	status = SyncInitTrigger(client, &pAwait->trigger,
+				 *pProtocolFences, RTFence,
+				 XSyncCAAllTrigger);
+	if (status != Success)
+	{
+	    /*  this should take care of removing any triggers created by
+	     *  this request that have already been registered on sync objects
+	     */
+	    FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
+	    return status;
+	}
+	/* this is not a mistake -- same function works for both cases */
+	pAwait->trigger.TriggerFired = SyncAwaitTriggerFired;
+	pAwait->trigger.CounterDestroyed = SyncAwaitTriggerFired;
+	/* event_threshold is unused for fence syncs */
+	XSyncIntToValue(&pAwait->event_threshold, 0);
+	pAwait->pHeader = &pAwaitUnion->header;
+	pAwaitUnion->header.num_waitconditions++;
+    }
+
+    SyncAwaitEpilogue(client, items, pAwaitUnion);
+
+    return client->noClientException;
+}
+
 /*
  * ** Given an extension request, call the appropriate request procedure
  */
@@ -2322,6 +2430,19 @@ SProcSyncQueryFence(ClientPtr client)
 }
 
 static int
+SProcSyncAwaitFence(ClientPtr client)
+{
+    REQUEST(xSyncAwaitFenceReq);
+    char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSyncAwaitFenceReq);
+    SwapRestL(stuff);
+
+    return ProcSyncAwaitFence(client);
+}
+
+static int
 SProcSyncDispatch(ClientPtr client)
 {
     REQUEST(xReq);
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index aa7dfb9..7ca1fba 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -117,7 +117,6 @@ typedef union {
     SyncAwait	    await;
 } SyncAwaitUnion;
 
-
 extern pointer SyncCreateSystemCounter(
     char *	/* name */,
     CARD64  	/* inital_value */,
commit 397dfd9f87e1cdf105d10a789a97230f4f0d204e
Author: James Jones <jajones at nvidia.com>
Date:   Fri Jun 25 17:59:14 2010 -0700

    Create/Destroy/Trigger/Reset/Query Fence Sync objs
    
    Initial server side implementation of fence sync
    objects.  Allows creation, management, and state
    queries of binary state objects.  Currently they
    are not very useful as there is no way to wait for
    them efficiently.
    
    The basic trigger operation added here triggers
    relative to a given X screen's rendering operations.
    To perform this operation, fence sync objects must
    be tied to a screen.  As Aaron Plattner pointed out,
    screens are identified but a drawable in X protocol,
    so a drawable argument is included in
    XSyncCreateFence().  The screen also could have been
    specified as part of the trigger operation.  However,
    it is also desireable to associate a screen with
    fence sync objects at creation time so that the
    associated screen's driver can allocate any HW-
    specific resources needed by the fence object up
    front.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index e444fd0..b6c95cb 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -15,7 +15,7 @@ INCLUDES = -I$(top_srcdir)/hw/xfree86/dixmods/extmod
 AM_CFLAGS = $(DIX_CFLAGS)
 
 if XORG
-sdk_HEADERS = xvdix.h xvmcext.h geext.h geint.h shmint.h
+sdk_HEADERS = xvdix.h xvmcext.h geext.h geint.h shmint.h syncsdk.h
 endif
 
 # Sources always included in libXextbuiltin.la & libXext.la
@@ -26,6 +26,7 @@ BUILTIN_SRCS =			\
 	sleepuntil.c		\
 	sleepuntil.h		\
 	sync.c			\
+	syncsdk.h		\
 	syncsrv.h		\
 	xcmisc.c		\
 	xtest.c
diff --git a/Xext/sync.c b/Xext/sync.c
index 2615c27..1e8dadf 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -63,10 +63,12 @@ PERFORMANCE OF THIS SOFTWARE.
 #include "os.h"
 #include "extnsionst.h"
 #include "dixstruct.h"
+#include "pixmapstr.h"
 #include "resource.h"
 #include "opaque.h"
 #include <X11/extensions/syncproto.h>
 #include "syncsrv.h"
+#include "syncsdk.h"
 #include "protocol-versions.h"
 
 #include <stdio.h>
@@ -85,6 +87,7 @@ static RESTYPE  RTCounter = 0;
 static RESTYPE  RTAwait;
 static RESTYPE  RTAlarm;
 static RESTYPE  RTAlarmClient;
+static RESTYPE  RTFence;
 static int SyncNumSystemCounters = 0;
 static SyncCounter **SysCounterList = NULL;
 
@@ -850,23 +853,34 @@ SyncCreate(ClientPtr client, XID id, unsigned char type)
 {
     SyncObject *pSync;
     RESTYPE resType;
-    unsigned long syncSize;
 
     switch (type) {
     case SYNC_COUNTER:
 	resType = RTCounter;
-	syncSize = sizeof(SyncCounter);
+	pSync = malloc(sizeof(SyncCounter));
+	break;
+    case SYNC_FENCE:
+	resType = RTFence;
+	pSync = dixAllocateObjectWithPrivates(SyncFence,
+					      PRIVATE_SYNC_FENCE);
 	break;
     default:
 	return NULL;
     }
 
-    if (!(pSync = (SyncObject *)malloc(syncSize)))
+    if (!pSync)
 	return NULL;
 
     if (!AddResource(id, resType, (pointer) pSync))
     {
-	free(pSync);
+	switch (type) {
+	case SYNC_FENCE:
+	    dixFreeObjectWithPrivates((SyncFence *)pSync, PRIVATE_SYNC_FENCE);
+	    break;
+	default:
+	    free(pSync);
+	}
+
 	return NULL;
     }
 
@@ -1866,6 +1880,145 @@ ProcSyncDestroyAlarm(ClientPtr client)
     return Success;
 }
 
+static int
+ProcSyncCreateFence(ClientPtr client)
+{
+    REQUEST(xSyncCreateFenceReq);
+    DrawablePtr pDraw;
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncCreateFenceReq);
+
+    rc = dixLookupDrawable(&pDraw, stuff->d, client, M_ANY, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    LEGAL_NEW_RESOURCE(stuff->fid, client);
+
+    if (!(pFence = (SyncFence *)SyncCreate(client,
+					   stuff->fid,
+					   SYNC_FENCE)))
+	return BadAlloc;
+
+    miSyncInitFence(pDraw->pScreen, pFence, stuff->initially_triggered);
+
+    return client->noClientException;
+}
+
+static int
+FreeFence(void *obj, XID id)
+{
+    SyncFence *pFence = (SyncFence *) obj;
+
+    miSyncDestroyFence(pFence);
+
+    return Success;
+}
+
+int SyncVerifyFence(SyncFence **ppSyncFence, XID fid,
+		    ClientPtr client, Mask mode)
+{
+    int rc = dixLookupResourceByType((pointer *)ppSyncFence, fid, RTFence,
+				     client, mode);
+
+    if (rc != Success)
+	client->errorValue = fid;
+
+    return rc;
+}
+
+static int
+ProcSyncTriggerFence(ClientPtr client)
+{
+    REQUEST(xSyncTriggerFenceReq);
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncTriggerFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence,
+				 client, DixWriteAccess);
+    if (rc != Success)
+	return rc;
+
+    miSyncTriggerFence(pFence);
+
+    return client->noClientException;
+}
+
+static int
+ProcSyncResetFence(ClientPtr client)
+{
+    REQUEST(xSyncResetFenceReq);
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncResetFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence,
+				 client, DixWriteAccess);
+    if (rc != Success)
+	return rc;
+
+    if (pFence->funcs.CheckTriggered(pFence) != TRUE)
+	return BadMatch;
+
+    pFence->funcs.Reset(pFence);
+
+    return client->noClientException;
+}
+
+static int
+ProcSyncDestroyFence(ClientPtr client)
+{
+    REQUEST(xSyncDestroyFenceReq);
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncDestroyFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence,
+				 client, DixDestroyAccess);
+    if (rc != Success)
+	return rc;
+
+    FreeResource(stuff->fid, RT_NONE);
+    return client->noClientException;
+}
+
+static int
+ProcSyncQueryFence(ClientPtr client)
+{
+    REQUEST(xSyncQueryFenceReq);
+    xSyncQueryFenceReply rep;
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncQueryFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid,
+				 RTFence, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    rep.triggered = pFence->funcs.CheckTriggered(pFence);
+
+    if (client->swapped)
+    {
+	char n;
+	swaps(&rep.sequenceNumber, n);
+	swapl(&rep.length, n);
+    }
+
+    WriteToClient(client, sizeof(xSyncQueryFenceReply), (char *) &rep);
+    return client->noClientException;
+}
+
 /*
  * ** Given an extension request, call the appropriate request procedure
  */
@@ -2103,6 +2256,70 @@ SProcSyncGetPriority(ClientPtr client)
     return ProcSyncGetPriority(client);
 }
 
+static int
+SProcSyncCreateFence(ClientPtr client)
+{
+    REQUEST(xSyncCreateFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncCreateFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncCreateFence(client);
+}
+
+static int
+SProcSyncTriggerFence(ClientPtr client)
+{
+    REQUEST(xSyncTriggerFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncTriggerFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncTriggerFence(client);
+}
+
+static int
+SProcSyncResetFence(ClientPtr client)
+{
+    REQUEST(xSyncResetFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncResetFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncResetFence(client);
+}
+
+static int
+SProcSyncDestroyFence(ClientPtr client)
+{
+    REQUEST(xSyncDestroyFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncDestroyFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncDestroyFence(client);
+}
+
+static int
+SProcSyncQueryFence(ClientPtr client)
+{
+    REQUEST(xSyncQueryFenceReq);
+    char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncQueryFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncQueryFence(client);
+}
 
 static int
 SProcSyncDispatch(ClientPtr client)
@@ -2210,6 +2427,7 @@ SyncExtensionInit(void)
     }
     RTAlarm = CreateNewResourceType(FreeAlarm, "SyncAlarm");
     RTAwait = CreateNewResourceType(FreeAwait, "SyncAwait");
+    RTFence = CreateNewResourceType(FreeFence, "SyncFence");
     if (RTAwait)
 	RTAwait |= RC_NEVERRETAIN;
     RTAlarmClient = CreateNewResourceType(FreeAlarmClient, "SyncAlarmClient");
@@ -2236,6 +2454,7 @@ SyncExtensionInit(void)
 
     SetResourceTypeErrorValue(RTCounter, SyncErrorBase + XSyncBadCounter);
     SetResourceTypeErrorValue(RTAlarm, SyncErrorBase + XSyncBadAlarm);
+    SetResourceTypeErrorValue(RTFence, SyncErrorBase + XSyncBadFence);
 
     /*
      * Although SERVERTIME is implemented by the OS layer, we initialise it
diff --git a/Xext/syncsdk.h b/Xext/syncsdk.h
new file mode 100644
index 0000000..a72c585
--- /dev/null
+++ b/Xext/syncsdk.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2010 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SYNCSDK_H_
+#define _SYNCSDK_H_
+
+#include "misync.h"
+
+extern _X_EXPORT int
+SyncVerifyFence(SyncFence **ppFence, XID fid, ClientPtr client, Mask mode);
+
+#define VERIFY_SYNC_FENCE(pFence, fid, client, mode)			\
+    do {								\
+	int rc;								\
+	rc = SyncVerifyFence(&(pFence), (fid), (client), (mode));	\
+	if (Success != rc) return rc;					\
+    } while (0)
+
+#define VERIFY_SYNC_FENCE_OR_NONE(pFence, fid, client, mode)		\
+    do {								\
+        pFence = 0;							\
+        if (None != fid)						\
+	    VERIFY_SYNC_FENCE((pFence), (fid), (client), (mode));	\
+    } while (0)
+
+#endif /* _SYNCSDK_H_ */
+
diff --git a/hw/xfree86/loader/sdksyms.sh b/hw/xfree86/loader/sdksyms.sh
index 2135430..4ac3c81 100755
--- a/hw/xfree86/loader/sdksyms.sh
+++ b/hw/xfree86/loader/sdksyms.sh
@@ -53,6 +53,7 @@ cat > sdksyms.c << EOF
 #include "geext.h"
 #include "geint.h"
 #include "shmint.h"
+#include "syncsdk.h"
 #if XINERAMA
 # include "panoramiXsrv.h"
 # include "panoramiX.h"
commit 53ea965d64bd9563e6bfcc81d04f283d2b85f09d
Author: James Jones <jajones at nvidia.com>
Date:   Mon Nov 29 10:09:36 2010 -0800

    Require xextproto 7.1.99
    
    Subsequent changes rely on fence sync protocol
    in the sync extension.  This protocol is only
    complete in xextproto version 7.1.99 and
    above.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index c6f9b2f..0108541 100644
--- a/configure.ac
+++ b/configure.ac
@@ -791,7 +791,7 @@ WINDOWSWMPROTO="windowswmproto"
 APPLEWMPROTO="applewmproto >= 1.4"
 
 dnl Core modules for most extensions, et al.
-SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.0.99.3] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto"
+SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto"
 # Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
 AC_SUBST(SDK_REQUIRED_MODULES)
 
commit 1c4a0db2c6bf0320cb630b84ab87bcfd3801a53d
Author: James Jones <jajones at nvidia.com>
Date:   Mon Jun 28 16:10:13 2010 -0700

    Add fence sync driver interface
    
    -Add fence sync objects
    
    -Add fence sync devPrivates
    
    -Add a X sync module screen private
    
    -Add wrappable functions to create and destroy
     fence sync objects
    
    -Give fence sync objects wrappable functions to
     trigger, test, and reset their 'triggered' value.
    
    -Give fence sync objects wrappable functions to
     notify driver when adding/removing triggers to/
     from the sync object.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index e5bc64f..2615c27 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -59,7 +59,7 @@ PERFORMANCE OF THIS SOFTWARE.
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include <X11/Xmd.h>
-#include "misc.h"
+#include "scrnintstr.h"
 #include "os.h"
 #include "extnsionst.h"
 #include "dixstruct.h"
@@ -2199,6 +2199,10 @@ void
 SyncExtensionInit(void)
 {
     ExtensionEntry *extEntry;
+    int 	    s;
+
+    for (s = 0; s < screenInfo.numScreens; s++)
+	miSyncSetup(screenInfo.screens[s]);
 
     if (RTCounter == 0)
     {
diff --git a/dix/privates.c b/dix/privates.c
index 687fa7a..d651258 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -447,6 +447,7 @@ static const char *key_names[PRIVATE_LAST] = {
     [PRIVATE_GLYPH] = "GLYPH",
     [PRIVATE_GLYPHSET] = "GLYPHSET",
     [PRIVATE_PICTURE] = "PICTURE",
+    [PRIVATE_SYNC_FENCE] = "SYNC_FENCE",
 };
 
 void
diff --git a/hw/xfree86/loader/sdksyms.sh b/hw/xfree86/loader/sdksyms.sh
index 4b3ed86..2135430 100755
--- a/hw/xfree86/loader/sdksyms.sh
+++ b/hw/xfree86/loader/sdksyms.sh
@@ -41,6 +41,9 @@ cat > sdksyms.c << EOF
 #include "damage.h"
 #include "damagestr.h"
 
+/* miext/sync/Makefile.am */
+#include "misync.h"
+#include "misyncstr.h"
 
 /* Xext/Makefile.am -- half is module, half is builtin */
 /*
diff --git a/include/privates.h b/include/privates.h
index 9fb6ae8..7ef2cb7 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -51,6 +51,7 @@ typedef enum {
     PRIVATE_GLYPH,
     PRIVATE_GLYPHSET,
     PRIVATE_PICTURE,
+    PRIVATE_SYNC_FENCE,
 
     /* last private type */
     PRIVATE_LAST,
diff --git a/miext/sync/misync.c b/miext/sync/misync.c
index 344810f..bcc68a2 100644
--- a/miext/sync/misync.c
+++ b/miext/sync/misync.c
@@ -21,5 +21,181 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "scrnintstr.h"
 #include "misync.h"
 #include "misyncstr.h"
+
+static DevPrivateKeyRec syncScreenPrivateKeyRec;
+static DevPrivateKey syncScreenPrivateKey = &syncScreenPrivateKeyRec;
+
+#define SYNC_SCREEN_PRIV(pScreen) 				\
+    (SyncScreenPrivPtr) dixLookupPrivate(&pScreen->devPrivates,	\
+					 syncScreenPrivateKey)
+
+typedef struct _syncScreenPriv {
+    /* Wrappable sync-specific screen functions */
+    SyncScreenFuncsRec		funcs;
+
+    /* Wrapped screen functions */
+    CloseScreenProcPtr		CloseScreen;
+} SyncScreenPrivRec, *SyncScreenPrivPtr;
+
+/* Default implementations of the sync screen functions */
+void
+miSyncScreenCreateFence(ScreenPtr pScreen, SyncFence* pFence,
+                        Bool initially_triggered)
+{
+    (void)pScreen;
+
+    pFence->triggered = initially_triggered;
+}
+
+void miSyncScreenDestroyFence(ScreenPtr pScreen, SyncFence* pFence)
+{
+    (void)pScreen;
+    (void)pFence;
+}
+
+/* Default implementations of the per-object functions */
+static void
+miSyncFenceSetTriggered(SyncFence* pFence)
+{
+    pFence->triggered = TRUE;
+}
+
+static void
+miSyncFenceReset(SyncFence* pFence)
+{
+    pFence->triggered = FALSE;
+}
+
+static Bool
+miSyncFenceCheckTriggered(SyncFence* pFence)
+{
+    return pFence->triggered;
+}
+
+static void
+miSyncFenceAddTrigger(SyncTrigger* pTrigger)
+{
+    (void)pTrigger;
+
+    return;
+}
+
+static void
+miSyncFenceDeleteTrigger(SyncTrigger* pTrigger)
+{
+    (void)pTrigger;
+
+    return;
+}
+
+/* Machine independent portion of the fence sync object implementation */
+void
+miSyncInitFence(ScreenPtr pScreen, SyncFence* pFence, Bool initially_triggered)
+{
+    SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
+    static const SyncFenceFuncsRec miSyncFenceFuncs = {
+	&miSyncFenceSetTriggered,
+	&miSyncFenceReset,
+	&miSyncFenceCheckTriggered,
+	&miSyncFenceAddTrigger,
+	&miSyncFenceDeleteTrigger
+    };
+
+    pFence->pScreen = pScreen;
+    pFence->funcs = miSyncFenceFuncs;
+
+    pScreenPriv->funcs.CreateFence(pScreen, pFence, initially_triggered);
+}
+
+void
+miSyncDestroyFence(SyncFence* pFence)
+{
+    ScreenPtr pScreen = pFence->pScreen;
+    SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
+    SyncTriggerList *ptl, *pNext;
+
+    pFence->sync.beingDestroyed = TRUE;
+    /* tell all the fence's triggers that the counter has been destroyed */
+    for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext)
+    {
+	(*ptl->pTrigger->CounterDestroyed)(ptl->pTrigger);
+	pNext = ptl->next;
+	free(ptl); /* destroy the trigger list as we go */
+    }
+
+    pScreenPriv->funcs.DestroyFence(pScreen, pFence);
+
+    dixFreeObjectWithPrivates(pFence, PRIVATE_SYNC_FENCE);
+}
+
+void
+miSyncTriggerFence(SyncFence* pFence)
+{
+    SyncTriggerList *ptl, *pNext;
+    CARD64 unused;
+
+    pFence->funcs.SetTriggered(pFence);
+
+    XSyncIntToValue(&unused, 0L);
+
+    /* run through triggers to see if any fired */
+    for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext)
+    {
+	pNext = ptl->next;
+	if ((*ptl->pTrigger->CheckTrigger)(ptl->pTrigger, unused))
+	    (*ptl->pTrigger->TriggerFired)(ptl->pTrigger);
+    }
+}
+
+SyncScreenFuncsPtr miSyncGetScreenFuncs(ScreenPtr pScreen)
+{
+    SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
+
+    return &pScreenPriv->funcs;
+}
+
+static Bool
+SyncCloseScreen (int i, ScreenPtr pScreen)
+{
+    SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
+
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    free(pScreenPriv);
+
+    return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+Bool
+miSyncSetup(ScreenPtr pScreen)
+{
+    SyncScreenPrivPtr	pScreenPriv;
+
+    static const SyncScreenFuncsRec miSyncScreenFuncs = {
+	&miSyncScreenCreateFence,
+	&miSyncScreenDestroyFence
+    };
+
+    if (dixPrivateKeyRegistered(syncScreenPrivateKey))
+	return TRUE;
+
+    if (!dixRegisterPrivateKey(syncScreenPrivateKey, PRIVATE_SCREEN,
+			       sizeof(SyncScreenPrivRec)))
+	return FALSE;
+
+    pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
+
+    pScreenPriv->funcs = miSyncScreenFuncs;
+
+    /* Wrap CloseScreen to clean up */
+    pScreenPriv->CloseScreen = pScreen->CloseScreen;
+    pScreen->CloseScreen = SyncCloseScreen;
+
+    return TRUE;
+}
diff --git a/miext/sync/misync.h b/miext/sync/misync.h
index c66be8d..1c82ea5 100644
--- a/miext/sync/misync.h
+++ b/miext/sync/misync.h
@@ -28,4 +28,50 @@
 #ifndef _MISYNC_H_
 #define _MISYNC_H_
 
+typedef struct _SyncFence SyncFence;
+typedef struct _SyncTrigger SyncTrigger;
+
+typedef void (*SyncScreenCreateFenceFunc) (ScreenPtr pScreen,
+					   SyncFence* pFence,
+					   Bool initially_triggered);
+typedef void (*SyncScreenDestroyFenceFunc) (ScreenPtr pScreen,
+					    SyncFence* pFence);
+
+typedef struct _syncScreenFuncs {
+    SyncScreenCreateFenceFunc	CreateFence;
+    SyncScreenDestroyFenceFunc	DestroyFence;
+} SyncScreenFuncsRec, *SyncScreenFuncsPtr;
+
+extern _X_EXPORT void
+miSyncScreenCreateFence(ScreenPtr pScreen, SyncFence* pFence,
+			Bool initially_triggered);
+extern _X_EXPORT void
+miSyncScreenDestroyFence(ScreenPtr pScreen, SyncFence* pFence);
+
+typedef void (*SyncFenceSetTriggeredFunc) (SyncFence* pFence);
+typedef void (*SyncFenceResetFunc) (SyncFence* pFence);
+typedef Bool (*SyncFenceCheckTriggeredFunc) (SyncFence* pFence);
+typedef void (*SyncFenceAddTriggerFunc) (SyncTrigger* pTrigger);
+typedef void (*SyncFenceDeleteTriggerFunc) (SyncTrigger* pTrigger);
+
+typedef struct _syncFenceFuncs {
+    SyncFenceSetTriggeredFunc	SetTriggered;
+    SyncFenceResetFunc		Reset;
+    SyncFenceCheckTriggeredFunc	CheckTriggered;
+    SyncFenceAddTriggerFunc	AddTrigger;
+    SyncFenceDeleteTriggerFunc	DeleteTrigger;
+} SyncFenceFuncsRec, *SyncFenceFuncsPtr;
+
+extern _X_EXPORT void
+miSyncInitFence(ScreenPtr pScreen, SyncFence* pFence, Bool initially_triggered);
+extern _X_EXPORT void
+miSyncDestroyFence(SyncFence* pFence);
+extern _X_EXPORT void
+miSyncTriggerFence(SyncFence* pFence);
+
+extern _X_EXPORT SyncScreenFuncsPtr
+miSyncGetScreenFuncs(ScreenPtr pScreen);
+extern _X_EXPORT Bool
+miSyncSetup(ScreenPtr pScreen);
+
 #endif /* _MISYNC_H_ */
diff --git a/miext/sync/misyncstr.h b/miext/sync/misyncstr.h
index eecf04f..40a865c 100644
--- a/miext/sync/misyncstr.h
+++ b/miext/sync/misyncstr.h
@@ -35,6 +35,7 @@
 
 /* Sync object types */
 #define SYNC_COUNTER		0
+#define SYNC_FENCE		1
 
 typedef struct _SyncObject {
     ClientPtr		client;	/* Owning client. 0 for system counters */
@@ -50,7 +51,15 @@ typedef struct _SyncCounter {
     struct _SysCounterInfo *pSysCounterInfo; /* NULL if not a system counter */
 } SyncCounter;
 
-typedef struct _SyncTrigger {
+struct _SyncFence {
+    SyncObject		sync;		/* Common sync object data */
+    ScreenPtr		pScreen;	/* Screen of this fence object */
+    SyncFenceFuncsRec	funcs;		/* Funcs for performing ops on fence */
+    Bool		triggered;	/* fence state */
+    PrivateRec		*devPrivates;	/* driver-specific per-fence data */
+};
+
+struct _SyncTrigger {
     SyncObject *pSync;
     CARD64	wait_value;	/* wait value */
     unsigned int value_type;	/* Absolute or Relative */
@@ -66,7 +75,7 @@ typedef struct _SyncTrigger {
     void	(*CounterDestroyed)(
 				struct _SyncTrigger * /*pTrigger*/
 				    );
-} SyncTrigger;
+};
 
 typedef struct _SyncTriggerList {
     SyncTrigger *pTrigger;
commit af0f9f913398d34a885c3fb4e8d40c1a7e2b3ee9
Author: James Jones <jajones at nvidia.com>
Date:   Mon Jun 28 15:39:04 2010 -0700

    Move some sync code to miext
    
    As a precursor to the fence sync object video driver
    and extension API, move some code from Xext to
    miext/sync.  Most of this is just code to set up the
    build system to include the new directory.  No
    functional code is added in this change.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/COPYING b/COPYING
index 3fb06b8..3aad5fa 100644
--- a/COPYING
+++ b/COPYING
@@ -14,7 +14,7 @@ Copyright © 2006-2007 Intel Corporation
 Copyright © 2006 Nokia Corporation
 Copyright © 2006-2008 Peter Hutterer
 Copyright © 2006 Adam Jackson
-Copyright © 2009 NVIDIA Corporation
+Copyright © 2009-2010 NVIDIA Corporation
 Copyright © 1999 Keith Packard
 Copyright © 2007-2009 Red Hat, Inc.
 Copyright © 2005-2008 Daniel Stone
diff --git a/Xext/sync.c b/Xext/sync.c
index d17a752..e5bc64f 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -2192,7 +2192,6 @@ SyncResetProc(ExtensionEntry *extEntry)
     RTCounter = 0;
 }
 
-
 /*
  * ** Initialise the extension.
  */
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index 64e42cd..aa7dfb9 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -51,24 +51,8 @@ PERFORMANCE OF THIS SOFTWARE.
 #ifndef _SYNCSRV_H_
 #define _SYNCSRV_H_
 
-#define CARD64 XSyncValue /* XXX temporary! need real 64 bit values for Alpha */
-
-/* Sync object types */
-#define SYNC_COUNTER		0
-
-typedef struct _SyncObject {
-    ClientPtr		client;	/* Owning client. 0 for system counters */
-    struct _SyncTriggerList *pTriglist;	/* list of triggers */
-    XID			id;		/* resource ID */
-    unsigned char	type;		/* SYNC_* */
-    Bool		beingDestroyed;	/* in process of going away */
-} SyncObject;
-
-typedef struct _SyncCounter {
-    SyncObject		sync;		/* Common sync object data */
-    CARD64		value;		/* counter value */
-    struct _SysCounterInfo *pSysCounterInfo; /* NULL if not a system counter */
-} SyncCounter;
+#include "misync.h"
+#include "misyncstr.h"
 
 /*
  * The System Counter interface
@@ -100,29 +84,6 @@ typedef struct _SysCounterInfo {
 
 
 
-typedef struct _SyncTrigger {
-    SyncObject *pSync;
-    CARD64	wait_value;	/* wait value */
-    unsigned int value_type;     /* Absolute or Relative */
-    unsigned int test_type;	/* transition or Comparision type */
-    CARD64	test_value;	/* trigger event threshold value */
-    Bool	(*CheckTrigger)(
-				struct _SyncTrigger * /*pTrigger*/,
-				CARD64 /*newval*/
-				);
-    void	(*TriggerFired)(
-				struct _SyncTrigger * /*pTrigger*/
-				);
-    void	(*CounterDestroyed)(
-				struct _SyncTrigger * /*pTrigger*/
-				    );
-} SyncTrigger;
-
-typedef struct _SyncTriggerList {
-    SyncTrigger *pTrigger;
-    struct _SyncTriggerList *next;
-} SyncTriggerList;
-
 typedef struct _SyncAlarmClientList {
     ClientPtr	client;
     XID		delete_id;
@@ -179,6 +140,7 @@ extern void SyncChangeCounter(
 extern void SyncDestroySystemCounter(
     pointer pCounter
 );
+
 extern void InitServertime(void);
 
 extern void SyncExtensionInit(void);
diff --git a/configure.ac b/configure.ac
index a80a13f..c6f9b2f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1353,6 +1353,8 @@ FB_LIB='$(top_builddir)/fb/libfb.la'
 FB_INC='-I$(top_srcdir)/fb'
 MIEXT_SHADOW_INC='-I$(top_srcdir)/miext/shadow'
 MIEXT_SHADOW_LIB='$(top_builddir)/miext/shadow/libshadow.la'
+MIEXT_SYNC_INC='-I$(top_srcdir)/miext/sync'
+MIEXT_SYNC_LIB='$(top_builddir)/miext/sync/libsync.la'
 CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include'
 
 # SHA1 hashing
@@ -1492,7 +1494,7 @@ AC_EGREP_CPP([I_AM_SVR4],[
 AC_DEFINE([SVR4],1,[Define to 1 on systems derived from System V Release 4])
 AC_MSG_RESULT([yes])], AC_MSG_RESULT([no]))
 
-XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC"
+XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SYNC_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC"
 
 dnl ---------------------------------------------------------------------------
 dnl DDX section.
@@ -1505,7 +1507,7 @@ AC_MSG_RESULT([$XVFB])
 AM_CONDITIONAL(XVFB, [test "x$XVFB" = xyes])
 
 if test "x$XVFB" = xyes; then
-	XVFB_LIBS="$FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB"
+	XVFB_LIBS="$FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB"
 	XVFB_SYS_LIBS="$XVFBMODULES_LIBS $GLX_SYS_LIBS"
 	AC_SUBST([XVFB_LIBS])
 	AC_SUBST([XVFB_SYS_LIBS])
@@ -1526,7 +1528,7 @@ if test "x$XNEST" = xyes; then
 	if test "x$have_xnest" = xno; then
 		AC_MSG_ERROR([Xnest build explicitly requested, but required modules not found.])
 	fi
-	XNEST_LIBS="$FB_LIB $FIXES_LIB $MI_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DIX_LIB $MAIN_LIB $OS_LIB"
+	XNEST_LIBS="$FB_LIB $FIXES_LIB $MI_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DIX_LIB $MAIN_LIB $OS_LIB"
 	XNEST_SYS_LIBS="$XNESTMODULES_LIBS $GLX_SYS_LIBS"
 	AC_SUBST([XNEST_LIBS])
 	AC_SUBST([XNEST_SYS_LIBS])
@@ -1554,7 +1556,7 @@ if test "x$XORG" = xyes; then
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB"
 
 	dnl ==================================================================
 	dnl symbol visibility
@@ -1889,7 +1891,7 @@ if test "x$XWIN" = xyes; then
 			XWIN_SYS_LIBS=-lwinsock2
 			;;
 	esac
-	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
+	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $CONFIG_LIB $RANDR_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
 	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS"
 	AC_SUBST(XWIN_LIBS)
 	AC_SUBST(XWIN_SERVER_NAME)
@@ -1919,7 +1921,7 @@ if test "x$XQUARTZ" = xyes; then
 	AC_DEFINE(XQUARTZ,1,[Have Quartz])
 	AC_DEFINE(ROOTLESS,1,[Build Rootless code])
 
-	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $MAIN_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB"
+	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $MAIN_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB"
 	AC_SUBST([DARWIN_LIBS])
 
 	AC_CHECK_LIB([Xplugin],[xp_init],[:])
@@ -1980,7 +1982,7 @@ if test "x$DMX" = xyes; then
 	fi
 	DMX_INCLUDES="$XEXT_INC $RENDER_INC $RECORD_INC"
 	XDMX_CFLAGS="$DMXMODULES_CFLAGS"
-	XDMX_LIBS="$FB_LIB $MI_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $XEXT_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
+	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
 	XDMX_SYS_LIBS="$DMXMODULES_LIBS"
 	AC_SUBST([XDMX_CFLAGS])
 	AC_SUBST([XDMX_LIBS])
@@ -2085,13 +2087,13 @@ if test "$KDRIVE" = yes; then
     
     # damage shadow extension glx (NOTYET) fb mi
     KDRIVE_INC='-I$(top_srcdir)/hw/kdrive/src'
-    KDRIVE_PURE_INCS="$KDRIVE_INC $MIEXT_DAMAGE_INC $MIEXT_SHADOW_INC $XEXT_INC $FB_INC $MI_INC"
+    KDRIVE_PURE_INCS="$KDRIVE_INC $MIEXT_SYNC_INC $MIEXT_DAMAGE_INC $MIEXT_SHADOW_INC $XEXT_INC $FB_INC $MI_INC"
     KDRIVE_OS_INC='-I$(top_srcdir)/hw/kdrive/linux'
     KDRIVE_INCS="$KDRIVE_PURE_INCS $KDRIVE_OS_INC"
     
     KDRIVE_CFLAGS="$XSERVER_CFLAGS -DHAVE_KDRIVE_CONFIG_H $TSLIB_CFLAGS"
 
-    KDRIVE_PURE_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $OS_LIB"
+    KDRIVE_PURE_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $OS_LIB"
     KDRIVE_LIB='$(top_builddir)/hw/kdrive/src/libkdrive.la'
     case $host_os in
 	*linux*)
@@ -2191,6 +2193,7 @@ record/Makefile
 config/Makefile
 mi/Makefile
 miext/Makefile
+miext/sync/Makefile
 miext/damage/Makefile
 miext/shadow/Makefile
 miext/cw/Makefile
diff --git a/miext/Makefile.am b/miext/Makefile.am
index 84ab708..bbedac2 100644
--- a/miext/Makefile.am
+++ b/miext/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = damage shadow
+SUBDIRS = sync damage shadow
 if COMPOSITE
 SUBDIRS += cw
 endif
@@ -8,4 +8,4 @@ endif
 if XWIN_MULTIWINDOWEXTWM
 SUBDIRS += rootless
 endif
-DIST_SUBDIRS = damage shadow cw rootless
+DIST_SUBDIRS = sync damage shadow cw rootless
diff --git a/miext/sync/Makefile.am b/miext/sync/Makefile.am
new file mode 100644
index 0000000..36b2816
--- /dev/null
+++ b/miext/sync/Makefile.am
@@ -0,0 +1,14 @@
+noinst_LTLIBRARIES = libsync.la
+
+AM_CFLAGS = $(DIX_CFLAGS)
+
+INCLUDES = 
+
+if XORG
+sdk_HEADERS = misync.h misyncstr.h
+endif
+
+libsync_la_SOURCES =	\
+	misync.c	\
+	misync.h	\
+	misyncstr.h
diff --git a/miext/sync/misync.c b/miext/sync/misync.c
new file mode 100644
index 0000000..344810f
--- /dev/null
+++ b/miext/sync/misync.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright © 2010 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "misync.h"
+#include "misyncstr.h"
diff --git a/miext/sync/misync.h b/miext/sync/misync.h
new file mode 100644
index 0000000..c66be8d
--- /dev/null
+++ b/miext/sync/misync.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2010 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _MISYNC_H_
+#define _MISYNC_H_
+
+#endif /* _MISYNC_H_ */
diff --git a/miext/sync/misyncstr.h b/miext/sync/misyncstr.h
new file mode 100644
index 0000000..eecf04f
--- /dev/null
+++ b/miext/sync/misyncstr.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright © 2010 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _MISYNCSTR_H_
+#define _MISYNCSTR_H_
+
+#include "dix.h"
+#include <X11/extensions/syncconst.h>
+
+#define CARD64 XSyncValue /* XXX temporary! need real 64 bit values for Alpha */
+
+/* Sync object types */
+#define SYNC_COUNTER		0
+
+typedef struct _SyncObject {
+    ClientPtr		client;	/* Owning client. 0 for system counters */
+    struct _SyncTriggerList *pTriglist;	/* list of triggers */
+    XID			id;		/* resource ID */
+    unsigned char	type;		/* SYNC_* */
+    Bool		beingDestroyed;	/* in process of going away */
+} SyncObject;
+
+typedef struct _SyncCounter {
+    SyncObject		sync;		/* Common sync object data */
+    CARD64		value;		/* counter value */
+    struct _SysCounterInfo *pSysCounterInfo; /* NULL if not a system counter */
+} SyncCounter;
+
+typedef struct _SyncTrigger {
+    SyncObject *pSync;
+    CARD64	wait_value;	/* wait value */
+    unsigned int value_type;	/* Absolute or Relative */
+    unsigned int test_type;	/* transition or Comparision type */
+    CARD64	test_value;	/* trigger event threshold value */
+    Bool	(*CheckTrigger)(
+				struct _SyncTrigger * /*pTrigger*/,
+				CARD64 /*newval*/
+				);
+    void	(*TriggerFired)(
+				struct _SyncTrigger * /*pTrigger*/
+				);
+    void	(*CounterDestroyed)(
+				struct _SyncTrigger * /*pTrigger*/
+				    );
+} SyncTrigger;
+
+typedef struct _SyncTriggerList {
+    SyncTrigger *pTrigger;
+    struct _SyncTriggerList *next;
+} SyncTriggerList;
+
+#endif /* _MISYNCSTR_H_ */
+
commit 12b65de7db6e3e8bf831914d247da269d01c5fbe
Author: James Jones <jajones at nvidia.com>
Date:   Mon Dec 6 10:11:45 2010 -0800

    Factor out generic code from ProcSyncAwait()
    
    In preparation for adding more sync object types
    that will need Await requests of their own, factor
    out some setup and finalization code from
    ProcSyncAwait() into SyncAwaitPrologue() and
    SyncAwaitEpilogue()
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index 2944903..d17a752 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -1465,6 +1465,66 @@ ProcSyncDestroyCounter(ClientPtr client)
     return Success;
 }
 
+static SyncAwaitUnion*
+SyncAwaitPrologue(ClientPtr client, int items)
+{
+    SyncAwaitUnion *pAwaitUnion;
+
+    /*  all the memory for the entire await list is allocated
+     *  here in one chunk
+     */
+    pAwaitUnion = malloc((items+1) * sizeof(SyncAwaitUnion));
+    if (!pAwaitUnion)
+	return NULL;
+
+    /* first item is the header, remainder are real wait conditions */
+
+    pAwaitUnion->header.delete_id = FakeClientID(client->index);
+    if (!AddResource(pAwaitUnion->header.delete_id, RTAwait, pAwaitUnion))
+    {
+	free(pAwaitUnion);
+	return NULL;
+    }
+
+    pAwaitUnion->header.client = client;
+    pAwaitUnion->header.num_waitconditions = 0;
+
+    return pAwaitUnion;
+}
+
+static void
+SyncAwaitEpilogue(ClientPtr client, int items, SyncAwaitUnion *pAwaitUnion)
+{
+    SyncAwait *pAwait;
+    int i;
+
+    IgnoreClient(client);
+
+    /* see if any of the triggers are already true */
+
+    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
+    for (i = 0; i < items; i++, pAwait++)
+    {
+	CARD64 value;
+
+	/*  don't have to worry about NULL counters because the request
+	 *  errors before we get here out if they occur
+	 */
+	switch (pAwait->trigger.pSync->type) {
+	case SYNC_COUNTER:
+	    value = ((SyncCounter *)pAwait->trigger.pSync)->value;
+	    break;
+	default:
+	    XSyncIntToValue(&value, 0);
+	}
+
+	if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger, value))
+	{
+	    (*pAwait->trigger.TriggerFired)(&pAwait->trigger);
+	    break; /* once is enough */
+	}
+    }
+}
 
 /*
  * ** Await
@@ -1496,28 +1556,12 @@ ProcSyncAwait(ClientPtr client)
 	return BadValue;
     }
 
-    pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1];
-
-    /*  all the memory for the entire await list is allocated
-     *  here in one chunk
-     */
-    pAwaitUnion = malloc((items+1) * sizeof(SyncAwaitUnion));
-    if (!pAwaitUnion)
+    if (!(pAwaitUnion = SyncAwaitPrologue(client, items)))
 	return BadAlloc;
 
-    /* first item is the header, remainder are real wait conditions */
-
-    pAwaitUnion->header.delete_id = FakeClientID(client->index);
-    if (!AddResource(pAwaitUnion->header.delete_id, RTAwait, pAwaitUnion))
-    {
-	free(pAwaitUnion);
-	return BadAlloc;
-    }
-
     /* don't need to do any more memory allocation for this request! */
 
-    pAwaitUnion->header.client = client;
-    pAwaitUnion->header.num_waitconditions = 0;
+    pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1];
 
     pAwait = &(pAwaitUnion+1)->await; /* skip over header */
     for (i = 0; i < items; i++, pProtocolWaitConds++, pAwait++)
@@ -1561,32 +1605,8 @@ ProcSyncAwait(ClientPtr client)
 	pAwaitUnion->header.num_waitconditions++;
     }
 
-    IgnoreClient(client);
-
-    /* see if any of the triggers are already true */
+    SyncAwaitEpilogue(client, items, pAwaitUnion);
 
-    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
-    for (i = 0; i < items; i++, pAwait++)
-    {
-	CARD64 value;
-
-	/*  don't have to worry about NULL counters because the request
-	 *  errors before we get here out if they occur
-	 */
-	switch (pAwait->trigger.pSync->type) {
-	case SYNC_COUNTER:
-	    value = ((SyncCounter *)pAwait->trigger.pSync)->value;
-	    break;
-	default:
-	    XSyncIntToValue(&value, 0);
-	}
-
-	if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger, value))
-	{
-	    (*pAwait->trigger.TriggerFired)(&pAwait->trigger);
-	    break; /* once is enough */
-	}
-    }
     return Success;
 }
 
commit c66a410d378090f350beb398649e9d9262933785
Author: James Jones <jajones at nvidia.com>
Date:   Mon Jun 28 14:59:01 2010 -0700

    Make Await SyncTrigger functions generic
    
    Update all the functions dealing with Await
    sync triggers handle generic sync objects
    instead of just counters.  This will
    facilitate code sharing between the counter
    sync waits and the fence sync waits.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index d5187dd..2944903 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -107,18 +107,19 @@ static void SyncInitIdleTime(void);
  *  delete and add triggers on this list.
  */
 static void
-SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
+SyncDeleteTriggerFromSyncObject(SyncTrigger *pTrigger)
 {
     SyncTriggerList *pCur;
     SyncTriggerList *pPrev;
+    SyncCounter *pCounter;
 
-    /* pCounter needs to be stored in pTrigger before calling here. */
+    /* pSync needs to be stored in pTrigger before calling here. */
 
-    if (!pTrigger->pCounter)
+    if (!pTrigger->pSync)
 	return;
 
     pPrev = NULL;
-    pCur = pTrigger->pCounter->sync.pTriglist;
+    pCur = pTrigger->pSync->pTriglist;
 
     while (pCur)
     {
@@ -127,7 +128,7 @@ SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
 	    if (pPrev)
 		pPrev->next = pCur->next;
 	    else
-		pTrigger->pCounter->sync.pTriglist = pCur->next;
+		pTrigger->pSync->pTriglist = pCur->next;
 
 	    free(pCur);
 	    break;
@@ -137,21 +138,27 @@ SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
 	pCur = pCur->next;
     }
 
-    if (IsSystemCounter(pTrigger->pCounter))
-	SyncComputeBracketValues(pTrigger->pCounter);
+    if (SYNC_COUNTER == pTrigger->pSync->type)
+    {
+	pCounter = (SyncCounter *)pTrigger->pSync;
+
+	if (IsSystemCounter(pCounter))
+	    SyncComputeBracketValues(pCounter);
+    }
 }
 
 
 static int
-SyncAddTriggerToCounter(SyncTrigger *pTrigger)
+SyncAddTriggerToSyncObject(SyncTrigger *pTrigger)
 {
     SyncTriggerList *pCur;
+    SyncCounter *pCounter;
 
-    if (!pTrigger->pCounter)
+    if (!pTrigger->pSync)
 	return Success;
 
     /* don't do anything if it's already there */
-    for (pCur = pTrigger->pCounter->sync.pTriglist; pCur; pCur = pCur->next)
+    for (pCur = pTrigger->pSync->pTriglist; pCur; pCur = pCur->next)
     {
 	if (pCur->pTrigger == pTrigger)
 	    return Success;
@@ -161,11 +168,16 @@ SyncAddTriggerToCounter(SyncTrigger *pTrigger)
 	return BadAlloc;
 
     pCur->pTrigger = pTrigger;
-    pCur->next = pTrigger->pCounter->sync.pTriglist;
-    pTrigger->pCounter->sync.pTriglist = pCur;
+    pCur->next = pTrigger->pSync->pTriglist;
+    pTrigger->pSync->pTriglist = pCur;
 
-    if (IsSystemCounter(pTrigger->pCounter))
-	SyncComputeBracketValues(pTrigger->pCounter);
+    if (SYNC_COUNTER == pTrigger->pSync->type)
+    {
+	pCounter = (SyncCounter *)pTrigger->pSync;
+
+	if (IsSystemCounter(pCounter))
+	    SyncComputeBracketValues(pCounter);
+    }
 
     return Success;
 }
@@ -188,69 +200,91 @@ SyncAddTriggerToCounter(SyncTrigger *pTrigger)
 static Bool
 SyncCheckTriggerPositiveComparison(SyncTrigger *pTrigger, CARD64 oldval)
 {
-    return (pTrigger->pCounter == NULL ||
-	    XSyncValueGreaterOrEqual(pTrigger->pCounter->value,
-				     pTrigger->test_value));
+    SyncCounter *pCounter;
+
+    assert(!pTrigger->pSync || (SYNC_COUNTER == pTrigger->pSync->type));
+    pCounter = (SyncCounter *)pTrigger->pSync;
+
+    return (pCounter == NULL ||
+	    XSyncValueGreaterOrEqual(pCounter->value, pTrigger->test_value));
 }
 
 static Bool
 SyncCheckTriggerNegativeComparison(SyncTrigger *pTrigger,  CARD64 oldval)
 {
-    return (pTrigger->pCounter == NULL ||
-	    XSyncValueLessOrEqual(pTrigger->pCounter->value,
-				  pTrigger->test_value));
+    SyncCounter *pCounter;
+
+    assert(!pTrigger->pSync || (SYNC_COUNTER == pTrigger->pSync->type));
+    pCounter = (SyncCounter *)pTrigger->pSync;
+
+    return (pCounter == NULL ||
+	    XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value));
 }
 
 static Bool
 SyncCheckTriggerPositiveTransition(SyncTrigger *pTrigger, CARD64 oldval)
 {
-    return (pTrigger->pCounter == NULL ||
+    SyncCounter *pCounter;
+
+    assert(!pTrigger->pSync || (SYNC_COUNTER == pTrigger->pSync->type));
+    pCounter = (SyncCounter *)pTrigger->pSync;
+
+    return (pCounter == NULL ||
 	    (XSyncValueLessThan(oldval, pTrigger->test_value) &&
-	     XSyncValueGreaterOrEqual(pTrigger->pCounter->value,
-				      pTrigger->test_value)));
+	     XSyncValueGreaterOrEqual(pCounter->value, pTrigger->test_value)));
 }
 
 static Bool
 SyncCheckTriggerNegativeTransition(SyncTrigger *pTrigger, CARD64 oldval)
 {
-    return (pTrigger->pCounter == NULL ||
+    SyncCounter *pCounter;
+
+    assert(!pTrigger->pSync || (SYNC_COUNTER == pTrigger->pSync->type));
+    pCounter = (SyncCounter *)pTrigger->pSync;
+
+    return (pCounter == NULL ||
 	    (XSyncValueGreaterThan(oldval, pTrigger->test_value) &&
-	     XSyncValueLessOrEqual(pTrigger->pCounter->value,
-				   pTrigger->test_value)));
+	     XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value)));
 }
 
 static int
-SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XSyncCounter counter,
-		Mask changes)
+SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject,
+		RESTYPE resType, Mask changes)
 {
-    SyncCounter *pCounter = pTrigger->pCounter;
+    SyncObject *pSync = pTrigger->pSync;
+    SyncCounter *pCounter = NULL;
     int		rc;
-    Bool	newcounter = FALSE;
+    Bool	newSyncObject = FALSE;
 
     if (changes & XSyncCACounter)
     {
-	if (counter == None)
-	    pCounter = NULL;
-	else if (Success != (rc = dixLookupResourceByType ((pointer *)&pCounter,
-				counter, RTCounter, client, DixReadAccess)))
+	if (syncObject == None)
+	    pSync = NULL;
+	else if (Success != (rc = dixLookupResourceByType ((pointer *)&pSync,
+				syncObject, resType, client, DixReadAccess)))
 	{
-	    client->errorValue = counter;
+	    client->errorValue = syncObject;
 	    return rc;
 	}
-	if (pCounter != pTrigger->pCounter)
+	if (pSync != pTrigger->pSync)
 	{ /* new counter for trigger */
-	    SyncDeleteTriggerFromCounter(pTrigger);
-	    pTrigger->pCounter = pCounter;
-	    newcounter = TRUE;
+	    SyncDeleteTriggerFromSyncObject(pTrigger);
+	    pTrigger->pSync = pSync;
+	    newSyncObject = TRUE;
 	}
     }
 
     /* if system counter, ask it what the current value is */
 
-    if (IsSystemCounter(pCounter))
+    if (SYNC_COUNTER == pSync->type)
     {
-	(*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter,
-						  &pCounter->value);
+	pCounter = (SyncCounter *)pSync;
+
+	if (IsSystemCounter(pCounter))
+	{
+	    (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter,
+						      &pCounter->value);
+	}
     }
 
     if (changes & XSyncCAValueType)
@@ -277,16 +311,16 @@ SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XSyncCounter counter,
 
 	switch (pTrigger->test_type)
 	{
-        case XSyncPositiveTransition:
+	case XSyncPositiveTransition:
 	    pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition;
 	    break;
-        case XSyncNegativeTransition:
+	case XSyncNegativeTransition:
 	    pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition;
 	    break;
-        case XSyncPositiveComparison:
+	case XSyncPositiveComparison:
 	    pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison;
 	    break;
-        case XSyncNegativeComparison:
+	case XSyncNegativeComparison:
 	    pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison;
 	    break;
 	}
@@ -315,12 +349,12 @@ SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XSyncCounter counter,
     /*  we wait until we're sure there are no errors before registering
      *  a new counter on a trigger
      */
-    if (newcounter)
+    if (newSyncObject)
     {
-	if ((rc = SyncAddTriggerToCounter(pTrigger)) != Success)
+	if ((rc = SyncAddTriggerToSyncObject(pTrigger)) != Success)
 	    return rc;
     }
-    else if (IsSystemCounter(pCounter))
+    else if (pCounter && IsSystemCounter(pCounter))
     {
 	SyncComputeBracketValues(pCounter);
     }
@@ -338,16 +372,21 @@ SyncSendAlarmNotifyEvents(SyncAlarm *pAlarm)
     SyncAlarmClientList *pcl;
     xSyncAlarmNotifyEvent ane;
     SyncTrigger *pTrigger = &pAlarm->trigger;
+    SyncCounter *pCounter;
+
+    assert(!pTrigger->pSync || (SYNC_COUNTER == pTrigger->pSync->type));
+
+    pCounter = (SyncCounter *)pTrigger->pSync;
 
     UpdateCurrentTime();
 
     ane.type = SyncEventBase + XSyncAlarmNotify;
     ane.kind = XSyncAlarmNotify;
     ane.alarm = pAlarm->alarm_id;
-    if (pTrigger->pCounter)
+    if (pTrigger->pSync && SYNC_COUNTER == pTrigger->pSync->type)
     {
-	ane.counter_value_hi = XSyncValueHigh32(pTrigger->pCounter->value);
-	ane.counter_value_lo = XSyncValueLow32(pTrigger->pCounter->value);
+	ane.counter_value_hi = XSyncValueHigh32(pCounter->value);
+	ane.counter_value_lo = XSyncValueLow32(pCounter->value);
     }
     else
     { /* XXX what else can we do if there's no counter? */
@@ -390,14 +429,25 @@ SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait **ppAwait,
 	SyncTrigger *pTrigger = &(*ppAwait)->trigger;
 	pev->type = SyncEventBase + XSyncCounterNotify;
 	pev->kind = XSyncCounterNotify;
-	pev->counter = pTrigger->pCounter->sync.id;
+	pev->counter = pTrigger->pSync->id;
 	pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value);
 	pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value);
-	pev->counter_value_lo = XSyncValueLow32(pTrigger->pCounter->value);
-	pev->counter_value_hi = XSyncValueHigh32(pTrigger->pCounter->value);
+	if (SYNC_COUNTER == pTrigger->pSync->type)
+	{
+	    SyncCounter *pCounter = (SyncCounter *)pTrigger->pSync;
+
+	    pev->counter_value_lo = XSyncValueLow32(pCounter->value);
+	    pev->counter_value_hi = XSyncValueHigh32(pCounter->value);
+	}
+	else
+	{
+	    pev->counter_value_lo = 0;
+	    pev->counter_value_hi = 0;
+	}
+
 	pev->time = currentTime.milliseconds;
 	pev->count = num_events - i - 1; /* events remaining */
-	pev->destroyed = pTrigger->pCounter->sync.beingDestroyed;
+	pev->destroyed = pTrigger->pSync->beingDestroyed;
     }
     /* swapping will be taken care of by this */
     WriteEventsToClient(client, num_events, (xEvent *)pEvents);
@@ -415,7 +465,7 @@ SyncAlarmCounterDestroyed(SyncTrigger *pTrigger)
 
     pAlarm->state = XSyncAlarmInactive;
     SyncSendAlarmNotifyEvents(pAlarm);
-    pTrigger->pCounter = NULL;
+    pTrigger->pSync = NULL;
 }
 
 
@@ -426,8 +476,12 @@ static void
 SyncAlarmTriggerFired(SyncTrigger *pTrigger)
 {
     SyncAlarm *pAlarm = (SyncAlarm *)pTrigger;
+    SyncCounter *pCounter;
     CARD64 new_test_value;
 
+    assert(!pTrigger->pSync || (SYNC_COUNTER == pTrigger->pSync->type));
+    pCounter = (SyncCounter *)pTrigger->pSync;
+
     /* no need to check alarm unless it's active */
     if (pAlarm->state != XSyncAlarmActive)
 	return;
@@ -437,7 +491,7 @@ SyncAlarmTriggerFired(SyncTrigger *pTrigger)
      *    no change is made to value (test-value) and the alarm
      *    state is changed to Inactive before the event is generated."
      */
-    if (pAlarm->trigger.pCounter == NULL
+    if (pCounter == NULL
 	|| (XSyncValueIsZero(pAlarm->delta)
 	    && (pAlarm->trigger.test_type == XSyncPositiveComparison
 		|| pAlarm->trigger.test_type == XSyncNegativeComparison)))
@@ -450,6 +504,10 @@ SyncAlarmTriggerFired(SyncTrigger *pTrigger)
 	Bool overflow;
 	CARD64 oldvalue;
 	SyncTrigger *paTrigger = &pAlarm->trigger;
+	SyncCounter *paCounter;
+
+	assert(!paTrigger->pSync || (SYNC_COUNTER == paTrigger->pSync->type));
+	paCounter = (SyncCounter *)pTrigger->pSync;
 
 	/* "The alarm is updated by repeatedly adding delta to the
 	 *  value of the trigger and re-initializing it until it
@@ -465,7 +523,7 @@ SyncAlarmTriggerFired(SyncTrigger *pTrigger)
 			  pAlarm->delta, &overflow);
 	} while (!overflow &&
 	      (*paTrigger->CheckTrigger)(paTrigger,
-					paTrigger->pCounter->value));
+					paCounter->value));
 
 	new_test_value = paTrigger->test_value;
 	paTrigger->test_value = oldvalue;
@@ -532,46 +590,51 @@ SyncAwaitTriggerFired(SyncTrigger *pTrigger)
 	 *  always generated if the counter for one of the triggers is
 	 *  destroyed."
 	 */
-	if (pAwait->trigger.pCounter->sync.beingDestroyed)
+	if (pAwait->trigger.pSync->beingDestroyed)
 	{
 	    ppAwait[num_events++] = pAwait;
 	    continue;
 	}
+	
+	if (SYNC_COUNTER == pAwait->trigger.pSync->type)
+	{
+	    SyncCounter *pCounter = (SyncCounter *) pAwait->trigger.pSync;
 
-	/* "The difference between the counter and the test value is
-	 *  calculated by subtracting the test value from the value of
-	 *  the counter."
-	 */
-	XSyncValueSubtract(&diff, pAwait->trigger.pCounter->value,
-			   pAwait->trigger.test_value, &overflow);
+	    /* "The difference between the counter and the test value is
+	     *  calculated by subtracting the test value from the value of
+	     *  the counter."
+	     */
+	    XSyncValueSubtract(&diff, pCounter->value,
+			       pAwait->trigger.test_value, &overflow);
 
-	/* "If the difference lies outside the range for an INT64, an
-	 *  event is not generated."
-	 */
-	if (overflow)
-	    continue;
-	diffgreater = XSyncValueGreaterThan(diff, pAwait->event_threshold);
-	diffequal   = XSyncValueEqual(diff, pAwait->event_threshold);
-
-	/* "If the test-type is PositiveTransition or
-	 *  PositiveComparison, a CounterNotify event is generated if
-	 *  the difference is at least event-threshold. If the test-type
-	 *  is NegativeTransition or NegativeComparison, a CounterNotify
-	 *  event is generated if the difference is at most
-	 *  event-threshold."
-	 */
+	    /* "If the difference lies outside the range for an INT64, an
+	     *  event is not generated."
+	     */
+	    if (overflow)
+		continue;
+	    diffgreater = XSyncValueGreaterThan(diff, pAwait->event_threshold);
+	    diffequal   = XSyncValueEqual(diff, pAwait->event_threshold);
+
+	    /* "If the test-type is PositiveTransition or
+	     *  PositiveComparison, a CounterNotify event is generated if
+	     *  the difference is at least event-threshold. If the test-type
+	     *  is NegativeTransition or NegativeComparison, a CounterNotify
+	     *  event is generated if the difference is at most
+	     *  event-threshold."
+	     */
 
-	if ( ((pAwait->trigger.test_type == XSyncPositiveComparison ||
-	       pAwait->trigger.test_type == XSyncPositiveTransition)
-	       && (diffgreater || diffequal))
-	     ||
-	     ((pAwait->trigger.test_type == XSyncNegativeComparison ||
-	       pAwait->trigger.test_type == XSyncNegativeTransition)
-	      && (!diffgreater) /* less or equal */
-	      )
-	   )
-	{
-	    ppAwait[num_events++] = pAwait;
+	    if ( ((pAwait->trigger.test_type == XSyncPositiveComparison ||
+		   pAwait->trigger.test_type == XSyncPositiveTransition)
+		  && (diffgreater || diffequal))
+		 ||
+		 ((pAwait->trigger.test_type == XSyncNegativeComparison ||
+		   pAwait->trigger.test_type == XSyncNegativeTransition)
+		  && (!diffgreater) /* less or equal */
+		 )
+	       )
+	    {
+		ppAwait[num_events++] = pAwait;
+	    }
 	}
     }
     if (num_events)
@@ -693,7 +756,7 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
     Mask	   origmask = mask;
 
     counter =
-	pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->sync.id : None;
+	pAlarm->trigger.pSync ? pAlarm->trigger.pSync->id : None;
 
     while (mask)
     {
@@ -773,7 +836,7 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
     }
 
     /* postpone this until now, when we're sure nothing else can go wrong */
-    if ((status = SyncInitTrigger(client, &pAlarm->trigger, counter,
+    if ((status = SyncInitTrigger(client, &pAlarm->trigger, counter, RTCounter,
 			     origmask & XSyncCAAllTrigger)) != Success)
 	return status;
 
@@ -996,7 +1059,7 @@ FreeAlarm(void *addr, XID id)
     while (pAlarm->pEventClients)
 	FreeResource(pAlarm->pEventClients->delete_id, RT_NONE);
 
-    SyncDeleteTriggerFromCounter(&pAlarm->trigger);
+    SyncDeleteTriggerFromSyncObject(&pAlarm->trigger);
 
     free(pAlarm);
     return Success;
@@ -1074,9 +1137,9 @@ FreeAwait(void *addr, XID id)
 	/* If the counter is being destroyed, FreeCounter will delete
 	 * the trigger list itself, so don't do it here.
 	 */
-	SyncCounter *pCounter = pAwait->trigger.pCounter;
-	if (pCounter && !pCounter->sync.beingDestroyed)
-	    SyncDeleteTriggerFromCounter(&pAwait->trigger);
+	SyncObject *pSync = pAwait->trigger.pSync;
+	if (pSync && !pSync->beingDestroyed)
+	    SyncDeleteTriggerFromSyncObject(&pAwait->trigger);
     }
     free(pAwaitUnion);
     return Success;
@@ -1462,7 +1525,7 @@ ProcSyncAwait(ClientPtr client)
 	if (pProtocolWaitConds->counter == None) /* XXX protocol change */
 	{
 	    /*  this should take care of removing any triggers created by
-	     *  this request that have already been registered on counters
+	     *  this request that have already been registered on sync objects
 	     */
 	    FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
 	    client->errorValue = pProtocolWaitConds->counter;
@@ -1470,7 +1533,7 @@ ProcSyncAwait(ClientPtr client)
 	}
 
 	/* sanity checks are in SyncInitTrigger */
-	pAwait->trigger.pCounter = NULL;
+	pAwait->trigger.pSync = NULL;
 	pAwait->trigger.value_type = pProtocolWaitConds->value_type;
 	XSyncIntsToValue(&pAwait->trigger.wait_value,
 			 pProtocolWaitConds->wait_value_lo,
@@ -1478,11 +1541,12 @@ ProcSyncAwait(ClientPtr client)
 	pAwait->trigger.test_type = pProtocolWaitConds->test_type;
 
 	status = SyncInitTrigger(client, &pAwait->trigger,
-			 pProtocolWaitConds->counter, XSyncCAAllTrigger);
+				 pProtocolWaitConds->counter, RTCounter,
+				 XSyncCAAllTrigger);
 	if (status != Success)
 	{
 	    /*  this should take care of removing any triggers created by
-	     *  this request that have already been registered on counters
+	     *  this request that have already been registered on sync objects
 	     */
 	    FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
 	    return status;
@@ -1504,11 +1568,20 @@ ProcSyncAwait(ClientPtr client)
     pAwait = &(pAwaitUnion+1)->await; /* skip over header */
     for (i = 0; i < items; i++, pAwait++)
     {
+	CARD64 value;
+
 	/*  don't have to worry about NULL counters because the request
 	 *  errors before we get here out if they occur
 	 */
-	if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger,
-					    pAwait->trigger.pCounter->value))
+	switch (pAwait->trigger.pSync->type) {
+	case SYNC_COUNTER:
+	    value = ((SyncCounter *)pAwait->trigger.pSync)->value;
+	    break;
+	default:
+	    XSyncIntToValue(&value, 0);
+	}
+
+	if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger, value))
 	{
 	    (*pAwait->trigger.TriggerFired)(&pAwait->trigger);
 	    break; /* once is enough */
@@ -1593,13 +1666,14 @@ ProcSyncCreateAlarm(ClientPtr client)
     /* set up defaults */
 
     pTrigger = &pAlarm->trigger;
-    pTrigger->pCounter = NULL;
+    pTrigger->pSync = NULL;
     pTrigger->value_type = XSyncAbsolute;
     XSyncIntToValue(&pTrigger->wait_value, 0L);
     pTrigger->test_type = XSyncPositiveComparison;
     pTrigger->TriggerFired = SyncAlarmTriggerFired;
     pTrigger->CounterDestroyed = SyncAlarmCounterDestroyed;
-    status = SyncInitTrigger(client, pTrigger, None, XSyncCAAllTrigger);
+    status = SyncInitTrigger(client, pTrigger, None, RTCounter,
+			     XSyncCAAllTrigger);
     if (status != Success)
     {
 	free(pAlarm);
@@ -1630,13 +1704,19 @@ ProcSyncCreateAlarm(ClientPtr client)
      *  in CreateAlarm and sets alarm state to Inactive.
      */
 
-    if (!pTrigger->pCounter)
+    if (!pTrigger->pSync)
     {
 	pAlarm->state = XSyncAlarmInactive; /* XXX protocol change */
     }
-    else if ((*pTrigger->CheckTrigger)(pTrigger, pTrigger->pCounter->value))
+    else
     {
-	(*pTrigger->TriggerFired)(pTrigger);
+	SyncCounter *pCounter;
+
+	assert(SYNC_COUNTER == pTrigger->pSync->type);
+	pCounter = (SyncCounter *)pTrigger->pSync;
+
+	if ((*pTrigger->CheckTrigger)(pTrigger, pCounter->value))
+	    (*pTrigger->TriggerFired)(pTrigger);
     }
 
     return Success;
@@ -1650,6 +1730,7 @@ ProcSyncChangeAlarm(ClientPtr client)
 {
     REQUEST(xSyncChangeAlarmReq);
     SyncAlarm   *pAlarm;
+    SyncCounter *pCounter = NULL;
     long        vmask;
     int         len, status;
 
@@ -1670,13 +1751,18 @@ ProcSyncChangeAlarm(ClientPtr client)
 					    (CARD32 *)&stuff[1])) != Success)
 	return status;
 
+    if (pAlarm->trigger.pSync)
+    {
+	assert(SYNC_COUNTER == pAlarm->trigger.pSync->type);
+	pCounter = (SyncCounter *)pAlarm->trigger.pSync;
+    }
+
     /*  see if alarm already triggered.  NULL counter WILL trigger
      *  in ChangeAlarm.
      */
 
-    if (!pAlarm->trigger.pCounter ||
-	(*pAlarm->trigger.CheckTrigger)(&pAlarm->trigger,
-					pAlarm->trigger.pCounter->value))
+    if (!pCounter ||
+	(*pAlarm->trigger.CheckTrigger)(&pAlarm->trigger, pCounter->value))
     {
 	(*pAlarm->trigger.TriggerFired)(&pAlarm->trigger);
     }
@@ -1704,7 +1790,7 @@ ProcSyncQueryAlarm(ClientPtr client)
     rep.sequenceNumber = client->sequence;
 
     pTrigger = &pAlarm->trigger;
-    rep.counter = (pTrigger->pCounter) ? pTrigger->pCounter->sync.id : None;
+    rep.counter = (pTrigger->pSync) ? pTrigger->pSync->id : None;
 
 #if 0 /* XXX unclear what to do, depends on whether relative value-types
        * are "consumed" immediately and are considered absolute from then
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index dafbfdf..64e42cd 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -101,7 +101,7 @@ typedef struct _SysCounterInfo {
 
 
 typedef struct _SyncTrigger {
-    SyncCounter *pCounter;
+    SyncObject *pSync;
     CARD64	wait_value;	/* wait value */
     unsigned int value_type;     /* Absolute or Relative */
     unsigned int test_type;	/* transition or Comparision type */
commit 99daf419a3070c347c0cd29b4a9bae07eca7bd6d
Author: James Jones <jajones at nvidia.com>
Date:   Mon Jun 28 14:51:54 2010 -0700

    Create SyncObject base type.
    
    SyncObject is now the base type for SyncCounter.
    Data to be used by all sync types is stored in
    the base object.  SyncCounter can be safely cast
    to SyncObject, and a SyncObject can be cast to
    the correct type based on SyncObject::type.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index 4da06ac..d5187dd 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -89,7 +89,7 @@ static int SyncNumSystemCounters = 0;
 static SyncCounter **SysCounterList = NULL;
 
 #define IsSystemCounter(pCounter) \
-    (pCounter && (pCounter->client == NULL))
+    (pCounter && (pCounter->sync.client == NULL))
 
 /* these are all the alarm attributes that pertain to the alarm's trigger */
 #define XSyncCAAllTrigger \
@@ -118,7 +118,7 @@ SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
 	return;
 
     pPrev = NULL;
-    pCur = pTrigger->pCounter->pTriglist;
+    pCur = pTrigger->pCounter->sync.pTriglist;
 
     while (pCur)
     {
@@ -127,7 +127,7 @@ SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
 	    if (pPrev)
 		pPrev->next = pCur->next;
 	    else
-		pTrigger->pCounter->pTriglist = pCur->next;
+		pTrigger->pCounter->sync.pTriglist = pCur->next;
 
 	    free(pCur);
 	    break;
@@ -151,7 +151,7 @@ SyncAddTriggerToCounter(SyncTrigger *pTrigger)
 	return Success;
 
     /* don't do anything if it's already there */
-    for (pCur = pTrigger->pCounter->pTriglist; pCur; pCur = pCur->next)
+    for (pCur = pTrigger->pCounter->sync.pTriglist; pCur; pCur = pCur->next)
     {
 	if (pCur->pTrigger == pTrigger)
 	    return Success;
@@ -161,8 +161,8 @@ SyncAddTriggerToCounter(SyncTrigger *pTrigger)
 	return BadAlloc;
 
     pCur->pTrigger = pTrigger;
-    pCur->next = pTrigger->pCounter->pTriglist;
-    pTrigger->pCounter->pTriglist = pCur;
+    pCur->next = pTrigger->pCounter->sync.pTriglist;
+    pTrigger->pCounter->sync.pTriglist = pCur;
 
     if (IsSystemCounter(pTrigger->pCounter))
 	SyncComputeBracketValues(pTrigger->pCounter);
@@ -390,14 +390,14 @@ SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait **ppAwait,
 	SyncTrigger *pTrigger = &(*ppAwait)->trigger;
 	pev->type = SyncEventBase + XSyncCounterNotify;
 	pev->kind = XSyncCounterNotify;
-	pev->counter = pTrigger->pCounter->id;
+	pev->counter = pTrigger->pCounter->sync.id;
 	pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value);
 	pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value);
 	pev->counter_value_lo = XSyncValueLow32(pTrigger->pCounter->value);
 	pev->counter_value_hi = XSyncValueHigh32(pTrigger->pCounter->value);
 	pev->time = currentTime.milliseconds;
 	pev->count = num_events - i - 1; /* events remaining */
-	pev->destroyed = pTrigger->pCounter->beingDestroyed;
+	pev->destroyed = pTrigger->pCounter->sync.beingDestroyed;
     }
     /* swapping will be taken care of by this */
     WriteEventsToClient(client, num_events, (xEvent *)pEvents);
@@ -532,7 +532,7 @@ SyncAwaitTriggerFired(SyncTrigger *pTrigger)
 	 *  always generated if the counter for one of the triggers is
 	 *  destroyed."
 	 */
-	if (pAwait->trigger.pCounter->beingDestroyed)
+	if (pAwait->trigger.pCounter->sync.beingDestroyed)
 	{
 	    ppAwait[num_events++] = pAwait;
 	    continue;
@@ -600,7 +600,7 @@ SyncChangeCounter(SyncCounter *pCounter, CARD64 newval)
     pCounter->value = newval;
 
     /* run through triggers to see if any become true */
-    for (ptl = pCounter->pTriglist; ptl; ptl = pnext)
+    for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext)
     {
 	pnext = ptl->next;
 	if ((*ptl->pTrigger->CheckTrigger)(ptl->pTrigger, oldval))
@@ -692,7 +692,8 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
     XSyncCounter   counter;
     Mask	   origmask = mask;
 
-    counter = pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->id : None;
+    counter =
+	pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->sync.id : None;
 
     while (mask)
     {
@@ -781,26 +782,52 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
     return Success;
 }
 
-
-static SyncCounter *
-SyncCreateCounter(ClientPtr client, XSyncCounter id, CARD64 initialvalue)
+static SyncObject *
+SyncCreate(ClientPtr client, XID id, unsigned char type)
 {
-    SyncCounter *pCounter;
+    SyncObject *pSync;
+    RESTYPE resType;
+    unsigned long syncSize;
 
-    if (!(pCounter = malloc(sizeof(SyncCounter))))
+    switch (type) {
+    case SYNC_COUNTER:
+	resType = RTCounter;
+	syncSize = sizeof(SyncCounter);
+	break;
+    default:
 	return NULL;
+    }
 
-    if (!AddResource(id, RTCounter, (pointer) pCounter))
+    if (!(pSync = (SyncObject *)malloc(syncSize)))
+	return NULL;
+
+    if (!AddResource(id, resType, (pointer) pSync))
     {
-	free(pCounter);
+	free(pSync);
 	return NULL;
     }
 
-    pCounter->client = client;
-    pCounter->id = id;
+    pSync->client = client;
+    pSync->id = id;
+    pSync->pTriglist = NULL;
+    pSync->beingDestroyed = FALSE;
+    pSync->type = type;
+
+    return pSync;
+}
+
+
+static SyncCounter *
+SyncCreateCounter(ClientPtr client, XSyncCounter id, CARD64 initialvalue)
+{
+    SyncCounter *pCounter;
+
+    if (!(pCounter = (SyncCounter *)SyncCreate(client,
+					       id,
+					       SYNC_COUNTER)))
+	return NULL;
+
     pCounter->value = initialvalue;
-    pCounter->pTriglist = NULL;
-    pCounter->beingDestroyed = FALSE;
     pCounter->pSysCounterInfo = NULL;
     return pCounter;
 }
@@ -852,7 +879,7 @@ SyncCreateSystemCounter(
 	psci = malloc(sizeof(SysCounterInfo));
 	if (!psci)
 	{
-	    FreeResource(pCounter->id, RT_NONE);
+	    FreeResource(pCounter->sync.id, RT_NONE);
 	    return pCounter;
 	}
 	pCounter->pSysCounterInfo = psci;
@@ -872,7 +899,7 @@ void
 SyncDestroySystemCounter(pointer pSysCounter)
 {
     SyncCounter *pCounter = (SyncCounter *)pSysCounter;
-    FreeResource(pCounter->id, RT_NONE);
+    FreeResource(pCounter->sync.id, RT_NONE);
 }
 
 static void
@@ -896,7 +923,7 @@ SyncComputeBracketValues(SyncCounter *pCounter)
     XSyncMaxValue(&psci->bracket_greater);
     XSyncMinValue(&psci->bracket_less);
 
-    for (pCur = pCounter->pTriglist; pCur; pCur = pCur->next)
+    for (pCur = pCounter->sync.pTriglist; pCur; pCur = pCur->next)
     {
 	pTrigger = pCur->pTrigger;
 	
@@ -986,9 +1013,9 @@ FreeCounter(void *env, XID id)
     SyncCounter     *pCounter = (SyncCounter *) env;
     SyncTriggerList *ptl, *pnext;
 
-    pCounter->beingDestroyed = TRUE;
+    pCounter->sync.beingDestroyed = TRUE;
     /* tell all the counter's triggers that the counter has been destroyed */
-    for (ptl = pCounter->pTriglist; ptl; ptl = pnext)
+    for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext)
     {
 	(*ptl->pTrigger->CounterDestroyed)(ptl->pTrigger);
 	pnext = ptl->next;
@@ -1048,7 +1075,7 @@ FreeAwait(void *addr, XID id)
 	 * the trigger list itself, so don't do it here.
 	 */
 	SyncCounter *pCounter = pAwait->trigger.pCounter;
-	if (pCounter && !pCounter->beingDestroyed)
+	if (pCounter && !pCounter->sync.beingDestroyed)
 	    SyncDeleteTriggerFromCounter(&pAwait->trigger);
     }
     free(pAwaitUnion);
@@ -1158,7 +1185,7 @@ ProcSyncListSystemCounters(ClientPtr client)
 	char *pname_in_reply;
 	SysCounterInfo *psci = SysCounterList[i]->pSysCounterInfo;
 
-	walklist->counter = SysCounterList[i]->id;
+	walklist->counter = SysCounterList[i]->sync.id;
 	walklist->resolution_hi = XSyncValueHigh32(psci->resolution);
 	walklist->resolution_lo = XSyncValueLow32(psci->resolution);
 	namelen = strlen(psci->name);
@@ -1371,7 +1398,7 @@ ProcSyncDestroyCounter(ClientPtr client)
 	client->errorValue = stuff->counter;
 	return BadAccess;
     }
-    FreeResource(pCounter->id, RT_NONE);
+    FreeResource(pCounter->sync.id, RT_NONE);
     return Success;
 }
 
@@ -1677,7 +1704,7 @@ ProcSyncQueryAlarm(ClientPtr client)
     rep.sequenceNumber = client->sequence;
 
     pTrigger = &pAlarm->trigger;
-    rep.counter = (pTrigger->pCounter) ? pTrigger->pCounter->id : None;
+    rep.counter = (pTrigger->pCounter) ? pTrigger->pCounter->sync.id : None;
 
 #if 0 /* XXX unclear what to do, depends on whether relative value-types
        * are "consumed" immediately and are considered absolute from then
@@ -2243,7 +2270,7 @@ static void
 IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
 {
     XSyncValue idle, old_idle;
-    SyncTriggerList *list = IdleTimeCounter->pTriglist;
+    SyncTriggerList *list = IdleTimeCounter->sync.pTriglist;
     SyncTrigger *trig;
 
     if (!pIdleTimeValueLess && !pIdleTimeValueGreater)
@@ -2264,7 +2291,7 @@ IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
 	 * immediately so we can reschedule.
 	 */
 
-	for (list = IdleTimeCounter->pTriglist; list; list = list->next) {
+	for (list = IdleTimeCounter->sync.pTriglist; list; list = list->next) {
 	    trig = list->pTrigger;
 	    if (trig->CheckTrigger(trig, old_idle)) {
 		AdjustWaitForDelay(wt, 0);
@@ -2290,7 +2317,7 @@ IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
 	                        idle, &overflow);
 	    timeout = min(timeout, XSyncValueLow32 (value));
 	} else {
-	    for (list = IdleTimeCounter->pTriglist; list; list = list->next) {
+	    for (list = IdleTimeCounter->sync.pTriglist; list; list = list->next) {
 		trig = list->pTrigger;
 		if (trig->CheckTrigger(trig, old_idle)) {
 		    timeout = min(timeout, 0);
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index 6d0e3d6..dafbfdf 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -53,12 +53,20 @@ PERFORMANCE OF THIS SOFTWARE.
 
 #define CARD64 XSyncValue /* XXX temporary! need real 64 bit values for Alpha */
 
-typedef struct _SyncCounter {
+/* Sync object types */
+#define SYNC_COUNTER		0
+
+typedef struct _SyncObject {
     ClientPtr		client;	/* Owning client. 0 for system counters */
-    XSyncCounter	id;		/* resource ID */
-    CARD64		value;		/* counter value */
     struct _SyncTriggerList *pTriglist;	/* list of triggers */
-    Bool		beingDestroyed; /* in process of going away */
+    XID			id;		/* resource ID */
+    unsigned char	type;		/* SYNC_* */
+    Bool		beingDestroyed;	/* in process of going away */
+} SyncObject;
+
+typedef struct _SyncCounter {
+    SyncObject		sync;		/* Common sync object data */
+    CARD64		value;		/* counter value */
     struct _SysCounterInfo *pSysCounterInfo; /* NULL if not a system counter */
 } SyncCounter;
 
commit 27593eea7efcbed8de0c6e8233cbd1a1b8a50459
Author: James Jones <jajones at nvidia.com>
Date:   Mon Dec 6 13:36:14 2010 -0800

    Add and use SERVER_SYNC_*_VERSION
    
    Most extensions have a version defined
    in the protocol headers, and also in the
    server's protocol-versions.h.  The latter
    defines which version the server advertises
    support for.  Sync wasn't included in
    protocol-versions.h, and was advertising
    support for whatever was in the protocol
    headers the server was built against.
    
    Signed-off-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index f23df6c..4da06ac 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -67,6 +67,7 @@ PERFORMANCE OF THIS SOFTWARE.
 #include "opaque.h"
 #include <X11/extensions/syncproto.h>
 #include "syncsrv.h"
+#include "protocol-versions.h"
 
 #include <stdio.h>
 #if !defined(WIN32)
@@ -1099,8 +1100,8 @@ ProcSyncInitialize(ClientPtr client)
     memset(&rep, 0, sizeof(xSyncInitializeReply));
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SYNC_MAJOR_VERSION;
-    rep.minorVersion = SYNC_MINOR_VERSION;
+    rep.majorVersion = SERVER_SYNC_MAJOR_VERSION;
+    rep.minorVersion = SERVER_SYNC_MINOR_VERSION;
     rep.length = 0;
 
     if (client->swapped)
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index c674465..ce28797 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -95,6 +95,10 @@
 #define SERVER_SHM_MAJOR_VERSION		1
 #define SERVER_SHM_MINOR_VERSION		1
 
+/* Sync */
+#define SERVER_SYNC_MAJOR_VERSION		3
+#define SERVER_SYNC_MINOR_VERSION		0
+
 /* Windows WM */
 #define SERVER_WINDOWSWM_MAJOR_VERSION		1
 #define SERVER_WINDOWSWM_MINOR_VERSION		0
commit 68a1b0de95f71f74835c6c0f002699fcdccbb268
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 6 14:58:37 2010 +1000

    xfree86: use xf86AllocateInput() for xorg.conf devices too.
    
    Single allocation point for input devices, most notably a single point to
    reset default values.
    Without this patch, the file descriptor default was -1 for hotplugged
    devices and 0 for config devices. Drivers that don't overwrite the default
    themselves would thus fail if configured in the xorg.conf.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index c352f3c..ae9592e 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1458,7 +1458,7 @@ configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp)
     irp = layout->lay_input_lst;
     count = 0;
     while (irp) {
-	indp[count] = xnfalloc(sizeof(InputInfoRec));
+	indp[count] = xf86AllocateInput();
 	if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) {
 	    while(count--)
 		free(indp[count]);
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 0fc5e1d..c2cf438 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -653,7 +653,7 @@ IgnoreInputClass(const InputInfoPtr idev, const InputAttributes *attrs)
     return ignore;
 }
 
-static InputInfoPtr
+InputInfoPtr
 xf86AllocateInput(void)
 {
     InputInfoPtr pInfo;
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 3a17116..1b0b16f 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -155,6 +155,7 @@ extern _X_EXPORT void xf86DisableDevice(DeviceIntPtr dev, Bool panic);
 extern _X_EXPORT void xf86EnableDevice(DeviceIntPtr dev);
 /* not exported */
 int xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL is_auto);
+InputInfoPtr xf86AllocateInput(void);
 
 /* xf86Helper.c */
 extern _X_EXPORT void xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags);
commit beea2378f142556471c62290e275935af848e137
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 6 14:33:43 2010 +1000

    xfree86: don't overwrite option list (#32115)
    
    Options set in the configuration file were unconditionally overwritten by
    the server. Merge the already existing options and the new options together
    instead of just overwriting ones.
    
    Introduced in commit 2199842ed50b3eb40d54146827fc58cae7e873ec
    Author: Peter Hutterer <peter.hutterer at who-t.net>
    Date:   Thu Sep 2 10:52:54 2010 +1000
    
        xfree86: remove extraOptions field from IDevRec.
    
    X.Org Bug 32115 <http://bugs.freedesktop.org/show_bug.cgi?id=32115>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
    Tested-by: David Ronis <ronis at ronispc.chem.mcgill.ca>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 5800700..c352f3c 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1465,7 +1465,8 @@ configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp)
 	    free(indp);
 	    return FALSE;
 	}
-	indp[count]->options = irp->iref_option_lst;
+	indp[count]->options = xf86OptionListMerge(indp[count]->options,
+						   irp->iref_option_lst);
 	count++;
 	irp = (XF86ConfInputrefPtr)irp->list.next;
     }
commit 8f3fa8fb0b0a75dac714fc213c034b20595898d3
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 6 15:44:50 2010 +1000

    xfree86: add option "Floating", deprecate SendCoreEvents and friends.
    
    Some devices should be initialised as floating from the start (e.g.
    Joysticks and accelerometers benefit from this). Currently users use the
    "SendCoreEvents" "off" flag for this, which isn't the most appropriate
    naming.
    
    Add an option "Floating", deprecate the others. Still parsed and handled by
    the server.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 81bb707..0fc5e1d 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -280,7 +280,8 @@ void
 xf86ProcessCommonOptions(InputInfoPtr pInfo,
                          pointer	list)
 {
-    if (!xf86SetBoolOption(list, "AlwaysCore", 1) ||
+    if (xf86SetBoolOption(list, "Floating", 0) ||
+        !xf86SetBoolOption(list, "AlwaysCore", 1) ||
         !xf86SetBoolOption(list, "SendCoreEvents", 1) ||
         !xf86SetBoolOption(list, "CorePointer", 1) ||
         !xf86SetBoolOption(list, "CoreKeyboard", 1)) {
diff --git a/hw/xfree86/doc/devel/Registry b/hw/xfree86/doc/devel/Registry
index e09228b..48e24a2 100644
--- a/hw/xfree86/doc/devel/Registry
+++ b/hw/xfree86/doc/devel/Registry
@@ -243,6 +243,7 @@ DemandLoad                O     I    ??
 Device                    S     I    Device file name
 DeviceName                S     I    Input device name
 FlowControl               S     I    Serial flow control ("xon", "none")
+Floating                  B     I    Device initialised as floating
 HistorySize               I     I    ??
 MaxX                      I     I    Maximum X coordinate
 MaxY                      I     I    Maximum Y coordinate
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index ba876c0..e3fd0ea 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -904,30 +904,42 @@ the server. This affects implied layouts as well as explicit layouts
 specified in the configuration and/or on the command line.
 .TP 7
 .BI "Option \*qCorePointer\*q"
-Deprecated, use
-.B SendCoreEvents
-instead.
+Deprecated, see
+.B Floating
 .TP 7
 .BI "Option \*qCoreKeyboard\*q"
-Deprecated, use
-.B SendCoreEvents
-instead.
+Deprecated, see
+.B Floating
 .TP 7
 .BI "Option \*qAlwaysCore\*q  \*q" boolean \*q
-.B
-Deprecated, use
-.B SendCoreEvents
-instead.
+Deprecated, see
+.B Floating
 .TP 7
 .BI "Option \*qSendCoreEvents\*q  \*q" boolean \*q
-Both of these options are equivalent, and when enabled cause the
-input device to report core events through the master device. They are
-enabled by default.  Any device configured to send core events will be
-attached to the virtual core pointer or keyboard and control the cursor by
-default. Devices with
-.B SendCoreEvents
-disabled will be \*qfloating\*q and only accessible by clients employing the
-X Input extension. This option controls the startup behavior only, a device
+Deprecated, see
+.B Floating
+
+.TP 7
+.BI "Option \*qFloating\*q  \*q" boolean \*q
+When enabled, the input device is set up floating and does not
+report events through any master device or control a cursor. The device is
+only available to clients using the X Input Extension API. This option is
+disabled by default.
+The options
+.B CorePointer,
+.B CoreKeyboard,
+.B AlwaysCore,
+and
+.B SendCoreEvents,
+are the inverse of option
+.B Floating
+(i.e.
+.B SendCoreEvents \*qon\*q
+is equivalent to
+.B Floating \*qoff\*q
+).
+
+This option controls the startup behavior only, a device
 may be reattached or set floating at runtime.
 .PP
 For pointing devices, the following options control how the pointer
commit 36b614dedf4ddc428e43ad1542d4f9314f73f60a
Author: Eoghan Sherry <ejsherry at gmail.com>
Date:   Sun Nov 28 16:15:51 2010 -0500

    Xi: Fix master button update when slave buttons are mapped. #24887
    
    It is currently assumed that an event button delieved to a master device
    corresponds to the slave button states. However, the event button is a
    logical (mapped) slave button and slave button states correspond to
    physical (unmapped) slave buttons. This leads to incorrect update of the
    master button state and incorrect events devlivered to clients. Fix the
    situation by taking the slave button map into account when querying a
    slave button state.
    
    Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=24887
    
    Signed-off-by: Eoghan Sherry <ejsherry at gmail.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index d57265e..8615fd4 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -870,8 +870,10 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
                     continue;
                 if (!sd->button)
                     continue;
-                if (button_is_down(sd, key, BUTTON_PROCESSED))
-                    return DONT_PROCESS;
+                for (i = 1; i <= sd->button->numButtons; i++)
+                    if (sd->button->map[i] == key &&
+                        button_is_down(sd, i, BUTTON_PROCESSED))
+                        return DONT_PROCESS;
             }
         }
         set_button_up(device, key, BUTTON_PROCESSED);
commit 31ab9f8860848504df18a8be9d19b817b191e0df
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Sep 3 11:54:41 2010 +1000

    mi: handle DGA subtypes when determining the master device.
    
    The subtype in the DGA event is the core type and all ET_ event types (where
    applicable) are identical to the core types. Thus the switch statement below
    will work as required and assign the right master device.
    
    Fixes a crasher bug on keyboard devices with valuators. If a device sends a
    motion event while grabbed and a DGA client is active (but has not selected
    input through DGA), the valuator event is posted through the VCK and
    eventually results in a NULL-pointer dereference on dev->valuator.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/mi/mieq.c b/mi/mieq.c
index d1441e2..01da52a 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -320,6 +320,7 @@ CopyGetMasterEvent(DeviceIntPtr sdev,
 {
     DeviceIntPtr mdev;
     int len = original->any.length;
+    int type = original->any.type;
 
     CHECKEVENT(original);
 
@@ -327,7 +328,12 @@ CopyGetMasterEvent(DeviceIntPtr sdev,
     if (!sdev || !sdev->u.master)
         return NULL;
 
-    switch(original->any.type)
+#if XFreeXDGA
+    if (type == ET_DGAEvent)
+        type = original->dga_event.subtype;
+#endif
+
+    switch(type)
     {
         case ET_KeyPress:
         case ET_KeyRelease:
commit 5d31c3e705dfd9f38f0fffcd07a6d8d06644735c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Nov 26 09:37:37 2010 +1000

    dix: don't stop processing valuators when the mode changes.
    
    XI 1.x events still contain absolute coordinates anyway. By the time we get
    to the InternalEvent to XI event conversion, the valuators are already
    absolute.
    
    Stopping because of a different mode on a valuator is not necessary.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index dd17898..7b894f0 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -326,14 +326,6 @@ countValuators(DeviceEvent *ev, int *first)
     {
         if (BitIsOn(ev->valuators.mask, i))
         {
-            /* Assume mode of first_valuator matches XI1 device mode. Stop when the
-             * event mode changes since XI1 can't handle mixed mode devices.
-             */
-            if (first_valuator > -1 &&
-                 BitIsOn(ev->valuators.mode, i) !=
-                 BitIsOn(ev->valuators.mode, first_valuator))
-                break;
-
             if (first_valuator == -1)
                 first_valuator = i;
             last_valuator = i;
commit 8f42b2b69387b006bfcd373c3d023ebea9035db2
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 22:34:57 2010 -0800

    Simplify Error() - don't allocate temporary copy of error string
    
    Doesn't seem to be any reason to just not pass the error string
    as another argument directly to LogVWrite()
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/include/os.h b/include/os.h
index e882a0c..566514d 100644
--- a/include/os.h
+++ b/include/os.h
@@ -526,7 +526,7 @@ extern _X_EXPORT void FatalError(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2) _X
 
 extern _X_EXPORT void VErrorF(const char *f, va_list args);
 extern _X_EXPORT void ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
-extern _X_EXPORT void Error(char *str);
+extern _X_EXPORT void Error(const char *str);
 extern _X_EXPORT void LogPrintMarkers(void);
 
 extern _X_EXPORT void xorg_backtrace(void);
diff --git a/os/log.c b/os/log.c
index d77708e..fdcf91c 100644
--- a/os/log.c
+++ b/os/log.c
@@ -571,21 +571,14 @@ ErrorF(const char * f, ...)
 /* A perror() workalike. */
 
 void
-Error(char *str)
+Error(const char *str)
 {
-    char *err = NULL;
-    int saveErrno = errno;
-
-    if (str) {
-	err = malloc(strlen(strerror(saveErrno)) + strlen(str) + 2 + 1);
-	if (!err)
-	    return;
-	sprintf(err, "%s: ", str);
-	strcat(err, strerror(saveErrno));
+    const char *err = strerror(errno);
+
+    if (str)
+	LogWrite(-1, "%s: %s", str, err);
+    else
 	LogWrite(-1, "%s", err);
-	free(err);
-    } else
-	LogWrite(-1, "%s", strerror(saveErrno));
 }
 
 void
commit 685286b17d30335d799a9da11914943e466ea955
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 20:43:28 2010 -0800

    FindModuleInSubdir: Stop allocating one more byte than needed
    
    15ac25627e7239629be59 removed the "/" from the sprintf strings,
    but failed to remove the extra byte allocated for the '/'.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 6e65227..06d082b 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -406,21 +406,21 @@ FindModuleInSubdir(const char *dirpath, const char *module)
  
         snprintf(tmpBuf, PATH_MAX, "lib%s.so", module);
         if (strcmp(direntry->d_name, tmpBuf) == 0) {
-            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 2);
+            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1);
             sprintf(ret, "%s%s", dirpath, tmpBuf);
             break;
         }
 
         snprintf(tmpBuf, PATH_MAX, "%s_drv.so", module);
         if (strcmp(direntry->d_name, tmpBuf) == 0) {
-            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 2);
+            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1);
             sprintf(ret, "%s%s", dirpath, tmpBuf);
             break;
         }
 
         snprintf(tmpBuf, PATH_MAX, "%s.so", module);
         if (strcmp(direntry->d_name, tmpBuf) == 0) {
-            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 2);
+            ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1);
             sprintf(ret, "%s%s", dirpath, tmpBuf);
             break;
         }
commit 40d5a019352fa8f12230c863e11cbb1f6258a93e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 19:50:38 2010 -0800

    xf86VIDrvMsgVerb: print args, not format string
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 78e6b20..ea0acbf 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1190,7 +1190,7 @@ xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *forma
     char *msg;
 
     msg = Xprintf("%s: %s: %s", dev->drv->driverName, dev->name, format);
-    LogVMessageVerb(type, verb, "%s", msg);
+    LogVMessageVerb(type, verb, msg, args);
     free(msg);
 }
 
commit 4bbc90cd8b7e749fd8072ce7cd8dd998f4396981
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 19:06:56 2010 -0800

    xf86AutoConfig: make copyScreen memory allocation & error handling more sane
    
    No point calling the no-fail-alloc if you check for failure and your
    only caller checks for failure.
    
    No point calling calloc to zero fill memory you're about to memcpy over.
    
    In the unlikely event of a loss of memory allocation, drop your previous
    allocations before returning to others.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 200cb8f..3cd5ef6 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -282,21 +282,31 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
 static Bool
 copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver)
 {
+    confScreenPtr nscreen;
     GDevPtr cptr = NULL;
 
-    xf86ConfigLayout.screens[i].screen = xnfcalloc(1, sizeof(confScreenRec));
-    if(!xf86ConfigLayout.screens[i].screen)
+    nscreen = malloc(sizeof(confScreenRec));
+    if (!nscreen)
         return FALSE;
-    memcpy(xf86ConfigLayout.screens[i].screen, oscreen, sizeof(confScreenRec));
+    memcpy(nscreen, oscreen, sizeof(confScreenRec));
 
-    cptr = calloc(1, sizeof(GDevRec));
-    if (!cptr)
+    cptr = malloc(sizeof(GDevRec));
+    if (!cptr) {
+        free(nscreen);
         return FALSE;
+    }
     memcpy(cptr, odev, sizeof(GDevRec));
 
     cptr->identifier = Xprintf("Autoconfigured Video Device %s", driver);
+    if (!cptr->identifier) {
+        free(cptr);
+        free(nscreen);
+        return FALSE;
+    }
     cptr->driver = driver;
 
+    xf86ConfigLayout.screens[i].screen = nscreen;
+
     /* now associate the new driver entry with the new screen entry */
     xf86ConfigLayout.screens[i].screen->device = cptr;
     cptr->myScreenSection = xf86ConfigLayout.screens[i].screen;
commit 2c8e534c8e9334562485aeaaef374871cf14d5fe
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 23:49:55 2010 -0800

    xf86ValidateModes: xnfalloc(strlen) + strcpy => xnfstrdup
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index 54fe021..644e5ce 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -1643,8 +1643,7 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
 	    new = xnfcalloc(1, sizeof(DisplayModeRec));
 	    new->prev = last;
 	    new->type = M_T_USERDEF;
-	    new->name = xnfalloc(strlen(modeNames[i]) + 1);
-	    strcpy(new->name, modeNames[i]);
+	    new->name = xnfstrdup(modeNames[i]);
 	    if (new->prev)
 		new->prev->next = new;
 	    *endp = last = new;
@@ -1716,10 +1715,9 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
 
 	    p = xnfcalloc(1, sizeof(DisplayModeRec));
 	    p->prev = last;
-	    p->name = xnfalloc(strlen(r->name) + 1);
+	    p->name = xnfstrdup(r->name);
 	    if (!userModes)
 		p->type = M_T_USERDEF;
-	    strcpy(p->name, r->name);
 	    if (p->prev)
 		p->prev->next = p;
 	    *endp = last = p;
commit 29e467a1f1548a826ee2793244e3ff416aa1a0f2
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri Nov 26 16:53:40 2010 -0800

    xf86OutputRename: Replace another strlen/malloc/strcpy set with strdup
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 7fc2a60..ae5aad3 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -660,13 +660,11 @@ xf86OutputCreate (ScrnInfoPtr		    scrn,
 Bool
 xf86OutputRename (xf86OutputPtr output, const char *name)
 {
-    int	    len = strlen(name) + 1;
-    char    *newname = malloc(len);
+    char    *newname = strdup(name);
     
     if (!newname)
 	return FALSE;	/* so sorry... */
     
-    strcpy (newname, name);
     if (output->name && output->name != (char *) (output + 1))
 	free(output->name);
     output->name = newname;
commit d346bc3083c6d4bea59b77f634c7c5ec6c1d8cc9
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Nov 28 13:48:16 2010 -0800

    Fix compiler warnings in hw/xfree86/os-support/solaris
    
    sun_init.c: In function `xf86OpenConsole':
    sun_init.c:99: warning: cast does not match function type
    sun_init.c:74: warning: unused variable `FreeVTslot'
    sun_init.c: In function `xf86UseMsg':
    sun_init.c:417: warning: old-style parameter declaration
    
    sun_vid.c: In function `solUnMapVidMem':
    sun_vid.c:162: warning: long unsigned int format, pointer arg (arg 6)
    sun_vid.c: In function `xf86ReadBIOS':
    sun_vid.c:217: warning: long unsigned int format, pointer arg (arg 5)
    sun_vid.c:217: warning: long unsigned int format, int arg (arg 6)
    
    sun_agp.c: In function `xf86EnableAGP':
    sun_agp.c:321: warning: unsigned int format, CARD32 arg (arg 4)
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/os-support/solaris/sun_agp.c b/hw/xfree86/os-support/solaris/sun_agp.c
index 9db5d63..dd4b1e2 100644
--- a/hw/xfree86/os-support/solaris/sun_agp.c
+++ b/hw/xfree86/os-support/solaris/sun_agp.c
@@ -318,7 +318,7 @@ xf86EnableAGP(int screenNum, CARD32 mode)
 	if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) {
 		xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: "
 		    "AGPIOC_SETUP with mode %x failed (%s)\n",
-		    mode, strerror(errno));
+		    (unsigned int) mode, strerror(errno));
 		return FALSE;
 	}
 
diff --git a/hw/xfree86/os-support/solaris/sun_init.c b/hw/xfree86/os-support/solaris/sun_init.c
index edcc60b..281a6df 100644
--- a/hw/xfree86/os-support/solaris/sun_init.c
+++ b/hw/xfree86/os-support/solaris/sun_init.c
@@ -71,7 +71,6 @@ xf86OpenConsole(void)
     int fd;
     struct vt_mode VT;
     struct vt_stat vtinfo;
-    int FreeVTslot;
     MessageType from = X_PROBED;
 #endif
 
@@ -95,8 +94,8 @@ xf86OpenConsole(void)
 	    }
 	    else
 	    {
-		if ((int)mmap(0, 0x1000, PROT_NONE,
-			      MAP_FIXED | MAP_SHARED, fd, 0) == -1)
+		if (mmap(0, 0x1000, PROT_NONE,
+			 MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED)
 		    xf86Msg(X_WARNING,
 			"xf86OpenConsole: failed to protect page 0 (%s)\n",
 			strerror(errno));
@@ -413,7 +412,7 @@ xf86ProcessArgument(int argc, char **argv, int i)
     return 0;
 }
 
-void xf86UseMsg()
+void xf86UseMsg(void)
 {
 #ifdef HAS_USL_VTS
     ErrorF("vtX                    Use the specified VT number\n");
diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c
index 5089ae7..9497973 100644
--- a/hw/xfree86/os-support/solaris/sun_vid.c
+++ b/hw/xfree86/os-support/solaris/sun_vid.c
@@ -157,7 +157,7 @@ solUnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
     if (munmap(Base, Size) != 0) {
 	xf86DrvMsgVerb(ScreenNum, X_WARNING, 0,
 		       "solUnMapVidMem: failed to unmap %s"
-		       " (0x%08lx,0x%lx) (%s)\n",
+		       " (0x%p,0x%lx) (%s)\n",
 		       apertureDevName, Base, Size,
 		       strerror(errno));
     }
@@ -212,8 +212,7 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
     (void)memcpy(Buf, (void *)(ptr + Offset), Len);
     if (munmap((caddr_t)ptr, mlen) != 0) {
 	xf86MsgVerb(X_WARNING, 0,
-		    "solUnMapVidMem: failed to unmap %s"
-		    " (0x%08lx,0x%lx) (%s)\n",
+		    "xf86ReadBIOS: failed to unmap %s (0x%p,0x%x) (%s)\n",
 		    apertureDevName, ptr, mlen, strerror(errno));
     }
 
commit d75777d54c2107163305f50e8ee4306da202b95e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Nov 28 13:45:40 2010 -0800

    Move xchomp inside #ifdef __linux__
    
    static function only called from the matchDriverFromFiles function
    that's inside #ifdef __linux__ section
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 3e9c455..d689832 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -1167,6 +1167,7 @@ videoPtrToDriverList(struct pci_device *dev,
     return i;	/* Number of entries added */
 }
 
+#ifdef __linux__
 static int
 xchomp(char *line)
 {
@@ -1183,7 +1184,6 @@ xchomp(char *line)
     return 0;
 }
 
-#ifdef __linux__
 /* This function is used to provide a workaround for binary drivers that
  * don't export their PCI ID's properly. If distros don't end up using this
  * feature it can and should be removed because the symbol-based resolution
commit ccbba444b7b8e1ba555532a847377600bea43d03
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Nov 28 10:45:17 2010 -0800

    config: Remove AC_PROG_CC, SED & INSTALL that XORG_DEFAULT_OPTIONS provide
    
    Most importantly removes AC_PROG_CC call that resets compiler flags back
    to C89 mode, breaking use of C99 isfinite() on Solaris in dix/devices.c.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/configure.ac b/configure.ac
index 2363e38..4365f5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,9 +64,7 @@ dnl version-config.h covers the version numbers so they can be bumped without
 dnl forcing an entire recompile.x
 AC_CONFIG_HEADERS(include/version-config.h)
 
-AC_PROG_CC
 AM_PROG_AS
-AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_LIBTOOL_WIN32_DLL
 AC_DISABLE_STATIC
@@ -77,7 +75,6 @@ AC_PROG_LEX
 AC_PROG_YACC
 AC_SYS_LARGEFILE
 XORG_PROG_RAWCPP
-AC_PROG_SED
 
 # Quoted so that make will expand $(CWARNFLAGS) in makefiles to allow
 # easier overrides at build time.
commit 92cde0b84cdec164cd698dc74a7512d0791d7708
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 08:15:52 2010 -0800

    Xserver-spec: Update discussion of font library
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index 391ecb9..a2aec2f 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -1182,7 +1182,8 @@ are requests in that client's input queue.
   <title>Font Support</title>
 <para>
 In the sample server, fonts are encoded in disk files or fetched from the
-font server.
+font server.   The two fonts required by the server, <quote>fixed</quote>
+and <quote>cursor</quote> are commonly compiled into the font library.
 For disk fonts, there is one file per font, with a file name like
 "fixed.pcf".  Font server fonts are read over the network using the
 X Font Server Protocol.  The disk directories containing disk fonts and
@@ -1196,9 +1197,10 @@ appropriate code in the Font Library, you will automatically export fonts in
 that format both through the X server and the Font server.
 </para>
 <para>
-With the incorporation of font-server based fonts and the Speedo donation
-from Bitstream, the font interfaces have been moved into a separate
-library, now called the Font Library (../fonts/lib).  These routines are
+The code for processing fonts in different formats, as well as handling the
+metadata files for them on disk (such as <filename>fonts.dir</filename>) is
+located in the libXfont library, which is provided as a separately compiled
+module.  These routines are
 shared between the X server and the Font server, so instead of this document
 specifying what you must implement, simply refer to the font
 library interface specification for the details.  All of the interface code to the Font
commit c1e769250078cbc74d7e6e6ddc5323c4f420ab14
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 08:06:40 2010 -0800

    Xserver-spec: Update location of log functions
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index 7430637..391ecb9 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -1344,7 +1344,7 @@ terminate the server; it must not return.
 </para>
 <para>
 The sample server implementation for these routines
-is in Xserver/os/util.c.
+is in Xserver/os/log.c along with other routines for logging messages.
 </para>
 </section>
 </section>
commit deae18f3cad94959110761ef2ecd9665690e3db5
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 00:45:48 2010 -0800

    Xserver-spec: Fix assorted typos
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index f35dd0c..7430637 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -480,7 +480,7 @@ these operations.</para>
 Before getting bogged down in the interface details, an typical usage
 example should establish the framework.  Let's look at the
 ClientStateCallback in dix/dispatch.c.  The purpose of this particular
-callback is to notify intereseted parties when a client's state
+callback is to notify interested parties when a client's state
 (initial, running, gone) changes.  The callback is "created" in this
 case by simply declaring a variable:
 <blockquote><programlisting>
@@ -489,7 +489,7 @@ case by simply declaring a variable:
 </para>
 <para>
 Whenever the client's state changes, the following code appears, which notifies
-all intereseted parties of the change:
+all interested parties of the change:
 <blockquote><programlisting>
 	if (ClientStateCallback) CallCallbacks(&amp;ClientStateCallback, (pointer)client);
 </programlisting></blockquote>
@@ -759,7 +759,7 @@ These registered block handlers are called after the per-screen handlers:
 <programlisting>
 	void (*BlockHandler) (blockData, pptv, pReadmask)
 		pointer	blockData;
-		OSTimePtr pptv;
+		OsTimerPtr pptv;
 		pointer	pReadmask;
 </programlisting>
 </blockquote>
@@ -770,7 +770,7 @@ which on UNIX family systems is generally represented by a struct timeval
 consisting of seconds and microseconds in 32 bit values.
 As a convenience to reduce error prone struct timeval computations which
 require modulus arithmetic and correct overflow behavior in the face of
-millisecond wrapping throrugh 32 bits,
+millisecond wrapping through 32 bits,
 <blockquote><programlisting>
 
 	void AdjustWaitForDelay(pointer /*waitTime*, unsigned long /* newdelay */)
@@ -875,7 +875,7 @@ and RemoveEnabledDevice are in Xserver/os/connection.c.
 Similarly, the X server or an extension may need to wait for some timeout.
 Early X releases implemented this functionality using block and wakeup handlers,
 but this has been rewritten to use a general timer facilty, and the
-internal screen saver facilties reimplemented to use Timers.
+internal screen saver facilities reimplemented to use Timers.
 These functions are TimerInit, TimerForce, TimerSet, TimerCheck, TimerCancel,
 and TimerFree, as defined in Xserver/include/os.h. A callback function will be called
 when the timer fires, along with the current time, and a user provided argument.
@@ -913,11 +913,11 @@ for the timer entry.
 
 	void TimerCancel(OsTimerPtr /* pTimer */)
 
-	void TimerFree(OSTimerPtr /* pTimer */)
+	void TimerFree(OsTimerPtr /* pTimer */)
 </programlisting></blockquote>
 </para>
 <para>
-TimerInit frees any exisiting timer entries. TimerForce forces a call to the timer's
+TimerInit frees any existing timer entries. TimerForce forces a call to the timer's
 callback function and returns true if the timer entry existed, else it returns false and
 does not call the callback function. TimerCancel will cancel the specified timer.
 TimerFree calls TimerCancel and frees the specified timer.
@@ -1807,7 +1807,7 @@ printed on each keycap. (See X11/keysym.h)
 <para>
 Legal modifier keys must generate both up and down transitions.  When
 a client tries to change a modifier key (for instance, to make "A" the
-"Control" key), DIX calls the following routine, which should retuurn
+"Control" key), DIX calls the following routine, which should return
 TRUE if the key can be used as a modifier on the given device:
 <blockquote><programlisting>
 
@@ -2708,7 +2708,7 @@ Xserver/dix/colormap.c.)</para>
 
 
 </programlisting></blockquote>
-ListInstalledColormaps fills the pCMapList in with the resource ids
+ListInstalledColormaps fills the pCmapList in with the resource ids
 of the installed maps and returns a count of installed maps.
 pCmapList will point to an array of size MaxInstalledMaps that was allocated
 by the caller.</para>
@@ -3606,7 +3606,7 @@ this screen function.  The new border width is given by width.</para>
 </programlisting></blockquote>
 This function is called for windows that are being unrealized as part of
 an UnrealizeTree.  pChild is the window being unrealized, pWin is an
-ancestor, and the fromConfigure value is simply propogated from UnrealizeTree.</para>
+ancestor, and the fromConfigure value is simply propagated from UnrealizeTree.</para>
 </section>
 </section>
 </section>
@@ -5011,7 +5011,7 @@ mi and fb implementations.</para>
 <row><entry><function>ListInstalledColormaps</function></entry><entry><literal>ddx</literal></entry><entry><para>Screen</para></entry></row>
 <row><entry><function>LookupKeyboardDevice</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
 <row><entry><function>LookupPointerDevice</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
-<row><entry><function>ModifyPixmapheader</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
+<row><entry><function>ModifyPixmapHeader</function></entry><entry><literal>mi</literal></entry><entry><para>Screen</para></entry></row>
 <row><entry><function>NextAvailableClient</function></entry><entry><literal>dix</literal></entry><entry><para></para></entry></row>
 <row><entry><function>OsInit</function></entry><entry><literal>os</literal></entry><entry><para></para></entry></row>
 <row><entry><function>PaintWindowBackground</function></entry><entry><literal>mi</literal></entry><entry><para>Window</para></entry></row>
commit a410bf53798bdca43f99476a01ef27cabdf73e01
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 00:35:28 2010 -0800

    Xserver-spec: Update lists of macros
    
    LOOKUP_DRAWABLE & VERIFY_GC are no longer in dix.h, but
    WriteReplyToClient & WriteSwappedDataToClient are.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index 6dc2911..f35dd0c 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -588,8 +588,9 @@ used here which takes the minor opcode from the normal place in the request
 There are a number of macros in Xserver/include/dix.h which
 are useful to the extension writer.  Ones of particular interest
 are: REQUEST, REQUEST_SIZE_MATCH, REQUEST_AT_LEAST_SIZE,
-REQUEST_FIXED_SIZE, LEGAL_NEW_RESOURCE, LOOKUP_DRAWABLE, VERIFY_GC, and
+REQUEST_FIXED_SIZE, LEGAL_NEW_RESOURCE, and
 VALIDATE_DRAWABLE_AND_GC. Useful byte swapping macros can be found
+in Xserver/include/dix.h: WriteReplyToClient and WriteSwappedDataToClient; and
 in Xserver/include/misc.h: lswapl, lswaps, LengthRestB, LengthRestS,
 LengthRestL, SwapRestS, SwapRestL, swapl, swaps, cpswapl, and cpswaps.</para>
 </section>
commit de518c8f378ea31345c946693d58a26a493af603
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 00:30:37 2010 -0800

    Xserver-spec: Remove CreateCallbackList
    
    The function is defined as a static, so can't be called by anyone
    but AddCallback.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index 1afae5d..6dc2911 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -510,24 +510,6 @@ When CallCallbacks is invoked on the list, func will be called thusly:
 Now for the details.
 <blockquote><programlisting>
 
-	Bool CreateCallbackList(pcbl, cbfuncs)
-	    CallbackListPtr  *pcbl;
-	    CallbackFuncsPtr cbfuncs;
-
-</programlisting></blockquote>
-CreateCallbackList creates a callback list.  We envision that this
-function will be rarely used because the callback list is created
-automatically (if it doesn't already exist) when the first call to
-AddCallback is made on the list.  The only reason to explicitly create
-the callback list with this function is if you want to override the
-implementation of some of the other operations on the list by passing
-your own cbfuncs.  You also lose something by explicit creation: you
-introduce an order dependency during server startup because the list
-must be created before any modules subscribe to it.  Returns TRUE if
-successful.</para>
-<para>
-<blockquote><programlisting>
-
 	Bool AddCallback(pcbl, callback, subscriber_data)
 	    CallbackListPtr *pcbl;
 	    CallbackProcPtr callback;
commit f6c880b257a21a574cf1a47095cb39f32252802e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 00:27:46 2010 -0800

    Xserver-spec: Replace deprecated resource id lookup functions
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index dbf0883..1afae5d 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -442,18 +442,29 @@ and type; if skipFree is true, then the deleteFunc is not called.
 To look up a resource, use one of the following.
 <blockquote><programlisting>
 
-	pointer LookupIDByType(id, rtype)
-	    XID id;
-	    RESTYPE rtype;
-
-	pointer LookupIDByClass(id, classes)
-	    XID id;
-	    RESTYPE classes;
-
-</programlisting></blockquote>
-LookupIDByType finds a resource with the given id and exact type.
-LookupIDByClass finds a resource with the given id whose type is
-included in any one of the specified classes.</para>
+	int dixLookupResourceByType(
+	    pointer *result,
+	    XID id,
+	    RESTYPE rtype,
+	    ClientPtr client,
+	    Mask access_mode);
+
+	int dixLookupResourceByClass(
+	    pointer *result,
+	    XID id,
+	    RESTYPE rclass,
+	    ClientPtr client,
+	    Mask access_mode);
+
+</programlisting></blockquote>
+dixLookupResourceByType finds a resource with the given id and exact type.
+dixLookupResourceByClass finds a resource with the given id whose type is
+included in any one of the specified classes.
+The client and access_mode must be provided to allow security extensions to
+check if the client has the right privileges for the requested access.
+The bitmask values defined in the dixaccess.h header are or'ed together
+to define the requested access_mode.
+</para>
 </section>
 </section>
 <section>
commit 922806a5aa6eafc432d6787495b475aaa3f1790d
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Nov 27 00:14:51 2010 -0800

    Xserver-spec: Update Memory Management functions
    
    Xalloc, Xrealloc, & Xfree are deprecated now
    ALLOCATE_LOCAL is removed due to stack overflow issues
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index ae15346..dbf0883 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -1215,20 +1215,12 @@ library is contained in dix/dixfonts.c
   <title>Memory Management</title>
 <para>
 Memory management is based on functions in the C runtime library.
-Xalloc(), Xrealloc(), and Xfree() work just like malloc(), realloc(),
-and free(), except that you can pass a null pointer to Xrealloc() to
-have it allocate anew or pass a null pointer to Xfree() and nothing
-will happen.  The versions in the sample server also do some checking
-that is useful for debugging.  Consult a C runtime library reference
+Xalloc(), Xrealloc(), and Xfree() are deprecated aliases for malloc(),
+realloc(), and free(), and you should simply call the C library functions
+directly.  Consult a C runtime library reference
 manual for more details.
 </para>
 <para>
-The macros ALLOCATE_LOCAL and DEALLOCATE_LOCAL are provided in
-Xserver/include/os.h.  These are useful if your compiler supports
-alloca() (or some method of allocating memory from the stack); and are
-defined appropriately on systems which support it.
-</para>
-<para>
 Treat memory allocation carefully in your implementation.  Memory
 leaks can be very hard to find and are frustrating to a user.  An X
 server could be running for days or weeks without being reset, just


More information about the Xquartz-changes mailing list